Hypergeometric functions
| Problem | Evaluate the Gauss hypergeometric function , Kummer’s confluent function and the limit function for real arguments |
| Devised by | John Wallis (1655), the name; Leonhard Euler (1769); Carl Friedrich Gauss (1812), the theory of ; Ernst Kummer (1836), transformations and the confluent function; Bernhard Riemann (1857), the differential equation |
| Accuracy | About relative for moderate parameters; near the singular point and for large |
| Cost | A power series of tens to hundreds of terms, after a transformation that makes it converge quickly |
| Read first | The gamma function and related functions |
| API | hypergeometric, hypergeometric_1f1, hypergeometric_0f1 |
Overview
The hypergeometric functions are the great unifiers of the special functions. The series
is characterised by the ratio of successive terms being a rational function of . With suitable parameters it reproduces almost every function in this chapter: logarithms and inverse trigonometric functions, the error function and incomplete gamma functions, Bessel functions, elliptic integrals, and the classical orthogonal polynomials. A routine for is therefore a routine for all of them, and identities between hypergeometric functions become identities between the special functions.
Where it is used
Many special functions are hypergeometric functions in disguise.
- Physics. Wave functions of the hydrogen atom, the Coulomb problem and scattering use confluent hypergeometric functions.
- Statistics. Distribution functions of non-central , and distributions.
- Antenna and electromagnetic theory. Fields in conical and spherical geometries.
- Software. Computer algebra systems express an integral or a series as a , and numerical evaluation is the way to get a number.
History
John Wallis used the word “hypergeometric” in 1655 for series generalising the geometric series. Euler studied and found its integral representation and its transformation . Gauss’s 1812 memoir established the series’ convergence (for ), its value at , and the contiguous relations between functions whose parameters differ by integers. Ernst Kummer (1836) found the 24 solutions of the hypergeometric differential equation and introduced the confluent function , obtained by letting the singular point at merge with the one at infinity. Bernhard Riemann (1857) characterised by its three regular singular points , and , a viewpoint that shaped complex analysis and differential equations.
The idea
The Gauss function ₂F₁
The most important member of the family has two upper parameters and one lower:
It solves the hypergeometric differential equation . Summing the series is trivial: each term is the previous one times . The difficulty is that the series is not usable everywhere. The ratio of successive terms tends to , so the series converges only for , and it converges slowly when is close to 1, like a geometric series with ratio near 1.
The remedy is a set of exact identities, the linear transformations, each of which expresses at in terms of at another point, with different parameters. By choosing the right one, any real can be moved to a point where the series converges fast.
- The Pfaff transformation handles negative . The map sends into the interval , where the series or the next formula applies.
- The connection formula handles . It expresses at as a sum of two hypergeometric functions at , which is at most , with coefficients that are ratios of gamma functions. When is an integer these coefficients are infinite, and the two infinite terms cancel to leave a finite limit, which needs a separate formula. The library does not implement that limiting form; in that case it sums the original series, slowly but correctly.
- At exactly, Gauss’s theorem gives the value in closed form: for .
Two special situations are visible in the series itself. If or is zero or a negative integer, a factor eventually vanishes and all later terms are zero: the series terminates, giving a polynomial (Jacobi, Legendre and Chebyshev polynomials are of this form). If is zero or a negative integer, a denominator eventually vanishes and the function is undefined.
Kummer’s function ₁F₁
With one upper and one lower parameter the series is
the confluent hypergeometric function, which solves . The ratio of successive terms is now about , which tends to zero, so the series converges for every , like the series of .
Convergence is not the same as accuracy, however. For large negative the terms alternate in sign and grow before they shrink, exactly as the series of does, and the small result is lost to cancellation among large terms. Kummer’s transformation
repairs this: for negative the series on the right has a positive argument and (for ) positive terms, and the smallness is carried by the explicit factor . For negative integer the series terminates and is a Laguerre polynomial.
Figure 6.10. Kummer's function.
The limit function ₀F₁
is a Bessel function in disguise: , and with for positive argument. For the series has positive terms. For large negative its terms alternate and grow to about times the result before decreasing, so the series can lose up to digits; at it lost seven. Below the library therefore uses the Bessel relation, with the accurate of the Bessel entry.
Special cases
Evaluating the library’s hypergeometric functions against elementary and special functions:
Table 6.6. Hypergeometric identities checked numerically.
| identity (at ) | elementary side | hypergeometric side | relative difference |
|---|---|---|---|
| 0.314810739840034 | 0.314810739840033 | 4e-16 | |
| 0.379009020695951 | 0.379009020695951 | 1e-16 | |
| 0.354379919123438 | 0.354379919123438 | 2e-16 | |
| , | 3.174304803974362 | 3.174304803974362 | 1e-16 |
| 0.343066583600000 | 0.343066583600004 | 1e-14 | |
| 1.629136727162264 | 1.629136727162264 | 1e-16 | |
| 1.447734614663325 | 1.447734614663324 | 2e-16 | |
| 0.399205984043000 | 0.399205984042999 | 6e-16 | |
| , | 0.053693967026824 | 0.053693967026824 | 1e-16 |
| 0.346881237093536 | 0.346881237093536 | 2e-16 | |
| 0.576724807756874 | 0.576724807756874 | 2e-16 |
Accuracy
Table 6.7. Accuracy of the hypergeometric functions.
| function | test points | median relative error | largest relative error | at arguments |
|---|---|---|---|---|
hypergeometric | 59 | 4e-16 | 7e-14 | (2, 3, 4.5, 0.7) |
hypergeometric_1f1 | 42 | 3e-16 | 5e-13 | (10, 3, -10) |
hypergeometric_0f1 | 24 | 2e-16 | 2e-14 | (2.5, -5) |
Algorithm
Each function first disposes of the special arguments, then chooses the transformation that puts the argument where its series converges quickly.
, in this order:
- is zero or a negative integer: return
NaN. - or is zero or a negative integer: the series terminates; sum it for any .
- : return
NaN(the function is not real there). - : return the value given by Gauss’s theorem if , and otherwise.
- : apply the Pfaff transformation and start again with the new argument , which lies in .
- and is not an integer: apply the connection formula, summing two series in .
- Otherwise: sum the defining series.
Summing a hypergeometric series. Start with term and sum . For , multiply the term by and add it to the sum. Stop when the term is below times the sum, or is exactly zero (a terminating series).
: for sum the series, with term ratio . For apply Kummer’s transformation and sum the series for , then multiply by .
: for sum the series, with term ratio . For use the Bessel relation with .
Implementation
/// Kummer's confluent hypergeometric function ₁F₁(a; b; x) = M(a, b, x), for real arguments.
///
/// Uses Kummer's transformation `M(a,b,x) = e^x M(b-a,b,-x)` for `x < 0` to avoid cancellation.
/// Returns `NaN` if `b` is a non-positive integer (unless the series terminates first).
pub fn hypergeometric_1f1(a: f64, b: f64, x: f64) -> f64 {
if a.is_nan() || b.is_nan() || x.is_nan() {
return f64::NAN;
}
if is_nonpositive_integer(b) && !(is_nonpositive_integer(a) && -a < -b) {
return f64::NAN;
}
if x < 0.0 && !is_nonpositive_integer(a) {
return x.exp() * hypergeometric_1f1(b - a, b, -x);
}
let mut term = 1.0;
let mut sum = 1.0;
for n in 0..1_000_000usize {
let nf = n as f64;
term *= (a + nf) / ((b + nf) * (nf + 1.0)) * x;
sum += term;
if term == 0.0 || (term.abs() < EPS * sum.abs() && n as f64 > x.abs()) {
break;
}
}
sum
}
- Real arguments only; for is complex and returns
NaN. - Large parameters (hundreds) make the series long and can lose accuracy; specialised methods (recurrences in the parameters, uniform asymptotics) are needed there.
In practice
//! Hypergeometric functions.
//!
//! Run with `cargo run -p lib_jsl_special_functions --example special_hypergeometric`.
use lib_jsl_special_functions::{hypergeometric, hypergeometric_0f1, hypergeometric_1f1};
fn main() {
// ₂F₁ contains many elementary functions: arcsin z = z ₂F₁(½, ½; 3/2; z²).
let z: f64 = 0.6;
println!("z ₂F₁(½, ½; 3/2; z²) = {:.15}, arcsin z = {:.15}", z * hypergeometric(0.5, 0.5, 1.5, z * z), z.asin());
// Gauss's theorem at z = 1: ₂F₁(a, b; c; 1) = Γ(c)Γ(c−a−b) / (Γ(c−a)Γ(c−b)).
println!("₂F₁(1, 1; 3; 1) = {} (exactly 2)", hypergeometric(1.0, 1.0, 3.0, 1.0));
// Kummer's function at a negative integer a is a (Laguerre) polynomial.
println!("₁F₁(−2; 1; x) at x = 3: {} (L₂(3) = 1 − 6 + 4.5 = −0.5)", hypergeometric_1f1(-2.0, 1.0, 3.0));
println!("₀F₁(; 1; −4) = J₀(4) = {:.15}", hypergeometric_0f1(1.0, -4.0));
}
Strengths
- One routine for many special functions, with the transformations that make it converge.
- Exact polynomial values for terminating series.
Weaknesses
- Real arguments, and moderate parameters only.
- The case of integer near is slow.
Exercises
- Show that the ratio of successive terms of is , and use it to prove convergence for .
- Verify by comparing series.
- Use the Pfaff transformation to evaluate and compare with .
- Show that the Legendre polynomial for .
- Estimate the number of digits lost summing directly for , and check with
hypergeometric_1f1, which uses Kummer’s transformation.
Hints and answers
- The term ratio is , so by the ratio test the series converges for .
- , since and . Then .
- Pfaff: . With , , : .
- ; with this is .
- The terms of grow to about in size while the sum is of order (much smaller), so about digits are lost at . Kummer’s transformation has positive terms and loses nothing.
Further reading
- G. E. Andrews, R. Askey and R. Roy, Special Functions, Cambridge University Press, 1999, chapters 2 and 4.
- J. W. Pearson, S. Olver and M. A. Porter, “Numerical methods for the computation of the confluent and Gauss hypergeometric functions”, Numerical Algorithms 74 (2017) 821–866.
- NIST Digital Library of Mathematical Functions, chapters 13, 15 and 16, https://dlmf.nist.gov/15.