Why does this raise an error
P[0, x_] := 1
P[1, x_] := x
P[n_, x_] := ((2 n - 1)/n)*x*P[n - 1, x] - ((n - 1)/n)*P[n - 2, x]
Simplify[P[n, x]] /. n -> 2
(*$RecursionLimit::reclim: Recursion depth of 256 exceeded. >>*)
But this does not
P[0, x_] := 1
P[1, x_] := x
P[n_, x_] := ((2 n - 1)/n)*x*P[n - 1, x] - ((n - 1)/n)*P[n - 2, x]
Simplify[P[2, x]]
1/2 (-1 + 3 x^2)
More generally how does one generate a list of 1000 polynomials from this recursion? All of the following still seem to raise errors.
Unevaluated@P[n, x] /. n -> {2, 3}
Simplify[Unevaluated@P[n, x] /. n -> {2, 3}]
Simplify[Unevaluated@P[n, x]] /. n -> {2, 3}
{Unevaluated@P[n, x] /. n -> z} /. z -> {2, 3}
If my questions indicate that I am not familiar with mathematica, it is because I am not. :-)
Simplify[P[n, x]]Mathematica enter the infinite recursion (ie, before the replacement occurs) – acl Dec 18 '12 at 22:50Simplify[Unevaluated@P[n, x] /. n -> 2]– Artes Dec 18 '12 at 22:54P[n_Integer, x] := .... But as acl notes, you still can't simplify before you give it a value. – wxffles Dec 18 '12 at 23:01Table[P[n, x], {n, 2, 10}]. As for udnerstanding, given the explanation @ssch gave, you should be able to work out why your attempt didn't work. – acl Dec 19 '12 at 0:04