March 6, 2025
18 minute read
I have loved and been interested in math for a very long time by now. However, even though it may be just be my inexperience with other fields, I have found generating functions to be one of the most fascinating and thought-provoking topics I have yet learned. So what are these curious mathematical objects, and how can we solve problems with them?
The most intuitive definition of generating functions I’ve heard is from Herbert Wilf’s generatingfunctionology
… Hence the thumbnail of this blogpost.
If you’ve studied a bit of calculus and learned about power series, generating functions go hand in hand with that concept! What I mean is that we have a sequence . It can be any sequence of numbers. Then, the ordinary power series generating function (the opsgf) of the sequence is as follows:
Definition
A function is defined to be the generating function of if
If I have the sequence , then the generating function for that sequence would be
You can see why Wilf alikened generating functions to clotheslines. These s are (almost) purely formal, and their only purpose is to sit there and help locate the term in the sequence.
For a more advanced example, consider the sequence . This means that for every single . So, the generating function would be . But, if we recall from Algebra 2, this looks like a geometric series!
If we remember, when we have an infinite geometric series with an initial term and a common ratio , then the sum is
In our case, starts at zero, so the initial term is just 1. in this case is also just . So, the generating function for this sequence is
Wait, why are we able to convert that series into that neat sum with the geometric series formula again? I thought it only converged when We are able to do this because this is a formal power series. isn’t really a concrete number (kinda), so we can kinda do anything to it, including what we just did.
Hopefully you can kind of see the power series-like nature. However, this just looks pointless. Why did we do all of this? The reason why we did this is because for larger, more complicated problems, generating functions are easy to manipulate and can even yield you recurrance formulas, explicit formulas, and other cool things. However, when they don’t, they’re usually the next best thing, letting you extract terms with methods like the Taylor expansion we learned in calculus.
What is the generating function for ? Well, this looks like a geometric sequence but every term is the previous term times -1. So, while our initial term is still 1, the common ratio is now instead of . Plugging into the formula yields
A reason why generating functions are so powerful is that they are really easy to manipulate. Say we’re given a sequence whose generating function is . How do we represent in terms of ? As an example, if we’re given , how do we represent ?
We know that ’s opsgf is
We want
How do we manipulate into ?
We can first note that dividing by gets us really close. We have
The only thing we’re missing is to backtrack and first eliminate that term so that there’s no pesky laying around. We can do this with to get a final result:
That’s great! But if I want to represent in terms of ? Now that we see the general pattern, we should first eliminate and first, then divide by to “shift” the series over to what we want. We end up getting
Definition
In general, for a sequence whose opsgf is , the generating function for for any is
Armed with this knowledge, we can now tackle one of the most well-known recurrance relations in all of math: the Fibonacci Sequence.
A recurrance relation is an equation that defines a term by referencing other previous terms. In the fibonacci sequence, the first terms are 0 and 1, and the next term is defined by the sum of the last two terms. So, the next term is , and the next is , the next being
The fibonacci sequence goes
Mathematically, the fibonacci sequence is defined as follows:
This is great, but there is an actual explicit formula for the fibonacci sequence, meaning that there’s a formula that we can just
plug in n
for the n
th term and get the result without recursion! Can we find it?
I mentioned that generating functions can be used to find these explicit formulas, so I’ll outline how we’ll do that, along with why we’re doing that.
Step 0: Define the generating function of the sequence to be
Step 1: Multiply both sides of the recurrance relation by (i.e “multiply by and sum over “)
Step 2: Simplify and find
Step 3: Convert into a series again with to prepare for “extraction”
Step 4: Profit
So, let’s try to tackle this!
Looks good to me. Let’s move on
When I multiply both sides of our recurrance relation of , I get
The result of step one looks very familiar… and it should! In Generating Function Operations, we talked about what the generating function would be if we “shift” to the right. We can just see what we did previously and plug in accordingly, also noting that is the definition of , leaving us with
Plugging in our starting terms and simplifies the equation down to
Multiplying both sides by yields
Moving F(x) to one side gives us
Finally, dividing yields us
Definition
The generating function for the fibonacci is defined as
Before we find the explicit formula, I just want to underline the fact that this generating function already works great! Remember that by definition, if we want to find , we look at the coefficient of . Recalling stuff we learned from calculus, how do we convert a function to an infinite polynomial of s? With Taylor/Maclaurin Expansion!
Say I wanted to find all fibonacci numbers from to . Because this is über impractical, I’ll ask an online calculator to help us in finding a 10th-order Maclaurin polynomial of . Feel free to check for yourself on emathhelp.net
(warning: it is NOT pretty)
Isn’t this crazy? the 0th term is defined to be 0, so it doesn’t appear in the polynomial. The 1st term is 1, so that’s why it’s just . The second term is , so in the polynomial, there’s . We are able to generate this sequence with this generating function, which is so cool already! However, let’s move on from this (incredibly important) tangent and tackle the final steps.
Is expanding with Taylor/Maclaurin a super efficient method of generating the fibonacci terms? Heck no! This just illustrates what you might do if this was your only option…
The hardest part is probably not getting the generating function but is actually converting it into a “useable” form. When I was doing those simple generating functions in the Examples section, I used the handy infinite geometric sum
I’m almost certain that we’re gonna have somewhere in our common ratio, since that’s what generating functions care about, so I’m looking for a way to convert into
If only there was a way to decompose my into a sum of partial fractions…
Hmm? There’s something called partial fraction decomposition that does exactly that? That’s sick.
First of all, we have
Even though might not be factorable with integers, we can still express it as
where we found with the quadratic formula. Now, let’s try to found and such that
Working with A, and with a shortcut, I found that
Working with B, and with the same shortcut, I found that
This looks complicated until we realize that
and that
By getting that
We ultimately get
We’re getting really, really close to our goal. However, when I look at the geometric sum formula, I notice that there must be a term on the denominator. So, I’m going to try to adjust the two partial fractions until it resembles that.
That’s better. Now, our equation is looking really nice:
Notice how now, the partial fractions are in the form that we we original looking for. We can now do the opposite of what we did in the earlier examples and work backwards, converting from this result to a series again.
For the first result, we can see that is , and that the common ratio is . So, this is the same thing as
Similarly, for the second result, we can see that is , while the common ratio is . This is now
We’re getting there! Our equation looks like
Finally, realizing that the two sums share the same variables and bounds, we combine the two to get a grand result of
Remember that is defined as . That is, the nth term of the fibonacci sequence will be the coefficient of What is the coefficient of in that giant summation we just found? Well, it’s just the stuff inside the parentheses, right, multiplied by the outside, right? We are finally done.
Definition
The n
th term of the fibonacci sequence can be found with the following explicit formula:
By doing some basic math, we find that
Giving us the more-commonly-recognized Binet’s Formula
Definition
The n
th term of the fibonacci sequence can be found with Binet’s Formula:
With generating functions, we have found the explicit form of a recurrance relation with (relatively) little effort! While there are shorter, more specific proofs for Binet’s formula, this demonstrates the ease in which generating functions can manipulate sequences. I’ll talk about one more thing, then we can wrap up.
Earlier, I said that the s found in generating functions are almost purely formal and can’t be plugged into? Well, not quite. To my understanding, despite the fact that it is a formal power series, we can still connect with the more analytical side of things and expect it to work, so long as the series converges (which we can verify with our calculus knowledge). So, let’s explore one last really cool thing about the fibonaccis and its GF.
For what values does the power series converge to? If we backtrack, we remember that
Because we know that the common ratio in an infinite geometric sequence must satisfy:
$ needs to be convergent for both series to make sense. This gives us
* The reason why it turns negative is because is already negative. So, the absolute value turns it positive, which is shown by it changing signs.
From this, we can see that the stricter bound is
which tells us that between ~, we can plug in x into
In a sense, this relates the fibonacci sequence with a simple constant! One very cool thing we can do is plug in into x, which fits comfortably within our bounds. Something really interesting happens…
Now let’s examine the first 50 or so digits of
Wait, what? That simple fraction contains the first 16 fibonacci terms?? That’s really cool, but it should also not be that big of a surprise. In the equation above, we said that the fraction was equal to
Thinking about it carefully, what this is basically saying is to write down the nth term of , then move right 3 decimal places (since we’re dividing by 1000), then repeat. It’s kinda like a factory, churning out fibonacci terms until there’s not enough space, when the fibonacci numbers get to 4 digits and it breaks.
In many cases, we can obtain some really cool results by plugging in real (and even complex numbers!) into
We’ve only begun to scratch the surface of generating functions, yet we’ve seen how powerful they can be. In future blogposts about generating functions, we might cover different types of generating functions, as well as even more things you can do with them, from counting to infinite sums to all sorts of cool number theory stuff. But for now, thanks for reading, and see you soon!