[mpmath] r1219 committed - fix most doctests failing in py3

0 views
Skip to first unread message

mpm...@googlecode.com

unread,
Jan 9, 2011, 12:48:51 PM1/9/11
to mpmath-...@googlegroups.com
Revision: 1219
Author: fredrik.johansson
Date: Sun Jan 9 09:47:36 2011
Log: fix most doctests failing in py3
http://code.google.com/p/mpmath/source/detail?r=1219

Modified:
/trunk/mpmath/__init__.py
/trunk/mpmath/calculus/differentiation.py
/trunk/mpmath/calculus/extrapolation.py
/trunk/mpmath/ctx_base.py
/trunk/mpmath/ctx_mp.py
/trunk/mpmath/function_docs.py
/trunk/mpmath/functions/zeta.py
/trunk/mpmath/identification.py
/trunk/mpmath/libmp/gammazeta.py
/trunk/mpmath/usertools.py

=======================================
--- /trunk/mpmath/__init__.py Sat Jan 8 15:12:58 2011
+++ /trunk/mpmath/__init__.py Sun Jan 9 09:47:36 2011
@@ -434,6 +434,7 @@
if not sum([pat in obj for pat in filter]):
continue
sys.stdout.write(str(obj) + " ")
+ sys.stdout.flush()
t1 = clock()
doctest.run_docstring_examples(globs[obj], {}, verbose=("-v" in
sys.argv))
t2 = clock()
=======================================
--- /trunk/mpmath/calculus/differentiation.py Sat Jan 8 15:52:03 2011
+++ /trunk/mpmath/calculus/differentiation.py Sun Jan 9 09:47:36 2011
@@ -1,6 +1,11 @@
from ..libmp.backend import xrange
from .calculus import defun

+try:
+ iteritems = dict.iteritems
+except AttributeError:
+ iteritems = dict.items
+

#----------------------------------------------------------------------------#
#
Differentiation #

#----------------------------------------------------------------------------#
@@ -242,7 +247,8 @@
>>> mp.dps = 15
>>> nprint(list(diffs(cos, 1, 5)))
[0.540302, -0.841471, -0.540302, 0.841471, 0.540302, -0.841471]
- >>> for i, d in zip(range(6), diffs(cos, 1)): print i, d
+ >>> for i, d in zip(range(6), diffs(cos, 1)):
+ ... print("%s %s" % (i, d))
...
0 0.54030230586814
1 -0.841470984807897
@@ -363,15 +369,15 @@
if not _cache:
_cache[0] = {(0,):1}
R = dpoly(n-1)
- R = dict((c+(0,),v) for (c,v) in R.iteritems())
+ R = dict((c+(0,),v) for (c,v) in iteritems(R))
Ra = {}
- for powers, count in R.iteritems():
+ for powers, count in iteritems(R):
powers1 = (powers[0]+1,) + powers[1:]
if powers1 in Ra:
Ra[powers1] += count
else:
Ra[powers1] = count
- for powers, count in R.iteritems():
+ for powers, count in iteritems(R):
if not sum(powers):
continue
for k,p in enumerate(powers):
@@ -434,7 +440,7 @@
i = 1
while 1:
s = ctx.mpf(0)
- for powers, c in dpoly(i).iteritems():
+ for powers, c in iteritems(dpoly(i)):
s += c*ctx.fprod(fn(k+1)**p for (k,p) in enumerate(powers) if
p)
yield s * f0
i += 1
=======================================
--- /trunk/mpmath/calculus/extrapolation.py Sat Jan 8 15:52:03 2011
+++ /trunk/mpmath/calculus/extrapolation.py Sun Jan 9 09:47:36 2011
@@ -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 xrange(-100000, 200001)))
10500155000624963999742499550000

"""
@@ -828,8 +828,8 @@
>>> for n in range(-8, 8):
... if n == 1:
... continue
- ... print mpf(n), mpf(1)/(1-n), nsum(lambda k: n**k, [0, inf],
- ... method='shanks')
+ ... print("%s %s %s" % (mpf(n), mpf(1)/(1-n),
+ ... nsum(lambda k: n**k, [0, inf], method='shanks')))
...
-8.0 0.111111111111111 0.111111111111111
-7.0 0.125 0.125
=======================================
--- /trunk/mpmath/ctx_base.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/ctx_base.py Sun Jan 9 09:47:36 2011
@@ -116,7 +116,7 @@

def nprint(ctx, x, n=6, **kwargs):
"""
- Equivalent to ``print nstr(x, n)``.
+ Equivalent to ``print(nstr(x, n))``.
"""
print(ctx.nstr(x, n, **kwargs))

@@ -432,7 +432,7 @@
>>> from mpmath import *
>>> mp.dps = 15
>>> f = maxcalls(sin, 10)
- >>> print sum(f(n) for n in range(10))
+ >>> print(sum(f(n) for n in range(10)))
1.95520948210738
>>> f(10)
Traceback (most recent call last):
=======================================
--- /trunk/mpmath/ctx_mp.py Sat Jan 8 15:52:03 2011
+++ /trunk/mpmath/ctx_mp.py Sun Jan 9 09:47:36 2011
@@ -738,19 +738,19 @@
Negating with and without roundoff::

>>> n = 200000000000000000000001
- >>> print int(-mpf(n))
+ >>> print(int(-mpf(n)))
-200000000000000016777216
- >>> print int(fneg(n))
+ >>> print(int(fneg(n)))
-200000000000000016777216
- >>> print int(fneg(n, prec=log(n,2)+1))
+ >>> print(int(fneg(n, prec=log(n,2)+1)))
-200000000000000000000001
- >>> print int(fneg(n, dps=log(n,10)+1))
+ >>> print(int(fneg(n, dps=log(n,10)+1)))
-200000000000000000000001
- >>> print int(fneg(n, prec=inf))
+ >>> print(int(fneg(n, prec=inf)))
-200000000000000000000001
- >>> print int(fneg(n, dps=inf))
+ >>> print(int(fneg(n, dps=inf)))
-200000000000000000000001
- >>> print int(fneg(n, exact=True))
+ >>> print(int(fneg(n, exact=True)))
-200000000000000000000001

"""
@@ -802,11 +802,11 @@
arithmetic with finite precision::

>>> x, y = mpf(2), mpf('1e-1000')
- >>> print x + y - x
+ >>> print(x + y - x)
0.0
- >>> print fadd(x, y, prec=inf) - x
+ >>> print(fadd(x, y, prec=inf) - x)
1.0e-1000
- >>> print fadd(x, y, exact=True) - x
+ >>> print(fadd(x, y, exact=True) - x)
1.0e-1000

Exact addition can be inefficient and may be impossible to perform
@@ -868,11 +868,11 @@
arithmetic with finite precision::

>>> x, y = mpf(2), mpf('1e1000')
- >>> print x - y + y
+ >>> print(x - y + y)
0.0
- >>> print fsub(x, y, prec=inf) + y
+ >>> print(fsub(x, y, prec=inf) + y)
2.0
- >>> print fsub(x, y, exact=True) + y
+ >>> print(fsub(x, y, exact=True) + y)
2.0

Exact addition can be inefficient and may be impossible to perform
@@ -924,17 +924,17 @@
Avoiding roundoff::

>>> x, y = 10**10+1, 10**15+1
- >>> print x*y
+ >>> print(x*y
10000000001000010000000001
- >>> print mpf(x) * mpf(y)
+ >>> print(mpf(x) * mpf(y))
1.0000000001e+25
- >>> print int(mpf(x) * mpf(y))
+ >>> print(int(mpf(x) * mpf(y)))
10000000001000011026399232
- >>> print int(fmul(x, y))
+ >>> print(int(fmul(x, y)))
10000000001000011026399232
- >>> print int(fmul(x, y, dps=25))
+ >>> print(int(fmul(x, y, dps=25)))
10000000001000010000000001
- >>> print int(fmul(x, y, exact=True))
+ >>> print(int(fmul(x, y, exact=True)))
10000000001000010000000001

Exact multiplication with complex numbers can be inefficient and
may
@@ -1045,23 +1045,29 @@

>>> from mpmath import *
>>> n, d = nint_distance(5)
- >>> print n, d
- 5 -inf
+ >>> print(n); print(d)
+ 5
+ -inf
>>> n, d = nint_distance(mpf(5))
- >>> print n, d
- 5 -inf
+ >>> print(n); print(d)
+ 5
+ -inf
>>> n, d = nint_distance(mpf(5.00000001))
- >>> print n, d
- 5 -26
+ >>> print(n); print(d)
+ 5
+ -26
>>> n, d = nint_distance(mpf(4.99999999))
- >>> print n, d
- 5 -26
+ >>> print(n); print(d)
+ 5
+ -26
>>> n, d = nint_distance(mpc(5,10))
- >>> print n, d
- 5 4
+ >>> print(n); print(d)
+ 5
+ 4
>>> n, d = nint_distance(mpc(5,0.000001))
- >>> print n, d
- 5 -19
+ >>> print(n); print(d)
+ 5
+ -19

"""
typx = type(x)
@@ -1167,11 +1173,11 @@
>>> mp.dps = 15
>>> a = fraction(1,100)
>>> b = mpf(1)/100
- >>> print a; print b
+ >>> print(a); print(b)
0.01
0.01
>>> mp.dps = 30
- >>> print a; print b # a will be accurate
+ >>> print(a); print(b) # a will be accurate
0.01
0.0100000000000000002081668171172
>>> mp.dps = 15
=======================================
--- /trunk/mpmath/function_docs.py Thu Nov 25 05:01:11 2010
+++ /trunk/mpmath/function_docs.py Sun Jan 9 09:47:36 2011
@@ -238,7 +238,7 @@
implementation of the following series::

>>> f = lambda n: (zeta(2*n)-1)/n*sum((-1)**(k+1)/mpf(k)
- ... for k in range(1,2*n))
+ ... for k in range(1,2*int(n)))
>>> exp(nsum(f, [1,inf])/log(2))
2.6854520010653064453097148354817956938203822939945
"""
@@ -810,7 +810,7 @@
`\cos^{-1}(\cos(x)) = x` only for `0 \le \Re[x] < \pi`::

>>> for x in [1, 10, -1, 2+3j, 10+3j]:
- ... print cos(acos(x)), acos(cos(x))
+ ... print("%s %s" % (cos(acos(x)), acos(cos(x))))
...
1.0 1.0
(10.0 + 0.0j) 2.566370614359172953850574
@@ -855,7 +855,7 @@
`\sin^{-1}(\sin(x)) = x` only for `-\pi/2 < \Re[x] < \pi/2`::

>>> for x in [1, 10, -1, 1+3j, -2+3j]:
- ... print chop(sin(asin(x))), asin(sin(x))
+ ... print("%s %s" % (chop(sin(asin(x))), asin(sin(x))))
...
1.0 1.0
10.0 -0.5752220392306202846120698
@@ -907,7 +907,7 @@

>>> mp.dps = 25
>>> for x in [1, 10, -1, 1+3j, -2+3j]:
- ... print tan(atan(x)), atan(tan(x))
+ ... print("%s %s" % (tan(atan(x)), atan(tan(x))))
...
1.0 1.0
10.0 0.5752220392306202846120698
@@ -1334,10 +1334,10 @@

>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
- >>> exp(1e-10)-1; print expm1(1e-10)
+ >>> exp(1e-10)-1; print(expm1(1e-10))
1.00000008274037e-10
1.00000000005e-10
- >>> exp(1e-20)-1; print expm1(1e-20)
+ >>> exp(1e-20)-1; print(expm1(1e-20))
0.0
1.0e-20
>>> 1/(exp(1e-20)-1)
@@ -1460,7 +1460,7 @@
All the 7th roots of a complex number::

>>> for r in [root(3+4j, 7, k) for k in range(7)]:
- ... print r, r**7
+ ... print("%s %s" % (r, r**7))
...
(1.24747270589553 + 0.166227124177353j) (3.0 + 4.0j)
(0.647824911301003 + 1.07895435170559j) (3.0 + 4.0j)
@@ -1472,7 +1472,7 @@

Cube roots of unity::

- >>> for k in range(3): print root(1, 3, k)
+ >>> for k in range(3): print(root(1, 3, k))
...
1.0
(-0.5 + 0.866025403784439j)
@@ -1543,7 +1543,7 @@
`r^0, r^1, \ldots, r^{n-1}` gives the whole set of unit roots (in
some permuted order)::

- >>> for r in unitroots(6): print r
+ >>> for r in unitroots(6): print(r)
...
1.0
(0.5 + 0.866025403784439j)
@@ -1552,7 +1552,7 @@
(-0.5 - 0.866025403784439j)
(0.5 - 0.866025403784439j)
>>> r = unitroots(6, primitive=True)[1]
- >>> for k in range(6): print chop(r**k)
+ >>> for k in range(6): print(chop(r**k))
...
1.0
(0.5 - 0.866025403784439j)
@@ -1722,19 +1722,36 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for i in range(10):
- ... print fibonacci(i),
+ ... print(fibonacci(i))
...
- 0.0 1.0 1.0 2.0 3.0 5.0 8.0 13.0 21.0 34.0
-
+ 0.0
+ 1.0
+ 1.0
+ 2.0
+ 3.0
+ 5.0
+ 8.0
+ 13.0
+ 21.0
+ 34.0
>>> fibonacci(50)
12586269025.0

The recurrence for `F(n)` extends backwards to negative `n`::

>>> for i in range(10):
- ... print fibonacci(-i),
+ ... print(fibonacci(-i))
...
- 0.0 1.0 -1.0 2.0 -3.0 5.0 -8.0 13.0 -21.0 34.0
+ 0.0
+ 1.0
+ -1.0
+ 2.0
+ -3.0
+ 5.0
+ -8.0
+ 13.0
+ -21.0
+ 34.0

Large Fibonacci numbers will be computed approximately unless
the precision is set high enough::
@@ -1812,7 +1829,7 @@
1.11803398874989
>>> phi - 0.5
1.11803398874989
- >>> f = lambda k:(-1)**(k+1) / sum(fib(n)**2 for n in range(1,k+1))
+ >>> f = lambda k:(-1)**(k+1) / sum(fib(n)**2 for n in
range(1,int(k+1)))
>>> nsum(f, [1, inf])
0.618033988749895
>>> phi-1
@@ -1907,7 +1924,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for k in range(6):
- ... print k, fac(k)
+ ... print("%s %s" % (k, fac(k)))
...
0 1.0
1 1.0
@@ -1964,7 +1981,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for k in range(1, 6):
- ... print k, gamma(k)
+ ... print("%s %s" % (k, gamma(k)))
...
1 1.0
2 1.0
@@ -2121,7 +2138,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for n in range(8):
- ... print n, harmonic(n)
+ ... print("%s %s" % (n, harmonic(n)))
...
0 0.0
1 1.0
@@ -2166,7 +2183,7 @@
>>> v
15092688622113788323693563264538101449859496.864101
>>> v = int(ceil(v))
- >>> print v
+ >>> print(v)
15092688622113788323693563264538101449859497
>>> harmonic(v-1)
99.999999999999999999999999999999999999999999942747
@@ -2189,7 +2206,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for n in range(15):
- ... print n, bernoulli(n)
+ ... print("%s %s" % (n, bernoulli(n)))
...
0 1.0
1 -0.5
@@ -6022,7 +6039,7 @@
>>> besselk(1,0)
+inf
>>> for n in range(-4, 5):
- ... print besselk(n, '1e-1000')
+ ... print(besselk(n, '1e-1000'))
...
4.8e+4001
8.0e+3000
@@ -6360,7 +6377,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for n in range(10):
- ... print n, superfac(n)
+ ... print("%s %s" % (n, superfac(n)))
...
0 1.0
1 1.0
@@ -6430,7 +6447,7 @@
>>> from mpmath import *
>>> mp.dps = 15; mp.pretty = True
>>> for n in range(10):
- ... print n, hyperfac(n)
+ ... print("%s %s" % (n, hyperfac(n)))
...
0 1.0
1 1.0
@@ -6760,7 +6777,8 @@
>>> siegelz(3+4j)
(-0.1852895764366314976003936 - 0.2773099198055652246992479j)

-The first four derivatives are supported:
+The first four derivatives are supported, using the
+optional *derivative* keyword argument::

>>> siegelz(1234567, derivative=3)
56.89689348495089294249178
@@ -6852,10 +6870,10 @@
>>> mp.dps = 15; mp.pretty = True
>>> primepi(50), riemannr(50)
(15, 14.9757023241462)
- >>> max(abs(primepi(n)-round(riemannr(n))) for n in range(100))
- 1.0
- >>> max(abs(primepi(n)-round(riemannr(n))) for n in range(300))
- 2.0
+ >>> max(abs(primepi(n)-int(round(riemannr(n)))) for n in range(100))
+ 1
+ >>> max(abs(primepi(n)-int(round(riemannr(n)))) for n in range(300))
+ 2

The Riemann R function can be evaluated for arguments far too large
for exact determination of `\pi(x)` to be computationally
@@ -6877,7 +6895,7 @@
... n += 1
... r, l = riemannr(10**n), li(10**n)
... rerr, lerr = nstr((r-p)/p,3), nstr((l-p)/p,3)
- ... print "%i %i %s(%s) %s(%s)" % (n, p, r, rerr, l, lerr)
+ ... print("%i %i %s(%s) %s(%s)" % (n, p, r, rerr, l, lerr))
...
1 4 4.56458314100509(0.141) 6.1655995047873(0.541)
2 25 25.6616332669242(0.0265) 30.1261415840796(0.205)
@@ -7426,7 +7444,7 @@
>>> mp.dps = 15; mp.pretty = True
>>> for n in range(9):
... p = chop(taylor(lambda x: cyclotomic(n,x), 0, 10))
- ... print n,; nprint(p[:10+1-p[::-1].index(1)])
+ ... print("%s %s" % (n, nstr(p[:10+1-p[::-1].index(1)])))
...
0 [1.0]
1 [-1.0, 1.0]
@@ -7460,13 +7478,13 @@

>>> p = taylor(lambda x: cyclotomic(6,x), 0, 6)[:3]
>>> for r in polyroots(p[::-1]):
- ... print r
+ ... print(r)
...
(0.5 - 0.8660254037844386467637232j)
(0.5 + 0.8660254037844386467637232j)
>>>
>>> for r in unitroots(6, primitive=True):
- ... print r
+ ... print(r)
...
(0.5 + 0.8660254037844386467637232j)
(0.5 - 0.8660254037844386467637232j)
@@ -8303,8 +8321,8 @@
... v *= (1+x/b)**(-q)
... v *= appellf1(r+1,-p,-q,2+r,-x/a,-x/b)
... return v
- ... print "Num. quad:", quad(f, [x1,x2])
- ... print "Appell F1:", F(x2)-F(x1)
+ ... print("Num. quad: %s" % quad(f, [x1,x2]))
+ ... print("Appell F1: %s" % (F(x2)-F(x1)))
...
>>> integral('1/5','4/3','-2','3','1/2',0,1)
Num. quad: 9.073335358785776206576981
@@ -8871,11 +8889,11 @@
(3230.72682687670422215339 + 14374.36950073615897616781j)
>>> zeta(0.5+100000000j, derivative=4)
(-11967.35573095046402130602 - 218945.7817789262839266148j)
- >>> print zeta(1+10000000j) # off the line
+ >>> zeta(1+10000000j) # off the line
(2.859846483332530337008882 + 0.491808047480981808903986j)
- >>> print zeta(1+10000000j, derivative=1)
+ >>> zeta(1+10000000j, derivative=1)
(-4.333835494679647915673205 - 0.08405337962602933636096103j)
- >>> print zeta(1+10000000j, derivative=4)
+ >>> zeta(1+10000000j, derivative=4)
(453.2764822702057701894278 - 581.963625832768189140995j)

For investigation of the zeta function zeros, the Riemann-Siegel
@@ -8914,7 +8932,7 @@

Generating a Taylor series at `s = 2` using derivatives::

- >>> for k in range(11): print zeta(2,1,k)/fac(k), "*", "(s-2)^%i" % k
+ >>> for k in range(11): print("%s * (s-2)^%i" % (zeta(2,1,k)/fac(k),
k))
...
1.644934066848226436472415 * (s-2)^0
-0.9375482543158437537025741 * (s-2)^1
@@ -9148,7 +9166,8 @@
>>> mp.dps = 10
>>> eta = 2; z = 5
>>> for l in [5, 4, 3, 2, 1, 0]:
- ... print l, coulombf(l,eta,z), diff(lambda z: coulombf(l,eta,z),
z)
+ ... print("%s %s %s" % (l, coulombf(l,eta,z),
+ ... diff(lambda z: coulombf(l,eta,z), z)))
...
5 0.09079533488 0.1042553261
4 0.2148205331 0.2029591779
@@ -9209,7 +9228,8 @@
>>> mp.dps = 10
>>> eta = 2; z = 5
>>> for l in [1, 2, 3, 4, 5]:
- ... print l, coulombg(l,eta,z), -diff(lambda z: coulombg(l,eta,z),
z)
+ ... print("%s %s %s" % (l, coulombg(l,eta,z),
+ ... -diff(lambda z: coulombg(l,eta,z), z)))
...
1 1.08148276 0.6028279961
2 1.496877075 0.5661803178
@@ -9524,9 +9544,9 @@

Pass ``exact=True`` to obtain exact values of Euler numbers as integers::

- >>> print eulernum(50, exact=True)
+ >>> print(eulernum(50, exact=True))
-6053285248188621896314383785111649088103498225146815121
- >>> print eulernum(200, exact=True) % 10**10
+ >>> print(eulernum(200, exact=True) % 10**10)
1925859625
>>> eulernum(1001, exact=True)
0
@@ -9684,10 +9704,10 @@
>>> Y1 = lambda t,p: fp.spherharm(l1,m1,t,p)
>>> Y2 = lambda t,p: fp.conj(fp.spherharm(l2,m2,t,p))
>>> l1 = l2 = 3; m1 = m2 = 2
- >>> print fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere)
+ >>> print(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere))
(1+0j)
>>> m2 = 1 # m1 != m2
- >>> fp.chop(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere))
+ >>> print(fp.chop(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p),
*sphere)))
0.0

Evaluation is accurate for large orders::
=======================================
--- /trunk/mpmath/functions/zeta.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/functions/zeta.py Sun Jan 9 09:47:36 2011
@@ -80,15 +80,15 @@


@defun_wrapped
-def siegelz(ctx, t, derivative=0):
- d = int(derivative)
+def siegelz(ctx, t, **kwargs):
+ d = int(kwargs.get("derivative", 0))
t = ctx.convert(t)
t1 = ctx._re(t)
t2 = ctx._im(t)
- prec=ctx.prec
+ prec = ctx.prec
try:
if abs(t1) > 500*prec and t2**2 < t1:
- v = ctx.rs_z(t, derivative)
+ v = ctx.rs_z(t, d)
if ctx._is_real_type(t):
return ctx._re(v)
return v
@@ -1125,7 +1125,7 @@
if ctx.re(a) < 1:
if ctx.isnpint(a):
raise ValueError("Lerch transcendent complex infinity")
- m = ctx.ceil(1-ctx.re(a))
+ m = int(ctx.ceil(1-ctx.re(a)))
v = ctx.zero
zpow = ctx.one
for n in xrange(m):
=======================================
--- /trunk/mpmath/identification.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/identification.py Sun Jan 9 09:47:36 2011
@@ -52,8 +52,9 @@
by at least one rational number with denominator less than `10^{12}`::

>>> p, q = pslq([-1, pi], maxcoeff=10**12)
- >>> print p, q
- 238410049439 75888275702
+ >>> print(p); print(q)
+ 238410049439
+ 75888275702
>>> mpf(p)/q
3.14159265358979

@@ -339,7 +340,7 @@
>>> nprint(polyval(findpoly(phi, 2), phi), 1)
-2.0e-16
>>> for r in polyroots(findpoly(phi, 2)):
- ... print r
+ ... print(r)
...
-0.618033988749895
1.61803398874989
@@ -654,7 +655,7 @@
the first few)::

>>> for p in identify(pi, ['e', 'catalan'], tol=1e-5, full=True):
- ... print p
+ ... print(p)
... # doctest: +ELLIPSIS
e/log((6 + (-4/3)*e))
(3**3*5*e*catalan**2)/(2*7**2)
=======================================
--- /trunk/mpmath/libmp/gammazeta.py Sat Jan 8 14:54:03 2011
+++ /trunk/mpmath/libmp/gammazeta.py Sun Jan 9 09:47:36 2011
@@ -498,7 +498,7 @@
>>> from mpmath import *
>>> for n in range(15):
... p, q = bernfrac(n)
- ... print n, "%s/%s" % (p, q)
+ ... print("%s %s/%s" % (n, p, q))
...
0 1/1
1 -1/2
@@ -519,14 +519,14 @@
This function works for arbitrarily large `n`::

>>> p, q = bernfrac(10**4)
- >>> print q
+ >>> print(q)
2338224387510
- >>> print len(str(p))
+ >>> print(len(str(p)))
27692
>>> mp.dps = 15
- >>> print mpf(p) / q
+ >>> print(mpf(p) / q)
-9.04942396360948e+27677
- >>> print bernoulli(10**4)
+ >>> print(bernoulli(10**4))
-9.04942396360948e+27677

.. note ::
=======================================
--- /trunk/mpmath/usertools.py Sat Jan 8 14:38:25 2011
+++ /trunk/mpmath/usertools.py Sun Jan 9 09:47:36 2011
@@ -30,10 +30,12 @@
mpf('3.1415926535897932')
>>> len(input) # Count number of evaluations
9
- >>> print input[3], output[3]
- ((mpf('3.1415076583334066'),), {}) 8.49952562843408e-5
- >>> print input[4], output[4]
- ((mpf('3.1415928201669122'),), {}) -1.66577118985331e-7
+ >>> print(input[3]); print(output[3])
+ ((mpf('3.1415076583334066'),), {})
+ 8.49952562843408e-5
+ >>> print(input[4]); print(output[4])
+ ((mpf('3.1415928201669122'),), {})
+ -1.66577118985331e-7

"""
if not input:

Reply all
Reply to author
Forward
0 new messages