[mpmath] r1221 committed - fix some py3 doctest failures

2 views
Skip to first unread message

mpm...@googlecode.com

unread,
Jan 28, 2011, 3:39:06 PM1/28/11
to mpmath-...@googlegroups.com
Revision: 1221
Author: fredrik.johansson
Date: Fri Jan 28 12:37:56 2011
Log: fix some py3 doctest failures
http://code.google.com/p/mpmath/source/detail?r=1221

Modified:
/trunk/mpmath/calculus/extrapolation.py
/trunk/mpmath/calculus/odes.py
/trunk/mpmath/calculus/polynomials.py
/trunk/mpmath/calculus/quadrature.py
/trunk/mpmath/ctx_mp.py
/trunk/mpmath/ctx_mp_python.py
/trunk/mpmath/function_docs.py
/trunk/mpmath/functions/zeta.py
/trunk/mpmath/functions/zetazeros.py

=======================================
--- /trunk/mpmath/calculus/extrapolation.py Sun Jan 9 09:47:36 2011
+++ /trunk/mpmath/calculus/extrapolation.py Fri Jan 28 12:37:56 2011
@@ -385,7 +385,7 @@
>>> sumem(lambda n: 1/n**2, [32, inf])
0.03174336652030209012658168043874142714132886413417
>>> I = mpf(1)/32
- >>> D = adiffs=((-1)**n*fac(n+1)*32**(-2-n) for n in xrange(999))
+ >>> D = adiffs=((-1)**n*fac(n+1)*32**(-2-n) for n in range(999))
>>> sumem(lambda n: 1/n**2, [32, inf], integral=I, adiffs=D)
0.03174336652030209012658168043874142714132886413417

@@ -393,7 +393,7 @@

>>> sumem(lambda n: n**5-12*n**2+3*n, [-100000, 200000])
10500155000624963999742499550000.0
- >>> print(sum(n**5-12*n**2+3*n for n in xrange(-100000, 200001)))
+ >>> print(sum(n**5-12*n**2+3*n for n in range(-100000, 200001)))
10500155000624963999742499550000

"""
@@ -1318,7 +1318,7 @@

(which converges notoriously slowly)::

- >>> f = lambda n: sum([mpf(1)/k for k in range(1,n+1)]) - log(n)
+ >>> f = lambda n: sum([mpf(1)/k for k in range(1,int(n)+1)]) -
log(n)
>>> limit(f, inf)
0.577215664901532860606512090082
>>> +euler
=======================================
--- /trunk/mpmath/calculus/odes.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/odes.py Fri Jan 28 12:37:56 2011
@@ -126,11 +126,11 @@
>>> mp.dps = 15; mp.pretty = True
>>> f = odefun(lambda x, y: y, 0, 1)
>>> for x in [0, 1, 2.5]:
- ... print f(x), exp(x)
+ ... print((f(x), exp(x)))
...
- 1.0 1.0
- 2.71828182845905 2.71828182845905
- 12.1824939607035 12.1824939607035
+ (1.0, 1.0)
+ (2.71828182845905, 2.71828182845905)
+ (12.1824939607035, 12.1824939607035)

The solution with high precision::

@@ -158,11 +158,11 @@

>>> f = odefun(lambda x, y: x*sin(y), 0, pi/2)
>>> for x in [2, 5, 10]:
- ... print f(x), 2*atan(exp(mpf(x)**2/2))
+ ... print((f(x), 2*atan(exp(mpf(x)**2/2))))
...
- 2.87255666284091 2.87255666284091
- 3.14158520028345 3.14158520028345
- 3.14159265358979 3.14159265358979
+ (2.87255666284091, 2.87255666284091)
+ (3.14158520028345, 3.14158520028345)
+ (3.14159265358979, 3.14159265358979)

If `F` is independent of `y`, an ODE can be solved using direct
integration. We can therefore obtain a reference solution with
@@ -198,7 +198,7 @@
>>> for x in [0, 1, 2.5, 10]:
... nprint(f(x), 15)
... nprint([cos(x), sin(x)], 15)
- ... print "---"
+ ... print("---")
...
[1.0, 0.0]
[1.0, 0.0]
=======================================
--- /trunk/mpmath/calculus/polynomials.py Sat Jan 8 15:52:03 2011
+++ /trunk/mpmath/calculus/polynomials.py Fri Jan 28 12:37:56 2011
@@ -69,7 +69,7 @@

>>> roots, err = polyroots([4,3,2], error=True)
>>> for r in roots:
- ... print r
+ ... print(r)
...
(-0.375 + 0.59947894041409j)
(-0.375 - 0.59947894041409j)
@@ -87,7 +87,7 @@

>>> mp.dps = 20
>>> for r in polyroots([1, 0, 0, 0, 0, -1]):
- ... print r
+ ... print(r)
...
1.0
(-0.8090169943749474241 + 0.58778525229247312917j)
=======================================
--- /trunk/mpmath/calculus/quadrature.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/calculus/quadrature.py Fri Jan 28 12:37:56 2011
@@ -615,9 +615,9 @@
Multiple integrals may be done over infinite ranges::

>>> mp.dps = 15
- >>> print quad(lambda x,y: exp(-x-y), [0, inf], [1, inf])
+ >>> print(quad(lambda x,y: exp(-x-y), [0, inf], [1, inf]))
0.367879441171442
- >>> print 1/e
+ >>> print(1/e)
0.367879441171442

For nonrectangular areas, one can call :func:`~mpmath.quad`
recursively.
=======================================
--- /trunk/mpmath/ctx_mp.py Sun Jan 9 09:47:36 2011
+++ /trunk/mpmath/ctx_mp.py Fri Jan 28 12:37:56 2011
@@ -924,7 +924,7 @@
Avoiding roundoff::

>>> x, y = 10**10+1, 10**15+1
- >>> print(x*y
+ >>> print(x*y)
10000000001000010000000001
>>> print(mpf(x) * mpf(y))
1.0000000001e+25
=======================================
--- /trunk/mpmath/ctx_mp_python.py Sat Jan 8 15:52:03 2011
+++ /trunk/mpmath/ctx_mp_python.py Fri Jan 28 12:37:56 2011
@@ -902,7 +902,7 @@
>>> B = [1, -1, 2]
>>> fdot(A, B)
mpf('6.5')
- >>> zip(A, B)
+ >>> list(zip(A, B))
[(2, 1), (1.5, -1), (3, 2)]
>>> fdot(_)
mpf('6.5')
=======================================
--- /trunk/mpmath/function_docs.py Sun Jan 9 09:47:36 2011
+++ /trunk/mpmath/function_docs.py Fri Jan 28 12:37:56 2011
@@ -1109,10 +1109,10 @@
To avoid rounding, use *prec=0*::

>>> mp.dps = 15
- >>> int(floor(10**30+1))
- 1000000000000000019884624838656L
- >>> int(floor(10**30+1, prec=0))
- 1000000000000000000000000000001L
+ >>> print(int(floor(10**30+1)))
+ 1000000000000000019884624838656
+ >>> print(int(floor(10**30+1, prec=0)))
+ 1000000000000000000000000000001

The floor function is defined for complex numbers and
acts on the real and imaginary parts separately::
=======================================
--- /trunk/mpmath/functions/zeta.py Sun Jan 9 09:47:36 2011
+++ /trunk/mpmath/functions/zeta.py Fri Jan 28 12:37:56 2011
@@ -42,8 +42,10 @@
@defun_wrapped
def siegeltheta(ctx, t, derivative=0):
d = int(derivative)
- if (t == ctx.inf or t == -ctx.inf):
+ if (t == ctx.inf or t == ctx.ninf):
if d < 2:
+ if t == ctx.ninf and d == 0:
+ return ctx.ninf
return ctx.inf
else:
return ctx.zero
=======================================
--- /trunk/mpmath/functions/zetazeros.py Sat Jan 8 14:15:29 2011
+++ /trunk/mpmath/functions/zetazeros.py Fri Jan 28 12:37:56 2011
@@ -540,7 +540,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> backlunds(217.3)
- 0.163022054311824
+ 0.16302205431184

Generally, the value is a small number. At Gram points it is an
integer,
frequently equal to 0::

Reply all
Reply to author
Forward
0 new messages