Generating Functions
A generating function stores a whole sequence as the coefficients of one power series, a₀ + a₁x + a₂x² + ⋯, with the power of x marking the position. The payoff is that ordinary algebra does the counting for you: multiplying two series automatically combines independent choices.
What the symbols mean
- Formal variable
A placeholder whose powers mark the positions in the sequence.
- Position
The coefficient of xⁿ is the nth term.
- Number of factors
How many independent choices are combined.
Explanation
A generating function is simply a way to store a whole infinite sequence as one expression, by using the sequence's numbers as the coefficients of a power series. It's called that because expanding the function generates the sequence, term by term. All we're really doing is using a polynomial as a filing cabinet: the number in drawer is written as the coefficient of . The formulas look scary, but is just the geometric series from earlier in this unit (every drawer holds a 1), and the second formula says what's in drawer when you multiply of those together ( is the drawer number, is how many factors). The variable never gets a value; it's only a label. Bear with it, because once you see why multiplying works, the rest is bookkeeping.
The sequence has generating function , and has , by the same geometric series with in place of .
Multiplication combines choices. Think about what happens when you multiply out . You get an term every time you pick from the first factor and from the second with , so the coefficient of adds up over all those splits. That's exactly the count of ways to split between two independent choices. So the number of ways to make cents from pennies and nickels is the coefficient of in
The first factor says "any number of cents from pennies," the second says "a multiple of 5 cents from nickels," and multiplying them lets the exponents add up.
Multiplying copies of counts ways to split among types, and we get back stars and bars: the coefficient is .
Recurrences become algebra. The Fibonacci recurrence turns into , so , and partial fractions give Binet's formula again. It's a second road to the answer from the last lesson.
A common mistake. It's tempting to worry about whether "equals" when, say, , since the series obviously blows up there. For counting it doesn't matter. These series are treated formally: we only care about the coefficients and never plug in numbers. (Inside the series really do converge to the functions, which is a nice bonus, not a requirement.)
See it
Worked examples
How many ways are there to make 10 cents from pennies and nickels?
- 1
We want the coefficient of in .
Practice
Type your answer and check it. Solve them all to complete the lesson.
What is the coefficient of in ?
How many ways are there to make 10 cents from pennies and nickels?
Which is the generating function of ?
What is the coefficient of in ?
In how many ways can you make 25 cents from pennies, nickels and dimes?
What is the coefficient of in ?
The hardest one here. Get it, and you've got this lesson.
In how many ways can you make 50 cents from pennies, nickels, dimes and quarters?
Where it's used
Probability theory, queueing models and the analysis of algorithms all count with generating functions.