3.5: Recurrence Relations
( \newcommand{\kernel}{\mathrm{null}\,}\)
A recurrence relation defines a sequence {ai}∞i=0 by expressing a typical term an in terms of earlier terms, ai for i<n. For example, the famous Fibonacci sequence is defined by
F0=0,F1=1,Fn=Fn−1+Fn−2.
Note that some initial values must be specified for the recurrence relation to define a unique sequence.
The starting index for the sequence need not be zero if it doesn't make sense or some other starting index is more convenient. We saw two recurrence relations for the number of derangements of [n]:
D1=0,Dn=nDn−1+(−1)n.
and
D1=0,D2=1,Dn=(n−1)(Dn−1+Dn−2).
To "solve'' a recurrence relation means to find a formula for an. There are a variety of methods for solving recurrence relations, with various advantages and disadvantages in particular cases. One method that works for some recurrence relations involves generating functions. The idea is simple, if the execution is not always: Let
f(x)=∞∑i=0aixi,
that is, let f(x) be the generating function for {ai}∞i=0. We now try to manipulate f(x), using the recurrence relation, until we can solve for f(x) explicitly. Finally, we hope that we can find a formula for the coefficients from the formula for f(x).
Solve F0=0, F1=1, Fn=Fn−1+Fn−2.
Solution
Let f(x)=∞∑i=0Fixi
and note that
xf(x)=∞∑i=0Fixi+1=∞∑i=1Fi−1xi.
To get the second sum we have simply "re-indexed'' so that the index value gives the exponent on x, just as in the series for f(x). Likewise,
x2f(x)=∞∑i=0Fixi+2=∞∑i=2Fi−2xi.
In somewhat more suggestive form, we have
f(x)=x+F2x2+F3x3+F4x4+⋯xf(x)=x2+F2x3+F3x4+⋯x2f(x)=x3+F2x4+⋯
and combining the three equations we get
f(x)−xf(x)−x2f(x)=x+(F2−1)x2+(F3−F2−1)x3+(F4−F3−F2)x4+⋯
or in more compact form
f(x)−xf(x)−x2f(x)=∞∑i=0Fixi−∞∑i=1Fi−1xi−∞∑i=2Fi−2xi=x+∞∑i=2(Fi−Fi−1−Fi−2)xi=x+∞∑i=20⋅xi=x,
recalling that F0=0 and F1=1. Now
f(x)=x1−x−x2=−xx2+x−1.
If we can find an explicit representation for the series for this function, we will have solved the recurrence relation. Here is where things could go wrong, but in this case it works out. Let a and b be the roots of x2+x−1; using the quadratic formula, we get a=−1+√52,b=−1−√52. Borrowing a technique from calculus, we write
−xx2+x−1=Ax−a+Bx−b.
Solving for A and B gives
A=1−√52√5,B=−1−√52√5.
Then
−xx2+x−1=−Aa11−x/a−Bb11−x/b.
From calculus we know that
11−x/a=∞∑i=0(1/a)ixiand11−x/b=∞∑i=0(1/b)ixi.
Finally, this means the coefficient of xi in the series for f(x) is
Fi=−Aa(1/a)i−Bb(1/b)i.
Simplifying gives
Fi=1√5(1+√52)i−1√5(1−√52)i.
Sage can solve many recurrence relations; this allows us to check our answers. Sometimes the format may be a bit different than what you get by hand.
1 | from sympy import Function, rsolve |
2 | from sympy.abc import n |
3 | y = Function( 'y' ) |
4 | g = y(n) - y(n - 1 ) - y(n - 2 ) |
5 | rsolve(g, y(n), { y( 0 ): 0 , y( 1 ): 1 }) |
Here's an interesting feature of this expression: since |(1−√5)/2|<1, the limit of ((1−√5)/2)i as i goes to infinity is 0. So when i is large,
Fi=round(1√5(1+√52)i),
that is, the first term rounded to the nearest integer. As it turns out, this is true starting with i=0.
We can check this in Sage.
1 | f(x) = (( 1 + sqrt( 5 )) / 2 )^x / sqrt( 5 ) |
2 | [ round (N(f(i))) for i in range ( 0 , 21 )] |
You can see how to do the entire solution in Sage.
We can also use this expression for Fn to compute limn→∞Fn/Fn−1.
limn→∞FnFn−1=limn→∞1√5(1+√52)n−1√5(1−√52)n1√5(1+√52)n−1−1√5(1−√52)n−1=1+√52.
This is the so-called "golden ratio''.