MatheramaMatherama
← Combinatorics
Combinatorics·Section 11·33 min read

Ordinary Generating Functions

In Sections 07 and 08, we counted integer solutions to equations like x1+x2+⋯+xr=nx_1 + x_2 + \dots + x_r = n using binary strings, variable shifts, and the Principle of Inclusion–Exclusion. Each new restriction—such as upper bounds, parity conditions, or weighted coefficients—required a separate counting trick.

Generating functions turn all of these counting problems into one unified method: multiplying polynomials and power series. Before stating any formula, we build the idea slowly from basic algebra so it is completely clear why it works.


How Multiplying Brackets Works§

Consider a simple algebraic product of two brackets:

(a1+b1)(a2+b2)=a1a2+a1b2+b1a2+b1b2(a_1 + b_1)(a_2 + b_2) = a_1 a_2 + a_1 b_2 + b_1 a_2 + b_1 b_2

Look closely at how every term on the right is formed. We do not mix terms from the same bracket. Instead, to produce one product term, we:

  • pick exactly one term from the first bracket (a1a_1 or b1b_1),
  • pick exactly one term from the second bracket (a2a_2 or b2b_2),
  • multiply those two chosen terms together.

Summing over every possible pair of choices gives the complete expansion.

Now try brackets of unequal sizes, such as (a1+b1+c1)(a2+b2)(a_1 + b_1 + c_1)(a_2 + b_2):

(a1+b1+c1)(a2+b2)=a1a2+a1b2+b1a2+b1b2+c1a2+c1b2(a_1 + b_1 + c_1)(a_2 + b_2) = a_1 a_2 + a_1 b_2 + b_1 a_2 + b_1 b_2 + c_1 a_2 + c_1 b_2

There are 33 choices in the first bracket and 22 choices in the second bracket. By the Multiplication Principle (Section 01), expanding the product generates 3×2=63 \times 2 = 6 raw products—one for every possible pair of picks.

Expanding a Product of Two Brackets by Picking One Term From Each

The same rule holds for three or more brackets. For (a1+b1)(a2+b2)(a3+b3)(a_1 + b_1)(a_2 + b_2)(a_3 + b_3):

(a1+b1)(a2+b2)(a3+b3)=a1a2a3+a1a2b3+a1b2a3+a1b2b3+b1a2a3+b1a2b3+b1b2a3+b1b2b3(a_1 + b_1)(a_2 + b_2)(a_3 + b_3) = a_1 a_2 a_3 + a_1 a_2 b_3 + a_1 b_2 a_3 + a_1 b_2 b_3 + b_1 a_2 a_3 + b_1 a_2 b_3 + b_1 b_2 a_3 + b_1 b_2 b_3

There are 2×2×2=82 \times 2 \times 2 = 8 raw products, corresponding to every way of choosing one term from each of the three brackets.

In general, when we expand a product of rr brackets whose sizes are k1,k2,…,krk_1, k_2, \dots, k_r:

Core Rule of Expansion: Every raw term in the product is obtained by selecting exactly one term from each of the rr brackets and multiplying them together. Before collecting like terms, there are k1k2⋯krk_1 k_2 \cdots k_r raw products—one for every possible tuple of choices.


Turning Choices into Exponents of One Symbol§

Now make one small but decisive change. Instead of putting distinct letters inside the brackets, place powers of a single symbol xx inside every bracket.

Consider the product:

(x0+x1+x2)(x0+x1+x2)(x^0 + x^1 + x^2)(x^0 + x^1 + x^2)

Expand it slowly by our bracket-picking rule, writing out all 3×3=93 \times 3 = 9 raw products before simplifying:

x0⋅x0+x0⋅x1+x0⋅x2+x1⋅x0+x1⋅x1+x1⋅x2+x2⋅x0+x2⋅x1+x2⋅x2x^0 \cdot x^0 + x^0 \cdot x^1 + x^0 \cdot x^2 + x^1 \cdot x^0 + x^1 \cdot x^1 + x^1 \cdot x^2 + x^2 \cdot x^0 + x^2 \cdot x^1 + x^2 \cdot x^2

Now apply the law of exponents, xa⋅xb=xa+bx^a \cdot x^b = x^{a + b}. Multiplying two chosen terms adds their exponents! Group the 99 raw products by their total exponent:

  • Exponent 00 (x0x^0): x0⋅x0x^0 \cdot x^0 ⟶\longrightarrow 11 way ⟶\longrightarrow solution (0,0)(0, 0) of x1+x2=0x_1 + x_2 = 0.
  • Exponent 11 (x1x^1): x0⋅x1+x1⋅x0x^0 \cdot x^1 + x^1 \cdot x^0 ⟶\longrightarrow 22 ways ⟶\longrightarrow solutions (0,1),  (1,0)(0, 1),\; (1, 0) of x1+x2=1x_1 + x_2 = 1.
  • Exponent 22 (x2x^2): x0⋅x2+x1⋅x1+x2⋅x0x^0 \cdot x^2 + x^1 \cdot x^1 + x^2 \cdot x^0 ⟶\longrightarrow 33 ways ⟶\longrightarrow solutions (0,2),  (1,1),  (2,0)(0, 2),\; (1, 1),\; (2, 0) of x1+x2=2x_1 + x_2 = 2.
  • Exponent 33 (x3x^3): x1⋅x2+x2⋅x1x^1 \cdot x^2 + x^2 \cdot x^1 ⟶\longrightarrow 22 ways ⟶\longrightarrow solutions (1,2),  (2,1)(1, 2),\; (2, 1) of x1+x2=3x_1 + x_2 = 3.
  • Exponent 44 (x4x^4): x2⋅x2x^2 \cdot x^2 ⟶\longrightarrow 11 way ⟶\longrightarrow solution (2,2)(2, 2) of x1+x2=4x_1 + x_2 = 4.

Putting the grouped terms together:

(1+x+x2)(1+x+x2)=1+2x+3x2+2x3+x4(1 + x + x^2)(1 + x + x^2) = 1 + 2x + 3x^2 + 2x^3 + x^4

Look at what algebra just did automatically:

  • Choosing xa1x^{a_1} from the first bracket is identical to setting x1=a1∈{0,1,2}x_1 = a_1 \in \{0, 1, 2\}.
  • Choosing xa2x^{a_2} from the second bracket is identical to setting x2=a2∈{0,1,2}x_2 = a_2 \in \{0, 1, 2\}.
  • Their product xa1⋅xa2=xa1+a2x^{a_1} \cdot x^{a_2} = x^{a_1 + a_2} equals xnx^n if and only if a1+a2=na_1 + a_2 = n.
  • Every valid solution (a1,a2)(a_1, a_2) contributes exactly +1+1 to the coefficient of xnx^n.

Therefore, the coefficient of xnx^n in the expanded product equals the exact number of integer solutions to x1+x2=nx_1 + x_2 = n with x1,x2∈{0,1,2}x_1, x_2 \in \{0, 1, 2\}.

The exact same bijection works for rr variables. For any rr brackets representing the allowed values of x1,x2,…,xrx_1, x_2, \dots, x_r, picking xa1x^{a_1} from bracket 11, xa2x^{a_2} from bracket 22, …\dots, and xarx^{a_r} from bracket rr gives:

xa1⋅xa2⋯xar=xa1+a2+⋯+arx^{a_1} \cdot x^{a_2} \cdots x^{a_r} = x^{a_1 + a_2 + \dots + a_r}

Why Multiplying Brackets Counts Solutions of x1 + x2 + x3 = 4

Coefficient Notation and the Role of the Placeholder§

We write [xn] F(x)[x^n]\,F(x) to mean "the coefficient of xnx^n in the expansion of F(x)F(x)." For instance:

[x2](1+x+x2)2=3,[x3](1+x+x2)2=2[x^2](1 + x + x^2)^2 = 3, \qquad [x^3](1 + x + x^2)^2 = 2

What Is xx Here?
In combinatorics, xx is not a number we are trying to solve for. It is purely a formal bookkeeping placeholder whose exponents add whenever we multiply brackets. Because we never substitute numerical values for xx, we treat infinite sums of powers of xx as formal power series—we do not need to worry about convergence tests such as ∣x∣<1|x| < 1.


Solving Non-Negative Integer Equations: Natural Bound vs. Infinity§

Now apply this method to the fundamental equation from Section 07:

x1+x2+⋯+xr=n,xi≥0(1≤i≤r)x_1 + x_2 + \dots + x_r = n, \qquad x_i \ge 0 \quad (1 \le i \le r)

Here, no upper bound is stated for any variable xix_i. What bracket should we write for each xix_i?

Step 1: The Natural Upper Bound§

Even though no upper bound is given in the problem, every variable satisfies xj≥0x_j \ge 0. Therefore, no single variable can ever exceed the total sum nn:

0≤xi≤nfor every i=1,2,…,r0 \le x_i \le n \quad \text{for every } i = 1, 2, \dots, r

We call nn the natural upper bound of the equation. Listing every value that xix_i can actually take gives the exact finite polynomial (1+x+x2+⋯+xn)(1 + x + x^2 + \dots + x^n) for each bracket. Hence the number of non-negative integer solutions is:

[xn] (1+x+x2+⋯+xn)r[x^n]\,(1 + x + x^2 + \dots + x^n)^r

Step 2: Why Extending to Infinity Does Not Change the Answer§

Now ask a careful question: what happens to [xn][x^n] if we replace the finite bracket (1+x+x2+⋯+xn)(1 + x + x^2 + \dots + x^n) with the infinite series (1+x+x2+⋯+xn+xn+1+xn+2+… )(1 + x + x^2 + \dots + x^n + x^{n+1} + x^{n+2} + \dots)?

Theorem (Safe Extension to Infinity): If every bracket in a product contains only non-negative powers of xx, then adding terms of degree strictly greater than nn (that is, xn+1+xn+2+…x^{n+1} + x^{n+2} + \dots) to any bracket does not change the coefficient of xnx^n.

Proof: Suppose we form a raw product by picking one term xaix^{a_i} from each bracket, where every ai≥0a_i \ge 0. If we pick any newly added term xkx^k with k≥n+1k \ge n + 1 from some bracket, then the sum of exponents across all rr brackets satisfies:

a1+a2+⋯+ar≥k+0+⋯+0=k≥n+1>na_1 + a_2 + \dots + a_r \ge k + 0 + \dots + 0 = k \ge n + 1 > n

Thus no raw product that uses a term from the infinite tail xn+1+xn+2+…x^{n+1} + x^{n+2} + \dots can ever yield xnx^n. The set of raw products that equal xnx^n is completely unchanged, so [xn][x^n] stays identical. ■\blacksquare

Natural Bound vs Infinite Tail and Active Upper Bound

Step 3: Why Extending to Infinity Makes Algebra Simpler§

Using the geometric series formula 1+x+x2+⋯+xn=1−xn+11−x1 + x + x^2 + \dots + x^n = \frac{1 - x^{n+1}}{1 - x} and its infinite counterpart 1+x+x2+⋯=11−x1 + x + x^2 + \dots = \frac{1}{1 - x}, compare the two expressions:

Finite form (stopping at xnx^n):

[xn](1−xn+11−x)r=[xn] (1−xn+1)r(1−x)−r[x^n]\left(\frac{1 - x^{n+1}}{1 - x}\right)^r = [x^n]\,(1 - x^{n+1})^r (1 - x)^{-r}

Expanding (1−xn+1)r=1−(r1)xn+1+(r2)x2n+2−…(1 - x^{n+1})^r = 1 - \binom{r}{1} x^{n+1} + \binom{r}{2} x^{2n+2} - \dots shows that every term except 11 already has degree >n> n, so all of them vanish when we extract [xn][x^n]!

Infinite form (extending to ∞\infty):

[xn] (1+x+x2+… )r=[xn](11−x)r=[xn] (1−x)−r[x^n]\,(1 + x + x^2 + \dots)^r = [x^n]\left(\frac{1}{1 - x}\right)^r = [x^n]\,(1 - x)^{-r}

Extending an unrestricted bracket up to ∞\infty throws away the useless (1−xn+1)r(1 - x^{n+1})^r factor upfront, leaving the clean expression (1−x)−r(1 - x)^{-r}.

Essential Precaution (No Negative Powers):
The extension-to-infinity theorem requires every bracket to have only non-negative exponents. If another bracket contains a negative power such as x−2x^{-2}, then a tail term xn+2x^{n+2} multiplied by x−2x^{-2} would produce xnx^n and corrupt the count! Whenever a variable has a negative lower bound, always shift it to a non-negative variable first.


The Master Expansion Formula§

To compute [xm] (1−x)−r[x^m]\,(1 - x)^{-r} quickly and rigorously, we need its explicit series expansion.

Theorem (Negative-Index Binomial Series): For every positive integer r≥1r \ge 1:

(1−x)−r=1(1−x)r=∑m=0∞(m+r−1r−1)xm(1 - x)^{-r} = \frac{1}{(1 - x)^r} = \sum_{m=0}^{\infty} \binom{m + r - 1}{r - 1} x^m

Equivalently, for every integer m≥0m \ge 0:

[xm] (1−x)−r=(m+r−1r−1)[x^m]\,(1 - x)^{-r} = \binom{m + r - 1}{r - 1}

We prove this in two independent ways—both use results we already established earlier in this chapter.

Proof 1 (Combinatorial Proof via Section 07): Rewrite (1−x)−r(1 - x)^{-r} as (1+x+x2+… )r(1 + x + x^2 + \dots)^r. By our exponent-addition bijection, [xm] (1+x+x2+… )r[x^m]\,(1 + x + x^2 + \dots)^r equals the number of non-negative integer solutions to:

x1+x2+⋯+xr=m,xi≥0x_1 + x_2 + \dots + x_r = m, \qquad x_i \ge 0

By the Combinations with Unlimited Repetition Theorem (Section 07), this count is (m+r−1r−1)\binom{m + r - 1}{r - 1}. Since this holds for every m≥0m \ge 0, the expansion follows immediately. ■\blacksquare

Proof 2 (Algebraic Proof by Induction on rr):

Base case (r=1r = 1): By the geometric series identity:

(1−x)−1=1+x+x2+x3+⋯=∑m=0∞1⋅xm=∑m=0∞(m+1−11−1)xm(1 - x)^{-1} = 1 + x + x^2 + x^3 + \dots = \sum_{m=0}^{\infty} 1 \cdot x^m = \sum_{m=0}^{\infty} \binom{m + 1 - 1}{1 - 1} x^m

since (m0)=1\binom{m}{0} = 1. The base case holds.

Inductive step: Assume the formula holds for rr. Write (1−x)−(r+1)=(1−x)−r⋅(1−x)−1(1 - x)^{-(r+1)} = (1 - x)^{-r} \cdot (1 - x)^{-1}:

(1−x)−(r+1)=(∑k=0∞(k+r−1r−1)xk)(1+x+x2+… )(1 - x)^{-(r+1)} = \left(\sum_{k=0}^{\infty} \binom{k + r - 1}{r - 1} x^k\right)\left(1 + x + x^2 + \dots\right)

To obtain xmx^m from this product, we pick xkx^k from the first series (for any 0≤k≤m0 \le k \le m) and xm−kx^{m - k} from the second series. Summing over all k=0,1,…,mk = 0, 1, \dots, m:

[xm] (1−x)−(r+1)=∑k=0m(k+r−1r−1)=(r−1r−1)+(rr−1)+⋯+(m+r−1r−1)[x^m]\,(1 - x)^{-(r+1)} = \sum_{k=0}^{m} \binom{k + r - 1}{r - 1} = \binom{r - 1}{r - 1} + \binom{r}{r - 1} + \dots + \binom{m + r - 1}{r - 1}

By the Hockey-Stick Identity (Section 04), this sum collapses to (m+rr)\binom{m + r}{r}, which matches the theorem for r+1r + 1. By mathematical induction, the formula holds for all r≥1r \ge 1. ■\blacksquare

(Note: This also agrees with the generalized Binomial Theorem (1−x)−r=∑m=0∞(−rm)(−x)m(1 - x)^{-r} = \sum_{m=0}^{\infty} \binom{-r}{m}(-x)^m, since (−rm)(−1)m=(−r)(−r−1)⋯(−r−m+1)m!(−1)m=r(r+1)⋯(r+m−1)m!=(m+r−1m)=(m+r−1r−1)\binom{-r}{m}(-1)^m = \frac{(-r)(-r-1)\cdots(-r-m+1)}{m!}(-1)^m = \frac{r(r+1)\cdots(r+m-1)}{m!} = \binom{m + r - 1}{m} = \binom{m + r - 1}{r - 1}.)

Example 1: Use generating functions to find the number of non-negative integer solutions to x1+x2+x3+x4=10x_1 + x_2 + x_3 + x_4 = 10.

Solution: Each variable xi≥0x_i \ge 0 has no upper bound, so each contributes the factor (1+x+x2+… )=(1−x)−1(1 + x + x^2 + \dots) = (1 - x)^{-1}. The number of solutions is:

[x10] (1−x)−4=(10+4−14−1)=(133)=13×12×116=286[x^{10}]\,(1 - x)^{-4} = \binom{10 + 4 - 1}{4 - 1} = \binom{13}{3} = \frac{13 \times 12 \times 11}{6} = 286

Encoding Restrictions into Brackets§

The real power of generating functions appears when variables carry restrictions. Because each bracket simply lists the allowed values of its variable as exponents of xx, every restriction translates directly into editing that variable's bracket.

Let us examine each type of restriction carefully, paying close attention to the difference between the natural bound and imposed bounds.

Case 1: Lower Bound Only§

Suppose a variable satisfies xi≥aix_i \ge a_i (where ai≥0a_i \ge 0) with no upper bound. Its smallest allowed value is aia_i, and its larger values can extend to ∞\infty. So its bracket is:

xai+xai+1+xai+2+⋯=xai(1+x+x2+… )=xai1−xx^{a_i} + x^{a_i + 1} + x^{a_i + 2} + \dots = x^{a_i}(1 + x + x^2 + \dots) = \frac{x^{a_i}}{1 - x}

When all rr variables satisfy xi≥aix_i \ge a_i (ai≥0a_i \ge 0), the product of brackets is:

xa11−x⋅xa21−x⋯xar1−x=xa1+a2+⋯+ar(1−x)r\frac{x^{a_1}}{1 - x} \cdot \frac{x^{a_2}}{1 - x} \cdots \frac{x^{a_r}}{1 - x} = \frac{x^{a_1 + a_2 + \dots + a_r}}{(1 - x)^r}

Let A=a1+a2+⋯+arA = a_1 + a_2 + \dots + a_r. To find [xn] xA(1−x)r[x^n]\,\frac{x^A}{(1 - x)^r}, notice that multiplying any power series by xAx^A shifts every exponent up by AA. Hence:

[xn](xA⋅F(x))=[xn−A] F(x)[x^n]\left(x^A \cdot F(x)\right) = [x^{n - A}]\,F(x)

Therefore, for n′=n−A≥0n' = n - A \ge 0:

[xn] xA(1−x)r=[xn′] (1−x)−r=(n′+r−1r−1)[x^n]\,\frac{x^A}{(1 - x)^r} = [x^{n'}]\,(1 - x)^{-r} = \binom{n' + r - 1}{r - 1}

Notice two important facts:

  • Factoring out xa1+⋯+arx^{a_1 + \dots + a_r} is the exact algebraic mirror of the variable shift yi=xi−aiy_i = x_i - a_i from Section 07.
  • Lower bounds reduce the remaining sum to n′=n−(a1+⋯+ar)n' = n - (a_1 + \dots + a_r), which lowers the effective natural upper bound of every shifted variable yiy_i to n′n'.

Example 2 (Positive and Negative Lower Bounds): Find the number of integer solutions to:

(a) x1+x2+x3=12x_1 + x_2 + x_3 = 12 with x1≥2,  x2≥3,  x3≥1x_1 \ge 2,\; x_2 \ge 3,\; x_3 \ge 1.

(b) x1+x2+x3=5x_1 + x_2 + x_3 = 5 with x1≥−2,  x2≥−1,  x3≥0x_1 \ge -2,\; x_2 \ge -1,\; x_3 \ge 0.

Solution:

(a) Write one bracket for each variable starting at its lower bound:

[x12] (x2+x3+… )(x3+x4+… )(x1+x2+… )=[x12] x21−x⋅x31−x⋅x11−x[x^{12}]\,(x^2 + x^3 + \dots)(x^3 + x^4 + \dots)(x^1 + x^2 + \dots) = [x^{12}]\,\frac{x^2}{1 - x} \cdot \frac{x^3}{1 - x} \cdot \frac{x^1}{1 - x} =[x12] x6(1−x)3=[x12−6] (1−x)−3=[x6] (1−x)−3=(6+3−13−1)=(82)=28= [x^{12}]\,\frac{x^6}{(1 - x)^3} = [x^{12 - 6}]\,(1 - x)^{-3} = [x^6]\,(1 - x)^{-3} = \binom{6 + 3 - 1}{3 - 1} = \binom{8}{2} = 28

(b) Here x1x_1 and x2x_2 can be negative! We must not write (x−2+x−1+… )(x^{-2} + x^{-1} + \dots) and blindly extend brackets to ∞\infty without checking, because negative powers can cancel higher powers (for example, x−2⋅x7⋅x0=x5x^{-2} \cdot x^7 \cdot x^0 = x^5 uses an exponent greater than 55). Instead, shift every variable to become non-negative first:

y1=x1+2≥0,y2=x2+1≥0,y3=x3≥0y_1 = x_1 + 2 \ge 0, \qquad y_2 = x_2 + 1 \ge 0, \qquad y_3 = x_3 \ge 0

Substituting x1=y1−2x_1 = y_1 - 2, x2=y2−1x_2 = y_2 - 1, x3=y3x_3 = y_3 gives:

(y1−2)+(y2−1)+y3=5  ⟹  y1+y2+y3=8,y1,y2,y3≥0(y_1 - 2) + (y_2 - 1) + y_3 = 5 \implies y_1 + y_2 + y_3 = 8, \qquad y_1, y_2, y_3 \ge 0

Now all exponents are non-negative, so we safely apply generating functions:

[x8] (1−x)−3=(8+3−13−1)=(102)=45[x^8]\,(1 - x)^{-3} = \binom{8 + 3 - 1}{3 - 1} = \binom{10}{2} = 45

Case 2: Upper Bound Only — Active vs. Redundant Bounds§

Now suppose a variable has an imposed upper bound: 0≤xi≤bi0 \le x_i \le b_i. Compare bib_i with the equation's natural upper bound nn:

Subcase 2A: Active Upper Bound (bi<nb_i < n). Here the problem cuts off xix_i strictly below its natural bound nn. We cannot extend this bracket to ∞\infty! Why? Because the powers xbi+1,xbi+2,…,xnx^{b_i + 1}, x^{b_i + 2}, \dots, x^n are smaller than or equal to nn, so they would combine with terms from the other brackets to produce fake xnx^n terms corresponding to illegal solutions with xi>bix_i > b_i.

Therefore, the bracket must stop at xbix^{b_i}:

1+x+x2+⋯+xbi=1−xbi+11−x1 + x + x^2 + \dots + x^{b_i} = \frac{1 - x^{b_i + 1}}{1 - x}

Subcase 2B: Redundant Upper Bound (bi≥nb_i \ge n). Here the imposed limit bib_i is at least as large as the natural bound nn. Because all other variables are non-negative, xix_i could never exceed nn anyway—so the bound xi≤bix_i \le b_i changes nothing! We may safely extend this bracket to ∞\infty as 11−x\frac{1}{1 - x}.

(Algebraic check: even if you kept the finite sum 1−xbi+11−x\frac{1 - x^{b_i + 1}}{1 - x} when bi≥nb_i \ge n, the extra term −xbi+1-x^{b_i + 1} has exponent bi+1≥n+1>nb_i + 1 \ge n + 1 > n, so it contributes zero to [xn][x^n]!)

Example 3 (Active vs. Redundant Upper Bounds): Find the number of non-negative integer solutions to:

x1+x2+x3=10,0≤x1≤4,0≤x2≤12,0≤x3≤10x_1 + x_2 + x_3 = 10, \qquad 0 \le x_1 \le 4,\quad 0 \le x_2 \le 12,\quad 0 \le x_3 \le 10

Solution: The natural upper bound of this equation is n=10n = 10. Check each variable's upper bound against n=10n = 10:

  • x1≤4<10x_1 \le 4 < 10: active bound ⟶\longrightarrow bracket must stop at x4x^4: (1+x+x2+x3+x4)=1−x51−x(1 + x + x^2 + x^3 + x^4) = \frac{1 - x^5}{1 - x}.
  • x2≤12≥10x_2 \le 12 \ge 10: redundant bound ⟶\longrightarrow behaves like no upper bound: 11−x\frac{1}{1 - x}.
  • x3≤10≥10x_3 \le 10 \ge 10: redundant bound ⟶\longrightarrow behaves like no upper bound: 11−x\frac{1}{1 - x}.

Multiplying the three factors gives:

[x10](1−x51−x⋅11−x⋅11−x)=[x10] 1−x5(1−x)3=[x10] (1−x)−3−[x10] x5(1−x)−3[x^{10}]\left(\frac{1 - x^5}{1 - x} \cdot \frac{1}{1 - x} \cdot \frac{1}{1 - x}\right) = [x^{10}]\,\frac{1 - x^5}{(1 - x)^3} = [x^{10}]\,(1 - x)^{-3} - [x^{10}]\,x^5 (1 - x)^{-3}

Using [x10] x5(1−x)−3=[x10−5] (1−x)−3=[x5] (1−x)−3[x^{10}]\,x^5 (1 - x)^{-3} = [x^{10 - 5}]\,(1 - x)^{-3} = [x^5]\,(1 - x)^{-3}:

(10+3−12)−(5+3−12)=(122)−(72)=66−21=45\binom{10 + 3 - 1}{2} - \binom{5 + 3 - 1}{2} = \binom{12}{2} - \binom{7}{2} = 66 - 21 = 45

Case 3: Both Lower and Upper Bounds, and Automatic Inclusion–Exclusion§

Suppose a variable must satisfy both a lower bound and an upper bound:

ai≤xi≤bi(0≤ai≤bi)a_i \le x_i \le b_i \qquad (0 \le a_i \le b_i)

Listing all allowed values from aia_i up to bib_i gives a finite geometric progression with bi−ai+1b_i - a_i + 1 terms:

xai+xai+1+⋯+xbi=xai(1+x+x2+⋯+xbi−ai)=xai 1−xbi−ai+11−xx^{a_i} + x^{a_i + 1} + \dots + x^{b_i} = x^{a_i}\left(1 + x + x^2 + \dots + x^{b_i - a_i}\right) = x^{a_i}\,\frac{1 - x^{b_i - a_i + 1}}{1 - x}

Look closely at the exponent bi−ai+1b_i - a_i + 1. After factoring out xa1+⋯+arx^{a_1 + \dots + a_r} from all brackets, the remaining target sum is:

n′=n−(a1+a2+⋯+ar)n' = n - (a_1 + a_2 + \dots + a_r)

So the upper bound on xix_i is active only if its allowed span bi−aib_i - a_i is strictly less than n′n' (that is, bi−ai<n′b_i - a_i < n'). If bi−ai≥n′b_i - a_i \ge n', then the term −xbi−ai+1-x^{b_i - a_i + 1} has degree >n′> n' and automatically drops out!

Even better: when several variables have active upper bounds, multiplying out the numerator factors ∏(1−xbi−ai+1)\prod (1 - x^{b_i - a_i + 1}) automatically performs the Principle of Inclusion–Exclusion (Section 08)—without manually defining violation sets A1,A2,…A_1, A_2, \dots!

Example 4 (Automatic PIE and Effective Bounds):

(a) Re-solve the three-bound equation from Section 08 using generating functions:

x1+x2+x3=15,0≤x1≤6,0≤x2≤7,0≤x3≤8x_1 + x_2 + x_3 = 15, \qquad 0 \le x_1 \le 6,\quad 0 \le x_2 \le 7,\quad 0 \le x_3 \le 8

(b) Find the number of integer solutions to:

x1+x2+x3=14,2≤x1≤6,1≤x2≤5,3≤x3≤12x_1 + x_2 + x_3 = 14, \qquad 2 \le x_1 \le 6,\quad 1 \le x_2 \le 5,\quad 3 \le x_3 \le 12

Solution:

(a) All three upper bounds are strictly less than 1515, so all three are active. The count is:

[x15](1−x71−x⋅1−x81−x⋅1−x91−x)=[x15] (1−x7)(1−x8)(1−x9)(1−x)3[x^{15}]\left(\frac{1 - x^7}{1 - x} \cdot \frac{1 - x^8}{1 - x} \cdot \frac{1 - x^9}{1 - x}\right) = [x^{15}]\,\frac{(1 - x^7)(1 - x^8)(1 - x^9)}{(1 - x)^3}

Expand the numerator, dropping every term whose exponent already exceeds 1515:

(1−x7)(1−x8)(1−x9)=1−x7−x8−x9+x15+x16+x17−x24(1 - x^7)(1 - x^8)(1 - x^9) = 1 - x^7 - x^8 - x^9 + x^{15} + x^{16} + x^{17} - x^{24}

The terms x16,x17,−x24x^{16}, x^{17}, -x^{24} all have degree >15> 15 and contribute 00 to [x15][x^{15}]. Retaining only terms of degree ≤15\le 15:

[x15] (1−x7−x8−x9+x15)(1−x)−3[x^{15}]\,(1 - x^7 - x^8 - x^9 + x^{15})(1 - x)^{-3} =[x15](1−x)−3−[x8](1−x)−3−[x7](1−x)−3−[x6](1−x)−3+[x0](1−x)−3= [x^{15}](1 - x)^{-3} - [x^8](1 - x)^{-3} - [x^7](1 - x)^{-3} - [x^6](1 - x)^{-3} + [x^0](1 - x)^{-3} =(172)−(102)−(92)−(82)+(22)=136−45−36−28+1=28= \binom{17}{2} - \binom{10}{2} - \binom{9}{2} - \binom{8}{2} + \binom{2}{2} = 136 - 45 - 36 - 28 + 1 = 28

Compare this line with Section 08: 136136 is ∣U∣|U|, 45+36+2845 + 36 + 28 is ∣A1∣+∣A2∣+∣A3∣|A_1| + |A_2| + |A_3|, and +1+1 is ∣A1∩A2∣|A_1 \cap A_2|! Generating functions executed PIE automatically.

(b) Write the exact bracket for each variable:

[x14] (x2+⋯+x6)(x1+⋯+x5)(x3+⋯+x12)[x^{14}]\,(x^2 + \dots + x^6)(x^1 + \dots + x^5)(x^3 + \dots + x^{12})

Factor out the lowest power from each bracket:

=[x14] x2⋅x1⋅x3⋅1−x6−2+11−x⋅1−x5−1+11−x⋅1−x12−3+11−x= [x^{14}]\,x^2 \cdot x^1 \cdot x^3 \cdot \frac{1 - x^{6 - 2 + 1}}{1 - x} \cdot \frac{1 - x^{5 - 1 + 1}}{1 - x} \cdot \frac{1 - x^{12 - 3 + 1}}{1 - x} =[x14] x6⋅(1−x5)(1−x5)(1−x10)(1−x)3=[x8] (1−x5)2(1−x10)(1−x)3= [x^{14}]\,x^6 \cdot \frac{(1 - x^5)(1 - x^5)(1 - x^{10})}{(1 - x)^3} = [x^8]\,\frac{(1 - x^5)^2 (1 - x^{10})}{(1 - x)^3}

Look at x3≤12x_3 \le 12: before shifting, 12<1412 < 14 looked like an active upper bound. However, once the lower bounds 2+1+3=62 + 1 + 3 = 6 reduced the remaining sum to n′=8n' = 8, the span of x3x_3 is 12−3=9≥812 - 3 = 9 \ge 8, so the factor (1−x10)(1 - x^{10}) has x10x^{10} exceeding 88 and becomes redundant! Expanding only up to degree 88:

(1−x5)2(1−x10)=(1−2x5+x10)(1−x10)=1−2x5+(terms of degree≥10)(1 - x^5)^2 (1 - x^{10}) = (1 - 2x^5 + x^{10})(1 - x^{10}) = 1 - 2x^5 + (\text{terms of degree} \ge 10)

Hence the number of solutions is:

[x8] (1−2x5)(1−x)−3=[x8](1−x)−3−2 [x3](1−x)−3=(102)−2(52)=45−20=25[x^8]\,(1 - 2x^5)(1 - x)^{-3} = [x^8](1 - x)^{-3} - 2\,[x^3](1 - x)^{-3} = \binom{10}{2} - 2\binom{5}{2} = 45 - 20 = 25

Case 4: Parity, Multiples, and Arbitrary Allowed Sets§

Unlike binary strings, generating functions handle gaps in allowed values effortlessly. You simply include only the allowed exponents inside that variable's bracket:

1. xix_i is even (xi∈{0,2,4,6,… }x_i \in \{0, 2, 4, 6, \dots\}):

1+x2+x4+x6+⋯=11−x21 + x^2 + x^4 + x^6 + \dots = \frac{1}{1 - x^2}

2. xix_i is odd (xi∈{1,3,5,7,… }x_i \in \{1, 3, 5, 7, \dots\}):

x+x3+x5+x7+⋯=x(1+x2+x4+… )=x1−x2x + x^3 + x^5 + x^7 + \dots = x(1 + x^2 + x^4 + \dots) = \frac{x}{1 - x^2}

3. xix_i is a non-negative multiple of kk (xi∈{0,k,2k,3k,… }x_i \in \{0, k, 2k, 3k, \dots\}):

1+xk+x2k+x3k+⋯=11−xk1 + x^k + x^{2k} + x^{3k} + \dots = \frac{1}{1 - x^k}

4. xix_i belongs to a specific finite set SS (for example, xi∈{0,2,5}x_i \in \{0, 2, 5\}):

x0+x2+x5=1+x2+x5x^0 + x^2 + x^5 = 1 + x^2 + x^5

Example 5: Find the number of non-negative integer solutions to x1+x2+x3=10x_1 + x_2 + x_3 = 10 such that x1x_1 is even, x2x_2 is odd, and x3∈{1,3,5}x_3 \in \{1, 3, 5\}.

Solution: Encode each variable's allowed values directly into its bracket:

  • x1x_1 even ⟶1+x2+x4+⋯=11−x2\longrightarrow 1 + x^2 + x^4 + \dots = \frac{1}{1 - x^2}.
  • x2x_2 odd ⟶x+x3+x5+⋯=x1−x2\longrightarrow x + x^3 + x^5 + \dots = \frac{x}{1 - x^2}.
  • x3∈{1,3,5}⟶x+x3+x5x_3 \in \{1, 3, 5\} \longrightarrow x + x^3 + x^5.

Multiply the three brackets and extract [x10][x^{10}]:

[x10](11−x2⋅x1−x2⋅(x+x3+x5))=[x10] x2+x4+x6(1−x2)2[x^{10}]\left(\frac{1}{1 - x^2} \cdot \frac{x}{1 - x^2} \cdot (x + x^3 + x^5)\right) = [x^{10}]\,\frac{x^2 + x^4 + x^6}{(1 - x^2)^2} =[x8](1−x2)−2+[x6](1−x2)−2+[x4](1−x2)−2= [x^8](1 - x^2)^{-2} + [x^6](1 - x^2)^{-2} + [x^4](1 - x^2)^{-2}

Set t=x2t = x^2 so that x2k=tkx^{2k} = t^k and (1−x2)−2=(1−t)−2=∑k=0∞(k+11)tk=∑k=0∞(k+1)tk(1 - x^2)^{-2} = (1 - t)^{-2} = \sum_{k=0}^{\infty} \binom{k + 1}{1} t^k = \sum_{k=0}^{\infty} (k + 1) t^k. Then:

  • [x8](1−x2)−2=[t4](1−t)−2=4+1=5[x^8](1 - x^2)^{-2} = [t^4](1 - t)^{-2} = 4 + 1 = 5,
  • [x6](1−x2)−2=[t3](1−t)−2=3+1=4[x^6](1 - x^2)^{-2} = [t^3](1 - t)^{-2} = 3 + 1 = 4,
  • [x4](1−x2)−2=[t2](1−t)−2=2+1=3[x^4](1 - x^2)^{-2} = [t^2](1 - t)^{-2} = 2 + 1 = 3.

Adding these gives 5+4+3=125 + 4 + 3 = 12 solutions.


Case 5: Weighted Linear Equations (Coin-Change Problems)§

Suppose variables have different positive integer coefficients:

c1x1+c2x2+⋯+crxr=n,xi≥0c_1 x_1 + c_2 x_2 + \dots + c_r x_r = n, \qquad x_i \ge 0

Think carefully about what each variable contributes to the sum nn. Variable xix_i does not add xix_i to the total—it adds cixic_i x_i! As xix_i runs through 0,1,2,3,…0, 1, 2, 3, \dots, its contribution cixic_i x_i runs through 0,ci,2ci,3ci,…0, c_i, 2c_i, 3c_i, \dots.

Therefore, the bracket representing cixic_i x_i is:

1+xci+x2ci+x3ci+⋯=11−xci1 + x^{c_i} + x^{2c_i} + x^{3c_i} + \dots = \frac{1}{1 - x^{c_i}}

When we pick xc1a1x^{c_1 a_1} from bracket 11, xc2a2x^{c_2 a_2} from bracket 22, …\dots, and xcrarx^{c_r a_r} from bracket rr, multiplying them gives xc1a1+c2a2+⋯+crarx^{c_1 a_1 + c_2 a_2 + \dots + c_r a_r}, so [xn][x^n] counts every solution of c1x1+⋯+crxr=nc_1 x_1 + \dots + c_r x_r = n!

Before solving coin-change and partition problems, we prove one small building-block formula that appears repeatedly whenever weights 11 and 22 occur together.

Lemma (Coefficient of xmx^m in 1(1−x)(1−x2)\frac{1}{(1 - x)(1 - x^2)}): For every integer m≥0m \ge 0:

[xm] 1(1−x)(1−x2)=⌊m2⌋+1[x^m]\,\frac{1}{(1 - x)(1 - x^2)} = \left\lfloor \frac{m}{2} \right\rfloor + 1

where ⌊y⌋\lfloor y \rfloor denotes the Greatest Integer Function (GIF)—the largest integer less than or equal to yy.

Proof: Expanding both factors gives (1+x+x2+… )(1+x2+x4+… )(1 + x + x^2 + \dots)(1 + x^2 + x^4 + \dots). Thus [xm] 1(1−x)(1−x2)[x^m]\,\frac{1}{(1 - x)(1 - x^2)} counts all non-negative integer solutions (a,b)(a, b) to:

a+2b=m,a≥0,  b≥0a + 2b = m, \qquad a \ge 0,\; b \ge 0

Notice that once we choose the integer bb, the value of aa is uniquely forced to be a=m−2ba = m - 2b. Since the first bracket contains every non-negative power of xx, this value of aa is valid if and only if a≥0a \ge 0, which means:

m−2b≥0  ⟺  2b≤m  ⟺  0≤b≤m2m - 2b \ge 0 \iff 2b \le m \iff 0 \le b \le \frac{m}{2}

Now count how many integers bb satisfy 0≤b≤m20 \le b \le \frac{m}{2} by checking the two cases:

Even mm (say m=2km = 2k): Here m2=k\frac{m}{2} = k is already an integer, so bb can take any value in {0,1,2,…,k}\{0, 1, 2, \dots, k\}. For example, if m=10m = 10, then 0≤b≤50 \le b \le 5, giving b∈{0,1,2,3,4,5}b \in \{0, 1, 2, 3, 4, 5\}—a total of 5+1=65 + 1 = 6 values. In general, counting from 00 to kk inclusive gives k+1=m2+1k + 1 = \frac{m}{2} + 1 values.

Odd mm (say m=2k+1m = 2k + 1): Here m2=k+0.5\frac{m}{2} = k + 0.5 is not an integer. Because bb must be an integer, b≤k+0.5b \le k + 0.5 forces b≤k=⌊m2⌋b \le k = \left\lfloor \frac{m}{2} \right\rfloor. For example, if m=5m = 5, then 0≤b≤2.50 \le b \le 2.5, so the largest allowed integer is ⌊2.5⌋=2\lfloor 2.5 \rfloor = 2, giving b∈{0,1,2}b \in \{0, 1, 2\}—a total of 2+1=32 + 1 = 3 values. In general, b∈{0,1,2,…,k}b \in \{0, 1, 2, \dots, k\} gives k+1=⌊m2⌋+1k + 1 = \left\lfloor \frac{m}{2} \right\rfloor + 1 values.

In both even and odd cases, the largest integer b≤m2b \le \frac{m}{2} is ⌊m2⌋\left\lfloor \frac{m}{2} \right\rfloor, so b∈{0,1,2,…,⌊m2⌋}b \in \left\{0, 1, 2, \dots, \left\lfloor \frac{m}{2} \right\rfloor\right\}. Including b=0b = 0 adds 11 to the count, giving exactly ⌊m2⌋+1\left\lfloor \frac{m}{2} \right\rfloor + 1 solutions. ■\blacksquare

(Quick check: multiplying out the first few terms gives 1(1−x)(1−x2)=1+x+2x2+2x3+3x4+3x5+…\frac{1}{(1 - x)(1 - x^2)} = 1 + x + 2x^2 + 2x^3 + 3x^4 + 3x^5 + \dots, whose coefficients 1,1,2,2,3,3,…1, 1, 2, 2, 3, 3, \dots match ⌊m/2⌋+1\lfloor m/2 \rfloor + 1 for every mm.)

Example 6 (Making Change with Coins): In how many ways can a sum of ₹1010 be formed using unlimited ₹11, ₹22, and ₹55 coins?

Solution: Let x1,x2,x3≥0x_1, x_2, x_3 \ge 0 be the numbers of ₹11, ₹22, and ₹55 coins used. We want the number of non-negative integer solutions to:

1⋅x1+2⋅x2+5⋅x3=101 \cdot x_1 + 2 \cdot x_2 + 5 \cdot x_3 = 10

The generating function is:

[x10] 1(1−x)(1−x2)(1−x5)[x^{10}]\,\frac{1}{(1 - x)(1 - x^2)(1 - x^5)}

First expand the factor with the largest step, 11−x5=1+x5+x10+…\frac{1}{1 - x^5} = 1 + x^5 + x^{10} + \dots (dropping powers >10> 10):

[x10] 1+x5+x10(1−x)(1−x2)=[x10] 1(1−x)(1−x2)+[x5] 1(1−x)(1−x2)+[x0] 1(1−x)(1−x2)[x^{10}]\,\frac{1 + x^5 + x^{10}}{(1 - x)(1 - x^2)} = [x^{10}]\,\frac{1}{(1 - x)(1 - x^2)} + [x^5]\,\frac{1}{(1 - x)(1 - x^2)} + [x^0]\,\frac{1}{(1 - x)(1 - x^2)}

Applying our Lemma [xm] 1(1−x)(1−x2)=⌊m2⌋+1[x^m]\,\frac{1}{(1 - x)(1 - x^2)} = \left\lfloor \frac{m}{2} \right\rfloor + 1 to m=10,5,0m = 10, 5, 0:

  • m=10m = 10 (x3=0x_3 = 0): ⌊10/2⌋+1=5+1=6\lfloor 10/2 \rfloor + 1 = 5 + 1 = 6,
  • m=5m = 5 (x3=1x_3 = 1): ⌊5/2⌋+1=2+1=3\lfloor 5/2 \rfloor + 1 = 2 + 1 = 3,
  • m=0m = 0 (x3=2x_3 = 2): ⌊0/2⌋+1=0+1=1\lfloor 0/2 \rfloor + 1 = 0 + 1 = 1.

Total number of ways =6+3+1=10= 6 + 3 + 1 = 10.


Formal Definition and Further Applications§

Now that we have built the full mechanism from scratch, we state the formal definition.

Definition (Ordinary Generating Function): Given a sequence of numbers (a0,a1,a2,… )(a_0, a_1, a_2, \dots), its Ordinary Generating Function (OGF) is the formal power series:

G(x)=a0+a1x+a2x2+a3x3+⋯=∑n=0∞anxnG(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \dots = \sum_{n=0}^{\infty} a_n x^n

In this compact language, the single function G(x)G(x) stores the entire infinite sequence of answers a0,a1,a2,…a_0, a_1, a_2, \dots as its coefficients, and an=[xn] G(x)a_n = [x^n]\,G(x). For example, the OGF for the sequence an=(n+r−1r−1)a_n = \binom{n + r - 1}{r - 1} is G(x)=(1−x)−rG(x) = (1 - x)^{-r}.

Below are five classic applications showing how broadly OGFs work across combinatorics.


Application 1: Dice Sums and Capped Selections§

Example 7 (Sum of Faces on Three Dice): Three distinct six-sided dice (labeled 11 through 66) are rolled. In how many ways can the sum of the three outcomes equal 1212?

Solution: Let x1,x2,x3x_1, x_2, x_3 be the numbers showing on the first, second, and third dice. We need integer solutions to:

x1+x2+x3=12,1≤x1,x2,x3≤6x_1 + x_2 + x_3 = 12, \qquad 1 \le x_1, x_2, x_3 \le 6

Each die contributes the bracket (x+x2+x3+x4+x5+x6)=x 1−x61−x(x + x^2 + x^3 + x^4 + x^5 + x^6) = x\,\frac{1 - x^6}{1 - x}. Multiplying all three brackets:

[x12] (x 1−x61−x)3=[x12] x3 (1−x6)3(1−x)3=[x9] (1−3x6+3x12−x18)(1−x)−3[x^{12}]\,\left(x\,\frac{1 - x^6}{1 - x}\right)^3 = [x^{12}]\,x^3\,\frac{(1 - x^6)^3}{(1 - x)^3} = [x^9]\,(1 - 3x^6 + 3x^{12} - x^{18})(1 - x)^{-3}

Drop terms of degree >9> 9 from (1−x6)3(1 - x^6)^3, leaving only 1−3x61 - 3x^6:

[x9] (1−x)−3−3 [x3] (1−x)−3=(9+3−12)−3(3+3−12)=(112)−3(52)=55−30=25[x^9]\,(1 - x)^{-3} - 3\,[x^3]\,(1 - x)^{-3} = \binom{9 + 3 - 1}{2} - 3\binom{3 + 3 - 1}{2} = \binom{11}{2} - 3\binom{5}{2} = 55 - 30 = 25

Application 2: Linear Inequalities via a Slack Variable§

How do we solve an inequality such as x1+x2+⋯+xr≤nx_1 + x_2 + \dots + x_r \le n using generating functions? Just as in Section 07, introduce a non-negative slack variable s=n−(x1+x2+⋯+xr)≥0s = n - (x_1 + x_2 + \dots + x_r) \ge 0, converting the inequality into the exact equation:

x1+x2+⋯+xr+s=n,s≥0x_1 + x_2 + \dots + x_r + s = n, \qquad s \ge 0

Since s≥0s \ge 0 has no upper bound, it simply multiplies the generating function by one extra factor 11−x\frac{1}{1 - x}!

Example 8: Find the number of non-negative integer solutions to x1+x2+x3≤10x_1 + x_2 + x_3 \le 10 subject to 0≤x1≤40 \le x_1 \le 4.

Solution: Introduce s≥0s \ge 0 so that x1+x2+x3+s=10x_1 + x_2 + x_3 + s = 10. The variables contribute 1−x51−x\frac{1 - x^5}{1 - x} for x1x_1, and 11−x\frac{1}{1 - x} for each of x2,x3,sx_2, x_3, s:

[x10] 1−x5(1−x)4=[x10](1−x)−4−[x5](1−x)−4[x^{10}]\,\frac{1 - x^5}{(1 - x)^4} = [x^{10}](1 - x)^{-4} - [x^5](1 - x)^{-4} =(10+4−13)−(5+4−13)=(133)−(83)=286−56=230= \binom{10 + 4 - 1}{3} - \binom{5 + 4 - 1}{3} = \binom{13}{3} - \binom{8}{3} = 286 - 56 = 230

Application 3: Ordering Restrictions and Integer Partitions§

Suppose variables are constrained by an ordering such as 0≤x1≤x2≤x30 \le x_1 \le x_2 \le x_3. At first glance, the variables seem coupled—you cannot write independent brackets for x1,x2,x3x_1, x_2, x_3 directly.

The key idea is to switch to non-negative differences (gaps):

d1=x1≥0,d2=x2−x1≥0,d3=x3−x2≥0d_1 = x_1 \ge 0, \qquad d_2 = x_2 - x_1 \ge 0, \qquad d_3 = x_3 - x_2 \ge 0

Expressing x1,x2,x3x_1, x_2, x_3 in terms of the independent variables d1,d2,d3d_1, d_2, d_3:

x1=d1,x2=d1+d2,x3=d1+d2+d3x_1 = d_1, \qquad x_2 = d_1 + d_2, \qquad x_3 = d_1 + d_2 + d_3

Now the sum x1+x2+x3=nx_1 + x_2 + x_3 = n transforms into a weighted equation in independent non-negative variables:

d1+(d1+d2)+(d1+d2+d3)=n  ⟹  3d1+2d2+1d3=n,d1,d2,d3≥0d_1 + (d_1 + d_2) + (d_1 + d_2 + d_3) = n \implies 3 d_1 + 2 d_2 + 1 d_3 = n, \qquad d_1, d_2, d_3 \ge 0

Example 9 (Ordered Triples and Integer Partitions): Find the number of integer solutions to x1+x2+x3=9x_1 + x_2 + x_3 = 9 with 0≤x1≤x2≤x30 \le x_1 \le x_2 \le x_3. (Equivalently, count the number of ways to distribute 99 identical balls into 33 identical boxes—the integer partitions of 99 into at most 33 parts from Section 09!)

Solution: Substituting x1=d1,  x2=d1+d2,  x3=d1+d2+d3x_1 = d_1,\; x_2 = d_1 + d_2,\; x_3 = d_1 + d_2 + d_3 turns the problem into 3d1+2d2+d3=93 d_1 + 2 d_2 + d_3 = 9 with d1,d2,d3≥0d_1, d_2, d_3 \ge 0. Its generating function is:

[x9] 1(1−x)(1−x2)(1−x3)[x^9]\,\frac{1}{(1 - x)(1 - x^2)(1 - x^3)}

Expand 11−x3=1+x3+x6+x9+…\frac{1}{1 - x^3} = 1 + x^3 + x^6 + x^9 + \dots (ignoring powers >9> 9) and apply our Lemma [xm] 1(1−x)(1−x2)=⌊m/2⌋+1[x^m]\,\frac{1}{(1 - x)(1 - x^2)} = \lfloor m/2 \rfloor + 1:

[x9] 1+x3+x6+x9(1−x)(1−x2)=(⌊92⌋+1)+(⌊62⌋+1)+(⌊32⌋+1)+(⌊02⌋+1)[x^9]\,\frac{1 + x^3 + x^6 + x^9}{(1 - x)(1 - x^2)} = \left(\left\lfloor \frac{9}{2} \right\rfloor + 1\right) + \left(\left\lfloor \frac{6}{2} \right\rfloor + 1\right) + \left(\left\lfloor \frac{3}{2} \right\rfloor + 1\right) + \left(\left\lfloor \frac{0}{2} \right\rfloor + 1\right) =5+4+2+1=12= 5 + 4 + 2 + 1 = 12

Connection to Section 09 (Euler's Generating Function for Integer Partitions):
An unrestricted integer partition of nn chooses c1≥0c_1 \ge 0 parts of size 11, c2≥0c_2 \ge 0 parts of size 22, c3≥0c_3 \ge 0 parts of size 33, and so on, such that 1⋅c1+2⋅c2+3⋅c3+⋯=n1 \cdot c_1 + 2 \cdot c_2 + 3 \cdot c_3 + \dots = n. Hence the OGF for the total partition number p(n)p(n) is Euler's famous infinite product: ∑n=0∞p(n)xn=∏k=1∞11−xk\sum_{n=0}^{\infty} p(n) x^n = \prod_{k=1}^{\infty} \frac{1}{1 - x^k}.


Application 4: Non-Congruent Integer Triangles (Alcuin's Sequence)§

One of the most striking uses of generating functions is counting distinct (non-congruent) triangles with integer side lengths and perimeter nn, denoted T(n)T(n). The sequence T(0),T(1),T(2),…T(0), T(1), T(2), \dots is known as Alcuin's sequence.

Because triangles with the same three side lengths are congruent regardless of how the sides are labeled, we list the sides in non-decreasing order:

1≤a≤b≤c,a+b+c=n1 \le a \le b \le c, \qquad a + b + c = n

For (a,b,c)(a, b, c) to form a genuine (non-degenerate) triangle, it must also satisfy the Triangle Inequality. Since a≤b≤ca \le b \le c, the inequalities a+c>ba + c > b and b+c>ab + c > a hold automatically; the only extra condition we need is:

a+b>c  ⟺  a+b−c≥1a + b > c \iff a + b - c \ge 1

(because a,b,ca, b, c are integers).

Step 1: Converting Coupled Inequalities into Independent Variables

Just as in Application 3, replace the coupled side lengths (a,b,c)(a, b, c) with three independent non-negative integers measuring the triangle-inequality excess and the two side gaps:

u=(a+b−c)−1≥0,v=b−a≥0,w=c−b≥0u = (a + b - c) - 1 \ge 0, \qquad v = b - a \ge 0, \qquad w = c - b \ge 0

Now solve for a,b,ca, b, c in terms of u,v,wu, v, w. From v=b−av = b - a and w=c−bw = c - b, we have b=a+vb = a + v and c=b+w=a+v+wc = b + w = a + v + w. Substituting into u=a+b−c−1u = a + b - c - 1:

u=a+(a+v)−(a+v+w)−1=a−w−1  ⟹  a=u+w+1u = a + (a + v) - (a + v + w) - 1 = a - w - 1 \implies a = u + w + 1

Hence:

a=u+w+1,b=u+v+w+1,c=u+v+2w+1a = u + w + 1, \qquad b = u + v + w + 1, \qquad c = u + v + 2w + 1

Verify the bijection in one glance: for every choice of non-negative integers (u,v,w)≥0(u, v, w) \ge 0, we automatically get a≥1a \ge 1, b−a=v≥0b - a = v \ge 0, c−b=w≥0c - b = w \ge 0, and a+b−c=u+1≥1a + b - c = u + 1 \ge 1. Conversely, every valid triangle (a,b,c)(a, b, c) determines a unique triple (u,v,w)≥0(u, v, w) \ge 0.

Encoding an Integer Triangle via Three Independent Non-Negative Gaps

Now substitute a,b,ca, b, c into the perimeter equation a+b+c=na + b + c = n:

(u+w+1)+(u+v+w+1)+(u+v+2w+1)=n(u + w + 1) + (u + v + w + 1) + (u + v + 2w + 1) = n 2v+3u+4w=n−3,u,v,w≥02v + 3u + 4w = n - 3, \qquad u, v, w \ge 0

This is a weighted linear equation with weights 2,3,42, 3, 4! Therefore, the Ordinary Generating Function for Alcuin's sequence T(n)T(n) is:

∑n=0∞T(n)xn=x3(1−x2)(1−x3)(1−x4)\sum_{n=0}^{\infty} T(n) x^n = \frac{x^3}{(1 - x^2)(1 - x^3)(1 - x^4)}

Step 2: Separating Even and Odd Perimeters

Multiply both numerator and denominator by (1+x3)(1 + x^3) and use (1−x3)(1+x3)=1−x6(1 - x^3)(1 + x^3) = 1 - x^6:

∑n=0∞T(n)xn=x3(1+x3)(1−x2)(1−x4)(1−x6)=x3(1−x2)(1−x4)(1−x6)+x6(1−x2)(1−x4)(1−x6)\sum_{n=0}^{\infty} T(n) x^n = \frac{x^3(1 + x^3)}{(1 - x^2)(1 - x^4)(1 - x^6)} = \frac{x^3}{(1 - x^2)(1 - x^4)(1 - x^6)} + \frac{x^6}{(1 - x^2)(1 - x^4)(1 - x^6)}

Notice that every power of xx in 1(1−x2)(1−x4)(1−x6)\frac{1}{(1 - x^2)(1 - x^4)(1 - x^6)} is even! Thus:

  • The first term x3(1−x2)(1−x4)(1−x6)\frac{x^3}{(1 - x^2)(1 - x^4)(1 - x^6)} supplies all odd-perimeter terms T(3),T(5),T(7),…T(3), T(5), T(7), \dots
  • The second term x6(1−x2)(1−x4)(1−x6)\frac{x^6}{(1 - x^2)(1 - x^4)(1 - x^6)} supplies all even-perimeter terms T(6),T(8),T(10),…T(6), T(8), T(10), \dots

This immediately reveals two remarkable facts:

1. Parity Symmetry: For every odd integer n≥1n \ge 1, the coefficient of xnx^n in the first term equals the coefficient of xn+3x^{n + 3} in the second term:

T(n)=T(n+3)(for every odd n≥1)T(n) = T(n + 3) \qquad (\text{for every odd } n \ge 1)

(Geometric reason: adding 11 to every side maps (a,b,c)↦(a+1,b+1,c+1)(a, b, c) \mapsto (a + 1, b + 1, c + 1), giving a bijection between odd-perimeter triangles of perimeter nn and even-perimeter triangles of perimeter n+3n + 3! In reverse, if a+b+ca + b + c is even, then a+b−ca + b - c is also even and thus ≥2\ge 2, and a≥2a \ge 2 automatically, so subtracting 11 from every side always keeps a valid triangle.)

2. Direct Link to Partitions into at Most 33 Parts: Setting t=x2t = x^2 inside 1(1−x2)(1−x4)(1−x6)\frac{1}{(1 - x^2)(1 - x^4)(1 - x^6)} turns it into 1(1−t)(1−t2)(1−t3)\frac{1}{(1 - t)(1 - t^2)(1 - t^3)}—the exact generating function from Application 3! Letting P3(k)=[tk] 1(1−t)(1−t2)(1−t3)P_3(k) = [t^k]\,\frac{1}{(1 - t)(1 - t^2)(1 - t^3)}:

T(2m)=P3(m−3)(m≥3),T(2m−3)=P3(m−3)(m≥3)T(2m) = P_3(m - 3) \quad (m \ge 3), \qquad T(2m - 3) = P_3(m - 3) \quad (m \ge 3)

Step 3: Alcuin's Closed-Form Formula

We can find a closed formula for P3(k)P_3(k)—and hence for T(n)T(n)—using only elementary algebra!

Theorem (Nearest-Integer Formula for P3(k)P_3(k)): For every integer k≥0k \ge 0:

P3(k)=[tk] 1(1−t)(1−t2)(1−t3)=round⁡ ⁣((k+3)212)P_3(k) = [t^k]\,\frac{1}{(1 - t)(1 - t^2)(1 - t^3)} = \operatorname{round}\!\left(\frac{(k + 3)^2}{12}\right)

where round⁡(y)\operatorname{round}(y) denotes the integer nearest to yy.

Proof: Multiply ∑k=0∞P3(k)tk=1(1−t)(1−t2)(1−t3)\sum_{k=0}^{\infty} P_3(k) t^k = \frac{1}{(1 - t)(1 - t^2)(1 - t^3)} by (1−t6)(1 - t^6). Factor 1−t6=(1−t3)(1+t3)1 - t^6 = (1 - t^3)(1 + t^3), cancel (1−t3)(1 - t^3), then factor 1+t3=(1+t)(1−t+t2)1 + t^3 = (1 + t)(1 - t + t^2) and 1−t2=(1−t)(1+t)1 - t^2 = (1 - t)(1 + t) to cancel (1+t)(1 + t):

(1−t6)∑k=0∞P3(k)tk=1+t3(1−t)(1−t2)=1−t+t2(1−t)2=(1−t)2+t(1−t)2=1+t(1−t)2(1 - t^6)\sum_{k=0}^{\infty} P_3(k) t^k = \frac{1 + t^3}{(1 - t)(1 - t^2)} = \frac{1 - t + t^2}{(1 - t)^2} = \frac{(1 - t)^2 + t}{(1 - t)^2} = 1 + \frac{t}{(1 - t)^2}

Since (1−t)−2=∑j=0∞(j+1)tj(1 - t)^{-2} = \sum_{j=0}^{\infty} (j + 1) t^j, multiplying by tt gives t(1−t)2=∑k=1∞k tk\frac{t}{(1 - t)^2} = \sum_{k=1}^{\infty} k\,t^k. Comparing [tk][t^k] on both sides for every k≥6k \ge 6 yields the step-66 recurrence:

P3(k)−P3(k−6)=k(k≥6)P_3(k) - P_3(k - 6) = k \qquad (k \ge 6)

Now test the quadratic function Q(k)=(k+3)212Q(k) = \frac{(k + 3)^2}{12}. Its step-66 difference is:

Q(k)−Q(k−6)=(k+3)2−(k−3)212=12k12=kQ(k) - Q(k - 6) = \frac{(k + 3)^2 - (k - 3)^2}{12} = \frac{12k}{12} = k

Because P3(k)P_3(k) and Q(k)Q(k) grow by the exact same amount kk whenever kk increases by 66, their difference E(k)=Q(k)−P3(k)E(k) = Q(k) - P_3(k) satisfies E(k)=E(k−6)E(k) = E(k - 6) for all k≥6k \ge 6—it repeats periodically every 66 steps! Check the first 66 values directly (computing P3(k)P_3(k) via our Lemma as in Example 9):

kk 00 11 22 33 44 55
P3(k)P_3(k) 11 11 22 33 44 55
Q(k)=(k+3)2/12Q(k) = (k + 3)^2 / 12 9/129/12 16/1216/12 25/1225/12 36/1236/12 49/1249/12 64/1264/12
Error ∣Q(k)−P3(k)∣\lvert Q(k) - P_3(k) \rvert 1/41/4 1/31/3 1/121/12 00 1/121/12 1/31/3

For every k∈{0,1,2,3,4,5}k \in \{0, 1, 2, 3, 4, 5\}—and therefore for every integer k≥0k \ge 0—the error satisfies ∣Q(k)−P3(k)∣≤13<12\lvert Q(k) - P_3(k) \rvert \le \frac{1}{3} < \frac{1}{2}. Hence P3(k)P_3(k) is always the unique integer nearest to (k+3)212\frac{(k + 3)^2}{12}. ■\blacksquare

Substituting k=n2−3k = \frac{n}{2} - 3 (so k+3=n2k + 3 = \frac{n}{2}) for even nn, and k=n−32k = \frac{n - 3}{2} (so k+3=n+32k + 3 = \frac{n + 3}{2}) for odd nn, gives Alcuin's Theorem immediately (and checking n=1,2,3,4n = 1, 2, 3, 4 shows it holds for all n≥1n \ge 1):

Theorem (Alcuin's Formula for Distinct Integer Triangles): The number T(n)T(n) of non-congruent triangles with integer side lengths and perimeter n≥1n \ge 1 is:

T(n)={round⁡ ⁣(n248)if n is even,round⁡ ⁣((n+3)248)if n is odd.T(n) = \begin{cases} \operatorname{round}\!\left(\dfrac{n^2}{48}\right) & \text{if } n \text{ is even,} \\[10pt] \operatorname{round}\!\left(\dfrac{(n + 3)^2}{48}\right) & \text{if } n \text{ is odd.} \end{cases}

Example 10 (Counting Distinct Integer Triangles): Find the number of non-congruent triangles with integer side lengths having perimeter: (a) n=15n = 15, (b) n=20n = 20.

Solution:

(a) Perimeter n=15n = 15 (odd):

Method 1 (Direct Coefficient Extraction): Since n=15n = 15 is odd, write 15=2m−3  ⟹  m=915 = 2m - 3 \implies m = 9, so k=m−3=6k = m - 3 = 6:

T(15)=P3(6)=[t6] 1(1−t)(1−t2)(1−t3)=[t6] 1+t3+t6(1−t)(1−t2)T(15) = P_3(6) = [t^6]\,\frac{1}{(1 - t)(1 - t^2)(1 - t^3)} = [t^6]\,\frac{1 + t^3 + t^6}{(1 - t)(1 - t^2)}

Applying our Lemma [tr] 1(1−t)(1−t2)=⌊r/2⌋+1[t^r]\,\frac{1}{(1 - t)(1 - t^2)} = \lfloor r/2 \rfloor + 1 for r=6,3,0r = 6, 3, 0:

T(15)=(⌊62⌋+1)+(⌊32⌋+1)+(⌊02⌋+1)=4+2+1=7T(15) = \left(\left\lfloor \frac{6}{2} \right\rfloor + 1\right) + \left(\left\lfloor \frac{3}{2} \right\rfloor + 1\right) + \left(\left\lfloor \frac{0}{2} \right\rfloor + 1\right) = 4 + 2 + 1 = 7

Method 2 (Alcuin's Formula): Since n=15n = 15 is odd:

T(15)=round⁡ ⁣((15+3)248)=round⁡ ⁣(32448)=round⁡(6.75)=7T(15) = \operatorname{round}\!\left(\frac{(15 + 3)^2}{48}\right) = \operatorname{round}\!\left(\frac{324}{48}\right) = \operatorname{round}(6.75) = 7

(Indeed, the 77 triangles are (1,7,7),  (2,6,7),  (3,5,7),  (3,6,6),  (4,4,7),  (4,5,6),  (5,5,5)(1, 7, 7),\; (2, 6, 7),\; (3, 5, 7),\; (3, 6, 6),\; (4, 4, 7),\; (4, 5, 6),\; (5, 5, 5).)

(b) Perimeter n=20n = 20 (even): Applying Alcuin's Formula directly:

T(20)=round⁡ ⁣(20248)=round⁡ ⁣(40048)=round⁡(8.33… )=8T(20) = \operatorname{round}\!\left(\frac{20^2}{48}\right) = \operatorname{round}\!\left(\frac{400}{48}\right) = \operatorname{round}(8.33\dots) = 8

Application 5: Proving Binomial Identities by Comparing Coefficients§

Two polynomials (or formal power series) are identical if and only if they have the exact same coefficient of xrx^r for every r≥0r \ge 0. Comparing [xr][x^r] on both sides of a simple algebraic identity often proves deep combinatorial identities in two lines!

Example 11 (Algebraic Proof of Vandermonde's Identity): For non-negative integers m,n,rm, n, r, prove that:

∑k=0r(mk)(nr−k)=(m+nr)\sum_{k=0}^{r} \binom{m}{k}\binom{n}{r - k} = \binom{m + n}{r}

Proof: Start from the elementary polynomial identity:

(1+x)m(1+x)n=(1+x)m+n(1 + x)^m (1 + x)^n = (1 + x)^{m + n}

Compare [xr][x^r] on both sides:

Right-hand side: By the Binomial Theorem, [xr] (1+x)m+n=(m+nr)[x^r]\,(1 + x)^{m + n} = \binom{m + n}{r}.

Left-hand side: Expand both factors using the Binomial Theorem:

(1+x)m(1+x)n=(∑k=0m(mk)xk)(∑j=0n(nj)xj)(1 + x)^m (1 + x)^n = \left(\sum_{k=0}^{m} \binom{m}{k} x^k\right)\left(\sum_{j=0}^{n} \binom{n}{j} x^j\right)

To obtain xrx^r by picking one term from each bracket, pick (mk)xk\binom{m}{k} x^k from the first bracket (for any 0≤k≤r0 \le k \le r) and the matching term (nr−k)xr−k\binom{n}{r - k} x^{r - k} from the second bracket (with the convention (pq)=0\binom{p}{q} = 0 if q>pq > p). Summing over all k=0,1,…,rk = 0, 1, \dots, r gives:

[xr] (1+x)m(1+x)n=∑k=0r(mk)(nr−k)[x^r]\,(1 + x)^m (1 + x)^n = \sum_{k=0}^{r} \binom{m}{k}\binom{n}{r - k}

Equating the two expressions for [xr][x^r] completes the proof. ■\blacksquare

(Compare this two-line generating-function proof with the committee-selection combinatorial proof we gave in Section 04!)


Summary Reference: Translating Restrictions into Factors§

For any linear equation with target sum nn (and all shifted variables non-negative), translate each variable's condition into its exact generating factor:

Variable Condition Allowed Exponents Exact Factor Notes
xi≥0x_i \ge 0 (no upper bound) 0,1,2,…0, 1, 2, \dots 11−x\dfrac{1}{1 - x} Natural bound nn; safe to extend to ∞\infty
xi≥aix_i \ge a_i (ai≥0a_i \ge 0, no upper bound) ai,ai+1,…a_i, a_i + 1, \dots xai1−x\dfrac{x^{a_i}}{1 - x} Lowers remaining budget to n′=n−∑ajn' = n - \sum a_j
xi≥−cix_i \ge -c_i (negative lower bound) Shift yi=xi+ci≥0y_i = x_i + c_i \ge 0 11−x\dfrac{1}{1 - x} (for yiy_i) Always shift first before extending to ∞\infty
0≤xi≤bi0 \le x_i \le b_i (bi<nb_i < n, active) 0,1,…,bi0, 1, \dots, b_i 1−xbi+11−x\dfrac{1 - x^{b_i + 1}}{1 - x} Must stop at xbix^{b_i}; cannot extend to ∞\infty
0≤xi≤bi0 \le x_i \le b_i (bi≥nb_i \ge n, redundant) 0,1,…,n,…0, 1, \dots, n, \dots 11−x\dfrac{1}{1 - x} Natural bound nn already enforces xi≤bix_i \le b_i
ai≤xi≤bia_i \le x_i \le b_i (0≤ai≤bi0 \le a_i \le b_i) ai,ai+1,…,bia_i, a_i + 1, \dots, b_i xai 1−xbi−ai+11−xx^{a_i}\,\dfrac{1 - x^{b_i - a_i + 1}}{1 - x} Active only when span bi−ai<n′b_i - a_i < n'
xi≥0x_i \ge 0 even 0,2,4,…0, 2, 4, \dots 11−x2\dfrac{1}{1 - x^2} Step size 22, starting at 00
xi≥1x_i \ge 1 odd 1,3,5,…1, 3, 5, \dots x1−x2\dfrac{x}{1 - x^2} Step size 22, starting at 11
xi≥0x_i \ge 0 multiple of kk (or weight kxik x_i) 0,k,2k,…0, k, 2k, \dots 11−xk\dfrac{1}{1 - x^k} Used for divisibility and weighted sums
xi∈Sx_i \in S (finite set) Elements of SS ∑s∈Sxs\sum_{s \in S} x^s Direct list of allowed exponents
Inequality x1+⋯+xr≤nx_1 + \dots + x_r \le n Add slack s≥0s \ge 0 Multiply by 11−x\dfrac{1}{1 - x} Converts ≤n\le n into =n= n
Section 11 of 11 · Combinatorics

Mark this section complete when you have worked through its proofs.