# LegendreP

LegendreP refers to the Legendre function and to the Legendre polynomial.

## Legendre polynomial

The Legendre polynomial $$\mathrm{LegendreP}_{\ell}$$ can be defined with the Rodrigues formula

$$\displaystyle \mathrm{LegendreP}_\ell(z) = \frac{1}{2^\ell \ell !} \frac{\mathrm d\, (z^2\!-\!1)^\ell } {\mathrm d z\, ^\ell}$$

In Mathematica, the polynomials above are denoted with identifier LegendreP

In C++, for integer values of subscript, evaluation of the coefficients of the polynomial can be performed with the code shown in the example below:

#include<math.h>
#include<stdio.h>
#define DO(x,y) for(x=0;x<y;x++)
#define DB double
#define N 12
int BC[N+1][N+1]; // Binomial coefficients;
int main(){ int m,n,k,l;
DO(n,N+1){BC[n][0]=1; BC[n][1]=n; BC[n][n]=1;} // Pascal triangle
for(m=2;m<N+1;m++)
for(n=2;n<N;n++) BC[m][n]=BC[m-1][n-1]+BC[m-1][n];
DO(m,N+1){ DO(n,N+1) printf("%4d ",BC[m][n]);
printf("\n");}
DB L[N+1][2*N+2]; DO(n,N+1) DO(m,2*N+2) {L[n][m]=0;}
DO(n,N+1){l=pow(-1,n); for(k=0;k<=n;k++){ L[n][2*k]=BC[n][k]*l; l=-l;}}
DO(n,N+1){ DO(k,2*N+1){ printf("%4.0lf ",L[n][k]);} printf("\n");}
DO(n,N+1){DO(m,n)
DO(l,2*N) L[n][l]=L[n][l+1]*(l+1)/2./(m+1);
} // n differentiations and normalization
DO(n,N+1){ DO(k,n+1) printf("%10.4f",L[n][k]); printf("\n");}
} // end of program

The output is

1.0000
0.0000 1.0000
-0.5000 0.0000 1.5000
0.0000 -1.5000 0.0000 2.5000
0.3750 0.0000 -3.7500 0.0000 4.3750
0.0000 1.8750 0.0000 -8.7500 0.0000 7.8750
-0.3125 0.0000 6.5625 0.0000 -19.6875 0.0000 14.4375
0.0000 -2.1875 0.0000 19.6875 0.0000 -43.3125 0.0000 26.8125
0.2734 0.0000 -9.8438 0.0000 54.1406 0.0000 -93.8438 0.0000 50.2734
0.0000 2.4609 0.0000 -36.0938 0.0000 140.7656 0.0000 -201.0938 0.0000 94.9609
-0.2461 0.0000 13.5352 0.0000 -117.3047 0.0000 351.9141 0.0000 -427.3242 0.0000 180.4258
0.0000 -2.7070 0.0000 58.6523 0.0000 -351.9141 0.0000 854.6484 0.0000 -902.1289 0.0000 344.4492
0.2256 0.0000 -17.5957 0.0000 219.9463 0.0000 -997.0898 0.0000 2029.7900 0.0000-1894.4707 0.0000 660.1943

It can be verified with Mathematica code
N[Table[Expand[D[(x^2-1)^n/2^n/n!, {x, n}]], {n,0,12}], 7]

or
N[Table[Expand[LegendreP[n, x]], {n,0,12}], 7]

that both do the same
{1.000000,
x,
-0.5000000 + 1.500000 x^2,
-1.500000 x + 2.500000 x^3,
0.3750000 - 3.750000 x^2 + 4.375000 x^4,
1.875000 x - 8.750000 x^3 + 7.875000 x^5,
-0.3125000 + 6.562500 x^2 - 19.68750 x^4 + 14.43750 x^6,
-2.187500 x + 19.68750 x^3 - 43.31250 x^5 + 26.81250 x^7,
0.2734375 - 9.843750 x^2 + 54.14063 x^4 - 93.84375 x^6 + 50.27344 x^8,
2.460938 x - 36.09375 x^3 + 140.7656 x^5 - 201.0938 x^7 + 94.96094 x^9,
-0.2460938 + 13.53516 x^2 - 117.3047 x^4 + 351.9141 x^6 - 427.3242 x^8 + 180.4258 x^10,
-2.707031 x + 58.65234 x^3 - 351.9141 x^5 + 854.6484 x^7 - 902.1289 x^9 + 344.4492 x^11,
0.2255859 - 17.59570 x^2 + 219.9463 x^4 - 997.0898 x^6 + 2029.790 x^8 - 1894.471 x^10 + 660.1943 x^12}

## Legendre function

Then, the Legendre function $$\mathrm{LegendreP}_{\ell,m}$$ appears as

$$\displaystyle \mathrm{LegendreP}_{\ell,m}(x) = (-1)^m \Big(1\!-\!x^2\Big)^{m/2} \frac{\mathrm d\, \mathrm{LegendreP}_{\ell}(x)} {\mathrm d x\,^m}$$

In such a way, $$\mathrm{LegendreP}_{\ell,0}=\mathrm{LegendreP}_{\ell}$$

## Legendre equation

Function $$P_{\ell, m}=\mathrm{LegendreP}_{\ell,m}$$ satisfies the Legendre equation

$$\displaystyle (1\!-\!x^2) P_{\ell,m}^{~\prime\prime}(x) - 2 x P_{\ell,m}^{~\prime}(x) +\left( \ell (\ell+1) - \frac{m^2}{1\!-\!x^2} \right) P_{\ell,m}(x) =0$$

## Usage

The Legendre function is used to construct the Hydrogen wave function.

Argument of function $$\mathrm{LegendreP}_{\ell, m}$$ has sense of $$\cos(\theta)$$, if the azimuthal angle $$\theta$$ ix measured from the "z" avis, and sense of $$\sin(\theta)$$, if the angle is counted from the equatorial plane; $$\ell$$ has sense of the orbital momentum od the corresponding wave function, and $$m$$ has sense of projection of the orbital moment on the axis of symmetry of the wave function. Parameter $$m$$ is called also magnetic quantum number.