# Unexpected behaviour of SeriesCoefficient?

Following this question/answer I discovered and played with SeriesCoefficient. In particular, I tried

SeriesCoefficient[Exp[λ x - x^2], {x, 0, n}]


which nicely returns

(* Piecewise[{{HermiteH[n, λ/2]/n!, n >= 0}}, 0] *)


Question

On the other hand, why does

SeriesCoefficient[Exp[ x - x^2], {x, 0, n}]


(a special case of the above) returns

(* Piecewise[
{{DifferenceRoot[Function[
{\[FormalY], \[FormalN]},
{2*\[FormalY][\[FormalN]] - \[FormalY][1 + \[FormalN]] +
(2 + \[FormalN])*\[FormalY][2 + \[FormalN]] ==
0, \[FormalY][0] == 1, \[FormalY][1] ==
1}]][n], n >= 0}}, 0] *)


An interesting observation is that the difference in output doesn't even depend on the value of the parameter $\lambda$. Instead, it depends on the form of the exponential:

SeriesCoefficient[Exp[(λ - x) x], {x, 0, n}]


SeriesCoefficient[Exp@Expand[(λ - x) x], {x, 0, n}]


So it looks like SeriesCoefficient picks different solution methods right from the start based on the form of the input, even though it doesn't have attribute Holdall or similar. The reason for this may have to do with the fact that there are different methods for special functions, and which of them is recognized as the most promising at the start depends on the initial form. That's all I can come up with. The upshot: for this functionality, $e^{x(\lambda -x)}$ is not the same as $e^{\lambda x-x^2}$.

• +1 Thanks for your observations. I was hoping someone from Wolfram would acknowledge this as a bizarre feature. Commented Mar 21, 2013 at 21:46

This is strange - because I haven't seen so many dots as the ones spat out in the DifferenceRoot (they are, documentation tells me, formal parameters never to be assigned a value. If anyone can add an answer with a mini-tutorial on how they are used, it would be appreciated. There's a few answers here with further explanation).

In any case, it doesn't seem to be wrong:

h1[n_]:=HermiteH[n, 1/2]/(n!)


which is what you expect as a special solution of your second case, and

h2[n_]:=DifferenceRoot[
Function[{\[FormalY], \[FormalN]}, {2 \[FormalY][\[FormalN]] - \[FormalY][
1 + \[FormalN]] + (2 + \[FormalN]) \[FormalY][
2 + \[FormalN]] == 0, \[FormalY][0] == 1, \[FormalY][1] ==
1}]][n]


which is what you actually get and looks intimidatingly like

seem to agree:

Table[h1[n] == h2[n], {n, 0, 100}]


Looking a bit at the documentation and the form of the second output, it seems that the DifferenceRoot expression is a recursive definition for the Hermite polynomial at the specific point but I can't offer you a proof more than the fact that they agree for the first few hundred values of n.

---EDIT---

As per your comments, I have no clue why this doesn't get "seen" as a Hermite polynomial. My guess was that at x=1/2, n! gets suspiciously cancelled at all terms of the series but it would be strange for Mathematica to not hold the expression before doing any pattern matching.

For the record, I insist this is not a wrong result mathematically (the recursive definition for Hermite at x=1/2 would be

    myh[n_] := DifferenceRoot[
Function[{\[FormalY], \[FormalN]},
{\[FormalY][\[FormalN] + 1] - \[FormalY][\[FormalN]] + 2 (\[FormalN]) \[FormalY][\[FormalN] - 1] == 0,
\[FormalY][0] == 1, \[FormalY][1] == 1}]][n]


and the series given is myh[n]/n! but I think I see your point and I agree - in terms of Mathematica evaluation the result is, well... wrong. Evaluating the second expression takes twenty+ times longer:

Divide @@ ({AbsoluteTiming[h2[i];], AbsoluteTiming[h1[i];]} /.
i -> 1000) // First
(*24.*)


I'll keep the answer up for a couple of days and then delete.

• Re: formal symbols, these posts should give you a good idea of the applications: (search result) Commented Mar 20, 2013 at 10:27
• I'm not voting for this answer, yet, because I think the real question is why doesn't Mathematica simplify the DifferenceRoot object to the shorter HermiteH form. Commented Mar 20, 2013 at 10:30
• Thanks for checking! I am after why it fails to give a closed form. It seems to me its a sort of shortcoming? Commented Mar 20, 2013 at 11:08
• @Mr.Wizard thanks for the link - searching for "formal parameters" gave poorer results than "formal symbols".I've edited accordingly
– gpap
Commented Mar 20, 2013 at 11:45