This is a version of the Rodrigues Formula

Pl(x)=((-1)^m)*((1-(x^2))^(m/2))/((2^l)*(l!))*D[((x^2)-1)^l,{x,(l+m)}]

where x=cos(theta)