Ask Your Question
0

complex number in Sagemath

asked 2023-05-03 21:53:15 +0200

lijr07 gravatar image

updated 2023-05-04 11:10:20 +0200

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)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-04 15:03:05 +0200

Max Alekseyev gravatar image

The error is caused by executing r=w.imag() where it happens that w is not of complex type but a floating point number. To make it work in all cases, you may like to add conversion of w into a complex type before extracting its imaginary part:

r=CC(w).imag()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-05-03 21:53:15 +0200

Seen: 144 times

Last updated: May 04 '23