Skip to main content

Special Functions

Erf(z:complex)

Evaluate to the error function of a complex number.

The error function is an odd function (

\operatorname{erf} -z = -
\operatorname{erf} z
) that is used in statistics to calculate probabilities of normally distributed events.

The formula for the error function of a complex number is:

\operatorname{erf} z = \frac{2}{\sqrt{\pi}} \int_0^z e^{-t^2} dt

where z is a complex number.

Erfc(z:complex)

Evaluate to the complementary error function of a complex number.

It is defined as \operatorname{erfc} z = 1 - \operatorname {erf} z.

ErfInv(x:real)

Evaluate to the inverse error function of a real number -1 < x < 1

It is defined as

\operatorname{erf} \left(\operatorname{erf} ^{-1}x\right)
= x
.

Factorial(n)

n!
$$$n!$$
["Factorial", 5]
// -> 120

Factorial2(n)

The double factorial of n:

n!! = n \cdot (n-2) \cdot (n-4) \times
\cdots
, that is the product of all the positive integers up to n that have the same parity (odd or even) as n.

n!!
$$$n!!$$
["Factorial2", 5]
// -> 15

It can also be written in terms of the \Gamma function:

n!! = 2^{\frac{n}{2}+\frac{1}{4}(1-\cos(\pi n))}\pi^{\frac{1}{4}(\cos(\pi
n)-1)}\Gamma\left(\frac{n}{2}+1\right)

This is not the same as the factorial of the factorial of n (i.e. ((n!)!)).

Reference

Gamma(z)

\Gamma(n) = (n-1)!
$$$\Gamma(n) = (n-1)!$$

The Gamma Function is an extension of the factorial function, with its argument shifted by 1, to real and complex numbers.

\operatorname{\Gamma}\left(z\right) = \int\limits_{0}^{\infty} t^{z-1}
\mathrm{e}^{-t} \, \mathrm{d}t
["Gamma", 5]
// 24

Gamma(s, z)

\Gamma(s, z)
$$$\Gamma(s, z)$$

With two arguments, Gamma is the upper incomplete Gamma function. The lower limit of the integral is the second argument z instead of 0:

\operatorname{\Gamma}\left(s, z\right) = \int\limits_{z}^{\infty} t^{s-1}
\mathrm{e}^{-t} \, \mathrm{d}t

The order s and the lower limit z may be real or complex, including negative and fractional orders. The two-argument form is evaluated numerically with .N() and otherwise stays symbolic; \Gamma(s, 0) reduces to \Gamma(s). (This matches the Gamma[s, z] convention of Mathematica.)

["N", ["Gamma", 2, 1]]
// 0.7357588823428849

GammaLn(z)

\ln(\Gamma(z))
$$$\ln(\Gamma(z))$$

This function is called gammaln in MatLab and SciPy and LogGamma in Mathematica.

Zeta(s)

\zeta(s)
$$$\zeta(s)$$

The Riemann zeta function, defined for complex numbers with real part greater than 1 as:

\zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s}

and extended to other values by analytic continuation.

["Zeta", 2]
// ➔ π²/6

Beta(a, b)

\Beta(a, b)
$$$\Beta(a, b)$$

The Euler beta function, defined as:

\operatorname{B}(a, b) = \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}

It can also be expressed as an integral:

\operatorname{B}(a, b) = \int_0^1 t^{a-1}(1-t)^{b-1} \, dt
["Beta", 2, 3]
// ➔ 1/12

LambertW(x)

\operatorname{W}(x)
$$$\operatorname{W}(x)$$

The Lambert W function, also called the product logarithm. It is the inverse function of f(w) = w e^w.

For a given value x, W(x) is the value w such that w e^w = x.

The derivative of the Lambert W function is:

\frac{d}{dx} W(x) = \frac{W(x)}{x(1 + W(x))}
["LambertW", 1]
// ➔ Ω ≈ 0.5671 (the Omega constant)

Fresnel Integrals

The Fresnel integrals arise in the description of near-field diffraction and in the geometry of the Cornu spiral (Euler spiral).

FresnelS(x)

\operatorname{FresnelS}(x)
$$$\operatorname{FresnelS}(x)$$

The Fresnel S integral:

S(x) = \int_0^x \sin\!\left(\frac{\pi t^2}{2}\right) dt

It is an odd function (S(-x) = -S(x)) with asymptotic value S(\infty) = \tfrac{1}{2}.

["FresnelS", 1]
// ➔ 0.4383

FresnelC(x)

\operatorname{FresnelC}(x)
$$$\operatorname{FresnelC}(x)$$

The Fresnel C integral:

C(x) = \int_0^x \cos\!\left(\frac{\pi t^2}{2}\right) dt

It is an odd function (C(-x) = -C(x)) with asymptotic value C(\infty) = \tfrac{1}{2}.

["FresnelC", 1]
// ➔ 0.7799

Bessel Functions

Bessel functions are solutions to Bessel's differential equation:

x^2 \frac{d^2 y}{dx^2} + x \frac{dy}{dx} + (x^2 - n^2)y = 0

They arise in problems with cylindrical or spherical symmetry.

BesselJ(n, x)

J_n(x)
$$$J_n(x)$$

The Bessel function of the first kind of order n.

The derivative with respect to x is:

\frac{d}{dx} J_n(x) = \frac{1}{2}(J_{n-1}(x) - J_{n+1}(x))
["BesselJ", 0, 1]
// ➔ J₀(1) ≈ 0.7652

BesselY(n, x)

Y_n(x)
$$$Y_n(x)$$

The Bessel function of the second kind of order n, also called the Neumann function.

The derivative with respect to x is:

\frac{d}{dx} Y_n(x) = \frac{1}{2}(Y_{n-1}(x) - Y_{n+1}(x))
["BesselY", 0, 1]
// ➔ Y₀(1) ≈ 0.0883

BesselI(n, x)

I_n(x)
$$$I_n(x)$$

The modified Bessel function of the first kind of order n.

The derivative with respect to x is:

\frac{d}{dx} I_n(x) = \frac{1}{2}(I_{n-1}(x) + I_{n+1}(x))
["BesselI", 0, 1]
// ➔ I₀(1) ≈ 1.2661

BesselK(n, x)

K_n(x)
$$$K_n(x)$$

The modified Bessel function of the second kind of order n, also called the MacDonald function.

The derivative with respect to x is:

\frac{d}{dx} K_n(x) = -\frac{1}{2}(K_{n-1}(x) + K_{n+1}(x))
["BesselK", 0, 1]
// ➔ K₀(1) ≈ 0.4210

Airy Functions

Airy functions are solutions to the Airy differential equation:

\frac{d^2 y}{dx^2} - xy = 0

They arise in physics, particularly in quantum mechanics and optics.

AiryAi(x)

\operatorname{Ai}(x)
$$$\operatorname{Ai}(x)$$

The Airy function of the first kind.

It is the solution to the Airy equation that decays exponentially for positive x and oscillates for negative x.

["AiryAi", 0]
// ➔ 1/(3^(2/3) Γ(2/3)) ≈ 0.3550

AiryBi(x)

\operatorname{Bi}(x)
$$$\operatorname{Bi}(x)$$

The Airy function of the second kind.

It is the solution to the Airy equation that grows exponentially for positive x and oscillates for negative x.

["AiryBi", 0]
// ➔ 1/(3^(1/6) Γ(2/3)) ≈ 0.6149

Elliptic Integrals

The complete elliptic integrals arise in computing the arc length of an ellipse, the period of a pendulum, and throughout number theory.

Convention: these functions use the parameter m = k^2, where k is the modulus. This matches Mathematica, mpmath and Fungrim. To evaluate in terms of the modulus k, pass k^2.

EllipticK(m)

K(m)
$$$K(m)$$

The complete elliptic integral of the first kind:

K(m) = \int_0^{\pi/2} \frac{d\theta}{\sqrt{1 - m \sin^2\theta}}

It is computed via the arithmetic-geometric mean:

K(m) =
\dfrac{\pi}{2\operatorname{agm}(1, \sqrt{1-m})}
.

K(1) = \infty. For m > 1 the value is complex.

["EllipticK", 0.5]
// ➔ 1.85407467730137

EllipticE(m)

E(m)
$$$E(m)$$

The complete elliptic integral of the second kind:

E(m) = \int_0^{\pi/2} \sqrt{1 - m \sin^2\theta} \, d\theta

The perimeter of an ellipse with semi-major axis a and eccentricity e is 4aE(e^2).

E(1) = 1. For m > 1 the value is complex.

["EllipticE", 0.5]
// ➔ 1.35064388104768

AGM(a, b)

AGM(z)

\operatorname{agm}(a, b)
$$$\operatorname{agm}(a, b)$$

The arithmetic-geometric mean of two numbers: the common limit of the sequences

a_{n+1} = \frac{a_n +
b_n}{2}
and b_{n+1} = \sqrt{a_n b_n}.

With a single argument, \operatorname{agm}(z) is shorthand for \operatorname{agm}(1, z).

["AGM", 1, 2]
// ➔ 1.45679103104691

Hypergeometric Functions

Hypergeometric2F1(a, b, c, z)

{}_2F_1(a, b; c; z)
$$${}_2F_1(a, b; c; z)$$

The Gauss hypergeometric function, defined for |z| < 1 by the series:

{}_2F_1(a, b; c; z) = \sum_{n=0}^{\infty} \frac{(a)_n (b)_n}{(c)_n}
\frac{z^n}{n!}

where (q)_n is the Pochhammer symbol (rising factorial), and extended elsewhere by analytic continuation.

Many elementary and special functions are particular cases. For example \ln(1+z) = z \cdot {}_2F_1(1, 1; 2; -z) and K(m) = \frac{\pi}{2} \, {}_2F_1\big(\frac12, \frac12; 1; m\big).

If a or b is a non-positive integer the series terminates and the function is a polynomial in z, evaluable for any z. Otherwise the function evaluates numerically for z \le 1 (real) and for complex z within the unit disk and the Pfaff-transform region.

["Hypergeometric2F1", 1, 1, 2, 0.5]
// ➔ 1.38629436111989 (= 2 ln 2)

Hypergeometric1F1(a, b, z)

{}_1F_1(a; b; z)
$$${}_1F_1(a; b; z)$$

The Kummer confluent hypergeometric function, also written M(a, b, z):

{}_1F_1(a; b; z) = \sum_{n=0}^{\infty} \frac{(a)_n}{(b)_n} \frac{z^n}{n!}

It is an entire function of z and evaluates numerically for any real or complex z.

["Hypergeometric1F1", 1, 2, 2]
// ➔ 3.19452804946533 (= (e² − 1)/2)

Theta and Modular Functions

JacobiTheta(j, z, τ)

\theta_j(z, \tau)
$$$\theta_j(z, \tau)$$

The Jacobi theta functions \theta_j(z, \tau) for j \in \{1, 2, 3, 4\}, with nome q = e^{i\pi\tau} and \operatorname{Im}(\tau) > 0:

\theta_3(z, \tau) = 1 + 2\sum_{n=1}^{\infty} q^{n^2} \cos(2n\pi z)

and similarly for \theta_1, \theta_2, \theta_4.

Convention: the trigonometric argument is a multiple of \pi z (the functions have period 1 in z), matching Fungrim and mpmath — not the classical convention with period \pi.

An optional fourth argument indicates the order of differentiation with respect to z; only order 0 currently evaluates numerically.

["JacobiTheta", 3, 0, "ImaginaryUnit"]
// ➔ 1.08643481121331 (= π^(1/4)/Γ(3/4))

DedekindEta(τ)

\eta(\tau)
$$$\eta(\tau)$$

The Dedekind eta function, defined on the upper half-plane (\operatorname{Im}(\tau) > 0) by:

\eta(\tau) = e^{i\pi\tau/12} \prod_{k=1}^{\infty} \left(1 - e^{2\pi i k
\tau}\right)

It is a modular form of weight \frac12, central to the theory of modular functions and integer partitions.

["DedekindEta", "ImaginaryUnit"]
// ➔ 0.768225422326057 (= Γ(1/4)/(2π^(3/4)))