## "Fossies" - the Fresh Open Source Software Archive

### Source code changes of the file "mpmath/function_docs.py" betweenmpmath-1.0.0.tar.gz and mpmath-1.1.0.tar.gz

About: mpmath is a Python library for arbitrary-precision floating-point arithmetic.

function_docs.py  (mpmath-1.0.0):function_docs.py  (mpmath-1.1.0)
skipping to change at line 17 skipping to change at line 17
circle, the half-period of trigonometric functions, and many other circle, the half-period of trigonometric functions, and many other
things in mathematics. things in mathematics.
Mpmath can evaluate \pi to arbitrary precision:: Mpmath can evaluate \pi to arbitrary precision::
>>> from mpmath import * >>> from mpmath import *
>>> mp.dps = 50; mp.pretty = True >>> mp.dps = 50; mp.pretty = True
>>> +pi >>> +pi
3.1415926535897932384626433832795028841971693993751 3.1415926535897932384626433832795028841971693993751
This shows digits 99991-100000 of This shows digits 99991-100000 of \pi (the last digit is actually
a 4 when the decimal expansion is truncated, but here the nearest
rounding is used)::
>>> mp.dps = 100000 >>> mp.dps = 100000
>>> str(pi)[-10:] >>> str(pi)[-10:]
'554936246' '5549362465'
**Possible issues** **Possible issues**
:data:pi always rounds to the nearest floating-point :data:pi always rounds to the nearest floating-point
number when used. This means that exact mathematical identities number when used. This means that exact mathematical identities
involving \pi will generally not be preserved in floating-point involving \pi will generally not be preserved in floating-point
arithmetic. In particular, multiples of :data:pi (except for arithmetic. In particular, multiples of :data:pi (except for
the trivial case 0*pi) are *not* the exact roots of the trivial case 0*pi) are *not* the exact roots of
:func:~mpmath.sin, but differ roughly by the current epsilon:: :func:~mpmath.sin, but differ roughly by the current epsilon::
skipping to change at line 76 skipping to change at line 78
natural logarithm (:func:~mpmath.ln) and of the exponential function natural logarithm (:func:~mpmath.ln) and of the exponential function
(:func:~mpmath.exp). (:func:~mpmath.exp).
Mpmath can be evaluate e to arbitrary precision:: Mpmath can be evaluate e to arbitrary precision::
>>> from mpmath import * >>> from mpmath import *
>>> mp.dps = 50; mp.pretty = True >>> mp.dps = 50; mp.pretty = True
>>> +e >>> +e
2.7182818284590452353602874713526624977572470937 2.7182818284590452353602874713526624977572470937
This shows digits 99991-100000 of This shows digits 99991-100000 of e (the last digit is actually
a 5 when the decimal expansion is truncated, but here the nearest
rounding is used)::
>>> mp.dps = 100000 >>> mp.dps = 100000
>>> str(e)[-10:] >>> str(e)[-10:]
'210042716' '2100427166'
**Possible issues** **Possible issues**
:data:e always rounds to the nearest floating-point number :data:e always rounds to the nearest floating-point number
when used, and mathematical identities involving e may not when used, and mathematical identities involving e may not
hold in floating-point arithmetic. For example, ln(e) hold in floating-point arithmetic. For example, ln(e)
might not evaluate exactly to 1. might not evaluate exactly to 1.
In particular, don't use e**x to compute the exponential In particular, don't use e**x to compute the exponential
function. Use exp(x) instead; this is both faster and more function. Use exp(x) instead; this is both faster and more
skipping to change at line 139 skipping to change at line 143
>>> mp.dps = 50; mp.pretty = True >>> mp.dps = 50; mp.pretty = True
>>> +euler >>> +euler
0.57721566490153286060651209008240243104215933593992 0.57721566490153286060651209008240243104215933593992
We can also compute \gamma directly from the definition, We can also compute \gamma directly from the definition,
although this is less efficient:: although this is less efficient::
>>> limit(lambda n: harmonic(n)-log(n), inf) >>> limit(lambda n: harmonic(n)-log(n), inf)
0.57721566490153286060651209008240243104215933593992 0.57721566490153286060651209008240243104215933593992
This shows digits 9991-10000 of This shows digits 9991-10000 of \gamma (the last digit is actually
a 5 when the decimal expansion is truncated, but here the nearest
rounding is used)::
>>> mp.dps = 10000 >>> mp.dps = 10000
>>> str(euler)[-10:] >>> str(euler)[-10:]
'467985816' '4679858166'
Integrals, series, and representations for \gamma in terms of Integrals, series, and representations for \gamma in terms of
special functions include the following (there are many others):: special functions include the following (there are many others)::
>>> mp.dps = 25 >>> mp.dps = 25
>>> -quad(lambda x: exp(-x)*log(x), [0,inf]) >>> -quad(lambda x: exp(-x)*log(x), [0,inf])
0.5772156649015328606065121 0.5772156649015328606065121
>>> quad(lambda x,y: (x-1)/(1-x*y)/log(x*y), [0,1], [0,1]) >>> quad(lambda x,y: (x-1)/(1-x*y)/log(x*y), [0,1], [0,1])
0.5772156649015328606065121 0.5772156649015328606065121
>>> nsum(lambda k: 1/k-log(1+1/k), [1,inf]) >>> nsum(lambda k: 1/k-log(1+1/k), [1,inf])
skipping to change at line 193 skipping to change at line 199
>>> mp.dps = 50; mp.pretty = True >>> mp.dps = 50; mp.pretty = True
>>> +catalan >>> +catalan
0.91596559417721901505460351493238411077414937428167 0.91596559417721901505460351493238411077414937428167
One can also compute K directly from the definition, although One can also compute K directly from the definition, although
this is significantly less efficient:: this is significantly less efficient::
>>> nsum(lambda k: (-1)**k/(2*k+1)**2, [0, inf]) >>> nsum(lambda k: (-1)**k/(2*k+1)**2, [0, inf])
0.91596559417721901505460351493238411077414937428167 0.91596559417721901505460351493238411077414937428167
This shows digits 9991-10000 of This shows digits 9991-10000 of K (the last digit is actually
a 3 when the decimal expansion is truncated, but here the nearest
rounding is used)::
>>> mp.dps = 10000 >>> mp.dps = 10000
>>> str(catalan)[-10:] >>> str(catalan)[-10:]
'953787150' '9537871504'
Catalan's constant has numerous integral representations:: Catalan's constant has numerous integral representations::
>>> mp.dps = 50 >>> mp.dps = 50
>>> quad(lambda x: -log(x)/(1+x**2), [0, 1]) >>> quad(lambda x: -log(x)/(1+x**2), [0, 1])
0.91596559417721901505460351493238411077414937428167 0.91596559417721901505460351493238411077414937428167
>>> quad(lambda x: atan(x)/x, [0, 1]) >>> quad(lambda x: atan(x)/x, [0, 1])
0.91596559417721901505460351493238411077414937428167 0.91596559417721901505460351493238411077414937428167
>>> quad(lambda x: ellipk(x**2)/2, [0, 1]) >>> quad(lambda x: ellipk(x**2)/2, [0, 1])
0.91596559417721901505460351493238411077414937428167 0.91596559417721901505460351493238411077414937428167
skipping to change at line 409 skipping to change at line 417
>>> sqrt(1+1j) >>> sqrt(1+1j)
(1.09868411346781 + 0.455089860562227j) (1.09868411346781 + 0.455089860562227j)
>>> sqrt(inf) >>> sqrt(inf)
+inf +inf
Square root evaluation is fast at huge precision:: Square root evaluation is fast at huge precision::
>>> mp.dps = 50000 >>> mp.dps = 50000
>>> a = sqrt(3) >>> a = sqrt(3)
>>> str(a)[-10:] >>> str(a)[-10:]
'932933281' '9329332815'
:func:mpmath.iv.sqrt supports interval arguments:: :func:mpmath.iv.sqrt supports interval arguments::
>>> iv.dps = 15; iv.pretty = True >>> iv.dps = 15; iv.pretty = True
>>> iv.sqrt([16,100]) >>> iv.sqrt([16,100])
[4.0, 10.0] [4.0, 10.0]
>>> iv.sqrt(2) >>> iv.sqrt(2)
[1.4142135623730949234, 1.4142135623730951455] [1.4142135623730949234, 1.4142135623730951455]
>>> iv.sqrt(2) ** 2 >>> iv.sqrt(2) ** 2
[1.9999999999999995559, 2.0000000000000004441] [1.9999999999999995559, 2.0000000000000004441]
skipping to change at line 1356 skipping to change at line 1364
Evaluation works for extremely tiny values:: Evaluation works for extremely tiny values::
>>> expm1(0) >>> expm1(0)
0.0 0.0
>>> expm1('1e-10000000') >>> expm1('1e-10000000')
1.0e-10000000 1.0e-10000000
""" """
log1p = r"""
Computes \log(1+x), accurately for small x.
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> log(1+1e-10); print(mp.log1p(1e-10))
1.00000008269037e-10
9.9999999995e-11
>>> mp.log1p(1e-100j)
(5.0e-201 + 1.0e-100j)
>>> mp.log1p(0)
0.0
"""
powm1 = r""" powm1 = r"""
Computes x^y - 1, accurately when x^y is very close to 1. Computes x^y - 1, accurately when x^y is very close to 1.
This avoids potentially catastrophic cancellation:: This avoids potentially catastrophic cancellation::
>>> from mpmath import * >>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True >>> mp.dps = 15; mp.pretty = True
>>> power(0.99999995, 1e-10) - 1 >>> power(0.99999995, 1e-10) - 1
0.0 0.0
>>> powm1(0.99999995, 1e-10) >>> powm1(0.99999995, 1e-10)
skipping to change at line 7248 skipping to change at line 7271
(-0.909670702980385, -0.909670702980385) (-0.909670702980385, -0.909670702980385)
Evaluation for arbitrary, nonintegral s is supported Evaluation for arbitrary, nonintegral s is supported
for z within the unit circle: for z within the unit circle:
>>> polylog(3+4j, 0.25) >>> polylog(3+4j, 0.25)
(0.24258605789446 - 0.00222938275488344j) (0.24258605789446 - 0.00222938275488344j)
>>> nsum(lambda k: 0.25**k / k**(3+4j), [1,inf]) >>> nsum(lambda k: 0.25**k / k**(3+4j), [1,inf])
(0.24258605789446 - 0.00222938275488344j) (0.24258605789446 - 0.00222938275488344j)
It is also supported outside of the unit It is also supported outside of the unit circle::
>>> polylog(1+j, 20+40j) >>> polylog(1+j, 20+40j)
(-7.1421172179728 - 3.92726697721369j) (-7.1421172179728 - 3.92726697721369j)
>>> polylog(1+j, 200+400j) >>> polylog(1+j, 200+400j)
(-5.41934747194626 - 9.94037752563927j)
**References** **References**
1. Richard Crandall, "Note on fast polylogarithm computation" 1. Richard Crandall, "Note on fast polylogarithm computation"
http://people.reed.edu/~crandall/papers/Polylog.pdf http://people.reed.edu/~crandall/papers/Polylog.pdf
2. http://en.wikipedia.org/wiki/Polylogarithm 2. http://en.wikipedia.org/wiki/Polylogarithm
3. http://mathworld.wolfram.com/Polylogarithm.html 3. http://mathworld.wolfram.com/Polylogarithm.html
""" """
End of changes. 12 change blocks.
14 lines changed or deleted 34 lines changed or added