I am not even sure if that is the best wording for what I'm trying to achieve, but I am trying to evaluate a power series in Python, and as I'd imagined, both because I'm new to Python and because power series evaluations are tricky when using floating-point numbers, my calculation is crashing.
My power series is an approximation for the simple prime-power counting function, J(x). In Mathematica I can evaluate this power series (I've done it up to prime 151, it's very time-consuming), but even in Mathematica, if I use floating-point in the formulas (instead of symbolic and then convert to decimal), the result is wrong. My plan is to create an executable that I can leave running on my job's remote desktop on Unix or Windows.
This is the code I created in Python (using scipy):
x = 12
M = 9 * x
soma = 0
for i in range(1, M+1):
termo1 = (-1)**i * x * (2*pi*x)**(2*i) / (2*i+1)
for j in range(1, i+1):
termo2 = (-1)**j * log(zeta(2*j))/((2*pi)**(2*j) * factorial(2*i+1-2*j))
soma = soma + termo1 * termo2
soma = -4 * soma
When we're new to something, the stress to figure out how to do even simple things can be tough (I'm a newbie so just saying use Decimal is greek to me). This is the error that I'm getting:
File "D:/iTunes/Python/PyCharm/Zeta.py", line 31, in <module>
termo1 = (-1)**i * x * (2*pi*x)**(2*i) / (2*i+1)
OverflowError: (34, 'Result too large')
How do I fix this? Or even better, is there a package that assumes that I need great precision in all the functions (zeta, log, factorial, etc.) and that spares me the trouble of having to figure things out myself?