thegooglecodearchive / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

taylor returns wrong number of coefficients when method='quad' is used. #216

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Here's a ipython session that demonstrates the problem:

In [1]: import mpmath as mp

In [2]: mp.mp.dps = 20

In [3]: mp.taylor(mp.sin, 0, 2)
Out[3]: [mpf('0.0'), mpf('1.0'), mpf('0.0')]

In [4]: mp.taylor(mp.sin, 0, 2, method='quad')
Out[4]: [mpf('0.0'), mpf('1.0')]

In [5]: mp.taylor(mp.sin, 0, 3)
Out[5]: [mpf('0.0'), mpf('1.0'), mpf('0.0'), mpf('-0.16666666666666666666674')]

In [6]: mp.taylor(mp.sin, 0, 3, method='quad')
Out[6]: [mpf('0.0'), mpf('1.0'), mpf('0.0')]

In [7]: mp.__version__
Out[7]: '0.17'

What is the expected output? What do you see instead?

When the option method='quad' is used, the number of coefficients returned by 
taylor is one less than it should be.

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

Version 0.17, Mac OSX.

Original issue reported on code.google.com by warren.w...@enthought.com on 16 Nov 2011 at 5:26

GoogleCodeExporter commented 9 years ago
It turns out there is an off-by-one bug in diffs().  When the method is not 
'step', the 'while' statement should be 'while k < n + 1:' (rather than 'while 
k < n:').

Patch attached.

Original comment by warren.w...@enthought.com on 16 Nov 2011 at 6:37

Attachments:

GoogleCodeExporter commented 9 years ago
Patched in r1242. Thank you very much!

Original comment by fredrik....@gmail.com on 16 Nov 2011 at 9:33