"Fossies" - the Fresh Open Source Software Archive

Source code changes of the file "mpmath/functions/bessel.py" betweenmpmath-0.18.tar.gz and mpmath-0.19.tar.gz

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

bessel.py  (mpmath-0.18):bessel.py  (mpmath-0.19)
skipping to change at line 619 skipping to change at line 619
T1 = [C1],[1],[],[],[],[ctx.mpq_2_3],w T1 = [C1],[1],[],[],[],[ctx.mpq_2_3],w
T2 = [z*C2],[1],[],[],[],[ctx.mpq_4_3],w T2 = [z*C2],[1],[],[],[],[ctx.mpq_4_3],w
return T1, T2 return T1, T2
return ctx.hypercomb(h, [], **kwargs) return ctx.hypercomb(h, [], **kwargs)
def _airy_zero(ctx, which, k, derivative, complex=False): def _airy_zero(ctx, which, k, derivative, complex=False):
# Asymptotic formulas are given in DLMF section 9.9 # Asymptotic formulas are given in DLMF section 9.9
def U(t): return t**(2/3.)*(1-7/(t**2*48)) def U(t): return t**(2/3.)*(1-7/(t**2*48))
def T(t): return t**(2/3.)*(1+5/(t**2*48)) def T(t): return t**(2/3.)*(1+5/(t**2*48))
k = int(k) k = int(k)
k if k < 1:
derivative in raise ValueError("k cannot be less than 1")
if not derivative in (0,1):
raise ValueError("Derivative should lie between 0 and 1")
if which == 0: if which == 0:
if derivative: if derivative:
return ctx.findroot(lambda z: ctx.airyai(z,1), return ctx.findroot(lambda z: ctx.airyai(z,1),
-U(3*ctx.pi*(4*k-3)/8)) -U(3*ctx.pi*(4*k-3)/8))
return ctx.findroot(ctx.airyai, -T(3*ctx.pi*(4*k-1)/8)) return ctx.findroot(ctx.airyai, -T(3*ctx.pi*(4*k-1)/8))
if which == 1 and complex == False: if which == 1 and complex == False:
if derivative: if derivative:
return ctx.findroot(lambda z: ctx.airybi(z,1), return ctx.findroot(lambda z: ctx.airybi(z,1),
-U(3*ctx.pi*(4*k-1)/8)) -U(3*ctx.pi*(4*k-1)/8))
return ctx.findroot(ctx.airybi, -T(3*ctx.pi*(4*k-3)/8)) return ctx.findroot(ctx.airybi, -T(3*ctx.pi*(4*k-3)/8))
skipping to change at line 833 skipping to change at line 835
return s, err return s, err
def generalized_bisection(ctx,f,a,b,n): def generalized_bisection(ctx,f,a,b,n):
""" """
Given f known to have exactly n simple roots within [a,b], Given f known to have exactly n simple roots within [a,b],
return a list of n intervals isolating the roots return a list of n intervals isolating the roots
and having opposite signs at the endpoints. and having opposite signs at the endpoints.
TODO: this can be optimized, e.g. by reusing evaluation points. TODO: this can be optimized, e.g. by reusing evaluation points.
""" """
n if n < 1:
raise ValueError("n cannot be less than 1")
N = n+1 N = n+1
points = [] points = []
signs = [] signs = []
while 1: while 1:
points = ctx.linspace(a,b,N) points = ctx.linspace(a,b,N)
signs = [ctx.sign(f(x)) for x in points] signs = [ctx.sign(f(x)) for x in points]
ok_intervals = [(points[i],points[i+1]) for i in range(N-1) \ ok_intervals = [(points[i],points[i+1]) for i in range(N-1) \
if signs[i]*signs[i+1] == -1] if signs[i]*signs[i+1] == -1]
if len(ok_intervals) == n: if len(ok_intervals) == n:
return ok_intervals return ok_intervals
skipping to change at line 857 skipping to change at line 860
return ctx.findroot(f, ab, solver='illinois', verify=False) return ctx.findroot(f, ab, solver='illinois', verify=False)
def bessel_zero(ctx, kind, prime, v, m, isoltol=0.01, _interval_cache={}): def bessel_zero(ctx, kind, prime, v, m, isoltol=0.01, _interval_cache={}):
prec = ctx.prec prec = ctx.prec
workprec = max(prec, ctx.mag(v), ctx.mag(m))+10 workprec = max(prec, ctx.mag(v), ctx.mag(m))+10
try: try:
ctx.prec = workprec ctx.prec = workprec
v = ctx.mpf(v) v = ctx.mpf(v)
m = int(m) m = int(m)
prime = int(prime) prime = int(prime)
v if v < 0:
m raise ValueError("v cannot be negative")
prime in if m < 1:
raise ValueError("m cannot be less than 1")
if not prime in (0,1):
raise ValueError("prime should lie between 0 and 1")
if kind == 1: if kind == 1:
if prime: f = lambda x: ctx.besselj(v,x,derivative=1) if prime: f = lambda x: ctx.besselj(v,x,derivative=1)
else: f = lambda x: ctx.besselj(v,x) else: f = lambda x: ctx.besselj(v,x)
if kind == 2: if kind == 2:
if prime: f = lambda x: ctx.bessely(v,x,derivative=1) if prime: f = lambda x: ctx.bessely(v,x,derivative=1)
else: f = lambda x: ctx.bessely(v,x) else: f = lambda x: ctx.bessely(v,x)
# The first root of J' is very close to 0 for small # The first root of J' is very close to 0 for small
# orders, and this needs to be special-cased # orders, and this needs to be special-cased
if kind == 1 and prime and m == 1: if kind == 1 and prime and m == 1:
if v == 0: if v == 0:
End of changes. 3 change blocks.
6 lines changed or deleted 12 lines changed or added