Ask Your Question

lijr07's profile - activity

2024-03-27 07:34:22 +0100 asked a question Type of variable is changed after using factor() function

Type of variable is changed after using factor() function I defined a polynomial using polynomial ring. In my program, I

2024-03-27 07:30:48 +0100 marked best answer How to substitute variables in a rational function by numbers?

I have a program in which the first part needs to use a polynomial ring in a[1], ..., a[n]. In the last part of the program, I need to substitute a[i] in a rational function by some numbers. I define

Ra=PolynomialRing(QQ,'a',n0)
Fa=Ra.fraction_field()
a=Ra.gens()

For example, I have a rational function

r1=(a[1]^2+a[2])/(a[3]+2*a[4])

I tried the following:

a_random=[2,4,2,5]
for i in [1..4]:
    a[i]=a_random[i-1]

But it has an error:

'tuple' object does not support item assignment

How to solve this problem? Thank you very much.

2024-03-26 03:03:10 +0100 asked a question How to substitute variables in a rational function by numbers?

How to substitute variables in a rational function by numbers? I have a program in which the first part needs to use a p

2024-03-24 12:26:17 +0100 marked best answer How to read a file which has rational functions?

I have a large file which has rational functions and I would like to read it to Sagemath. The first two lines are

[[[4, -1]], (x7 + x20)/x19]
[[[4, -3], [4, -1]], (x8*x19 + x7*x21 + x20*x21)/(x19*x20)]

When I tried to read it, sagemath said that x_i's are not defined. Thank you very much!

2024-03-24 11:19:42 +0100 asked a question How to read a file which has rational functions?

How to read a file which has rational functions? I have a large file which has rational functions and I would like to re

2024-02-02 13:45:23 +0100 received badge  Famous Question (source)
2023-11-10 20:57:12 +0100 received badge  Notable Question (source)
2023-10-30 19:50:09 +0100 received badge  Popular Question (source)
2023-10-27 22:10:25 +0100 marked best answer find all m-tuples of lists whose union is a given list

I would like a fast way to solve the following problem: given a list (the list can have numbers appearing many times). For example,

L=[1, 2, 3, 4, 5, 14, 6, 8, 9, 10, 11, 12, 7, 9, 10, 11, 12, 13]

The length of the list is $mk$ for some $m,k$ (k is fixed in the beginning). I would like to find all m-tuples of lists such that all the numbers in each list are different and each list is ordered from small to large, and there is 0 or 1 gap in each list, and the union of the m-tuple of lists is the given list, and all the lists in one m-tuple has length k. For example, [1,2,3,4] does not have gap, and [1,2,5,6] has one gap, and [1,3,6,7] has two gaps. For example,

t1=[[1, 2, 3, 4, 5, 14], [6, 8, 9, 10, 11, 12], [7, 9, 10, 11, 12, 13]]

is a 3-tuple which satisfies all the conditions and whose union is L. Here k=6, m=3.

In the case of L=[1,2,3,4,5,6] and k=3. The result should be (each line is a 2-tuple):

((1, 2, 3), (4, 5, 6)),
((1, 2, 4), (3, 5, 6)),
((1, 2, 5), (3, 4, 6)),
((1, 2, 6), (3, 4, 5)),
((1, 3, 4), (2, 5, 6)),
((1, 4, 5), (2, 3, 6)),
((1, 5, 6), (2, 3, 4))

I wrote the following to try to find all m-tuples which satisfies the condition of all numbers in each list are different. But it is not very fast. Is there some fast way to solve the problem? Thank you very much.

import itertools
import random
from collections import Counter

def SetDifferenceListDifference(a, b):
    diff = Counter(a) - Counter(b)
    return list(diff.elements())

def removeDuplicatesListOfLists(l): # very fast
    l.sort()
    r=list(l for l,_ in itertools.groupby(l))

    return r 

def number_of_gaps_in_list(L):
    r=0
    l=sorted(L)
    for i in range(len(l)-1):
        if abs(l[i+1]-l[i])>1:
            r=r+1
    return r


L=[1,2,3,4,5,6]
k=3 
c1=[]
sn=0
m=len(L)/k
while sn<3000:
    l=L
    temp=len(c1)
    c2=[]
    while l!=[]:
        t1=removeDuplicatesListOfLists(l)
        #print(t1)
        if len(t1)<k:
            break
        t2=sorted(random.sample(t1, k))
        #print(t2)
        c2.append(t2)
        l=SetDifferenceListDifference(l,t2)
    if len(c2)==m:
        c1.append(sorted(c2))
    c1=removeDuplicatesListOfLists(c1)
    #print(len(c1))
    if len(c1)==temp:
        sn=sn+1 

len(c1)

c2=[]
for i in c1:
    sn=1
    for j in i:
        if number_of_gaps_in_list(j)>1:
            sn=0
            break
    if sn==1:
        c2.append(i)
len(c2)
2023-09-27 11:56:30 +0100 received badge  Notable Question (source)
2023-09-13 07:10:59 +0100 received badge  Popular Question (source)
2023-08-28 21:57:07 +0100 commented answer find all m-tuples of lists whose union is a given list

@Max, thank you very much!

2023-08-28 09:54:03 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-28 09:46:57 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-28 09:29:48 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-28 09:28:59 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-28 09:27:21 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-28 09:21:41 +0100 commented answer find all m-tuples of lists whose union is a given list

@Max, there many ways to cut a given list of length $mk$ into $m$ pieces. I would like to find a fast way to find all po

2023-08-27 21:28:57 +0100 commented answer find all m-tuples of lists whose union is a given list

@Max, thank you very much for your answer! I am sorry I forgot to say that the lists in each m-tuple has the same length

2023-08-27 19:12:51 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-27 19:11:37 +0100 edited question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-27 18:36:11 +0100 asked a question find all m-tuples of lists whose union is a given list

find all m-tuples of lists whose union is a given list I would like a fast way to solve the following problem: given a l

2023-08-16 16:01:53 +0100 received badge  Popular Question (source)
2023-08-16 16:01:53 +0100 received badge  Notable Question (source)
2023-08-10 14:36:47 +0100 received badge  Notable Question (source)
2023-08-10 14:36:47 +0100 received badge  Popular Question (source)
2023-07-29 23:47:40 +0100 received badge  Nice Question (source)
2023-07-28 11:27:46 +0100 asked a question How to find the number of parameters in the result of solve function?

How to find the number of parameters in the result of solve function? I would like to find a way to obtain the number of

2023-07-15 14:15:32 +0100 received badge  Famous Question (source)
2023-06-06 14:53:21 +0100 marked best answer errors when read a file with symbols

I am trying to read a file with contents like:

[4/t^4, [[-3, 3, -3], [-1, 1, -3], [1, 1, -1]]]

I use the following codes:

fp1='/Users/jianrongli/Dropbox/Georgios/data/decomposition_of_Lm_tensor_Lm.txt'
with open(fp1, 'r') as fp:
    L = [sage_eval(line) for line in fp.readlines() if line.strip()]

But it has errors:

NameError: name 't' is not defined

Is there some way to fix this? Thank you very much.

2023-06-02 11:11:00 +0100 asked a question errors when read a file with symbols

errors when read a file with symbols I am trying to read a file with contents like: [4/t^4, [[-3, 3, -3], [-1, 1, -3],

2023-05-27 19:45:23 +0100 received badge  Notable Question (source)
2023-05-24 06:48:14 +0100 received badge  Popular Question (source)
2023-05-19 21:56:00 +0100 received badge  Popular Question (source)
2023-05-11 14:08:40 +0100 received badge  Notable Question (source)
2023-05-05 11:17:29 +0100 marked best answer complex number in Sagemath

I wrote some codes for a computation which involves complex numbers. There is an error when I run

RZagier(2, -N(y[1,3]^(-1)))

The error is: 'numpy.float64' object is not callable

Do you know how to fix it? Thank you very much.

The codes are

import numpy as np
import sympy as sp 
from numpy import matrix  
import random
from numpy import array 
import scipy  

from scipy.special import bernoulli, zeta 


def PluckerToMinors(A,l):
    r=l[0]
    #print('l[1]',l[1])
    for i in l[1]:
        #print(i,r)
        r=r*Minor(A, ListAToN(1, len(i)), i) 
        r=r.expand().factor()
    return r

def Minor(M, rows, cols):
    #r=np.linalg.det(subMatrix(M,rows, cols))
    #r=det(subMatrix(M,rows, cols))
    r=det(sub_matrix_general(M,rows, cols))
    #r=detSelfDefined(subMatrix(M,rows, cols))
    return r


def sub_matrix_general(M, c1, c2):
    m,n=len(c1),len(c2)
    r=Matrix(SR, m, n)
    for i in range(m):
        for j in range(n):
            r[i,j]=M[c1[i]-1, c2[j]-1]
    return r


def ListAToN(a,n):
    r=list(range(a,n+1))
    return r


def RZagier(n,z): # polylogarithm, Clean Single-Valued Polylogarithms paper
    w=0
    for k in [0..n-1]:
        t1=2^k*bernoulli(k)[k]/factorial(k)*polylog( n-k , z )*log(abs(z))^k
        w=w+t1
    if n%2==0:
        r=w.imag()
    else:
        r=w.real()
    r=N(r)
    return r 

L=[[[[1, 3]], [[[1, 4]], [[2, 3]]], [[[2, 4]], [[1, 3]]]],
 [[[2, 4]], [[[2, 5]], [[3, 4]]], [[[3, 5]], [[2, 4]]]],
 [[[3, 5]], [[[1, 3]], [[4, 5]]], [[[1, 4]], [[3, 5]]]],
 [[[1, 4]], [[[1, 5]], [[2, 4]]], [[[2, 5]], [[1, 4]]]],
 [[[2, 5]], [[[1, 2]], [[3, 5]]], [[[2, 5]], [[1, 3]]]]]

k,n=2,5
t0=random.randint(2, 5)
t1= random.randint(3, 9)
x1=complex(t0,t1)
t0=random.randint(2, 5)
t1= random.randint(3, 9)
x2=complex(t0,t1)
r2=Matrix([[1,0,-1,-x1-1,-x1*x2-x1-1],[0,1,1,1,1]])

u=np.zeros((n+1,n+1), dtype=complex)
y=np.zeros((n+1,n+1), dtype=complex)
for i in range(n+1):
    for j in range(n+1):
        u[i,j]=0
        y[i,j]=0
for i in L:
    t1=1
    #print(i[0])
    for j in i[1]:
        #print(j)
        t1=t1*PluckerToMinors(r2, [1, j])
    t2=1
    for j in i[2]:
        t2=t2*PluckerToMinors(r2, [1, j])
    u[i[0][0][0],i[0][0][1]]=t1/t2
    y[i[0][0][0],i[0][0][1]]=u[i[0][0][0],i[0][0][1]]/(1-u[i[0][0][0],i[0][0][1]])
    #print(t1/t2)
2023-05-04 11:10:20 +0100 edited question complex number in Sagemath

complex number in Sagemath I wrote some codes for a computation which involves complex numbers. There is an error when I

2023-05-03 21:53:15 +0100 asked a question complex number in Sagemath

complex number in Sagemath I wrote some codes for a computation which involves complex numbers. There is an error when I

2023-05-03 20:38:33 +0100 marked best answer How to write an involution in Weyl group as a product of $2$-cycles?

Is there some method in Sage to decompose an involution in Weyl group as a product of $2$-cycles (transpositions)?

For example, I define

W=WeylGroup(['A', 3], prefix='s')
t1=[1,2,3,1,2,1]
t2=W.from_reduced_word(t1)

How to write t2 as a product of $2$-cycles? The result should be $(1,4)(2,3)$. Thank you very much.

2023-04-30 16:43:28 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much. It is a permutation on the set ${1,2,3,4}$. $s_i$ interchange $i,i+1$. So under t2, 1,2,3,4 i

2023-04-30 16:42:53 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much. It is a permutation on the set ${1,2,3,4}$. $s_i$ interchange $i,i+1$. So under t2, 1,2,3,4 i

2023-04-30 16:42:31 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much. It is a permutation on the set ${1,2,3,4}$. $s_i$ interchange $i,i+1$. So under t2, 1,2,3,4 i

2023-04-29 12:09:19 +0100 received badge  Popular Question (source)
2023-04-29 12:09:19 +0100 received badge  Notable Question (source)
2023-04-28 15:55:22 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much. I tried simple_roots() but it has errors. The t2 is the product of simple reflections $s_1s_2

2023-04-27 22:24:38 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much! But the result I got is [(1, 12), (2, 11), (3, 10), (4, 9), (5, 8), (6, 7)] not (1,4)(2,3).

2023-04-27 22:24:26 +0100 commented question How to write an involution in Weyl group as a product of $2$-cycles?

@Max, thank you very much! But the result I got is [(1, 12), (2, 11), (3, 10), (4, 9), (5, 8), (6, 7)] not (1,4)(2,3).

2023-04-27 22:22:45 +0100 edited question How to write an involution in Weyl group as a product of $2$-cycles?

How to write an involution in Weyl group as a product of $2$-cycles? Is there some method in Sage to decompose an involu

2023-04-24 22:18:18 +0100 received badge  Popular Question (source)
2023-04-22 19:16:11 +0100 edited question How to write an involution in Weyl group as a product of $2$-cycles?

How to write an involution in Weyl group as a product of $2$-cycles? Is there some method in Sage to decompose an involu