Generating Functions

Discrete MathDifficulty: ███░░Depth: 4Unlocks: 0

Power series encoding sequences. Solving counting problems.

Interactive Visualization

t=0s

Core Concepts

  • Ordinary generating function: represent a sequence (a_n) as the formal power series A(x) = sum_{n>=0} a_n x^n.
  • Coefficient extraction: recover sequence terms from the series via the coefficient-of-x^n operation (a_n = coefficient_of_x^n(A(x))).
  • Algebraic reduction: convert counting problems or recurrence relations into algebraic equations for generating functions to solve for closed forms or sequence values.

Key Symbols & Notation

A(x) = sum_{n>=0} a_n x^n (ordinary generating function)

Essential Relationships

  • Algebra <-> sequence: algebraic operations on generating functions correspond to sequence operations (Cauchy product = convolution; multiplication by x^k = index shift) and rational generating functions correspond to linear recurrences with constant coefficients.
▶ Advanced Learning Details

Graph Position

52
Depth Cost
0
Fan-Out (ROI)
0
Bottleneck Score
4
Chain Length

Cognitive Load

5
Atomic Elements
27
Total Elements
L1
Percentile Level
L3
Atomic Level

All Concepts (11)

  • Ordinary generating function (OGF): representing a sequence (a_n) by the formal power series A(x)=∑_{n≥0} a_n x^n
  • Formal power series viewpoint: treat generating functions algebraically (manipulate coefficients) without requiring analytic convergence or radius of convergence
  • Coefficient extraction: the operation of retrieving a_n as the coefficient of x^n in A(x), often written [x^n]A(x)
  • Cauchy product (convolution) of sequences: coefficients of the product of two GFs given by discrete convolution of the sequences
  • Index shift by multiplication: multiplying a GF by x^k shifts the sequence indices (x^k A(x) corresponds to inserting k leading zeros / shifting a_n→a_{n-k})
  • Geometric-series GF: 1/(1-x) as the generating function for the constant sequence 1, and related closed forms for simple sequences (e.g., 1/(1-x)^2 for the sequence n+1)
  • Algebraic manipulation of GFs to solve problems: formulating an algebraic equation for a GF from a recurrence or combinatorial description and solving that equation for A(x)
  • Rational generating functions: GFs that are ratios of polynomials, typically arising from linear recurrences with constant coefficients
  • Partial-fraction (and related) coefficient-extraction techniques: decomposing a rational GF to obtain an explicit formula for a_n
  • Translation of basic combinatorial constructions into GF operations (disjoint union → sum of GFs; ordered product → product of GFs; sequence/zero-or-more → 1/(1−A(x)))
  • Using GFs to model counting problems: encoding combinatorial counting constraints as algebraic operations on series to derive counts

Teaching Strategy

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.

TL;DR:

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).

What Is a Generating Function?

Why we bother (motivation before formulas)

You already know two common ways to describe a sequence:

  1. 1)Explicitly: “an=32naₙ = 3·2ⁿ.”
  2. 2)Recursively: “an=2an1aₙ = 2a_{n-1} with a0=3a₀=3.”

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.

Definition: ordinary generating function (OGF)

Given a sequence (an)n0(aₙ)_{n≥0}, its ordinary generating function is

A(x)=n0anxn.A(x) = \sum_{n\ge 0} a_n x^n.
  • Think of xx as a bookkeeping variable that tracks “size” (like number of steps, total sum, total length).
  • Think of anaₙ as “how many objects have size nn.”

Important: in discrete math we often treat A(x)A(x) as a formal power series. That means we’re not worried (at first) about whether the series converges for a numeric value of xx. We’re using it as an algebraic container for coefficients.

Coefficient extraction

To recover the original sequence, we use the coefficient operator:

an=[xn]A(x).a_n = [x^n]A(x).

Read [xn]A(x)[x^n]A(x) as: “the coefficient of xnxⁿ in the series A(x)A(x).”

Example:

If A(x)=2+0x+5x2+7x3+A(x)=2 + 0x + 5x^2 + 7x^3 + \cdots, then

  • [x0]A(x)=2[x^0]A(x)=2
  • [x1]A(x)=0[x^1]A(x)=0
  • [x2]A(x)=5[x^2]A(x)=5
  • [x3]A(x)=7[x^3]A(x)=7

One minute of intuition: why a power series encodes a sequence

Because powers of xx act like “bins” labeled by nn:

  • The x0x^0 bin stores a0a₀.
  • The x1x^1 bin stores a1a₁.
  • The x2x^2 bin stores a2a₂.

When you add or multiply series, the bins combine in structured ways—and those structures match common combinatorial constructions.

Quick examples of OGFs you should recognize

1) Constant 1’s:

n0xn=1+x+x2+x3+=11x.\sum_{n\ge0} x^n = 1 + x + x^2 + x^3 + \cdots = \frac{1}{1-x}.

So the sequence (1,1,1,1,)(1,1,1,1,\dots) has OGF 11x\frac{1}{1-x}.

2) Geometric weights (cn)(c^n):

n0cnxn=11cx.\sum_{n\ge0} c^n x^n = \frac{1}{1-cx}.

So (1,c,c2,)(1,c,c^2,\dots) has OGF 11cx\frac{1}{1-cx}.

3) A shifted sequence:

If A(x)=n0anxnA(x)=\sum_{n\ge0}aₙxⁿ, then

xA(x)=n0anxn+1=n1an1xn.xA(x)=\sum_{n\ge0}a_n x^{n+1}=\sum_{n\ge1}a_{n-1}x^n.

So multiplying by xx shifts coefficients to the right.

That “shift = multiply by xx” fact will be one of our core tools.

Core Mechanic 1: Coefficient Extraction, Shifts, and Simple Algebra

Why this matters

Most generating-function solutions follow a pattern:

  1. 1)Express a recurrence or a counting construction as an equation involving A(x)A(x).
  2. 2)Solve that equation with algebra.
  3. 3)Extract [xn][x^n] from the result.

To do step 1 correctly, you need fluency with coefficient extraction and shifts.

The coefficient operator behaves like a “read-off” function

The operator [xn][x^n] is linear:

[xn](F(x)+G(x))=[xn]F(x)+[xn]G(x),[x^n](F(x)+G(x)) = [x^n]F(x) + [x^n]G(x),

and constants pull out:

[xn](cF(x))=c[xn]F(x).[x^n](cF(x)) = c\,[x^n]F(x).

These properties let you extract terms after you do algebra.

Shifts: multiplying by x moves the sequence

Let

A(x)=n0anxn.A(x)=\sum_{n\ge0}a_nx^n.

Then:

  • Right shift (delay by 1):
xA(x)=n0anxn+1=n1an1xn.xA(x)=\sum_{n\ge0}a_nx^{n+1}=\sum_{n\ge1}a_{n-1}x^n.

So

[xn](xA(x))=an1(n1).[x^n](xA(x)) = a_{n-1}\quad (n\ge1).
  • Right shift by k:
xkA(x)=nkankxn.x^kA(x)=\sum_{n\ge k} a_{n-k}x^n.

So

[xn](xkA(x))=ank(nk).[x^n](x^kA(x)) = a_{n-k}\quad (n\ge k).
  • Left shift is slightly trickier because you lose initial terms. Observe:
A(x)a0x=n1anxn1=n0an+1xn.\frac{A(x)-a_0}{x} = \sum_{n\ge1}a_n x^{n-1} = \sum_{n\ge0} a_{n+1} x^n.

So

[xn]A(x)a0x=an+1.[x^n]\frac{A(x)-a_0}{x} = a_{n+1}.

This is the algebraic way to represent “drop the first term and shift left.”

A small but crucial identity: summing a recurrence becomes multiplying by a power series

Suppose you have a recurrence like

an=an1+1(n1),a0=0.a_n = a_{n-1} + 1 \quad (n\ge1),\qquad a_0 = 0.

If you multiply both sides by xnx^n and sum over n1n\ge1, you get

Left side:

n1anxn=A(x)a0=A(x).\sum_{n\ge1} a_n x^n = A(x) - a_0 = A(x).

Right side:

n1an1xn+n11xn=xn1an1xn1+x1x.\sum_{n\ge1} a_{n-1}x^n + \sum_{n\ge1}1\cdot x^n = x\sum_{n\ge1}a_{n-1}x^{n-1} + \frac{x}{1-x}.

But

n1an1xn1=m0amxm=A(x).\sum_{n\ge1}a_{n-1}x^{n-1} = \sum_{m\ge0}a_m x^m = A(x).

So the equation becomes

A(x)=xA(x)+x1x.A(x) = xA(x) + \frac{x}{1-x}.

Now solve:

A(x)(1x)=x1xA(x)=x(1x)2.A(x)(1-x) = \frac{x}{1-x}\quad\Rightarrow\quad A(x)=\frac{x}{(1-x)^2}.

Finally extract coefficients. A known expansion is

1(1x)2=n0(n+1)xn,\frac{1}{(1-x)^2} = \sum_{n\ge0}(n+1)x^n,

so

A(x)=xn0(n+1)xn=n1nxn.A(x)=x\sum_{n\ge0}(n+1)x^n = \sum_{n\ge1} n x^n.

Thus an=na_n = n (with a0=0a_0=0), matching the recurrence.

The point isn’t this easy recurrence—the point is the workflow:

  • turn shift terms into xA(x)xA(x),
  • use a geometric series for simple sums,
  • solve algebraically,
  • read off coefficients.

Partial fractions: how we often get closed forms

When A(x)A(x) is a rational function like

A(x)=P(x)Q(x),A(x)=\frac{P(x)}{Q(x)},

you can often decompose it into sums of terms like

C1αx,C(1αx)2,etc.\frac{C}{1-\alpha x},\quad \frac{C}{(1-\alpha x)^2},\quad\text{etc.}

Then coefficient extraction is straightforward because

11αx=n0αnxn,\frac{1}{1-\alpha x} = \sum_{n\ge0} \alpha^n x^n,

and

1(1αx)2=n0(n+1)αnxn.\frac{1}{(1-\alpha x)^2} = \sum_{n\ge0} (n+1)\alpha^n x^n.

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.”

Core Mechanic 2: Products as Convolution (and a Visualization You Can Hold Onto)

Why products show up in counting

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

A(x)=n0anxn,B(x)=n0bnxn.A(x)=\sum_{n\ge0} a_n x^n,\qquad B(x)=\sum_{n\ge0} b_n x^n.

Then

A(x)B(x)=(i0aixi)(j0bjxj)=i0j0aibjxi+j.A(x)B(x)=\left(\sum_{i\ge0} a_i x^i\right)\left(\sum_{j\ge0} b_j x^j\right) =\sum_{i\ge0}\sum_{j\ge0} a_i b_j x^{i+j}.

Group terms by total exponent n=i+jn=i+j:

A(x)B(x)=n0(i=0naibni)xn.A(x)B(x)=\sum_{n\ge0}\left(\sum_{i=0}^n a_i b_{n-i}\right)x^n.

So the coefficient rule is:

[xn](A(x)B(x))=i=0naibni.[x^n](A(x)B(x)) = \sum_{i=0}^n a_i b_{n-i}.

That inner sum is the convolution of sequences (an)(aₙ) and (bn)(bₙ).

Static visualization: coefficient extraction in a product

Think of a grid where rows are ii (from AA) and columns are jj (from BB). Each cell contributes to exponent i+ji+j.

            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    a4b4

Cells on the same diagonal have the same sum i+ji+j.

  • The diagonal for n=3n=3 is:
  • (i,j)=(0,3)(i,j)=(0,3) contributes a0b3a₀b₃
  • (1,2)(1,2) contributes a1b2a₁b₂
  • (2,1)(2,1) contributes a2b1a₂b₁
  • (3,0)(3,0) contributes a3b0a₃b₀

So

[x3](A(x)B(x))=a0b3+a1b2+a2b1+a3b0.[x^3](A(x)B(x)) = a_0b_3 + a_1b_2 + a_2b_1 + a_3b_0.

This diagonal-summing picture is the most important visualization for OGFs.

Interpreting convolution combinatorially

If aia_i counts ways to build something of size ii (Part A), and bjb_j counts ways to build something of size jj (Part B), then:

  • Choose a split n=i+(ni)n=i+(n-i).
  • Choose Part A in aia_i ways.
  • Choose Part B in bnib_{n-i} ways.
  • Multiply for independent choices, then sum over all splits.

That is exactly

i=0naibni.\sum_{i=0}^n a_i b_{n-i}.

A concrete “canvas-style” mental animation (shifts + product + read-off)

Even without an actual interactive widget, you can rehearse the same moves:

Example goal: compute [x4](1+x+x2)(1+2x+3x2+4x3+)[x^4] \,(1 + x + x^2)(1 + 2x + 3x^2 + 4x^3 + \cdots).

1) Shift/limit idea: the polynomial (1+x+x2)(1+x+x^2) 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:

(1+x+x2)B(x)=B(x)+xB(x)+x2B(x).(1+x+x^2)B(x) = B(x) + xB(x) + x^2B(x).

3) Now “read off” coefficient of x4x^4:

  • From B(x)B(x) you need [x4]B(x)=5[x^4]B(x)=5 (since coefficients are 1,2,3,4,5,...)
  • From xB(x)xB(x) you need [x3]B(x)=4[x^3]B(x)=4
  • From x2B(x)x^2B(x) you need [x2]B(x)=3[x^2]B(x)=3

So

[x4](1+x+x2)B(x)=5+4+3=12.[x^4](1+x+x^2)B(x) = 5 + 4 + 3 = 12.

This is the same as diagonal summing, but it highlights shifts explicitly: multiplication by xkx^k delays coefficients by kk.

Summary of the mechanics

  • Addition of generating functions: add counts for each size.
  • Multiplication: combine independent parts; coefficient becomes a convolution/diagonal sum.
  • Multiplying by xkx^k: shift sizes by kk.

Once these feel natural, counting problems become “write the right product, then extract the coefficient.”

Application/Connection: Solving Counting Problems and Recurrences with OGFs

Two main use cases

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 anaₙ defined in terms of previous terms, and want a closed form.

We’ll do one of each, and point out the shared pattern.


A) Counting by construction: compositions with restricted parts

A classic problem:

How many ways are there to write nn as an ordered sum of 1s and 2s?

This is the “stairs” problem: number of ways to climb nn steps taking 1 or 2 at a time. You might know the answer is Fibonacci-like.

Build the generating function

A single step can contribute size 1 or 2. So the OGF for “one step” is

S(x)=x+x2.S(x) = x + x^2.

A whole walk is a sequence of steps of any length: 0 steps, 1 step, 2 steps, …

  • 0 steps contributes size 0, counted by 1.
  • 1 step contributes S(x)S(x).
  • 2 steps contributes S(x)2S(x)^2.

So the total generating function is a geometric series in S(x)S(x):

W(x)=1+S(x)+S(x)2+S(x)3+=11S(x)=11(x+x2).W(x) = 1 + S(x) + S(x)^2 + S(x)^3 + \cdots = \frac{1}{1 - S(x)} = \frac{1}{1 - (x+x^2)}.

Thus

W(x)=11xx2.W(x) = \frac{1}{1 - x - x^2}.

Now [xn]W(x)[x^n]W(x) is the number of walks summing to nn.

Connection to recurrence automatically

If

W(x)=n0wnxn,W(x)=\sum_{n\ge0} w_n x^n,

then the identity

(1xx2)W(x)=1(1 - x - x^2)W(x)=1

implies, by matching coefficients, that for n2n\ge2:

wnwn1wn2=0wn=wn1+wn2.w_n - w_{n-1} - w_{n-2} = 0\quad\Rightarrow\quad w_n = w_{n-1} + w_{n-2}.

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.


B) Solving a recurrence directly with OGFs

Suppose you have a recurrence:

an=3an1+2(n1),a0=1.a_n = 3a_{n-1} + 2\quad(n\ge1),\qquad a_0=1.

You can solve this with characteristic equations, but let’s practice the OGF method because it generalizes well.

Let

A(x)=n0anxn.A(x)=\sum_{n\ge0}a_n x^n.

Multiply the recurrence by xnx^n and sum over n1n\ge1:

Left:

n1anxn=A(x)a0=A(x)1.\sum_{n\ge1} a_n x^n = A(x)-a_0 = A(x)-1.

Right:

n13an1xn+n12xn.\sum_{n\ge1} 3a_{n-1}x^n + \sum_{n\ge1} 2x^n.

Handle each term:

  • For the shifted term:
n13an1xn=3xn1an1xn1=3xA(x).\sum_{n\ge1} 3a_{n-1}x^n = 3x\sum_{n\ge1} a_{n-1}x^{n-1} = 3xA(x).
  • For the constant forcing term:
n12xn=2x1x.\sum_{n\ge1}2x^n = 2\cdot \frac{x}{1-x}.

So we get an algebraic equation:

A(x)1=3xA(x)+2x1x.A(x)-1 = 3xA(x) + 2\frac{x}{1-x}.

Solve for A(x)A(x):

A(x)(13x)=1+2x1x.A(x)(1-3x) = 1 + \frac{2x}{1-x}.

Put the right side over a common denominator:

1+2x1x=1x1x+2x1x=1+x1x.1 + \frac{2x}{1-x} = \frac{1-x}{1-x} + \frac{2x}{1-x} = \frac{1+x}{1-x}.

So

A(x)=1+x(1x)(13x).A(x)= \frac{1+x}{(1-x)(1-3x)}.

Now do partial fractions:

Assume

1+x(1x)(13x)=C1x+D13x.\frac{1+x}{(1-x)(1-3x)} = \frac{C}{1-x} + \frac{D}{1-3x}.

Then

1+x=C(13x)+D(1x)=(C+D)+(3CD)x.1+x = C(1-3x) + D(1-x) = (C+D) + (-3C-D)x.

Match coefficients:

  • Constant: C+D=1C+D = 1
  • xx coefficient: 3CD=1-3C - D = 1

Solve:

From D=1CD=1-C:

3C(1C)=12C1=1C=1.-3C-(1-C)=1 \Rightarrow -2C - 1 = 1 \Rightarrow C=-1.

Then D=1(1)=2D=1-(-1)=2.

So

A(x)=11x+213x.A(x)=\frac{-1}{1-x} + \frac{2}{1-3x}.

Extract coefficients using geometric expansions:

11x=n0xn,113x=n03nxn.\frac{1}{1-x}=\sum_{n\ge0}x^n,\qquad \frac{1}{1-3x}=\sum_{n\ge0}3^n x^n.

Thus

A(x)=n0(1)xn+n023nxn=n0(1+23n)xn.A(x)=\sum_{n\ge0}(-1)\,x^n + \sum_{n\ge0} 2\cdot 3^n x^n = \sum_{n\ge0} ( -1 + 2\cdot 3^n )x^n.

So

an=1+23n.a_n = -1 + 2\cdot 3^n.

Check: a0=1+2=1a₀=-1+2=1 ok; and a1=1+6=5a₁=-1+6=5, while recurrence gives 31+2=53·1+2=5.


What to remember about the “reduction” step

The core skill is converting “sequence language” into “A(x)A(x) algebra.” A helpful cheat sheet:

Sequence statementGenerating-function translation
n0anxn\sum_{n\ge0} a_n x^nA(x)A(x)
n1anxn\sum_{n\ge1} a_n x^nA(x)a0A(x) - a_0
n1an1xn\sum_{n\ge1} a_{n-1} x^nxA(x)xA(x)
Add independent optionsadd OGFs
Concatenate independent partsmultiply OGFs (convolution)
Any number of repeats of a component with OGF C(x)C(x)1+C+C2+=1/(1C)1 + C + C^2+\cdots = 1/(1-C)

If you can do these translations slowly and correctly, you can solve a wide range of counting and recurrence problems.


Connections you’re about to unlock

From here, generating functions connect naturally to:

  • solving more complex linear recurrences (including Fibonacci closed forms),
  • more expressive generating functions (exponential generating functions),
  • analytic techniques (asymptotics) when you do care about convergence.

But the foundation is what you’ve learned here: encode → manipulate → extract.

Worked Examples (3)

Coefficient extraction in a product (convolution by diagonals)

Let A(x) = 1 + 2x + 3x² and B(x) = 1 + x + x² + x³ + … = 1/(1−x). Find [x⁴] A(x)B(x).

  1. 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.

  2. 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.

  3. Compute the convolution sum:

    x⁴=a₀b₄ + a₁b₃ + a₂b₂ + a₃b₁ + a₄b₀

    = 1·1 + 2·1 + 3·1 + 0·1 + 0·1

    = 6.

  4. 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 recurrence with an OGF (linear, constant coefficients, non-homogeneous)

Solve aₙ = 2aₙ₋₁ + 3 for n≥1 with a₀ = 0 using generating functions.

  1. Define the generating function:

    A(x)=∑_{n≥0} aₙ xⁿ.

  2. Multiply the recurrence by xⁿ and sum for n≥1:

    ∑_{n≥1} aₙ xⁿ = ∑_{n≥1} (2aₙ₋₁ + 3)xⁿ.

  3. 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).

  4. Obtain an algebraic equation:

    A(x) = 2xA(x) + 3x/(1−x).

  5. Solve for A(x):

    A(x)(1−2x) = 3x/(1−x)

    ⇒ A(x) = 3x / ((1−x)(1−2x)).

  6. 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.

  7. 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)).

Counting with a construction: number of solutions to i + j = n with bounds

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.

  1. 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).

  2. Combine independent choices by multiplication:

    Total OGF is T(x)=I(x)J(x) = (1+x+x²)/(1−x).

  3. Extract coefficient:

    The count we want is tₙ = [xⁿ]T(x).

  4. Use the “shifted copies” view:

    T(x) = (1+x+x²)J(x) = J(x) + xJ(x) + x²J(x).

  5. 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).

  6. Combine cases:

    If n=0: t₀ = 1.

    If n=1: t₁ = 1+1 = 2.

    If n≥2: tₙ = 1+1+1 = 3.

  7. 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.

Key Takeaways

  • 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.

Common Mistakes

  • 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.

Practice

easy

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.

Show solution

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².

medium

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).

Show solution

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).

hard

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².

Show solution

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.

Connections

Quality: A (4.4/5)