+ SETUP::
+
+ sage: from mjo.orthogonal_polynomials import legendre_p
+
+ EXAMPLES:
+
+ Create the standard Legendre polynomials in `x`::
+
+ sage: legendre_p(0,x)
+ 1
+ sage: legendre_p(1,x)
+ x
+
+ Reuse the variable from a polynomial ring::
+ sage: P.<t> = QQ[]
+ sage: legendre_p(2,t)
+ 3/2*t^2 - 1/2
+
+ If ``x`` is a real number, the result should be as well::
+
+ sage: legendre_p(3, 1.1)
+ 1.67750000000000
+
+ Similarly for complex numbers::
+
+ sage: legendre_p(3, 1 + I)
+ 7/2*I - 13/2
+
+ Even matrices work::
+
+ sage: legendre_p(3, MatrixSpace(ZZ, 2)([1, 2, -4, 7]))
+ [-179 242]
+ [-484 547]
+
+ And finite field elements::
+
+ sage: legendre_p(3, GF(11)(5))
+ 8
+
+ Solve a simple least squares problem over `[-\pi, \pi]`::
+
+ sage: a = -pi
+ sage: b = pi
+ sage: def inner_product(v1, v2):
+ ....: return integrate(v1*v2, x, a, b)
+ sage: def norm(v):
+ ....: return sqrt(inner_product(v,v))
+ sage: def project(basis, v):
+ ....: return sum( inner_product(v, b)*b/norm(b)**2
+ ....: for b in basis)
+ sage: f = sin(x)
+ sage: legendre_basis = [ legendre_p(k, x, a, b) for k in range(4) ]
+ sage: proj = project(legendre_basis, f)
+ sage: proj.simplify_trig()
+ 5/2*(7*(pi^2 - 15)*x^3 - 3*(pi^4 - 21*pi^2)*x)/pi^6
+