How do I ask Mathematica to try to solve a recursive relation that defines a sequence of functions? For example, suppose I know that $g_n(x) = g_{n-1}'(x)$ for $n > 0$ and that $g_0(x) = e^{2x}$. How can I ask Mathematica to find a closed form for $g_n(x)$? (This is just a placeholder equation to highlight my question; I know the answer of $g_n(x) = 2^n e^{2x}$, $n\geq 0$.)

A less trivial instance of the problem would be the Hermite polynomial recursion, $$H_{n+1}(x) = 2xH_n(x) - H_n'(x)$$

I don't see how to convince either DSolve or RSolve to solve it for me. DSolve is unhappy because $n-1$ is used on the RHS:

DSolve[{g[n, x] == 2*D[g[n - 1, x], x]}, g, {n, x}]

RSolve just echoes my input:

RSolve[{g[n, x] == 2*D[g[n - 1, x], x], g[0, x] == Exp[2*x]}, g, {n, x}]

I know finding a closed-form solution is going to be hopeless in most instances, but it seems like some cases like the above $g_n(x)$ should be doable. I have been unable to find any examples in the Mathematica documentation addressing this type of problem.

  • $\begingroup$ Are you looking for a closed form solution in terms of $n$, or you just want to compute the result for each $n$ successively? $\endgroup$
    – Szabolcs
    Apr 24, 2012 at 15:38
  • 1
    $\begingroup$ You may look here, for recursive definitions of Hermite polynomials : mathematica.stackexchange.com/questions/4652/… $\endgroup$
    – Artes
    Apr 24, 2012 at 15:42
  • $\begingroup$ I tried Solve[{Series[g[n, x], {x, 0, 5}, {n, 0, 5}] == Series[2*D[g[n - 1, x], x], {x, 0, 5}, {n, 0, 5}]}, g, {n, x}] but didn't found the solution. I think you will try to search a closed form asymptotically. $\endgroup$
    – GarouDan
    Apr 24, 2012 at 16:33
  • $\begingroup$ @Szabolcs I'm looking for closed forms. I know that g=Table[0,{t,0,10}]; g[[1]]=Exp[2*x]; Table[g[[i+1]]=D[g[[i]],x],{i,1,9}] will compute the result (I'm sure there are more elegant ways). Artes Thanks. I'm more interested in how to deal with this paradigm rather than Hermite polynomials in particular. $\endgroup$
    – UVW
    Apr 24, 2012 at 17:01

2 Answers 2


For the simple example in the question, FindSequenceFunction can be used to infer the general form:


Out[3]= 2^n E^(2 x)
  • 1
    $\begingroup$ +1 Really nice. The sentence For the simple example in the question should not be taken lightly, as FindInstance is not able to find many "easy" sequences. $\endgroup$ Apr 24, 2012 at 21:53
  • $\begingroup$ Thanks, @Simon. It was probably unreasonable of me to hope for more. This looks like a reasonable approach. $\endgroup$
    – UVW
    Apr 25, 2012 at 16:35

This is recursion, not solution-finding. That makes it fast and straightforward. For instance, the Hermite polynomial example, with memoization of the function (not just of its values at previous arguments of $x$), might look like this (although I'm sure the real experts can find a more elegant way to accomplish the same thing):

g[n_Integer, x_] := g[n][x];
g[0] = Function[{x}, 0];
g[1] = Function[{x}, 1];
g[n_Integer][x_] := With[{},
  g[n] = Function[{y}, Evaluate@ Expand[2 y g[n - 1, y] - D[g[n - 1, y], y]]];

After executing, say,

In[2]:= g[5,x]
Out[2]= 12 - 48 x^2 + 16 x^4

the definition of g will be

? g

g[n_Integer][x_]:=With[{},g[n]=Function[{y},Evaluate[Expand[2 y g[n-1,y]-\!\(
\*SubscriptBox[\(\[PartialD]\), \(y\)]\(g[n - 1, y]\)\)]]];g[n][x]]

g[2]=Function[{y$},2 y$]
g[3]=Function[{y$},-2+4 y$^2]
g[4]=Function[{y$},-12 y$+8 y$^3]
g[5]=Function[{y$},12-48 y$^2+16 y$^4]

There are your closed forms.

  • $\begingroup$ Those are just closed-forms for particular values of $n$. I thought the O.P. wanted a closed-form expression as a function of $n$ (and $x$, of course). $\endgroup$
    – murray
    Apr 24, 2012 at 19:34
  • $\begingroup$ In most cases, there's no such thing, @Murray. Examples are the classical functions of mathematical physics: the polynomials of Hermite, Lagrange, Chebyshev, Laguerre, Legendre, etc. Usually these have to be found via recursion rather than in closed form or if not, it's still simpler just to use the recursion (and other relationships among the polynomials). When you look at general differential-difference equations the situation gets even worse. $\endgroup$
    – whuber
    Apr 24, 2012 at 19:49
  • $\begingroup$ @whuber Thanks, that is certainly helpful to see more sophisticated syntax than I know. murray is correct that I'm looking for closed form for all n simultaneously. Sure, such answers are rare. But if my equation could expressed, say, in terms of one of these classic families, it would be nice if Mathematica could tell me that. I was hoping that I could at least ask Mathematica to try. But your point that it's simpler to just work with the recursion is well taken. $\endgroup$
    – UVW
    Apr 24, 2012 at 19:59
  • $\begingroup$ OK, thanks for the clarification @UVW. Nevertheless, often a list of solutions can be a good start: you can then pick out the coefficients of the components of the solutions and search for closed forms using FindSequenceFunction and their ilk. Sometimes it works! $\endgroup$
    – whuber
    Apr 24, 2012 at 20:14
  • $\begingroup$ @whuber: yes, I'm well aware of the limitations on finding closed-form expressions (at least in terms of functions that are "elementary" in the technical sense of the term)! It was the O.P. who asked about such. $\endgroup$
    – murray
    Apr 25, 2012 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.