7. Ordinary generating functions: definitions and series multiplication#
In rook polynomials, we used polynomials as an efficient bookkeeping tool to record the number of ways to place nonattacking rooks on a board. The polynomial
This bookkeeping idea is the foundation of generating functions. Many fundamental combinatorial problems depend on a nonnegative integer parameter
After studying these notes, you will be able to do the following.
Define the ordinary generating function of a sequence and identify the combinatorial meaning of its exponents and coefficients.
Recover specified counts from a generating function using the
coefficient extraction operator. Translate coin selections and change-making problems with finite and infinite supplies into polynomial and series products.
Substitute variables to count aggregate quantities such as monetary value rather than raw item counts.
Multiply formal power series and explain the Cauchy product algebraically, combinatorially, and via nested loops.
Model selections with parity constraints, upper bounds, and combinations with repetition using series multiplication.
7.1 Packaging sequences into generating functions#
When we have a sequence of combinatorial numbers
The ordinary generating function (abbreviated OGF) of a sequence
The variable
The exponent
Let us examine four basic examples to see how combinatorial questions translate into generating functions.
How many subsets of an
The ordinary generating function for the sequence of subset counts is
How many ways are there to choose
Solution: An unordered selection of
Because the sequence is zero for all
Suppose you have in front of you a pile containing an unlimited supply of identical coins. How many ways can you choose
Solution: Because all the coins are identical, two selections of
The sequence of counts is
The generating function
Now suppose you have a pile of dimes, and instead of counting the number of coins you take, you want to track the total monetary value in cents that you obtain. How do we write a generating function for this?
Solution: In the generating function
To track value rather than coin count, we replace
This still looks like a needlessly complicated way of keeping track of something quite simple.
Next, we will see how to use this idea to keep track of the value obtained by electing coins from several piles of different denominations. The total value is going to be the sum of the values contributed by each type of coin. Next we examine how and why multiplication records this combined selections.
7.2 Selecting multiple coins and polynomial multiplication#
Suppose we have three piles of different coins:
pennies, nickels, dimes.
We may choose any number of pennies from
For pennies:
For nickels:
For dimes:
In each polynomial, the exponent of the variable records the number of coins of that denomination selected. For example,
What happens if we multiply these three polynomials together?
7.2.1 Tracking monetary value by substitution#
Now suppose we want to count the total monetary value in cents of each selection.
A penny is worth
Before collecting terms, let us look at how individual selections map to powers of
Different selections can have the same total value. After substituting powers of
7.2.2 Substituting before expanding#
We do not need to expand the product in three variables
Let us summarize this discussion in a self-contained problem and solution.
A coin purse contains at most
Find the ordinary generating function for the number of ways to make change for
cents using coins from this purse. Find the number of ways to make change for
cents.
Solution:
Each coin denomination provides an independent choice of how many coins to use, bounded by the supply in the purse:
Pennies contribute a value
, represented by . Nickels contribute a value
with , represented by . Dimes contribute a value
with , represented by .
Because the total value is the sum of the values from each coin type, the generating function for the number of ways to make change for
cents is the product: The coefficient gives the number of ways to make change for cents. The following code expands the generating function in SageCell.
t = var('t') P(t) = 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 N(t) = 1 + t^5 + t^10 + t^15 + t^20 + t^25 + t^30 D(t) = 1 + t^10 + t^20 + t^30 + t^40 C(t) = P(t)*N(t)*D(t) show( C(t).expand() )The call to
C(t).expand()returnsThus the coefficient of is . If the expanded polynomial is too long to display, first expand it and then extract the requested coefficient:
show( C(t).expand().coefficient(t, 12) )
7.2.3 Infinite generating functions: unlimited supplies#
What changes if we have an unlimited supply of coins of each denomination?
Find the generating function for the number of ways to make change for
Solution: Because there is no upper limit on the number of coins of any type, the choices for each denomination run over all nonnegative integers
t = var('t')
P(t) = 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + t^10 + t^11 + t^12
N(t) = 1 + t^5 + t^10
D(t) = 1 + t^10
C(t) = P(t)*N(t)*D(t)
show(
C(t).expand()
)The output is
Because each coefficient involves only a finite number of arithmetic operations, we do not need to evaluate the series at any real number or discuss limits and convergence.
7.3 The algebra of series and the Cauchy product#
We have seen that multiplying generating functions corresponds to combining independent choices and adding their sizes or values. Let us now examine how the multiplication of two infinite power series is defined algebraically.
Let
7.3.1 Double sums and commuting summations#
The double sum
Summing row by row corresponds to evaluating
7.3.2 Grouping by degree: the anti-diagonals#
To write the product
Degree
: . The coefficient is . Degree
: . The coefficient is . Degree
: . The coefficient is . Degree
: . The coefficient is .
In general, for a fixed degree
7.3.3 Nested loops analogy in programming#
This change in the order of summation is familiar from computer programming. Suppose we want to compute the array of coefficients
The first method corresponds to two independent nested loops over the indices
# Approach 1: Double loop over independent indices j and k
for j from 0 to N:
for k from 0 to N - j:
C[j + k] = C[j + k] + A[j] * B[k]In this approach, every pair
The second method groups the work by the target degree
# Approach 2: Outer loop over the target degree n
for n from 0 to N:
C[n] = 0
for j from 0 to n:
C[n] = C[n] + A[j] * B[n - j]Both algorithms perform the exact same multiplications and produce the exact same array
Let
7.4 Selections with conditions and combinatorial models#
We can now use the algebra of series to model a variety of combinatorial problems where individual components must satisfy specified conditions.
A student climbs a flight of stairs. In each stride, the student may climb either
Find the polynomial that represents the number of steps taken in a single stride.
Find the generating function for the number of steps climbed in
strides. How many ways can the student climb
steps in exactly strides?
Solution:
A single stride can cover either
step or steps. We assign the exponent to the number of steps covered, giving the polynomial The term records taking step, and records taking steps. In
strides, the total number of steps climbed is the sum of the steps taken in stride , stride , and so on through stride . By the product rule, the generating function for the total steps in strides is the th power of : To find the number of ways to climb
steps in exactly strides, we extract the coefficient of in : The coefficient ofis : . The
ways to climb steps in strides correspond to the ordered sequences of strides: Each sequence has strides and total sum steps.
How many ways can we make change for
Solution:
We formulate a generating function in the variable
Even number of pennies: The allowed coin counts are
. Since each penny is cent, the value contributed is cents, giving the series At most 2 nickels: We may choose
nickels. The values contributed are cents, giving the polynomial Unlimited dimes: The allowed counts are
dimes, contributing multiples of cents:
The generating function for making change under these constraints is their product:
Case
( nickels, cents): The equation becomes , which simplifies to : If
: ( pennies, dimes). If
: ( pennies, dime). If
: ( pennies, dimes).
This gives
valid combinations. Case
( nickels, cents): The equation becomes , so , which simplifies to : If
: ( pennies, dimes). If
: ( pennies, dime).
This gives
valid combinations.
No solutions exist for
Adding the two cases gives
Consider the product of three identical geometric series:
Solution:
When we expand this product, choose
7.4.1 Looking forward: closed forms and algebraic operations#
Writing series as expanded sums like
In calculus, we know that the geometric series
Next, we develop the formal algebra of rational generating functions, prove closed-form formulas for standard series, and establish systematic tools for coefficient extraction.