fn

legendre_polynomial_p

Tensor
legendre_polynomial_p(x: Tensor, n: int)
source

Legendre polynomial Pn(x)P_n(x).

The Legendre polynomials are orthogonal on [1,1][-1, 1] with uniform weight, and serve as the angular eigenfunctions of the Laplacian on the sphere (spherical harmonics with m=0m = 0) and as a basis for Gauss-Legendre quadrature.

Parameters

xTensor
Argument tensor; any floating-point dtype. Customarily evaluated on [1,1][-1, 1].
nint
Non-negative polynomial degree.

Returns

Tensor

Pn(x)P_n(x) element-wise, same shape and dtype as x.

Notes

Bonnet recurrence:

P0(x)=1,P1(x)=x,(k+1)Pk+1(x)=(2k+1)xPk(x)kPk1(x).P_0(x) = 1, \quad P_1(x) = x, \quad (k+1)\, P_{k+1}(x) = (2k + 1)\, x\, P_k(x) - k\, P_{k-1}(x).

On [1,1][-1, 1], Pn(x)1|P_n(x)| \le 1 with boundary values Pn(1)=1P_n(1) = 1, Pn(1)=(1)nP_n(-1) = (-1)^n. Raises ValueError for n < 0.

Examples

>>> import lucid
>>> from lucid.special import legendre_polynomial_p
>>> legendre_polynomial_p(lucid.tensor([-1.0, 0.0, 0.5, 1.0]), n=3)
Tensor([-1.0000, 0.0000, -0.4375, 1.0000])