Issue 236 in mpmath: nsum convergence criteria

3 views
Skip to first unread message

mpm...@googlecode.com

unread,
Mar 21, 2013, 6:52:10 AM3/21/13
to mpmath...@googlegroups.com
Status: New
Owner: ----

New issue 236 by jbrezm...@gmail.com: nsum convergence criteria
http://code.google.com/p/mpmath/issues/detail?id=236

Hi,

I have tried to use nsum() for some cosine series, like: cos(nx)/(n^2)
however it doesn't work for x=pi*0.05. All methods produce wrong result
with fixed error.
The reason is wrong stopping criteria for direct summation method
(which is also used for all other methods). The direct method stops if
the last term after an update() is smaller then tolerance. In my case
in term for n=10 is cos(nx)=1e-17 and ever 20th term is nearly zero.
So if the method do not stop after the first 10 terms it will stop sooner
then desired.

extrapolation.py, function

adaptive_extrapolation
lines 507-509 in
https://github.com/sympy/sympy/blob/master/sympy/mpmath/calculus/extrapolation.py


# Check direct error
best = partial[-1]
error = abs(best - partial[-2])

The problem is that error is equal to absolute value of the last term only
which can be very close to zero.
Rather one should use something like:

error = abs(partial[-1] - partial[last_index])

where "last_index" is index before last update() call, similarly to the
error computed for extrapolation methods.

What version of the product are you using? On what operating system?

mpmath 0.17-1 on KUbuntu 12.04

Jan Brezina


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

mpm...@googlecode.com

unread,
Mar 21, 2013, 7:10:29 AM3/21/13
to mpmath...@googlegroups.com

Comment #1 on issue 236 by fredrik....@gmail.com: nsum convergence criteria
http://code.google.com/p/mpmath/issues/detail?id=236

Hi Jan, thanks for the bug report.

I'm not sure if the proposed fix is sufficient, and it would slow down
convergence of the direct method for well-behaved series.

I think there is a fairly easy workaround: explicitly add several terms at
a time, say three: instead of

nsum(f, [1,inf])

do

nsum(lambda n: f(3*n-2) + f(3*n-1) + f(3*n), [1,inf])

mpm...@googlecode.com

unread,
Mar 21, 2013, 9:34:37 AM3/21/13
to mpmath...@googlegroups.com

Comment #2 on issue 236 by jbrezm...@gmail.com: nsum convergence criteria
http://code.google.com/p/mpmath/issues/detail?id=236

Hi Fredrik,

Thank you for the workaround. However, there is still problem, that
tolerance has different meaning in direct method and in extrapolation
method. In the first case you measure only magnitude of terms in the
second case you measure difference between individual steps.

If you woldn't touch convergence speed of direct method what about
average over updated terms, this has straightforward counterpart in
extrapolation methods. The average has advantage that the meaning of
tolerance is "independent" of the value of steps.

Jan
Reply all
Reply to author
Forward
0 new messages