FLINT3.7.0-dev
Algorithm

Legendre functions and orthogonal polynomials

The Legendre polynomials Pn(x)P_n(x), and more generally the classical orthogonal polynomials (Jacobi, Gegenbauer, Chebyshev, Laguerre, Hermite), are terminating hypergeometric series, for example

Pn(x)=2F1(−n,n+1;1;1−x2),Pn(a,b)(z)=(a+1)nn! 2F1(−n,n+a+b+1;a+1;1−z2).P_n(x) = {}_2F_1\left(-n, n+1; 1; \frac{1-x}{2}\right), \qquad P_n^{(a,b)}(z) = \frac{(a+1)_n}{n!}\,{}_2F_1\left(-n,n+a+b+1;a+1;\frac{1-z}{2}\right).

For integer degree they can be evaluated directly as polynomials, but for large nn this is slow and numerically unstable: the coefficients grow exponentially while ∣Pn(x)∣≤1|P_n(x)| \le 1 on [−1,1][-1,1]. FLINT has a dedicated algorithm for Pn(x)P_n(x) with real xx and word-size nn, which also gives the nodes and weights of Gauss–Legendre quadrature; the other functions use the general 2F1{}_2F_1 and 1F1{}_1F_1 code with a few direct methods for integer degrees.

Legendre polynomials#

The algorithm of arb_hypgeom_legendre_p_ui is that of Johansson and Mezzarobba [JM2018]. It computes Pn(x)P_n(x) and Pn′(x)P_n'(x) together for real xx, and by Pn(−x)=(−1)nPn(x)P_n(-x) = (-1)^n P_n(x) only x≥0x \ge 0 is needed. Four expansions are available.

  • Expansion at x=1x = 1 (arb_hypgeom_legendre_p_ui_one):

    Pn(x)=∑k=0n(nk)(n+kk)(x−12)k.P_n(x) = \sum_{k=0}^{n} \binom{n}{k}\binom{n+k}{k} \left(\frac{x-1}{2}\right)^k.

    The terms decrease quickly when ∣1−x∣|1 - x| is small, and the series can be truncated after K<n+1K < n+1 terms with a bound for the remainder.

  • Expansion at x=0x = 0 (arb_hypgeom_legendre_p_ui_zero): for even n=2mn = 2m,

    P2m(x)=(−1)m(1/2)mm! 2F1(−m,m+12;12;x2),P_{2m}(x) = (-1)^m \frac{(1/2)_m}{m!}\, {}_2F_1\left(-m, m + \tfrac12; \tfrac12; x^2\right),

    and an analogous formula with x 2F1(−m,m+32;32;x2)x\,{}_2F_1(-m, m + \frac32; \frac32; x^2) for odd nn. The terms decrease when ∣x∣|x| is small.

  • Asymptotic expansion (arb_hypgeom_legendre_p_ui_asymp): with x=cos⁡θx = \cos\theta, 0<θ<π0 < \theta < \pi, the Stieltjes series

    Pn(cos⁡θ)=4πΓ(n+1)Γ(n+32)∑k=0K−1(12)k2k! (n+32)kcos⁡((n+k+12)θ−(k+12)π2)(2sin⁡θ)k+1/2+RK,P_n(\cos\theta) = \frac{4}{\pi} \frac{\Gamma(n+1)}{\Gamma(n+\frac32)} \sum_{k=0}^{K-1} \frac{(\frac12)_k^2}{k!\,(n+\frac32)_k} \frac{\cos\left((n + k + \tfrac12)\theta - (k+\tfrac12)\tfrac{\pi}{2}\right)}{(2\sin\theta)^{k+1/2}} + R_K,

    summed as the real part of a complex series in (1−icot⁡θ)(1 - i\cot\theta), with the explicit bound ∣RK∣≤0.50795 K! n!2K(n+K)! yKny|R_K| \le 0.50795\, \frac{K!\, n!}{2^K (n+K)!\, y^K \sqrt{ny}}, y=sin⁡θy = \sin\theta, which follows from the analysis of Bogaert, Michiels and Fostier [Bog2012]. The number of terms needed decreases as nn grows; for nn much larger than the precision a handful of terms suffice, independently of nn.

  • Recurrence (arb_hypgeom_legendre_p_ui_rec): the three-term recurrence (k+1)Pk+1=(2k+1)xPk−kPk−1(k+1)P_{k+1} = (2k+1)xP_k - kP_{k-1}, evaluated in fixed-point arithmetic with machine words and a rigorous bound for the accumulated rounding error. It is stable on (−1,1)(-1, 1), costs O(n)O(n) cheap operations, and is the fastest method for moderate nn and precision.

arb_hypgeom_legendre_p_ui selects the method from estimates of the cost of each expansion: the number of terms, the precision lost to cancellation in the series at 0 and at 1 (whose terms can be much larger than Pn(x)P_n(x)), and the size of the error term of the asymptotic expansion. The recurrence is used for nn below a few hundred at low precision, unless xx is very close to 0 or 1; for ∣x∣>1|x| > 1 only the expansion at 1 is used (with an early stop if it converges quickly). The working precision is raised by the estimated cancellation, and for inexact xx the function evaluates at the midpoint and adds the error propagated from the radius rr, bounded by r⋅max⁡∣Pn′∣r \cdot \max|P_n'| and r⋅max⁡∣Pn′′∣r \cdot \max|P_n''| on the ball (arb_hypgeom_legendre_p_ui_deriv_bound, which uses ∣Pn′(x)∣≤min⁡((n+1)2/2, cn (1−x2)−3/4)|P_n'(x)| \le \min((n+1)^2/2,\ c\sqrt{n}\,(1 - x^2)^{-3/4}) and ∣Pn′′(x)∣≤min⁡((n+1)4/8, 2c n3/2(1−x2)−5/4)|P_n''(x)| \le \min((n+1)^4/8,\ 2c\, n^{3/2}(1-x^2)^{-5/4}) for ∣x∣≤1|x| \le 1, with c≥23/2/πc \ge 2^{3/2}/\sqrt\pi).

Gauss–Legendre nodes and weights#

The roots 1>x0>⋯>xn−1>−11 > x_0 > \cdots > x_{n-1} > -1 of PnP_n and the weights wk=2/((1−xk2)Pn′(xk)2)w_k = 2/((1-x_k^2)P_n'(x_k)^2) are computed by arb_hypgeom_legendre_p_ui_root: an initial approximation with an explicit error bound due to Petras [Pet1999], Newton iteration with a priori error bounds at low precision, and interval Newton iteration at doubling precisions above; each step evaluates PnP_n and Pn′P_n' with the method above, and the doubling of the precision means that the final evaluation dominates the cost. This is what makes high-degree Gauss–Legendre quadrature in acb_calc_integrate practical at high precision [JM2018]. See Roots of Legendre polynomials and Gauss–Legendre nodes.

Legendre functions#

For complex degree nn, order mm and argument zz, the associated Legendre function of the first kind is

Pnm(z)=(1+z1−z)m/2F(−n,n+1;1−m;1−z2)(type 0),Pnm(z)=(z+1z−1)m/2F(−n,n+1;1−m;1−z2)(type 1),P_n^m(z) = \left(\frac{1+z}{1-z}\right)^{m/2} \mathbf{F}\left(-n, n+1; 1-m; \frac{1-z}{2}\right) \quad\text{(type 0)}, \qquad \mathcal{P}_n^m(z) = \left(\frac{z+1}{z-1}\right)^{m/2} \mathbf{F}\left(-n, n+1; 1-m; \frac{1-z}{2}\right) \quad\text{(type 1)},

with the regularized 2F1{}_2F_1 (type 0 has cuts on (−∞,−1](-\infty, -1] and [1,∞)[1, \infty), type 1 on (−∞,1](-\infty, 1]), and the function of the second kind is

Qnm(z)=π2sin⁡(πm)(cos⁡(πm)Pnm(z)−Γ(1+m+n)Γ(1−m+n)Pn−m(z))Q_n^m(z) = \frac{\pi}{2 \sin(\pi m)} \left( \cos(\pi m) P_n^m(z) - \frac{\Gamma(1+m+n)}{\Gamma(1-m+n)} P_n^{-m}(z)\right)

(and analogously for type 1). acb_hypgeom_legendre_p evaluates the 2F1{}_2F_1 representation with acb_hypgeom_2f1, which handles the transformations needed for large ∣z∣|z|. For integers 0≤m≤n0 \le m \le n it uses instead the recurrence of acb_hypgeom_legendre_p_uiui_rec for (1−z2)−m/2Pnm(z)(1-z^2)^{-m/2}P_n^m(z), starting from PmmP_m^m and Pm+1mP_{m+1}^m, when the precision is low compared to nn, n−mn - m is small, or zz is near 1 (where the transformations are singular); real zz with m=0m = 0 goes to arb_hypgeom_legendre_p_ui. If n−m>2pn - m > 2p the recurrence would lose all accuracy and the result is indeterminate.

For integer mm, the defining formula for QnmQ_n^m is a 0⋅∞0 \cdot \infty limit, so acb_hypgeom_legendre_q uses connection formulas without the removable singularity. For type 0 it evaluates two ordinary 2F1{}_2F_1 series in z2z^2 with gamma and trigonometric prefactors [WQ3a]. For type 1 it evaluates one regularized 2F1{}_2F_1 in 1/z21/z^2 [WQ3b] when the ball zz is away from the real half-line [−1,∞)[-1, \infty) and from the square ∣Re⁡z∣,∣Im⁡z∣<1/4|\operatorname{Re} z|, |\operatorname{Im} z| < 1/4 (the formula is invalid on (−1,0)(-1, 0)), and otherwise combines the type 0 function QnmQ_n^m and Pnm\mathcal{P}_n^m [WQ3c]. (The formula [WQ3d] would also be convenient, but it is incorrect in the lower half-plane.)

The spherical harmonics

Ynm(θ,ϕ)=2n+14π(n−m)!(n+m)!eimϕPnm(cos⁡θ)Y_n^m(\theta, \phi) = \sqrt{\frac{2n+1}{4\pi} \frac{(n-m)!}{(n+m)!}} e^{im\phi} P_n^m(\cos\theta)

are polynomials in cos⁡θ\cos\theta and sin⁡θ\sin\theta, which acb_hypgeom_spherical_y evaluates with acb_hypgeom_legendre_p_uiui_rec.

Other orthogonal polynomials#

The other classical families are defined for complex degree through 2F1{}_2F_1 or 1F1{}_1F_1:

FunctionDefinitionDirect method for integer n≥0n \ge 0
Chebyshev Tn(z)T_n(z), Un(z)U_n(z)2F1(−n,n;12;1−z2){}_2F_1(-n, n; \frac12; \frac{1-z}{2}), (n+1) 2F1(−n,n+2;32;1−z2)(n+1)\,{}_2F_1(-n, n+2; \frac32; \frac{1-z}{2})acb_chebyshev_t_ui, acb_chebyshev_u_ui (word-size nn)
Jacobi Pn(a,b)(z)P_n^{(a,b)}(z)(a+1)nn! 2F1(−n,n+a+b+1;a+1;1−z2)\frac{(a+1)_n}{n!}\,{}_2F_1(-n, n+a+b+1; a+1; \frac{1-z}{2})explicit double sum for n≤pn \le p and a<−0.9a < -0.9
Gegenbauer Cnm(z)C_n^m(z)(2m)nn! 2F1(−n,2m+n;m+12;1−z2)\frac{(2m)_n}{n!}\,{}_2F_1(-n, 2m+n; m+\frac12; \frac{1-z}{2})recurrence in nn for n≤pn \le p and m<0m < 0
Laguerre Lnm(z)L_n^m(z)(m+1)nn! 1F1(−n;m+1;z)\frac{(m+1)_n}{n!}\,{}_1F_1(-n; m+1; z)recurrence in nn for n≤pn \le p and ∣m∣>n\lvert m\rvert > n
Hermite Hn(z)H_n(z)2nπ(1F1(−n2;12;z2)Γ(1−n2)−2z 1F1(1−n2;32;z2)Γ(−n2))2^n\sqrt\pi\left(\frac{{}_1F_1(-\frac n2; \frac12; z^2)}{\Gamma(\frac{1-n}{2})} - \frac{2z\,{}_1F_1(\frac{1-n}{2}; \frac32; z^2)}{\Gamma(-\frac n2)}\right)—

The direct methods cover the cases where the hypergeometric representation is singular although the polynomial is defined (the lower parameter a+1a + 1, m+12m + \frac12 or m+1m + 1 is near a nonpositive integer). For non-integer degree, the Chebyshev functions use Tν(cos⁡θ)=cos⁡(νθ)T_\nu(\cos\theta) = \cos(\nu\theta) and Uν(cos⁡θ)=sin⁡((ν+1)θ)/sin⁡θU_\nu(\cos\theta) = \sin((\nu+1)\theta)/\sin\theta (with cosh⁡\cosh for zz outside [−1,1][-1,1]) away from z=1z = 1, and the 2F1{}_2F_1 series near it.

Use in FLINT#

Referenced from#

References#

Cite this page

The FLINT team, “Legendre functions and orthogonal polynomials,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/special-functions/legendre.html (generated 2026-11-02).