# Coding of the Legendre polynomial and the infinite sum using python

I'm looking to code the following function:

$$|g(\theta)=\frac{1}{2k}\sum_{\ell=0}^{\infty} (2\ell +1)\sin(2\delta_{\ell})P_{\ell}\cos(\theta)|^2$$

 import numpy as np

import scipy.special as sp

def Legendre(n,x):
x=np.array(x)
if (n==0):
return x*0+1.0
elif (n==1):
return x
else:
return ((2.0*n-1.0)*x*Legendre(n-1,x)-(n-1)*Legendre(n-2,x))/n
def RealFn(x):
"""
Fuction to evaluate the Real element of Phase Shift
"""
# Test for valid input
if (x<0):
print("Error: x must be non negative");
return
RealFn = (1/(2*k)*(?)(2*l + 1)*np.sin(2*delta)*Legendre(??)*np.cos(x))**2
return RealFn
`

If anyone can help me with the coding of the Legendre Polynomial and the infinite sum I'd really appreciate it!

The value of $$\delta$$ is known also so that's just a simple input.

I believe I'm missing bounds for $$\theta$$ also.