4 #include "base/cl_sysdep.h"
7 #include "cln/univpoly_rational.h"
12 #include "cln/integer.h"
13 #include "cln/rational.h"
17 const cl_UP_RA legendre (sintL n)
19 // The Legendre polynomials P_n(x) are defined as
22 // P_n(x) = ------ (----) (x^2 - 1)
25 // They satisfy the recurrence relation
28 // P_{n+1}(x) = 1/(n+1) * ((2n+1)x P_n(x) - n P_{n-1}(x)) for n >= 0.
31 // P_n(x) satisfies the differential equation
32 // (1-x^2)*P_n''(x) - 2x*P_n'(x) + (n^2+n)*P_n(x) = 0.
34 // Proof: See elsewhere.
37 // The coefficients c_{n,k} of P_n(x) = sum(k=0..n, c_{n,k} x^k)
39 // c_{n,n} = (2n)!/(n!^2 2^n),
41 // c_{n,k} = (k+1)(k+2)/(k-n)(k+n+1)*c_{n,k+2}
43 // It follows that for n>=0
45 // P_n(x) = sum(j=0..floor(n/2), (-1)^j (2n-2j)!/j!(n-2j)!(n-j)! 2^-n x^(n-2j))
47 var cl_univpoly_rational_ring R = find_univpoly_ring(cl_RA_ring);
48 var cl_UP_RA p = R->create(n);
49 var cl_I denom = ash(1,n);
51 var cl_I c_k = binomial(2*n,n);
53 p.set_coeff(k,c_k/denom);
57 c_k = exquo((cl_I)(k+1) * (cl_I)(k+2) * c_k,
58 (cl_I)(k-n) * (cl_I)(k+n+1));