AUTHORS:
This module provides easy access to many of Maxima and PARI’s special functions.
Maxima’s special functions package (which includes spherical harmonic functions, spherical Bessel functions (of the 1st and 2nd kind), and spherical Hankel functions (of the 1st and 2nd kind)) was written by Barton Willis of the University of Nebraska at Kearney. It is released under the terms of the General Public License (GPL).
Support for elliptic functions and integrals was written by Raymond Toy. It is placed under the terms of the General Public License (GPL) that governs the distribution of Maxima.
Next, we summarize some of the properties of the functions implemented here.
Airy function The function \(Ai(x)\) and the related function \(Bi(x)\), which is also called an Airy function, are solutions to the differential equation
known as the Airy equation. They belong to the class of ‘Bessel functions of fractional order’. The initial conditions \(Ai(0) = (\Gamma(2/3)3^{2/3})^{-1}\), \(Ai'(0) = -(\Gamma(1/3)3^{1/3})^{-1}\) define \(Ai(x)\). The initial conditions \(Bi(0) = 3^{1/2}Ai(0)\), \(Bi'(0) = -3^{1/2}Ai'(0)\) define \(Bi(x)\).
They are named after the British astronomer George Biddell Airy.
Spherical harmonics: Laplace’s equation in spherical coordinates is:
Note that the spherical coordinates \(\theta\) and \(\varphi\) are defined here as follows: \(\theta\) is the colatitude or polar angle, ranging from \(0\leq\theta\leq\pi\) and \(\varphi\) the azimuth or longitude, ranging from \(0\leq\varphi<2\pi\).
The general solution which remains finite towards infinity is a linear combination of functions of the form
and
where \(P_\ell^m\) are the associated Legendre polynomials, and with integer parameters \(\ell \ge 0\) and \(m\) from \(0\) to \(\ell\). Put in another way, the solutions with integer parameters \(\ell \ge 0\) and \(- \ell\leq m\leq \ell\), can be written as linear combinations of:
where the functions \(Y\) are the spherical harmonic functions with parameters \(\ell\), \(m\), which can be written as:
The spherical harmonics obey the normalisation condition
When solving for separable solutions of Laplace’s equation in spherical coordinates, the radial equation has the form:
The spherical Bessel functions \(j_n\) and \(y_n\), are two linearly independent solutions to this equation. They are related to the ordinary Bessel functions \(J_n\) and \(Y_n\) by:
For \(x>0\), the confluent hypergeometric function \(y = U(a,b,x)\) is defined to be the solution to Kummer’s differential equation
which satisfies \(U(a,b,x) \sim x^{-a}\), as \(x\rightarrow \infty\). (There is a linearly independent solution, called Kummer’s function \(M(a,b,x)\), which is not implemented.)
Jacobi elliptic functions can be thought of as generalizations of both ordinary and hyperbolic trig functions. There are twelve Jacobian elliptic functions. Each of the twelve corresponds to an arrow drawn from one corner of a rectangle to another.
n ------------------- d
| |
| |
| |
s ------------------- c
Each of the corners of the rectangle are labeled, by convention, s, c, d and n. The rectangle is understood to be lying on the complex plane, so that s is at the origin, c is on the real axis, and n is on the imaginary axis. The twelve Jacobian elliptic functions are then pq(x), where p and q are one of the letters s,c,d,n.
The Jacobian elliptic functions are then the unique doubly-periodic, meromorphic functions satisfying the following three properties:
We can write
where \(p\), \(q\), and \(r\) are any of the letters \(s\), \(c\), \(d\), \(n\), with the understanding that \(ss=cc=dd=nn=1\).
Let
Then the Jacobi elliptic function \(sn(u)\) is given by
and \(cn(u)\) is given by
and
To emphasize the dependence on \(m\), one can write \(sn(u,m)\) for example (and similarly for \(cn\) and \(dn\)). This is the notation used below.
For a given \(k\) with \(0 < k < 1\) they therefore are solutions to the following nonlinear ordinary differential equations:
\(\mathrm{sn}\,(x;k)\) solves the differential equations
and
\(\mathrm{cn}\,(x;k)\) solves the differential equations
and \(\left(\frac{\mathrm{d} y}{\mathrm{d}x}\right)^2 = (1-y^2) (1-k^2 + k^2 y^2)\).
\(\mathrm{dn}\,(x;k)\) solves the differential equations
and \(\left(\frac{\mathrm{d} y}{\mathrm{d}x}\right)^2= y^2 (1 - k^2 - y^2)\).
If \(K(m)\) denotes the complete elliptic integral of the first kind (denoted elliptic_kc), the elliptic functions \(sn (x,m)\) and \(cn (x,m)\) have real periods \(4K(m)\), whereas \(dn (x,m)\) has a period \(2K(m)\). The limit \(m\rightarrow 0\) gives \(K(0) = \pi/2\) and trigonometric functions: \(sn(x, 0) = \sin x\), \(cn(x, 0) = \cos x\), \(dn(x, 0) = 1\). The limit \(m \rightarrow 1\) gives \(K(1) \rightarrow \infty\) and hyperbolic functions: \(sn(x, 1) = \tanh x\), \(cn(x, 1) = \mbox{\rm sech} x\), \(dn(x, 1) = \mbox{\rm sech} x\).
The incomplete elliptic integrals (of the first kind, etc.) are:
and the complete ones are obtained by taking \(\phi =\pi/2\).
REFERENCES:
TODO: Resolve weird bug in commented out code in hypergeometric_U below.
AUTHORS:
Added 16-02-2008 (wdj): optional calls to scipy and replace all ‘#random’ by ‘...’ (both at the request of William Stein)
Warning
SciPy’s versions are poorly documented and seem less accurate than the Maxima and PARI versions.
Bases: sage.functions.special.MaximaFunction
This returns the value of the “incomplete elliptic integral of the second kind,”
i.e., integrate(sqrt(1 - m*sin(x)^2), x, 0, phi). Taking \(\phi = \pi/2\) gives elliptic_ec.
EXAMPLES:
sage: z = var("z")
sage: # this is still wrong: must be abs(sin(z)) + 2*round(z/pi)
sage: elliptic_e(z, 1)
2*round(z/pi) + sin(z)
sage: elliptic_e(z, 0)
z
sage: elliptic_e(0.5, 0.1)
0.498011394498832
sage: loads(dumps(elliptic_e))
elliptic_e
Bases: sage.functions.special.MaximaFunction
This returns the value of the “complete elliptic integral of the second kind,”
EXAMPLES:
sage: elliptic_ec(0.1)
1.53075763689776
sage: elliptic_ec(x).diff()
1/2*(elliptic_ec(x) - elliptic_kc(x))/x
sage: loads(dumps(elliptic_ec))
elliptic_ec
Bases: sage.functions.special.MaximaFunction
This returns the value of the “incomplete elliptic integral of the second kind,”
where \(\tau = \mathrm{sn}(u, m)\).
EXAMPLES:
sage: elliptic_eu (0.5, 0.1)
0.496054551286597
Bases: sage.functions.special.MaximaFunction
This returns the value of the “incomplete elliptic integral of the first kind,”
i.e., integrate(1/sqrt(1 - m*sin(x)^2), x, 0, phi). Taking \(\phi = \pi/2\) gives elliptic_kc.
EXAMPLES:
sage: z = var("z")
sage: elliptic_f (z, 0)
z
sage: elliptic_f (z, 1)
log(tan(1/4*pi + 1/2*z))
sage: elliptic_f (0.2, 0.1)
0.200132506747543
Bases: sage.functions.special.MaximaFunction
This returns the value of the “complete elliptic integral of the first kind,”
EXAMPLES:
sage: elliptic_kc(0.5)
1.85407467730137
sage: elliptic_f(RR(pi/2), 0.5)
1.85407467730137
Bases: sage.functions.special.MaximaFunction
This returns the value of the “incomplete elliptic integral of the third kind,”
INPUT:
EXAMPLES:
sage: N(elliptic_pi(1, pi/4, 1))
1.14779357469632
Compare the value computed by Maxima to the definition as a definite integral (using GSL):
sage: elliptic_pi(0.1, 0.2, 0.3)
0.200665068220979
sage: numerical_integral(1/(1-0.1*sin(x)^2)/sqrt(1-0.3*sin(x)^2), 0.0, 0.2)
(0.2006650682209791, 2.227829789769088e-15)
ALGORITHM:
Numerical evaluation and symbolic manipulation are provided by Maxima.
REFERENCES:
Bases: sage.symbolic.function.BuiltinFunction
EXAMPLES:
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1,1)
tanh(1)
sage: f(1/2,1/2).n()
0.470750473655657
The function \(Ai(x)\) and the related function \(Bi(x)\), which is also called an Airy function, are solutions to the differential equation
known as the Airy equation. The initial conditions \(Ai(0) = (\Gamma(2/3)3^{2/3})^{-1}\), \(Ai'(0) = -(\Gamma(1/3)3^{1/3})^{-1}\) define \(Ai(x)\). The initial conditions \(Bi(0) = 3^{1/2}Ai(0)\), \(Bi'(0) = -3^{1/2}Ai'(0)\) define \(Bi(x)\).
They are named after the British astronomer George Biddell Airy. They belong to the class of “Bessel functions of fractional order”.
EXAMPLES:
sage: airy_ai(1.0) # last few digits are random
0.135292416312881400
sage: airy_bi(1.0) # last few digits are random
1.20742359495287099
REFERENCE:
The function \(Ai(x)\) and the related function \(Bi(x)\), which is also called an Airy function, are solutions to the differential equation
known as the Airy equation. The initial conditions \(Ai(0) = (\Gamma(2/3)3^{2/3})^{-1}\), \(Ai'(0) = -(\Gamma(1/3)3^{1/3})^{-1}\) define \(Ai(x)\). The initial conditions \(Bi(0) = 3^{1/2}Ai(0)\), \(Bi'(0) = -3^{1/2}Ai'(0)\) define \(Bi(x)\).
They are named after the British astronomer George Biddell Airy. They belong to the class of “Bessel functions of fractional order”.
EXAMPLES:
sage: airy_ai(1) # last few digits are random
0.135292416312881400
sage: airy_bi(1) # last few digits are random
1.20742359495287099
REFERENCE:
Returns the elliptic modular \(j\)-function evaluated at \(z\).
INPUT:
OUTPUT:
(complex) The value of \(j(z)\).
ALGORITHM:
Calls the pari function ellj().
AUTHOR:
John Cremona
EXAMPLES:
sage: elliptic_j(CC(i))
1728.00000000000
sage: elliptic_j(sqrt(-2.0))
8000.00000000000
sage: z = ComplexField(100)(1,sqrt(11))/2
sage: elliptic_j(z)
-32768.000...
sage: elliptic_j(z).real().round()
-32768
The complementary error function \(\frac{2}{\sqrt{\pi}}\int_t^\infty e^{-x^2} dx\) (t belongs to RR). This function is currently always evaluated immediately.
EXAMPLES:
sage: error_fcn(6)
2.15197367124989e-17
sage: error_fcn(RealField(100)(1/2))
0.47950012218695346231725334611
Note this is literally equal to \(1 - erf(t)\):
sage: 1 - error_fcn(0.5)
0.520499877813047
sage: erf(0.5)
0.520499877813047
Default is a wrap of PARI’s hyperu(alpha,beta,x) function. Optionally, algorithm = “scipy” can be used.
The confluent hypergeometric function \(y = U(a,b,x)\) is defined to be the solution to Kummer’s differential equation
This satisfies \(U(a,b,x) \sim x^{-a}\), as \(x\rightarrow \infty\), and is sometimes denoted x^{-a}2_F_0(a,1+a-b,-1/x). This is not the same as Kummer’s \(M\)-hypergeometric function, denoted sometimes as _1F_1(alpha,beta,x), though it satisfies the same DE that \(U\) does.
Warning
In the literature, both are called “Kummer confluent hypergeometric” functions.
EXAMPLES:
sage: hypergeometric_U(1,1,1,"scipy")
0.596347362323...
sage: hypergeometric_U(1,1,1)
0.59634736232319...
sage: hypergeometric_U(1,1,1,"pari",70)
0.59634736232319407434...
Here sym = “pq”, where p,q in c,d,n,s. This returns the value of the inverse Jacobi function \(pq^{-1}(x,m)\). There are a total of 12 functions described by this.
EXAMPLES:
sage: jacobi("sn",1/2,1/2)
jacobi_sn(1/2, 1/2)
sage: float(jacobi("sn",1/2,1/2))
0.4707504736556572
sage: float(inverse_jacobi("sn",0.47,1/2))
0.4990982313222196
sage: float(inverse_jacobi("sn",0.4707504,0.5))
0.4999999114665548
sage: P = plot(inverse_jacobi('sn', x, 0.5), 0, 1, plot_points=20)
Now to view this, just type show(P).
Here sym = “pq”, where p,q in c,d,n,s. This returns the value of the Jacobi function pq(x,m), as described in the documentation for Sage’s “special” module. There are a total of 12 functions described by this.
EXAMPLES:
sage: jacobi("sn",1,1)
tanh(1)
sage: jacobi("cd",1,1/2)
jacobi_cd(1, 1/2)
sage: RDF(jacobi("cd",1,1/2))
0.724009721659
sage: RDF(jacobi("cn",1,1/2)); RDF(jacobi("dn",1,1/2)); RDF(jacobi("cn",1,1/2)/jacobi("dn",1,1/2))
0.595976567672
0.823161001632
0.724009721659
sage: jsn = jacobi("sn",x,1)
sage: P = plot(jsn,0,1)
To view this, type P.show().
This method is deprecated, please use log_gamma() instead.
See the log_gamma() function for ‘ documentation and examples.
EXAMPLES:
sage: lngamma(RR(6))
doctest:...: DeprecationWarning: The method lngamma() is deprecated. Use log_gamma() instead.
See http://trac.sagemath.org/6992 for details.
4.78749174278205
Returns a function which is evaluated both symbolically and numerically via Maxima. In particular, it returns an instance of MaximaFunction.
Note
This function is cached so that duplicate copies of the same function are not created.
EXAMPLES:
sage: spherical_hankel2(2,i)
-e
Returns x evaluated in Maxima, then returned to Sage. This is used to evaluate several of these special functions.
TEST:
sage: from sage.functions.special import airy_ai
sage: airy_bi(1.0)
1.20742359495
Returns the spherical Bessel function of the first kind for integers n >= 1.
Reference: AS 10.1.8 page 437 and AS 10.1.15 page 439.
EXAMPLES:
sage: spherical_bessel_J(2,x)
((3/x^2 - 1)*sin(x) - 3*cos(x)/x)/x
sage: spherical_bessel_J(1, 5.2, algorithm='scipy')
-0.12277149950007...
sage: spherical_bessel_J(1, 3, algorithm='scipy')
0.345677499762355...
Returns the spherical Bessel function of the second kind for integers n -1.
Reference: AS 10.1.9 page 437 and AS 10.1.15 page 439.
EXAMPLES:
sage: x = PolynomialRing(QQ, 'x').gen()
sage: spherical_bessel_Y(2,x)
-((3/x^2 - 1)*cos(x) + 3*sin(x)/x)/x
Returns the spherical Hankel function of the first kind for integers \(n > -1\), written as a string. Reference: AS 10.1.36 page 439.
EXAMPLES:
sage: spherical_hankel1(2, x)
(I*x^2 - 3*x - 3*I)*e^(I*x)/x^3
Returns the spherical Hankel function of the second kind for integers \(n > -1\), written as a string. Reference: AS 10.1.17 page 439.
EXAMPLES:
sage: spherical_hankel2(2, x)
(-I*x^2 - 3*x + 3*I)*e^(-I*x)/x^3
Here I = sqrt(-1).
Returns the spherical Harmonic function of the second kind for integers \(n > -1\), \(|m|\leq n\). Reference: Merzbacher 9.64.
EXAMPLES:
sage: x,y = var('x,y')
sage: spherical_harmonic(3,2,x,y)
15/4*sqrt(7/30)*cos(x)*e^(2*I*y)*sin(x)^2/sqrt(pi)
sage: spherical_harmonic(3,2,1,2)
15/4*sqrt(7/30)*cos(1)*e^(4*I)*sin(1)^2/sqrt(pi)