Power series encoding sequences. Solving counting problems.
Quick unlock - significant prerequisite investment but simple final step. Verify prerequisites first.
A generating function is a “sequence in disguise”: you pack the entire list (a₀, a₁, a₂, …) into a single algebraic object A(x). Then you solve counting problems by doing algebra on A(x) and reading answers back out as coefficients.
An ordinary generating function (OGF) encodes a sequence (aₙ) as A(x) = ∑ₙ≥0 aₙxⁿ. The operator [xⁿ]A(x) extracts the coefficient aₙ. The main power move: algebra on series corresponds to combinatorics on sequences—especially shifts and products (convolution). This turns recurrences and counting constructions into solvable equations for A(x).
You already know two common ways to describe a sequence:
Generating functions add a third option: describe the sequence as a single formal power series and then use algebra to manipulate it. The surprise is that many sequence operations (shifting, summing, combining choices) become simple algebra.
This is especially useful for counting: when you build objects out of parts, generating functions let you multiply the “part choices” and automatically produce counts for each size.
Given a sequence , its ordinary generating function is
Important: in discrete math we often treat as a formal power series. That means we’re not worried (at first) about whether the series converges for a numeric value of . We’re using it as an algebraic container for coefficients.
To recover the original sequence, we use the coefficient operator:
Read as: “the coefficient of in the series .”
Example:
If , then
Because powers of act like “bins” labeled by :
When you add or multiply series, the bins combine in structured ways—and those structures match common combinatorial constructions.
1) Constant 1’s:
So the sequence has OGF .
2) Geometric weights :
So has OGF .
3) A shifted sequence:
If , then
So multiplying by shifts coefficients to the right.
That “shift = multiply by ” fact will be one of our core tools.
Most generating-function solutions follow a pattern:
To do step 1 correctly, you need fluency with coefficient extraction and shifts.
The operator is linear:
and constants pull out:
These properties let you extract terms after you do algebra.
Let
Then:
So
So
So
This is the algebraic way to represent “drop the first term and shift left.”
Suppose you have a recurrence like
If you multiply both sides by and sum over , you get
Left side:
Right side:
But
So the equation becomes
Now solve:
Finally extract coefficients. A known expansion is
so
Thus (with ), matching the recurrence.
The point isn’t this easy recurrence—the point is the workflow:
When is a rational function like
you can often decompose it into sums of terms like
Then coefficient extraction is straightforward because
and
You don’t need to master every algebra trick yet; you do need to recognize that “rational generating function” usually means “closed form exists and can be extracted with algebra.”
When you build a combinatorial object by choosing Part A and Part B independently, the total size is usually the sum of sizes. Generating functions model exactly that: multiplying series adds exponents.
Let
Then
Group terms by total exponent :
So the coefficient rule is:
That inner sum is the convolution of sequences and .
Think of a grid where rows are (from ) and columns are (from ). Each cell contributes to exponent .
j=0 1 2 3 4
----------------------------------------
i=0 | a0b0 a0b1 a0b2 a0b3 a0b4
i=1 | a1b0 a1b1 a1b2 a1b3 a1b4
i=2 | a2b0 a2b1 a2b2 a2b3 a2b4
i=3 | a3b0 a3b1 a3b2 a3b3 a3b4
i=4 | a4b0 a4b1 a4b2 a4b3 a4b4Cells on the same diagonal have the same sum .
So
This diagonal-summing picture is the most important visualization for OGFs.
If counts ways to build something of size (Part A), and counts ways to build something of size (Part B), then:
That is exactly
Even without an actual interactive widget, you can rehearse the same moves:
Example goal: compute .
1) Shift/limit idea: the polynomial says: take one copy of the second series, plus a copy shifted right by 1, plus a copy shifted right by 2.
2) Write that algebraically:
3) Now “read off” coefficient of :
So
This is the same as diagonal summing, but it highlights shifts explicitly: multiplication by delays coefficients by .
Once these feel natural, counting problems become “write the right product, then extract the coefficient.”
Generating functions shine in two common scenarios:
1) Counting via construction: you build objects from components and want a formula for “# of objects of size n.”
2) Solving recurrences: you have defined in terms of previous terms, and want a closed form.
We’ll do one of each, and point out the shared pattern.
A classic problem:
How many ways are there to write as an ordered sum of 1s and 2s?
This is the “stairs” problem: number of ways to climb steps taking 1 or 2 at a time. You might know the answer is Fibonacci-like.
A single step can contribute size 1 or 2. So the OGF for “one step” is
A whole walk is a sequence of steps of any length: 0 steps, 1 step, 2 steps, …
So the total generating function is a geometric series in :
Thus
Now is the number of walks summing to .
If
then the identity
implies, by matching coefficients, that for :
So the recurrence drops out of the algebra.
This is a key theme: a rational OGF often corresponds to a linear recurrence with constant coefficients, and vice versa.
Suppose you have a recurrence:
You can solve this with characteristic equations, but let’s practice the OGF method because it generalizes well.
Let
Multiply the recurrence by and sum over :
Left:
Right:
Handle each term:
So we get an algebraic equation:
Solve for :
Put the right side over a common denominator:
So
Now do partial fractions:
Assume
Then
Match coefficients:
Solve:
From :
Then .
So
Extract coefficients using geometric expansions:
Thus
So
Check: ok; and , while recurrence gives .
The core skill is converting “sequence language” into “ algebra.” A helpful cheat sheet:
| Sequence statement | Generating-function translation |
|---|---|
| Add independent options | add OGFs |
| Concatenate independent parts | multiply OGFs (convolution) |
| Any number of repeats of a component with OGF |
If you can do these translations slowly and correctly, you can solve a wide range of counting and recurrence problems.
From here, generating functions connect naturally to:
But the foundation is what you’ve learned here: encode → manipulate → extract.
Let A(x) = 1 + 2x + 3x² and B(x) = 1 + x + x² + x³ + … = 1/(1−x). Find [x⁴] A(x)B(x).
Write the coefficient rule:
x⁴ = ∑_{i=0}^4 a_i b_{4−i}, where a_i=[x^i]A and b_j=[x^j]B.
List coefficients:
A(x)=1+2x+3x² so a₀=1, a₁=2, a₂=3, and a₃=a₄=0.
B(x)=1/(1−x)=∑_{n≥0}x^n so b_j=1 for all j≥0.
Optional “shift” viewpoint:
A(x)B(x) = (1+2x+3x²)B(x) = B(x) + 2xB(x) + 3x²B(x).
Now [x⁴] of that is b₄ + 2b₃ + 3b₂ = 1 + 2 + 3 = 6.
Insight: Products of OGFs turn into diagonal sums: to make x⁴, you can split 4 as i+(4−i). This is the algebraic mirror of “choose a size i from A and the rest from B.”
Solve aₙ = 2aₙ₋₁ + 3 for n≥1 with a₀ = 0 using generating functions.
Define the generating function:
A(x)=∑_{n≥0} aₙ xⁿ.
Multiply the recurrence by xⁿ and sum for n≥1:
∑_{n≥1} aₙ xⁿ = ∑_{n≥1} (2aₙ₋₁ + 3)xⁿ.
Translate each sum into A(x):
Left: ∑_{n≥1} aₙ xⁿ = A(x) − a₀ = A(x).
Right first term: ∑_{n≥1} 2aₙ₋₁ xⁿ = 2x∑_{n≥1} aₙ₋₁ xⁿ⁻¹ = 2xA(x).
Right second term: ∑_{n≥1} 3xⁿ = 3·x/(1−x).
Obtain an algebraic equation:
A(x) = 2xA(x) + 3x/(1−x).
Solve for A(x):
A(x)(1−2x) = 3x/(1−x)
⇒ A(x) = 3x / ((1−x)(1−2x)).
Partial fractions:
Assume 3x/((1−x)(1−2x)) = C/(1−x) + D/(1−2x).
Then 3x = C(1−2x) + D(1−x) = (C+D) + (−2C−D)x.
Match coefficients:
C + D = 0
−2C − D = 3
Solve: from D=−C, −2C + C = 3 ⇒ −C=3 ⇒ C=−3, D=3.
Expand and extract coefficients:
A(x)= −3/(1−x) + 3/(1−2x)
= −3∑_{n≥0} xⁿ + 3∑_{n≥0} 2ⁿ xⁿ
= ∑_{n≥0} (3·2ⁿ − 3)xⁿ.
So aₙ = 3·2ⁿ − 3.
Insight: The recurrence becomes a solvable algebra problem because shifts like aₙ₋₁ translate to xA(x). Non-homogeneous terms (like +3) translate to simple known series (like x/(1−x)).
Count the number of integer pairs (i,j) with i≥0, j≥0, i≤2, and i+j=n. Use generating functions to derive a formula for the count as a function of n.
Translate choices into OGFs:
The variable i can be 0,1,2. So its OGF is I(x)=1 + x + x².
The variable j can be any nonnegative integer. So its OGF is J(x)=1 + x + x² + … = 1/(1−x).
Combine independent choices by multiplication:
Total OGF is T(x)=I(x)J(x) = (1+x+x²)/(1−x).
Extract coefficient:
The count we want is tₙ = [xⁿ]T(x).
Use the “shifted copies” view:
T(x) = (1+x+x²)J(x) = J(x) + xJ(x) + x²J(x).
Read off coefficients:
Since [xⁿ]J(x)=1 for all n≥0,
[xⁿ]J(x)=1,
[xⁿ]xJ(x)=[xⁿ⁻¹]J(x)=1 for n≥1 (and 0 for n=0),
[xⁿ]x²J(x)=[xⁿ⁻²]J(x)=1 for n≥2 (and 0 for n=0,1).
Combine cases:
If n=0: t₀ = 1.
If n=1: t₁ = 1+1 = 2.
If n≥2: tₙ = 1+1+1 = 3.
State the result:
There are 1 solution for n=0, 2 solutions for n=1, and 3 solutions for all n≥2.
Insight: The product encodes all splits n=i+j, but the bounded i means only three diagonals contribute—visually: only i=0,1,2 rows exist, so each diagonal has at most three cells.
An ordinary generating function encodes a sequence as A(x)=∑ₙ≥0 aₙxⁿ; it’s a formal container for coefficients.
Coefficient extraction is written aₙ = [xⁿ]A(x). The operator [xⁿ] is linear and is how you “read answers.”
Multiplying by x^k shifts the sequence: xⁿ) = aₙ₋ₖ (for n≥k).
Products correspond to convolution: xⁿ=∑_{i=0}^n a_i b_{n−i}. This matches “split n into i+(n−i).”
Counting via construction often becomes “write a product/series, then extract [xⁿ].”
Recurrences become algebraic equations in A(x) once you multiply by xⁿ and sum over n; shift terms turn into xA(x)-style expressions.
Rational generating functions typically lead to closed forms via partial fractions and geometric-series expansions.
Forgetting to subtract initial terms when converting ∑_{n≥1} aₙxⁿ into A(x)−a₀ (or more generally handling offsets).
Mixing up the shift direction: xA(x) shifts coefficients right (delays indices), while (A(x)−a₀)/x shifts left.
Treating a formal power series as a numeric function too early (worrying about convergence instead of coefficient algebra).
When multiplying series, forgetting that coefficients convolve (diagonal sums) and incorrectly multiplying term-by-term.
Let A(x)=∑ₙ≥0 aₙxⁿ. Express the generating function for the shifted sequence bₙ=aₙ₊₂ in terms of A(x), a₀, and a₁.
Hint: First remove the first two terms from A(x), then divide by x² to shift left by 2.
We have A(x)=a₀ + a₁x + ∑_{n≥2} aₙxⁿ.
So A(x)−a₀−a₁x = ∑_{n≥2} aₙxⁿ.
Divide by x²:
(A(x)−a₀−a₁x)/x² = ∑_{n≥2} aₙ x^{n−2} = ∑_{m≥0} a_{m+2} x^m.
Thus B(x)=∑_{n≥0} bₙxⁿ = (A(x)−a₀−a₁x)/x².
Compute [x⁵] (1 + x + x² + x³) · 1/(1−x). Interpret your answer as a counting statement.
Hint: Use the shift idea: (1+x+x²+x³)J(x)=J + xJ + x²J + x³J where J=1/(1−x).
Let J(x)=1/(1−x)=∑_{n≥0}xⁿ so [x^k]J(x)=1 for k≥0.
Then T(x)=(1+x+x²+x³)J(x)=J + xJ + x²J + x³J.
[x⁵]T = [x⁵]J + [x⁴]J + [x³]J + [x²]J = 1+1+1+1=4.
Counting interpretation: number of pairs (i,j) with i∈{0,1,2,3}, j≥0, and i+j=5. There are 4 such pairs: (0,5),(1,4),(2,3),(3,2).
Let a₀=1 and for n≥1, aₙ = aₙ₋₁ + 2aₙ₋₂ (assume this holds for n≥2). Use OGFs to find a closed form for aₙ.
Hint: Multiply by xⁿ and sum; you’ll get an equation involving A(x), xA(x), and x²A(x). Solve for A(x) and use partial fractions by factoring the denominator 1−x−2x².
Let A(x)=∑_{n≥0} aₙxⁿ. The recurrence for n≥2 is aₙ − aₙ₋₁ − 2aₙ₋₂ = 0.
Sum from n=2 to ∞ after multiplying by xⁿ:
∑_{n≥2} aₙxⁿ − ∑_{n≥2} aₙ₋₁xⁿ − 2∑_{n≥2} aₙ₋₂xⁿ = 0.
Translate:
∑_{n≥2} aₙxⁿ = A(x) − a₀ − a₁x.
∑_{n≥2} aₙ₋₁xⁿ = x∑_{n≥2} aₙ₋₁x^{n−1} = x(A(x) − a₀).
∑_{n≥2} aₙ₋₂xⁿ = x²∑_{n≥2} aₙ₋₂x^{n−2} = x²A(x).
So:
(A − a₀ − a₁x) − x(A − a₀) − 2x²A = 0.
Plug a₀=1. Also compute a₁ from the recurrence base; using a₁ = a₀ + 2a_{−1} is not valid, so we need a₁ given or inferable. If we interpret the problem as also giving a₁=1 (common default), then proceed; otherwise the closed form depends on a₁.
Assuming a₁=1:
A − 1 − x − xA + x − 2x²A = 0
⇒ A(1 − x − 2x²) = 1
⇒ A(x)=1/(1 − x − 2x²).
Factor: 1 − x − 2x² = (1 − 2x)(1 + x).
Partial fractions:
1/((1−2x)(1+x)) = C/(1−2x) + D/(1+x).
1 = C(1+x) + D(1−2x) = (C+D) + (C−2D)x.
So C+D=1 and C−2D=0 ⇒ C=2D ⇒ 2D + D = 1 ⇒ D=1/3, C=2/3.
Thus A(x)= (2/3)/(1−2x) + (1/3)/(1+x).
Expand:
(2/3)∑_{n≥0}2^n x^n + (1/3)∑_{n≥0} (−1)^n x^n
So aₙ = (2/3)·2^n + (1/3)(−1)^n.
If a₁ is different, the same method works but constants C,D change.