Generating Functions

Polynomial multiplication, Fibonacci, and coin counting

Generating Functions

Write a sequence as the coefficients of a power series and counting problems turn into algebra.

Polynomial Multiplication as Convolution

Click a result coefficient to see which pairs of input coefficients multiply and add to make it.

Inspect c_k:

Polynomial multiplication is convolution: c_k = Σ a_i · b_(k-i). Click an index to see contributing pairs.

Go deeper:Polynomial Multiplication as Convolution

A generating function encodes a sequence a₀, a₁, a₂, ... as the coefficients of a formal power series: f(x) = a₀ + a₁x + a₂x² + ... This algebraic trick transforms counting problems into polynomial (or series) arithmetic. Multiplication of generating functions corresponds to convolution of sequences.

When you multiply two polynomials, each coefficient of the result is a sum of products: cₖ = Σ aᵢ · bₖ₋ᵢ. This is exactly convolution. Click a result coefficient to see which pairs of input coefficients contribute to it.

Key insight: Convolution is the algebraic engine behind generating functions. Many counting problems reduce to multiplying generating functions and reading off coefficients.

Fibonacci Numbers via Generating Functions

Step through the derivation, from the Fibonacci recurrence to an exact formula with the golden ratio.

Fibonacci Numbers via Generating FunctionsStep 1: Define the Generating FunctionF(x) = f₀ + f₁x + f₂x² + f₃x³ + ⋯ = Σ fₙxⁿPack all Fibonacci numbers into a single power series.Fibonacci sequence (first 3 terms)0f(0)1f(1)1f(2)
Step 1 of 5

Generating functions turn recurrences into algebra. Step through to see how F(x) = x/(1-x-x²) yields Binet's formula.

Go deeper:Fibonacci Numbers via Generating Functions

The Fibonacci recurrence fₙ = fₙ₋₁ + fₙ₋₂ translates into an algebraic equation for the generating function F(x). Solving it and decomposing into partial fractions yields Binet's formula: an exact closed form involving the golden ratio. Step through the derivation.

Key insight: Generating functions turn recurrences into algebra. The recurrence becomes multiplication by x and x², which leads to a rational function whose partial fraction expansion gives the closed form.

The Coin Change Problem

Select your coin denominations and a target amount, and read off how many ways there are to make change.

Coin Change via Generating FunctionsGenerating function:G(x) = 1/(1−x) × 1/(1−x^5) × 1/(1−x^10) × 1/(1−x^25)[x^12] G(x) = 4 ways to make 12¢All combinations:1.12×1¢ = 12¢2.7×1¢ + 1×5¢ = 12¢3.2×1¢ + 2×5¢ = 12¢4.2×1¢ + 1×10¢ = 12¢
Coins:

Each coin denomination contributes a factor 1/(1-x^d). The coefficient of x^n in the product counts the number of ways.

Go deeper:The Coin Change Problem

How many ways can you make change for a given amount using coins of specified denominations? Each denomination contributes a factor 1/(1-xᵈ) to the generating function. The coefficient of xⁿ in the product gives the number of ways to make n cents. Select your denominations and explore.

Key insight: The factor 1/(1-xᵈ) = 1 + xᵈ + x²ᵈ + ... encodes using 0, 1, 2, ... coins of denomination d. Multiplying these factors for all denominations produces the generating function whose coefficients count the combinations.

Key Takeaways

  • Generating functions encode sequences as power series coefficients.
  • Polynomial multiplication corresponds to sequence convolution.
  • Recurrences translate to algebraic equations solvable in closed form.
  • Product-of-series generating functions naturally solve partition-type counting problems.

Spot a mistake or have an idea?

Search