Fibonacci's recurrence is easy to run and hard to solve: unrolling it doubles the work at every step, and its values suggest no formula to guess.
The previous lesson set up recurrences, rules that give each term of a sequence from earlier ones, and solved the simple ones by unrolling, or by guessing a formula and proving it by induction. Both methods stalled on the Fibonacci numbers , which also count the bit strings with no two consecutive 1s, and left one clue: the ratio of consecutive terms settles near , as if the sequence grew like a power. This lesson follows the clue to a method that solves every recurrence of that shape, then extends it to recurrences with an extra term, the Tower of Hanoi's among them.
Trying a power
A recurrence is linear with constant coefficients if each term is a fixed combination of the terms before it, , where the numbers do not depend on . The number is the order, and it is also how many initial conditions are needed. It is homogeneous, meaning nothing is added beyond the combination; a later section adds something.
Geometric sequences reproduce themselves under a shift: shifted back by one is , the same sequence divided by . So try with in the order recurrence . It needs for every , and dividing by removes altogether:
This is the characteristic equation. For order it reads , and each root gives a solution , though not yet one that meets the initial conditions.
For the equation is , so and both satisfy the recurrence. Check one: .
Two roots, two constants
The recurrence is linear, and that supplies the second ingredient. If and both satisfy it, so does for any constants and : multiply the equation for by , the one for by , and add. So when the characteristic equation has distinct roots and , every sequence
satisfies the recurrence, and the constants are free to meet the initial conditions. Setting and gives and . Subtracting times the first from the second leaves , solvable precisely because , and then .
That settles every such recurrence, not just some. The fitted formula and the true sequence agree at and , and both compute each term from the two before it by the same rule, so by induction they agree forever. The formula is the solution, and the characteristic equation has missed nothing. Always check a fitted formula against the first few terms, since that catches almost every slip in the fit.
Example. A path unit wide and units long is paved with square tiles in colours and dominoes, by , in colours. Find a formula for the number of pavings, and the number for length .
Sort the pavings by the last tile. A square, in colours, leaves any paving of length ; a domino, in colours, leaves any paving of length . So , with (the empty path has one paving) and . The characteristic equation has roots and , so . The conditions and give and :
Check: the recurrence gives and , and the formula gives and . So . Fractional constants are normal: the recurrence guarantees integers.
Now you. Solve with and , check against and , and find .
Answer
The equation has roots and . Then and give , , so . The recurrence gives and ; the formula gives and . So .
Binet's formula
For the characteristic equation is , with roots
The first is the golden ratio, the the ratios were approaching (the letter has nothing to do with the totient of an earlier lesson). Their difference is .
The roots are distinct, so . The condition gives , and then gives , so . Therefore
This is Binet's formula, published by Jacques Binet in 1843, though Abraham de Moivre and Daniel Bernoulli had it more than a century before. A formula full of that returns an integer for every looks miraculous, but expanding and by the binomial theorem shows why: the terms with even powers of cancel in the difference, and each survivor carries exactly one to cancel the denominator.
The formula also finishes a count from the previous lesson. Bit strings of length with no two consecutive 1s number , so length has of them among strings, and each extra bit multiplies the count by about , where unrestricted strings double.
The nearest integer
Since , the powers shrink towards zero, alternating in sign: . So the second term of Binet's formula, , has size at most for every , which is less than . The number is therefore within a half of the integer :
This holds even at , where rounds to , and the approximation tightens fast: against , and against . It is the same shape as the derangement count of an earlier lesson, an exact count equal to a simple expression rounded, and for the same reason: an error term known to be below a half.
The fading term also explains the ratios. In the terms vanish in the limit, so the ratio tends to , overshooting and undershooting in turn as changes sign: , then . In any order recurrence with distinct real roots, the root of larger size sets the growth and the other only decides the rounding.
A repeated root
The fit needed . The recurrence has characteristic equation and the single root , so is the only family on offer, and one constant cannot meet two initial conditions. A second solution is missing.
Nearby recurrences show where it hides. With distinct roots and , linearity makes a solution. As approaches the recurrence approaches the one with a double root, and this solution approaches the derivative of at , which is . Dividing by the constant gives the candidate : the old solution with an extra factor .
The limit only suggests it, so check. A double root means , so and , and then
So the general solution is , fitted by and , and the induction argument shows it is every solution. At higher orders a root of multiplicity contributes .
Example. Solve with and .
The double root is , so . From , ; from , , so and . The recurrence gives and , and the formula gives and .
Now you. Solve with and , and find .
Answer
The equation has the double root , so with and , so and . Check: the recurrence gives . So .
Adding a forcing term
The Tower of Hanoi recurrence , the fewest moves for discs, is not homogeneous: the is a forcing term, added whatever the earlier terms are. In general , and linearity still does the work. If is one solution, a particular solution, and is any other, subtracting their recurrences cancels , so solves the homogeneous recurrence. Every solution is therefore plus the general homogeneous solution, with the constants fitted last, to the whole formula.
A particular solution is guessed from the shape of the forcing term, with unknown coefficients: a constant for a constant, a polynomial of degree for a polynomial of degree . For Hanoi, gives , the homogeneous part has root , so , and gives . That is , as unrolling found, with no series to sum.
Example. A procedure given an input of size does steps of work and then calls itself twice on size ; size costs nothing. Find the total work .
The recurrence is with . The forcing term has degree , so try . Substituting, , and matching coefficients gives and , so and . Then , and gives :
Check: the recurrence gives for , and the formula gives , and . At size the work is steps.
Now you. Solve with , and find .
Answer
A constant needs , so . The roots of are and , so . The conditions give and , so , and . Check: the recurrence gives and , as does the formula. So .
The guess fails in one case, for the reason the double root did. The regions cut by lines in general position satisfy , whose homogeneous part has root , so constants already solve it and cannot produce the . Multiply the guess by , as with a repeated root: gives , so and , the formula the previous lesson reached by guessing.
How far the method reaches
At any order the steps are the same: find the roots of the characteristic equation, write one term per root (with extra factors of for a repeated one), add a particular solution if there is a forcing term, and fit initial conditions. Bit strings with no three consecutive 1s obey , whose cubic has one real root near and two complex ones of size below , so those counts grow like . Complex roots need no new idea; the answer comes out real.
The method needs both halves of its name. The derangement recurrence has a coefficient that grows with , and trying leaves in the equation. The Catalan numbers, which count the ways to bracket a product, obey a recurrence in which terms multiply each other, so superposition fails. A tool that turned the counting argument itself into algebra would reach further, and the next lesson builds one: the generating function.