Generating
Functions
Encode entire sequences into a single algebraic expression, then use algebra to solve counting and recurrence problems.
What Is a Generating Function?
A generating function is a formal power series that encodes a sequence \( a_0, a_1, a_2, \ldots \) as coefficients of powers of \( x \):
Think of \( x \) as a placeholder: we don't plug in numbers. We just use the variable to "tag" each term with its position in the sequence.
The Big Idea: Sequences as Algebra
Instead of working with terms one-by-one, we pack the whole sequence into a closed-form function, manipulate it with algebra, then read off answers from the coefficients.
Why Do Generating Functions Matter?
The Fundamental Closed Form
This is the building block for nearly every generating function. By substituting, scaling, and differentiating this identity, we can derive generating functions for a huge variety of sequences.
Key Generating Function Pairs
| Sequence \( \{a_n\} \) | OGF \( A(x) \) |
|---|---|
| \( 1, 1, 1, 1, \ldots \) | \( \dfrac{1}{1 - x} \) |
| \( 1, c, c^2, c^3, \ldots \) | \( \dfrac{1}{1 - cx} \) |
| \( 1, 2, 3, 4, \ldots \) | \( \dfrac{1}{(1 - x)^2} \) |
| \( a_n = \binom{n+k-1}{k-1} \) | \( \dfrac{1}{(1 - x)^k} \) |
OGF vs. EGF: Key Distinction
| Feature | Ordinary (OGF) | Exponential (EGF) |
|---|---|---|
| General term | \( a_n x^n \) | \( a_n \dfrac{x^n}{n!} \) |
| Product means | Convolution (unordered) | Labeled merge (ordered) |
| Best for | Combinations, selections | Permutations, labelings |
| Example | Coin change, partitions | Derangements, arrangements |
Operations on Generating Functions
How to Apply Generating Functions
Example 1: Constant Sequence
Problem: Find the generating function for the sequence \( 3, 3, 3, 3, \ldots \).
Example 2: Powers of 2
Problem: Find the generating function for \( 1, 2, 4, 8, 16, \ldots \) (i.e., \( a_n = 2^n \)).
Example 3: Fibonacci Numbers
Problem: Derive the GF for the Fibonacci sequence \( F_0 = 0,\; F_1 = 1,\; F_n = F_{n-1} + F_{n-2} \).
Visualizing Convolution
When you multiply two generating functions, the coefficient of \( x^n \) in the product is the convolution of the original sequences. This is the algebraic heart of counting arguments.
Counting with Products
Problem: How many ways can you select \( n \) items from two types, where you pick between \( 0 \) and \( 3 \) of type A and any number of type B?
Common Mistakes
Summary: Operation Cheat Sheet
| Sequence Operation | GF Operation |
|---|---|
| Scale by \( c \) | \( c \cdot A(x) \) |
| Add sequences | \( A(x) + B(x) \) |
| Right-shift by \( k \) | \( x^k \cdot A(x) \) |
| Multiply terms by \( n \) | \( x \cdot A'(x) \) |
| Convolution | \( A(x) \cdot B(x) \) |
| Partial sums \( \sum_{k=0}^n a_k \) | \( \dfrac{A(x)}{1-x} \) |
Question 1 of 5
What is the ordinary generating function for the sequence \( 1, 1, 1, 1, \ldots \)?
Question 2 of 5
The generating function \( \dfrac{1}{1-3x} \) encodes which sequence?
Question 3 of 5
If \( A(x) \) is the GF for \( \{a_n\} \), what does multiplying \( A(x) \) by \( x^2 \) do to the sequence?
Question 4 of 5
What is the generating function for the Fibonacci recurrence \( F_n = F_{n-1} + F_{n-2} \) with \( F_0=0, F_1=1 \)?
Question 5 of 5
When we multiply two ordinary generating functions \( A(x) \cdot B(x) \), the coefficient of \( x^n \) in the product equals: