8. Ordinary generating functions: constructions and coefficient extraction#
In earlier notes, we introduced ordinary generating functions as polynomials to solve finite selection problems. However, many counting problems involve unrestricted choices or sequences that go on indefinitely. To tackle these, we must extend our toolkit from finite polynomials to infinite formal power series.
Our main goal in this note is to learn how to efficiently manipulate infinite power series (which are not polynomials) using algebraic tricks, Taylor series expansions, and operational rules.
8.1 Infinite formal power series and rational functions#
Let’s start with a fundamental question: how can we represent an infinite sequence using a compact algebraic expression?
Consider the sequence
Let’s try a clever algebraic trick. Multiply
The identity
However, division is not generally defined for arbitrary generating functions! We have not formally defined what it means to divide one series by another. In practice, we do it anyway whenever the denominator has a non-zero constant term (like
Connecting generating functions to Taylor series.
Where do these closed-form expressions come from in calculus?
If a calculus function
Let’s compute the first 4 terms of the Taylor expansion of
8.2 Solving constrained integer equations#
Generating functions give us a powerful, automated way to count non-negative integer solutions to equations.
Suppose we want to find the number of integer solutions to
Encoding variable bounds with shifting and geometric series.
Each variable
Lower bounds (Shifting): A lower bound
means we factor out . For example, gives: Finite ranges: For a range
, begin with the unrestricted series shifted by , then remove the unrestricted series shifted by . The ensures that values through remain:
Putting all 5 factors together, the overall generating function
Find the number of solutions when
Write
8.2.1 Expanding a rational generating function in Sage#
Once the generating function has been written in closed form, Sage can expand
it as a power series and extract a specified coefficient. In the following
example,
The following code may be run in SageCell.
var('x')
U(x)=1/(1-x^2)
V(x)=x/(1-x^2)
W(x)=(x^10-x^21)/(1-x)
A(x)=U(x)*V(x)*W(x)
show(A(x).series(x,100))
show(A(x).series(x,100).coefficient(x,25))The command var(’x’) declares A(x).series(x,100) expands the rational expression at .coefficient(x,25) to that expansion returns the coefficient of
8.3 Combinatorial interpretations of powers and products#
We begin with the familiar algebraic identity that will guide the first interpretation.
For every integer
We will reinterpret the Binomial Theorem using generating functions: each factor will encode one choice, and the coefficient of
The same multiplication principle also explains the generating functions for multisets and for the restricted integer equations studied earlier.
Subset selection: generating function for
When choosing a subset of size
Why does the product
Let’s assign a distinct variable
Let’s expand
If we substitute
Multiset selection: generating function for
Now consider finding non-negative integer solutions to
For a single variable
Each individual factor becomes
8.4 Operations on generating functions#
By applying algebraic operations to a generating function
Argument Scaling (
): Replacing with multiplies the -th coefficient by : Right Index Shift (
): Multiplying by shifts all sequence terms one position to the right (inserting a at index ): Index Multiplication (
): Differentiating and multiplying by multiplies each term by its index : Cumulative Summation (
): Multiplying by builds running partial sums of the sequence:
Summary of standard operations.
| Operation | Generating Function | Generated Sequence |
|---|---|---|
| Scaling | ||
| Right Shift | ||
| Index Multiplication | ||
| Double Index Multiplication | ||
| Cumulative Sum | ||
| Cauchy Product |
8.5 Application: computing the sum of squares#
Let’s use these operational rules to derive the classic formula for the sum of squares
Step 1: Start with the constant sequence.
The generating function for
Step 2: Generate
Step 3: Generate
Step 4: Accumulate the sum up to
The columns below accumulate the functions obtained in Steps 1–4. Each entry is the coefficient of
| 0 | 1 | 0 | ||
| 1 | 1 | 1 | ||
| 2 | 1 | 2 | ||
| 3 | 1 | 3 | ||
| 4 | 1 | 4 | ||
| 5 | 1 | 5 | ||
| 6 | 1 | 6 | ||
| 7 | 1 | 7 | ||
| 8 | 1 | 8 | ||
| 9 | 1 | 9 |
Step 5: Extract the coefficient manually.
Split the numerator into two terms:
8.6 Exercises and solutions#
Compute closed-form expressions for the coefficients
for . for . for . for .
Solutions:
Solution to Part 1: Using argument scaling (
) together with the negative binomial series formula : Thus the requested coefficients are when , when , and when . Solution to Part 2: Distribute the term
: Applying the shift rule : Since the first shifted series begins in degree and the second begins in degree , the coefficient formula valid for every is For the requested values, the coefficients are when , when , when , and when . Solution to Part 3: We first simplify the finite sum before multiplying it by
. Since , this is a finite geometric series: The exponent marks the first term after the final term . Now multiply by the remaining factor: To extract the coefficient for every
, define Thus . The zero case makes the shifts below work even when is smaller than one of the displayed exponents. Therefore, At , this gives , , and , respectively. The zero at occurs because the smallest degree in the product is . Solution to Part 4: Let
. The finite sum in this part is obtained by applying to the finite geometric series from Part 3: Multiplying byadds five more factors of to the denominator: Define so that . Distributing the numerator and shifting the coefficients gives, for every , At, the corresponding coefficients are , , and .