Skip to content

LegendrePolynomial ​

The Legendre polynomial Pn(x)P_n(x), orthogonal on [−1,1][-1, 1] with unit weight and normalised by Pn(1)=1P_n(1) = 1. Provided by @enumeratio/analytic.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaLegendre polynomialsMathWorldLegendrePolynomialDLMF18.3.T1.t1.r10FungrimLegendrePolynomial✓Fungrim entryWolfram LanguageLegendreP✓
LegendrePolynomial(n, x)the degree-nn Legendre polynomial at xx, for an integer nn.
Typed signatures
TypePackageApplies
(integer, number) -> numberanalyticalways

Domain: Special functions

Details
  • P0=1P_0 = 1, P1=xP_1 = x, and Bonnet's recurrence (n+1) Pn+1=(2n+1) x Pn−n Pn−1(n+1)\,P_{n+1} = (2n+1)\,x\,P_n - n\,P_{n-1}. The coefficients are rationals whose denominators are powers of 2.
  • ∫−11Pm(x) Pn(x) dx=22n+1 δmn\int_{-1}^{1} P_m(x)\,P_n(x)\,dx = \dfrac{2}{2n+1}\,\delta_{mn}.
  • Pn(1)=1P_n(1) = 1 and Pn(−1)=(−1)nP_n(-1) = (-1)^n. Parity follows the degree: Pn(−x)=(−1)nPn(x)P_n(-x) = (-1)^n P_n(x).
  • A negative order folds as Wolfram does: P−n=Pn−1P_{-n} = P_{n-1}.
  • At an integer nn and a symbolic or exact xx the result is the expanded polynomial. At a floating-point or complex xx the recurrence runs directly on the number.
  • The name is Fungrim's. Wolfram calls it LegendreP, which also takes a non-integer degree and, with three arguments, the associated functions; only the integer-degree polynomial is implemented here.

Examples

7 more kept as data, checked against the oracles
Basic #

P2(x)=12(3x2−1)P_2(x) = \tfrac12(3x^2 - 1)

live ↗
InLegendrePolynomial(2,x)\mathrm{LegendrePolynomial}(2, x)Out3x22−12\frac{3x^2}{2}-\frac{1}{2}

P3(x)=12(5x3−3x)P_3(x) = \tfrac12(5x^3 - 3x)

live ↗
InLegendrePolynomial(3,x)\mathrm{LegendrePolynomial}(3, x)Out5x32−3x2\frac{5x^3}{2}-\frac{3x}{2}

P4(x)=18(35x4−30x2+3)P_4(x) = \tfrac18(35x^4 - 30x^2 + 3)

live ↗
InLegendrePolynomial(4,x)\mathrm{LegendrePolynomial}(4, x)Out35x48−15x24+38\frac{35x^4}{8}-\frac{15x^2}{4}+\frac{3}{8}

At a floating-point xx

live ↗
InLegendrePolynomial(5,0.7)\mathrm{LegendrePolynomial}(5, 0.7)Out−0.365 198 749 999 999 9-0.365\,198\,749\,999\,999\,9
Scope #

At a rational xx the value is an exact rational

live ↗
InLegendrePolynomial(3,12)\mathrm{LegendrePolynomial}(3, \frac{1}{2})Out−716-\frac{7}{16}

At a Gaussian integer

live ↗
InLegendrePolynomial(3,2+3i)\mathrm{LegendrePolynomial}(3, 2+3i)Out−118+18i-118+18i

A symbolic order stays unevaluated

live ↗
InLegendrePolynomial(n,x)\mathrm{LegendrePolynomial}(n, x)OutLegendrePolynomial(n,x)\mathrm{LegendrePolynomial}(n, x)
Properties #

Pn(1)=1P_n(1) = 1

live ↗
InLegendrePolynomial(6,1)\mathrm{LegendrePolynomial}(6, 1)Out11

Pn(−1)=(−1)nP_n(-1) = (-1)^n

live ↗
InLegendrePolynomial(5,−1)\mathrm{LegendrePolynomial}(5, -1)Out−1-1

P2m(0)=(−1)m(2mm)/4mP_{2m}(0) = (-1)^m \binom{2m}{m}/4^m, here (42)/16\binom42/16

live ↗
InLegendrePolynomial(4,0)\mathrm{LegendrePolynomial}(4, 0)Out38\frac{3}{8}

Bonnet's recurrence (n+1)Pn+1=(2n+1)xPn−nPn−1(n+1)P_{n+1} = (2n+1)xP_n - nP_{n-1}, at n=3n = 3, x=3x = 3

live ↗
In4LegendrePolynomial(4,3)=7×3LegendrePolynomial(3,3)−3LegendrePolynomial(2,3)4\mathrm{LegendrePolynomial}(4, 3)=7×3\mathrm{LegendrePolynomial}(3, 3)-3\mathrm{LegendrePolynomial}(2, 3)OutTrue\mathrm{True}

A negative order folds: P−n=Pn−1P_{-n} = P_{n-1}

live ↗
InLegendrePolynomial(−3,x)\mathrm{LegendrePolynomial}(-3, x)Out3x22−12\frac{3x^2}{2}-\frac{1}{2}
About
Examples19
Checked againstWolfram Language 19 agree
CrosswalkWikipediaMathWorldDLMFFungrimFungrim entry ×23Wolfram Language

Implementation

primitive · kernela kernel — an algorithm over mutable state that would not be readable as a tree

nativeenginetypescriptpackages/symbols/analysis/analytic/src/legendre.ts
mappedexternalwolfram / mpmath / sympypackages/oracle/src/mappings.ts

LegendreP[n, x]; mpmath.legendre(n, x); sympy.legendre(n, x).

See also: ChebyshevT, ChebyshevU