Finding recursive relations in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter mnb96
  • Start date Start date
  • Tags Tags
    Mathematica Relations
Click For Summary

Discussion Overview

The discussion revolves around finding recursive relations for a sequence of polynomials defined as the k-th derivative of the exponential function of a quadratic polynomial, evaluated at zero. Participants explore methods to derive these relations using Mathematica, including both symbolic and numeric approaches.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Exploratory

Main Points Raised

  • One participant defines the polynomials P_k(x) as the k-th derivative of e^{s(x)} evaluated at x=0, where s(x) is a second-degree polynomial.
  • Another participant suggests using the SeriesCoefficient function in Mathematica to derive a recurrence relation, providing a DifferenceRoot object that represents the relation and initial conditions.
  • It is noted that both the DifferenceRoot and RecurrenceTable methods can be inefficient for symbolic functions, leading to complex expressions that are difficult to simplify.
  • A different approach is proposed for obtaining the recurrence relation without evaluating at x=0, using the SeriesCoefficient function with x as the variable.
  • One participant acknowledges the oversight of not mentioning that the provided solution relates to exponential generating functions and suggests looking into resources on generating functions for a broader understanding.
  • A later reply expresses gratitude for the insights shared, particularly regarding generating functions.

Areas of Agreement / Disagreement

Participants generally agree on the methods to derive recurrence relations but express differing views on the efficiency and complexity of the approaches used. The discussion remains unresolved regarding the optimal method for symbolic functions.

Contextual Notes

Limitations include the complexity of expressions generated by the methods discussed, particularly when dealing with symbolic functions, and the dependence on the specific form of the polynomial s(x).

mnb96
Messages
711
Reaction score
5
Hello,
I have a sequence of polynomials defined in the following way:
P_k(x) = \frac{\partial^k}{\partial x^k}e^{s(x)}\vert_{x=0}

Essentially the polynomial Pk is the k-th derivative of \exp(s(x)) evaluated at x=0. The function s(x) is a polynomial of 2nd degree in x.

In mathematica I define the polynomials with the following code:

D[Exp[s[x]], {x, k}]

For k=1..n one obtains a list of n polynomials P1(x),...,Pn(x).
My question is: is it possible to ask Mathematica to find a recurrent relation that expresses any Pk as a function of the previous polynomials Pk-1, Pk-2... ? (assuming it exists).

A similar well-known problem exists for http://en.wikipedia.org/wiki/Hermite_polynomials#Definition"

Thanks.
 
Last edited by a moderator:
Physics news on Phys.org
Try

Code:
In[1]:= s[x_] := a x^2+b x+c

In[2]:= poly[k_] = Simplify[SeriesCoefficient[Exp[s[x]], {x, 0, k}], k>0]

Out[2]= DifferenceRoot[Function[{y,n}, 
       {-2 a y[n] - b y[1+n] + (2+n) y[2+n]==0, y[0]==E^c,  y[1]==b E^c} ]]

The above shows the difference equation (recurrence relation) and the initial conditions that the polynomials must satisfy for any given quadratic s[x]. We can now use the recurrence relation to calculate the sequence. Below we compare calculating using poly[n] (the DifferenceRoot object) and Recurrence table

Code:
In[11]:= dr = Table[poly[n], {n, 0, 20}]; // Timing
         drExp = Expand[dr]; // Timing

Out[11]= {0.21, Null}
Out[12]= {1.57, Null}

In[13]:= rt = RecurrenceTable[{-2 a y[n] - b y[1 + n] + (2 + n) y[2 + n] == 0, 
               y[0] == E^c, y[1] == b E^c}, y, {n, 0, 20}]; // Timing
         rtExp = Expand[rt]; // Timing

Out[13]= {0.01, Null}
Out[14]= {1.66, Null}

In[15]:= dr == rt
Out[15]= True

In[16]:= drExp == rtExp
Out[16]= True

The problem is that both evaluating the DifferenceRoot poly[k] and using RecurrenceTable, whilst great for purely numeric functions, are horrible for symbolic functions such as the one above. the reason for this is that they don't simplify y[n] after every step and end up with a terrible mess, e.g.

Code:
In[17]:= dr[[6]]
         drExp[[6]]
Out[17]= 1/5 (2/3 a (2 a b E^c+1/2 b (2 a E^c+b^2 E^c))+1/4 b (a (2 a E^c+b^2 E^c)+1/3 b (2 a b E^c+1/2 b (2 a E^c+b^2 E^c))))
Out[18]= 1/2 a^2 b E^c+1/6 a b^3 E^c+(b^5 E^c)/120

Finally, compare calculating by taking derivatives with calculating using http://reference.wolfram.com/mathematica/tutorial/FunctionsThatRememberValuesTheyHaveFound.html" (in the latter, it's the Expand that makes the difference compared to the DifferenceRoot and RecurrenceTable options given above)

Code:
In[25]:= deriv=Table[1/k! D[Exp[s[x]], {x,k}] /. x->0, {k, 0, 100}]//Expand;//Timing
Out[25]= {0.36, Null}

In[26]:= Clear[y]
         y[n_Integer?Positive] := y[n] = 1/n (2 a y[-2+n] + b y[-1+n]) //Expand
         y[0] = E^c;
         y[1] = b E^c;

In[30]:= mem = Table[y[n], {n, 0, 100}]//Expand;//Timing
Out[30]= {0.3, Null}

In[31]:= deriv==mem
Out[31]= True
 
Last edited by a moderator:
Also, if you want the recurrence relation for the polynomials not evaluated at x=0, try

Code:
s[x_] := a x^2 + b x + c
poly[k_] = Simplify[SeriesCoefficient[Exp[s[x]], {x, x, k}], k > 0]

which returns

Code:
DifferenceRoot[Function[{y,n},
   {-2 a y[n] - (b + 2 a x) y[1+n] + (2+n) y[2+n]==0,
   y[0]==E^(c+b x+a x^2),  y[1]==(b+2 a x) E^(c+b x+a x^2)}
   ]][k]
 
I must have had my brain turned off this morning, since I didn't mention that what you supplied was an exponential generating function. Just google "generating function recursion relation" to find stuff on how to approach these problems more generally. In particular the free book "generatingfunctionology" is worth reading (not that I can remember much of it)
 
Thanks a lot for the answers!
Your hint about generating functions was also very useful. I hadn't thought about that!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K