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

### Source code changes of the file "mpmath/tests/test_levin.py" betweenmpmath-0.19.tar.gz and mpmath-1.0.0.tar.gz

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

test_levin.py  (mpmath-0.19):test_levin.py  (mpmath-1.0.0)
skipping to change at line 104 skipping to change at line 104
exact = mp.quad(lambda x: mp.exp( -x * x / 2 - z * x ** 4), [0,mp.inf]) * 2 / mp.sqrt(2 * mp.pi) exact = mp.quad(lambda x: mp.exp( -x * x / 2 - z * x ** 4), [0,mp.inf]) * 2 / mp.sqrt(2 * mp.pi)
# there is also a symbolic expression for the integral: # there is also a symbolic expression for the integral:
# exact = mp.exp(mp.one / (32 * z)) * mp.besselk(mp.one / 4, mp.one / (32 * z)) / (4 * mp.sqrt(z * mp.pi)) # exact = mp.exp(mp.one / (32 * z)) * mp.besselk(mp.one / 4, mp.one / (32 * z)) / (4 * mp.sqrt(z * mp.pi))
err = abs(v - exact) err = abs(v - exact)
assert err < eps assert err < eps
w = mp.nsum(lambda n: (-z)**n * mp.fac(4 * n) / (mp.fac(n) * mp.fac(2 * n) * (4 ** n)), [0, mp.inf], method = "levin", levin_variant = "t", workprec = 8*mp. prec, steps = [2] + [1 for x in xrange(1000)]) w = mp.nsum(lambda n: (-z)**n * mp.fac(4 * n) / (mp.fac(n) * mp.fac(2 * n) * (4 ** n)), [0, mp.inf], method = "levin", levin_variant = "t", workprec = 8*mp. prec, steps = [2] + [1 for x in xrange(1000)])
err = abs(v - w) err = abs(v - w)
assert err < eps assert err < eps
def test_levin_nsum(): def test_levin_nsum():
mp.dps = 17 mp.dps = 17
with mp.extraprec(mp.prec): with mp.extraprec(mp.prec):
z = mp.mpf(10) ** (-10) z = mp.mpf(10) ** (-10)
a = mp.nsum(lambda n: n**(-(1+z)), [1, mp.inf], method = "l") - 1 / z a = mp.nsum(lambda n: n**(-(1+z)), [1, mp.inf], method = "l") - 1 / z
assert abs(a - mp.euler) < 1e-10 assert abs(a - mp.euler) < 1e-10
eps = mp.exp(0.8 * mp.log(mp.eps)) eps = mp.exp(0.8 * mp.log(mp.eps))
a = mp.nsum(lambda n: (-1)**(n-1) / n, [1, mp.inf], method = "sidi") a = mp.nsum(lambda n: (-1)**(n-1) / n, [1, mp.inf], method = "sidi")
assert abs(a - mp.log(2)) < eps assert abs(a - mp.log(2)) < eps
z = 2 + 1j z = 2 + 1j
f = lambda n: mp.rf(2 / mp.mpf(3), n) * mp.rf(4 / mp.mpf(3), n) * z**n / f = lambda n: mp.rf(2 / mp.mpf(3), n) * mp.rf(4 / mp.mpf(3), n) * z**n / (mp
/ mp.mpf(3), n) * mp.fac(n)) .rf(1 / mp.mpf(3), n) * mp.fac(n))
v = mp.nsum(f, [0, mp.inf], method = "levin", steps = [10 for x in v = mp.nsum(f, [0, mp.inf], method = "levin", steps = [10 for x in xrange(10
00)])
exact = mp.hyp2f1(2 / mp.mpf(3), 4 / mp.mpf(3), 1 / mp.mpf(3), z) exact = mp.hyp2f1(2 / mp.mpf(3), 4 / mp.mpf(3), 1 / mp.mpf(3), z)
assert abs(exact - v) < eps assert abs(exact - v) < eps
def test_cohen_alt_0(): def test_cohen_alt_0():
mp.dps = 17 mp.dps = 17
AC = mp.cohen_alt() AC = mp.cohen_alt()
S, s, n = [], 0, 1 S, s, n = [], 0, 1
while 1: while 1:
s += -((-1) ** n) * mp.one / (n * n) s += -((-1) ** n) * mp.one / (n * n)
n += 1 n += 1
S.append(s) S.append(s)
v, e = AC.update_psum(S) v, e = AC.update_psum(S)
End of changes. 2 change blocks.
18 lines changed or deleted 18 lines changed or added