Describing the Reimann Xi Function in Python (Scipy, Mpmath, etc)

207 Views Asked by At

I am attempting to describe the Riemann Xi function in python for visualization. It is an entire function, with no holes or poles. When converting the math to some simple python code, I notice that there is an infinity*zero cancellation, and obviously, Python cannot deal with that.

My current code is this, using the mpmath library:

def xi(s):
   return 1/2*s*(s-1)*cmath.pi**(-s/2)*mpmath.gamma(s/2)*mpmath.zeta(s)

Nothing special, but the point is that it doesn't work because of how infinity and zero are multiplied. Is there a good library or way of programming the Riemann Xi function?

Thank you.

1

There are 1 best solutions below

0
On

In essence, I had to use the reflection law of the Xi function, and then hard-code two outputs myself. This code was sort of quickly cobbled together, but it works just fine:

def xi(n):
    if n.real <= 1:
        s = 1-n
    else:
        s = n
    print(s)
    if s == complex(1, 0) or s == complex(0, 0):
        return 1/2
    else:
        return 1/2*s*(s-1)*cmath.pi**(-s/2)*mpmath.gamma(s/2)*mpmath.zeta(s)