A number of algorithms exist for computing the values of spherical Bessel functions with fixed-precision arithmetic. This repository contains implementations of these algorithms, as well as code for comparing their accuracy over a wide range of parameters. It's an extension of the work of Jabłoński (1994) to complex-valued arguments.
The ultimate objective of this work is to design a new implementation of spherical Bessel functions for SciPy.
- Throughout,
x
denotes a real argument andz
a complex argument. j_n(z)
: spherical Bessel function of the first kind.y_n(z)
: spherical Bessel function of the second kind.
I compare the following implementations:
- The current SciPy implementation, which uses the algorithms described by
Zhang and Jin in Computation of Special Functions (Wiley, 1996). The
algorithm uses backward recurrence for
j_n(x)
andj_n(z)
, a forward recurrence fory_n(x)
, and a recurrence based on the Wronskian relation betweenj_n(z)
andy_n(z)
for computingy_n(z)
. The algorithm forj_n(x)
is reported to be unstable for moderately large values of the argument (see these issues). This problem motivates the investigation reported here. - An implementation using the SciPy implementations of the Bessel functions, based on their connection to the spherical Bessel functions (DLMF 10.47.ii).
- An algorithm recently proposed by Liang-Wu Cai (2011).
- The explicit or analytical formulas in terms of trigonometric functions (DLMF 10.49).
- Ascending recurrence.
- Descending recurrence.
- Power series expansion about
z = 0
.
All of the tested algorithms are used to compute the spherical Bessel
functions at a range of order and argument values, and compared to the output
of a variant of algorithm 2 implemented using the mpmath
arbitrary-
precision arithmetic library. The goal is to identify regions of order and
argument space in which each of the fixed-precision algorithms of the previous
section is correct. Correctness is defined (somewhat arbitrarily, but
following Jabłoński) as matching the first 10 significant figures of the exact
result.
The inputs at which the algorithms are tested are those generated by
reference/reference_points.py
. By default, 100 logarithmically spaced
points along each of 5 rays in the complex plane are used. The reference
mpmath
values themselves are computed by reference/reference_values.py
.
To run the algorithms' unit tests, run nosetests
in the sbf
directory.
These tests only check the mpmath
algorithms used for computing the
reference values.