Orthogonal polynomials and spherical harmonics
| Problem | Evaluate the classical orthogonal polynomials (Legendre, Chebyshev, Hermite, Laguerre, Jacobi), the associated Legendre functions and the spherical harmonics |
| Devised by | Adrien-Marie Legendre (1782) and Pierre-Simon Laplace (1782), Legendre polynomials and spherical harmonics; Carl Gustav Jacobi (1859); Pafnuty Chebyshev (1854); Charles Hermite (1864); Edmond Laguerre (1879); Elwin Christoffel (1858) and Gaston Darboux (1878), the general theory; Edward Condon and George Shortley (1935), the phase convention |
| Accuracy | Near machine precision; values of polynomials far outside their interval, and of high degree near the ends of it, are limited by rounding in the recurrence |
| Cost | operations by the three-term recurrence; for a spherical harmonic |
| Read first | Polynomial interpolation |
| API | legendre, legendre_with_derivative, chebyshev_t, chebyshev_u, hermite, hermite_he, laguerre, jacobi, associated_legendre, normalized_associated_legendre, spherical_harmonic, real_spherical_harmonic |
Overview
A family of polynomials , with of degree , is orthogonal with respect to a weight on an interval if for . Orthogonal polynomials are the natural bases for approximating functions: expansions in them converge rapidly for smooth functions, and their zeros are the nodes of Gaussian quadrature. The classical families, those whose derivatives are again orthogonal, solve the eigenvalue problems of mathematical physics: Legendre polynomials for the Laplace equation in spherical coordinates, Hermite polynomials for the quantum harmonic oscillator, Laguerre polynomials for the hydrogen atom, and Chebyshev polynomials for minimax approximation and spectral methods.
Spherical harmonics, built from the associated Legendre functions, are the orthogonal functions on the sphere: the angular parts of atomic orbitals, the multipole expansion of gravitational and electric fields, and the basis of global weather and geophysical models.
Where it is used
Orthogonal polynomials are the standard bases for approximation.
- Numerical analysis. Gaussian quadrature nodes, Chebyshev interpolation and spectral methods are built on them.
- Physics and chemistry. Legendre polynomials and spherical harmonics describe gravitational and electric multipoles, atomic orbitals and the angular parts of waves; Hermite functions are the harmonic oscillator’s wave functions.
- Geodesy and climate science. The gravity field of the Earth and global weather fields are expanded in spherical harmonics.
- Filter and window design. Chebyshev polynomials define the Chebyshev filters and windows.
History
Legendre and Laplace introduced Legendre polynomials and spherical harmonics in 1782, expanding the gravitational attraction of the planets. Chebyshev (1854) found his polynomials as the solution of the problem of best uniform approximation, which arose from his work on steam-engine linkages. Hermite (1864) and Laguerre (1879) studied the families named after them, though both had appeared earlier (Hermite’s in Laplace’s probability theory). Jacobi (1859) introduced the two-parameter family that contains Legendre, Chebyshev and Gegenbauer polynomials. Elwin Christoffel and Gaston Darboux established the general theory, including the three-term recurrence and the Christoffel-Darboux formula, and Jean Favard (1935) proved that every three-term recurrence of the right form defines an orthogonal family. Edward Condon and George Shortley’s 1935 textbook on atomic spectra fixed the sign convention for spherical harmonics that physics still uses.
The idea
Classical orthogonal polynomials
Two functions are orthogonal with respect to a weight function on an interval if the integral of their product, weighted by , is zero: . This is the analogue for functions of two vectors having zero dot product. A family of orthogonal polynomials has one polynomial of each degree, every pair of which is orthogonal. Each choice of weight and interval gives a different family, and the classical ones are:
| family | weight | interval | recurrence |
|---|---|---|---|
| Legendre | 1 | ||
| Chebyshev | |||
| Chebyshev | |||
| Hermite | |||
| Hermite | |||
| Laguerre | |||
| Jacobi | a three-term recurrence with rational coefficients |
The last column is the key to computing them. Every orthogonal family satisfies a three-term recurrence : each polynomial is determined by the two before it. Starting from and and applying the recurrence upward gives the value of in steps. For Legendre polynomials, for example, and give , so .
This is the standard way to evaluate the polynomials, and it is numerically stable. The obvious alternative, writing out in powers of and summing, is not. has coefficients as large as , yet its values on never exceed 1 in magnitude: the huge terms cancel almost completely, and in double precision nothing correct is left.
On the orthogonality interval the polynomial of degree oscillates, with exactly zeros:
Figure 6.11. Legendre polynomials.
Multiplying by the square root of the weight and normalising gives orthonormal functions. The Hermite functions are the energy eigenstates of the quantum harmonic oscillator:
Figure 6.12. Hermite functions.
legendre_with_derivative also returns , from , as Newton’s method for
the Gauss-Legendre nodes needs.
Associated Legendre functions and spherical harmonics
The associated Legendre functions are, with the Condon-Shortley phase ,
and . They arise when Laplace’s equation is separated in spherical coordinates, where they describe the dependence on the polar angle through . Multiplying by the dependence on the azimuthal angle , and normalising, gives the spherical harmonics
They play the role on the surface of a sphere that sines and cosines play on a circle: any reasonable function on the sphere can be expanded in them. The degree sets how rapidly the function varies (there are harmonics of degree , with ), and the order counts the oscillations around the axis. They are orthonormal on the unit sphere and satisfy . The real spherical harmonics, combinations and , are used in chemistry and geophysics.
The unnormalised grow like and overflow beyond , although the normalised functions are
bounded. normalized_associated_legendre therefore runs the recurrence directly on the normalised
functions, starting from and recurring in ; it is stable and free of overflow for degrees in the
thousands, as geophysical models need.
Accuracy
Table 6.8. Accuracy of the orthogonal polynomials.
| function | test points | median relative error | largest relative error | at arguments |
|---|---|---|---|---|
legendre | 61 | 0 | 8e-15 | (30, -0.7) |
chebyshev_t | 61 | 0 | 2e-13 | (100, 0.99) |
chebyshev_u | 61 | 0 | 1e-15 | (100, 3) |
hermite | 61 | 0 | 6e-15 | (30, -0.2) |
hermite_he | 59 | 0 | 7e-16 | (100, -0.2) |
laguerre | 62 | 1e-16 | 5e-14 | (30, 0.5, 0.3) |
jacobi | 63 | 6e-16 | 2e-13 | (100, 0.5, -0.3, 1) |
associated_legendre | 36 | 2e-16 | 7e-15 | (10, 3, -0.3) |
spherical_harmonic, real part | 15 | 4e-16 | 2e-15 | (20, -7, 2.9, -1) |
spherical_harmonic, imaginary part | 15 | 4e-16 | 2e-15 | (20, -7, 2.9, -1) |
real_spherical_harmonic | 15 | 4e-16 | 2e-15 | (20, -7, 2.9, -1) |
Algorithm
A polynomial of degree at (Legendre, Chebyshev, Hermite, Laguerre, Jacobi).
- If , return . If , return the family’s (for example for Legendre and Chebyshev , for Chebyshev and Hermite ).
- Keep the two latest values. For , compute from and by the family’s recurrence, and shift.
- Return .
The cost is operations and no storage beyond two numbers.
Associated Legendre functions , . The recurrence in the degree , for fixed order , needs two starting values, and they are available in closed form.
- Compute , where is the product of the odd numbers up to . If , return it.
- Compute . If , return it.
- For : .
normalized_associated_legendre runs the same three steps on the normalised functions
, with the normalising factors absorbed into the starting value and the recurrence
coefficients, so that no intermediate quantity overflows.
Spherical harmonics . Compute and multiply by . For negative , apply .
Implementation
The shared recurrence driver:
/// Runs `p_{k+1} = a_k(x) p_k − b_k p_{k−1}` from `p_0 = 1`, `p_1` and returns `(p_n, p_{n−1})`
/// (`p_{−1} = 0`).
fn recurrence(n: u32, p1: f64, step: impl Fn(u32, f64, f64) -> f64) -> (f64, f64) {
match n {
0 => (1.0, 0.0),
_ => {
let (mut prev, mut cur) = (1.0, p1);
for k in 1..n {
let next = step(k, cur, prev);
prev = cur;
cur = next;
}
(cur, prev)
}
}
}
- Hermite polynomials are the physicists’ (leading coefficient ) or the probabilists’ monic .
- Spherical harmonics use the physics convention: is the polar angle from the axis, the azimuth.
In practice
//! Orthogonal polynomials and spherical harmonics.
//!
//! Run with `cargo run -p lib_jsl_special_functions --example special_orthogonal_polynomials`.
use lib_jsl_special_functions::{chebyshev_t, hermite, jacobi, laguerre, legendre, real_spherical_harmonic, spherical_harmonic};
fn main() {
let x = 0.3;
println!("P₅({x}) = {:.15}", legendre(5, x));
// T_n(cos t) = cos(n t).
let t: f64 = 0.7;
println!("T₇(cos 0.7) = {:.15}, cos 4.9 = {:.15}", chebyshev_t(7, t.cos()), (7.0 * t).cos());
println!("H₄(1) = {}, L₃^(½)(2) = {:.15}, P₄^(1,2)(0.5) = {:.15}", hermite(4, 1.0), laguerre(3, 0.5, 2.0), jacobi(4, 1.0, 2.0, 0.5));
// Orthogonality of Legendre polynomials, by midpoint-rule integration of P₃ P₅ and P₄².
let n = 200_000;
let h = 2.0 / n as f64;
let (mut i35, mut i44) = (0.0, 0.0);
for k in 0..n {
let x = -1.0 + (k as f64 + 0.5) * h;
i35 += legendre(3, x) * legendre(5, x) * h;
i44 += legendre(4, x).powi(2) * h;
}
println!("∫P₃P₅ = {i35:.2e}, ∫P₄² = {i44:.8} (2/9 = {:.8})", 2.0 / 9.0);
// Spherical harmonics: complex and real forms.
let y = spherical_harmonic(2, 1, 0.8, 0.3);
println!("Y₂¹(0.8, 0.3) = {:.12} {:+.12}i; real form {:.12}", y.re, y.im, real_spherical_harmonic(2, 1, 0.8, 0.3));
}
Strengths
- Stable evaluation for any degree, by recurrences.
- Normalised spherical harmonics free of overflow to very high degree.
Weaknesses
- One value at a time: no evaluation of whole expansions (Clenshaw’s algorithm) or of the zeros and weights, which the Gaussian quadrature module provides for some families.
Exercises
- Show that satisfies the Chebyshev recurrence, and deduce that on .
- Verify the orthogonality numerically with Gauss-Legendre quadrature.
- Compute by the recurrence and by its power-series coefficients, and explain the difference.
- Show that (Unsöld’s theorem) and check it numerically for .
- Evaluate the Hermite functions for at and compare computed directly with a normalised recurrence. Which overflows?
Hints and answers
- is the recurrence with . Since , for .
- With -point Gauss-Legendre quadrature the product is integrated exactly when , so the numerical inner products should match to rounding.
- . The recurrence is stable on and reproduces it to full precision; the power-series coefficients of are of order with alternating signs, so summing them loses all digits to cancellation.
- Unsöld’s theorem follows from the addition theorem for spherical harmonics at coincident points, ; for the numerical check, evaluate the sum for at several .
- Compare the magnitudes of and separately: their product is moderate while the factors differ by many orders of magnitude, so for larger or the direct product overflows or underflows. The normalised recurrence for the Hermite functions stays in range throughout.
Further reading
- G. Szegő, Orthogonal Polynomials, 4th ed., American Mathematical Society, 1975.
- W. Gautschi, Orthogonal Polynomials: Computation and Approximation, Oxford University Press, 2004.
- S. A. Holmes and W. E. Featherstone, “A unified approach to the Clenshaw summation and the recursive computation of very high degree and order normalised associated Legendre functions”, Journal of Geodesy 76 (2002) 279–299.
- NIST Digital Library of Mathematical Functions, chapters 14 and 18, https://dlmf.nist.gov/18.