Increase working precision in polylog_general() for negative s#898
Conversation
Tries to address error in polylog precision when abs(z) > 1 and s is close to an integer
|
I still have to fix the issues rising from these tests, please do not check. Thanks |
|
I'm afraid, but you need more arguments than "empirical testing".
At least you could add tests from the issue. |
|
Probably the precision in polylog should be increased by Edit: specifically, this is required in To make polylog even more reliable (but potentially much slower), |
|
Tomorrow I'll work on it. Thanks for the suggestion |
|
Hello @fredrik-johansson, I tried this approach but it doesn't seem to work: return ctx.gamma(1-s)*(-u)**(s-1) + v + max(0, -(round(s)-s)) I think I am missing something because, of course, the output does not differ of that value. Can you help me? Thank you |
|
@ricor07, I guess you changed last line of the polylog_general(). Could you explain what means your code? Increasing precision seems to be working for me: diff --git a/mpmath/functions/zeta.py b/mpmath/functions/zeta.py
index 3e3b542..8944666 100644
--- a/mpmath/functions/zeta.py
+++ b/mpmath/functions/zeta.py
@@ -456,6 +456,8 @@ def polylog_general(ctx, s, z):
return ctx.gamma(v)*(j**v*ctx.zeta(v,0.5+y) + j**-v*ctx.zeta(v,0.5-y))/(2*ctx.pi)**v
t = 1
k = 0
+ prec = ctx.prec
+ ctx.prec += max(0, -ctx.nint_distance(s)[1])
while 1:
term = ctx.zeta(s-k) * t
if not abs(term) >= ctx.eps:
@@ -464,7 +466,9 @@ def polylog_general(ctx, s, z):
k += 1
t *= u
t /= k
- return ctx.gamma(1-s)*(-u)**(s-1) + v
+ r = ctx.gamma(1-s)*(-u)**(s-1) + v
+ ctx.prec = prec
+ return r
@defun_wrapped
def polylog(ctx, s, z):On OP example: >>> import mpmath as mp
... def check(s, z):
... pl1 = mp.polylog(s, z)
... print(pl1.real)
... with mp.workdps(32):
... pl2 = mp.polylog(s, z)
... print(pl2.real)
...
>>> check(1+1e-15, -2) # that one was bad
-1.09861228866811
-1.0986122886681101262592914356806
>>> check(1, -2 + 1e-8j)
-1.09861228866811
-1.0986122886681096969508007924781
>>> check(1+1e-15, -0.5 + 1e-8j)
-0.405465108108164
-0.40546510810816446598993214576279 |
|
Hello, thanks to your suggestion i could fix the issue. I added a control for inf and nan values because your implementation couldn't fit test_issue_505 in test_function2. The tests fit. Let me know what you think |
skirpichev
left a comment
There was a problem hiding this comment.
You also should add tests.
|
Thanks. |
Closes #634