# The Fibonacci generating function

The recurrence relation for the Fibonacci sequence is ubiquitous:

for $F_0 = 0$ and $F_1 = 1$.

Suppose we want to know the $n$th Fibonacci number ($F_n)$ without dealing with all the recursion above. How can that be found?

What follows is a neat derivation for $F_n$ using generating functions. The setup was taken from both Cormen, Leiserson and Rivest (1st Edition), and Wilf’s “Generating Functionology.” If you’d like to fill in the blanks in their derivations, best stop reading here! Otherwise, let’s see how it works.

Suppose we want the generatiing function for the Fibonacci sequence

By definition, the generating function

This isn’t particularly helpful, let’s get a better solution for $F(z)$, we’ll multiply $F(z)$ by $z$:

Subtracting 2 from 1 gives us

You should see a nice, closed form solution now:

Interesting, but not useful. We can go further, let’s work out a partial fraction decomposition.

First we determine the roots of the equation

which for easier factoring we want to write as

By the quadratic formula, we find the roots

and

Note that $\phihat = 1 - \phi$, and $\phi\phihat = -1$. To check the result, plug the roots back into the equation:

Now that we have the roots, we can decompose the Fibonacci generating function $F(z)$ into its constituent fractions. However, for reasons which will become apparent shortly, let’s do a little more work to rewrite the factors into a convenient form. Starting with the factors above,

Note that $(\phi\phihat/\phi\phihat)(z/\phi) = -\phihat z$ and $(\phi\phihat/\phi\phihat)(z/\phihat) = -\phi z$ and substitute to obtain

Using partial fraction decomposition,

and we can write

Solving first for $\alpha$, let $z = 1/\phi$:

After convincing yourself that $(\phi - \phihat) = \sqrt{5}$, it’s easy to see

By similar computation,

The end result of these computations produces the very useful

Continuing, recall for $% $

Choose $y = \phi z$ where $z > 1/\phi$ and write

resulting in an expression for the $n$th coefficient, that is, the $n$th Fibonacci number:

That’s all for now.