In Sections 07 and 08, we counted integer solutions to equations like x1+x2+⋯+xr=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.
There are 3 choices in the first bracket and 2 choices in the second bracket. By the Multiplication Principle (Section 01), expanding the product generates 3×2=6 raw products—one for every possible pair of picks.
The same rule holds for three or more brackets. For (a1+b1)(a2+b2)(a3+b3):
There are 2×2×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 r brackets whose sizes are k1,k2,…,kr:
Core Rule of Expansion: Every raw term in the product is obtained by selecting exactly one term from each of the r brackets and multiplying them together. Before collecting like terms, there are k1k2⋯kr raw products—one for every possible tuple of choices.
Now make one small but decisive change. Instead of putting distinct letters inside the brackets, place powers of a single symbol x inside every bracket.
Consider the product:
(x0+x1+x2)(x0+x1+x2)
Expand it slowly by our bracket-picking rule, writing out all 3×3=9 raw products before simplifying:
Now apply the law of exponents, xa⋅xb=xa+b. Multiplying two chosen terms adds their exponents! Group the 9 raw products by their total exponent:
Exponent 0 (x0):x0⋅x0⟶1 way ⟶ solution (0,0) of x1+x2=0.
Exponent 1 (x1):x0⋅x1+x1⋅x0⟶2 ways ⟶ solutions (0,1),(1,0) of x1+x2=1.
Exponent 2 (x2):x0⋅x2+x1⋅x1+x2⋅x0⟶3 ways ⟶ solutions (0,2),(1,1),(2,0) of x1+x2=2.
Exponent 3 (x3):x1⋅x2+x2⋅x1⟶2 ways ⟶ solutions (1,2),(2,1) of x1+x2=3.
Exponent 4 (x4):x2⋅x2⟶1 way ⟶ solution (2,2) of x1+x2=4.
Putting the grouped terms together:
(1+x+x2)(1+x+x2)=1+2x+3x2+2x3+x4
Look at what algebra just did automatically:
Choosing xa1 from the first bracket is identical to setting x1=a1∈{0,1,2}.
Choosing xa2 from the second bracket is identical to setting x2=a2∈{0,1,2}.
Their product xa1⋅xa2=xa1+a2 equals xnif and only ifa1+a2=n.
Every valid solution (a1,a2) contributes exactly +1 to the coefficient of xn.
Therefore, the coefficient of xn in the expanded product equals the exact number of integer solutions to x1+x2=n with x1,x2∈{0,1,2}.
The exact same bijection works for r variables. For any r brackets representing the allowed values of x1,x2,…,xr, picking xa1 from bracket 1, xa2 from bracket 2, …, and xar from bracket r gives:
xa1⋅xa2⋯xar=xa1+a2+⋯+ar
Coefficient Notation and the Role of the Placeholder§
We write [xn]F(x) to mean "the coefficient of xn in the expansion of F(x)." For instance:
[x2](1+x+x2)2=3,[x3](1+x+x2)2=2
What Is x Here?
In combinatorics, x 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 x, we treat infinite sums of powers of x as formal power series—we do not need to worry about convergence tests such as ∣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)
Here, no upper bound is stated for any variable xi. What bracket should we write for each xi?
Even though no upper bound is given in the problem, every variable satisfies xj≥0. Therefore, no single variable can ever exceed the total sum n:
0≤xi≤nfor every i=1,2,…,r
We call n the natural upper bound of the equation. Listing every value that xi can actually take gives the exact finite polynomial (1+x+x2+⋯+xn) for each bracket. Hence the number of non-negative integer solutions is:
[xn](1+x+x2+⋯+xn)r
Step 2: Why Extending to Infinity Does Not Change the Answer§
Now ask a careful question: what happens to [xn] if we replace the finite bracket (1+x+x2+⋯+xn) with the infinite series (1+x+x2+⋯+xn+xn+1+xn+2+…)?
Theorem (Safe Extension to Infinity): If every bracket in a product contains only non-negative powers of x, then adding terms of degree strictly greater than n (that is, xn+1+xn+2+…) to any bracket does not change the coefficient of xn.
Proof: Suppose we form a raw product by picking one term xai from each bracket, where every ai≥0. If we pick any newly added term xk with k≥n+1 from some bracket, then the sum of exponents across all r brackets satisfies:
a1+a2+⋯+ar≥k+0+⋯+0=k≥n+1>n
Thus no raw product that uses a term from the infinite tail xn+1+xn+2+… can ever yield xn. The set of raw products that equal xn is completely unchanged, so [xn] stays identical. ■
Step 3: Why Extending to Infinity Makes Algebra Simpler§
Using the geometric series formula 1+x+x2+⋯+xn=1−x1−xn+1 and its infinite counterpart 1+x+x2+⋯=1−x1, compare the two expressions:
Finite form (stopping at xn):
[xn](1−x1−xn+1)r=[xn](1−xn+1)r(1−x)−r
Expanding (1−xn+1)r=1−(1r)xn+1+(2r)x2n+2−… shows that every term except 1 already has degree >n, so all of them vanish when we extract [xn]!
Infinite form (extending to ∞):
[xn](1+x+x2+…)r=[xn](1−x1)r=[xn](1−x)−r
Extending an unrestricted bracket up to ∞ throws away the useless (1−xn+1)r factor upfront, leaving the clean expression (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−2, then a tail term xn+2 multiplied by x−2would produce xn and corrupt the count! Whenever a variable has a negative lower bound, always shift it to a non-negative variable first.
To compute [xm](1−x)−r quickly and rigorously, we need its explicit series expansion.
Theorem (Negative-Index Binomial Series): For every positive integer r≥1:
(1−x)−r=(1−x)r1=m=0∑∞(r−1m+r−1)xm
Equivalently, for every integer m≥0:
[xm](1−x)−r=(r−1m+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 as (1+x+x2+…)r. By our exponent-addition bijection, [xm](1+x+x2+…)r equals the number of non-negative integer solutions to:
x1+x2+⋯+xr=m,xi≥0
By the Combinations with Unlimited Repetition Theorem (Section 07), this count is (r−1m+r−1). Since this holds for every m≥0, the expansion follows immediately. ■
Proof 2 (Algebraic Proof by Induction on r):
Base case (r=1): By the geometric series identity:
By the Hockey-Stick Identity (Section 04), this sum collapses to (rm+r), which matches the theorem for r+1. By mathematical induction, the formula holds for all r≥1. ■
(Note: This also agrees with the generalized Binomial Theorem (1−x)−r=∑m=0∞(m−r)(−x)m, since (m−r)(−1)m=m!(−r)(−r−1)⋯(−r−m+1)(−1)m=m!r(r+1)⋯(r+m−1)=(mm+r−1)=(r−1m+r−1).)
Example 1: Use generating functions to find the number of non-negative integer solutions to x1+x2+x3+x4=10.
Solution: Each variable xi≥0 has no upper bound, so each contributes the factor (1+x+x2+…)=(1−x)−1. The number of solutions is:
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 x, 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.
Suppose a variable satisfies xi≥ai (where ai≥0) with no upper bound. Its smallest allowed value is ai, and its larger values can extend to ∞. So its bracket is:
xai+xai+1+xai+2+⋯=xai(1+x+x2+…)=1−xxai
When all r variables satisfy xi≥ai (ai≥0), the product of brackets is:
1−xxa1⋅1−xxa2⋯1−xxar=(1−x)rxa1+a2+⋯+ar
Let A=a1+a2+⋯+ar. To find [xn](1−x)rxA, notice that multiplying any power series by xA shifts every exponent up by A. Hence:
[xn](xA⋅F(x))=[xn−A]F(x)
Therefore, for n′=n−A≥0:
[xn](1−x)rxA=[xn′](1−x)−r=(r−1n′+r−1)
Notice two important facts:
Factoring out xa1+⋯+ar is the exact algebraic mirror of the variable shift yi=xi−ai from Section 07.
Lower bounds reduce the remaining sum to n′=n−(a1+⋯+ar), which lowers the effective natural upper bound of every shifted variable yi to n′.
Example 2 (Positive and Negative Lower Bounds): Find the number of integer solutions to:
(a)x1+x2+x3=12 with x1≥2,x2≥3,x3≥1.
(b)x1+x2+x3=5 with x1≥−2,x2≥−1,x3≥0.
Solution:
(a) Write one bracket for each variable starting at its lower bound:
(b) Here x1 and x2 can be negative! We must not write (x−2+x−1+…) and blindly extend brackets to ∞ without checking, because negative powers can cancel higher powers (for example, x−2⋅x7⋅x0=x5 uses an exponent greater than 5). Instead, shift every variable to become non-negative first:
y1=x1+2≥0,y2=x2+1≥0,y3=x3≥0
Substituting x1=y1−2, x2=y2−1, x3=y3 gives:
(y1−2)+(y2−1)+y3=5⟹y1+y2+y3=8,y1,y2,y3≥0
Now all exponents are non-negative, so we safely apply generating functions:
[x8](1−x)−3=(3−18+3−1)=(210)=45
Case 2: Upper Bound Only — Active vs. Redundant Bounds§
Now suppose a variable has an imposed upper bound: 0≤xi≤bi. Compare bi with the equation's natural upper bound n:
Subcase 2A: Active Upper Bound (bi<n). Here the problem cuts off xistrictly below its natural bound n. We cannot extend this bracket to ∞! Why? Because the powers xbi+1,xbi+2,…,xn are smaller than or equal to n, so they would combine with terms from the other brackets to produce fake xn terms corresponding to illegal solutions with xi>bi.
Therefore, the bracket must stop at xbi:
1+x+x2+⋯+xbi=1−x1−xbi+1
Subcase 2B: Redundant Upper Bound (bi≥n). Here the imposed limit bi is at least as large as the natural bound n. Because all other variables are non-negative, xi could never exceed n anyway—so the bound xi≤bi changes nothing! We may safely extend this bracket to ∞ as 1−x1.
(Algebraic check: even if you kept the finite sum 1−x1−xbi+1 when bi≥n, the extra term −xbi+1 has exponent bi+1≥n+1>n, so it contributes zero to [xn]!)
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≤10
Solution: The natural upper bound of this equation is n=10. Check each variable's upper bound against n=10:
x1≤4<10: active bound⟶ bracket must stop at x4: (1+x+x2+x3+x4)=1−x1−x5.
x2≤12≥10: redundant bound⟶ behaves like no upper bound: 1−x1.
x3≤10≥10: redundant bound⟶ behaves like no upper bound: 1−x1.
Look closely at the exponent bi−ai+1. After factoring out xa1+⋯+ar from all brackets, the remaining target sum is:
n′=n−(a1+a2+⋯+ar)
So the upper bound on xi is active only if its allowed span bi−ai is strictly less than n′ (that is, bi−ai<n′). If bi−ai≥n′, then the term −xbi−ai+1 has degree >n′ and automatically drops out!
Even better: when several variables have active upper bounds, multiplying out the numerator factors ∏(1−xbi−ai+1)automatically performs the Principle of Inclusion–Exclusion (Section 08)—without manually defining violation sets A1,A2,…!
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≤8
(b) Find the number of integer solutions to:
x1+x2+x3=14,2≤x1≤6,1≤x2≤5,3≤x3≤12
Solution:
(a) All three upper bounds are strictly less than 15, so all three are active. The count is:
Look at x3≤12: before shifting, 12<14 looked like an active upper bound. However, once the lower bounds 2+1+3=6 reduced the remaining sum to n′=8, the span of x3 is 12−3=9≥8, so the factor (1−x10) has x10 exceeding 8 and becomes redundant! Expanding only up to degree 8:
(1−x5)2(1−x10)=(1−2x5+x10)(1−x10)=1−2x5+(terms of degree≥10)
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. xi is even (xi∈{0,2,4,6,…}):
1+x2+x4+x6+⋯=1−x21
2. xi is odd (xi∈{1,3,5,7,…}):
x+x3+x5+x7+⋯=x(1+x2+x4+…)=1−x2x
3. xi is a non-negative multiple of k (xi∈{0,k,2k,3k,…}):
1+xk+x2k+x3k+⋯=1−xk1
4. xi belongs to a specific finite set S (for example, xi∈{0,2,5}):
x0+x2+x5=1+x2+x5
Example 5: Find the number of non-negative integer solutions to x1+x2+x3=10 such that x1 is even, x2 is odd, and x3∈{1,3,5}.
Solution: Encode each variable's allowed values directly into its bracket:
Set t=x2 so that x2k=tk and (1−x2)−2=(1−t)−2=∑k=0∞(1k+1)tk=∑k=0∞(k+1)tk. Then:
[x8](1−x2)−2=[t4](1−t)−2=4+1=5,
[x6](1−x2)−2=[t3](1−t)−2=3+1=4,
[x4](1−x2)−2=[t2](1−t)−2=2+1=3.
Adding these gives 5+4+3=12 solutions.
Case 5: Weighted Linear Equations (Coin-Change Problems)§
Suppose variables have different positive integer coefficients:
c1x1+c2x2+⋯+crxr=n,xi≥0
Think carefully about what each variable contributes to the sum n. Variable xi does not add xi to the total—it adds cixi! As xi runs through 0,1,2,3,…, its contribution cixi runs through 0,ci,2ci,3ci,….
Therefore, the bracket representing cixi is:
1+xci+x2ci+x3ci+⋯=1−xci1
When we pick xc1a1 from bracket 1, xc2a2 from bracket 2, …, and xcrar from bracket r, multiplying them gives xc1a1+c2a2+⋯+crar, so [xn] counts every solution of c1x1+⋯+crxr=n!
Before solving coin-change and partition problems, we prove one small building-block formula that appears repeatedly whenever weights 1 and 2 occur together.
Lemma (Coefficient of xm in (1−x)(1−x2)1): For every integer m≥0:
[xm](1−x)(1−x2)1=⌊2m⌋+1
where ⌊y⌋ denotes the Greatest Integer Function (GIF)—the largest integer less than or equal to y.
Proof: Expanding both factors gives (1+x+x2+…)(1+x2+x4+…). Thus [xm](1−x)(1−x2)1 counts all non-negative integer solutions (a,b) to:
a+2b=m,a≥0,b≥0
Notice that once we choose the integer b, the value of a is uniquely forced to be a=m−2b. Since the first bracket contains every non-negative power of x, this value of a is valid if and only if a≥0, which means:
m−2b≥0⟺2b≤m⟺0≤b≤2m
Now count how many integers b satisfy 0≤b≤2m by checking the two cases:
Even m (say m=2k): Here 2m=k is already an integer, so b can take any value in {0,1,2,…,k}. For example, if m=10, then 0≤b≤5, giving b∈{0,1,2,3,4,5}—a total of 5+1=6 values. In general, counting from 0 to k inclusive gives k+1=2m+1 values.
Odd m (say m=2k+1): Here 2m=k+0.5 is not an integer. Because b must be an integer, b≤k+0.5 forces b≤k=⌊2m⌋. For example, if m=5, then 0≤b≤2.5, so the largest allowed integer is ⌊2.5⌋=2, giving b∈{0,1,2}—a total of 2+1=3 values. In general, b∈{0,1,2,…,k} gives k+1=⌊2m⌋+1 values.
In both even and odd cases, the largest integer b≤2m is ⌊2m⌋, so b∈{0,1,2,…,⌊2m⌋}. Including b=0 adds 1 to the count, giving exactly ⌊2m⌋+1 solutions. ■
(Quick check: multiplying out the first few terms gives (1−x)(1−x2)1=1+x+2x2+2x3+3x4+3x5+…, whose coefficients 1,1,2,2,3,3,… match ⌊m/2⌋+1 for every m.)
Example 6 (Making Change with Coins): In how many ways can a sum of ₹10 be formed using unlimited ₹1, ₹2, and ₹5 coins?
Solution: Let x1,x2,x3≥0 be the numbers of ₹1, ₹2, and ₹5 coins used. We want the number of non-negative integer solutions to:
1⋅x1+2⋅x2+5⋅x3=10
The generating function is:
[x10](1−x)(1−x2)(1−x5)1
First expand the factor with the largest step, 1−x51=1+x5+x10+… (dropping powers >10):
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,…), its Ordinary Generating Function (OGF) is the formal power series:
G(x)=a0+a1x+a2x2+a3x3+⋯=n=0∑∞anxn
In this compact language, the single function G(x) stores the entire infinite sequence of answers a0,a1,a2,… as its coefficients, and an=[xn]G(x). For example, the OGF for the sequence an=(r−1n+r−1) is G(x)=(1−x)−r.
Below are five classic applications showing how broadly OGFs work across combinatorics.
Example 7 (Sum of Faces on Three Dice): Three distinct six-sided dice (labeled 1 through 6) are rolled. In how many ways can the sum of the three outcomes equal 12?
Solution: Let x1,x2,x3 be the numbers showing on the first, second, and third dice. We need integer solutions to:
x1+x2+x3=12,1≤x1,x2,x3≤6
Each die contributes the bracket (x+x2+x3+x4+x5+x6)=x1−x1−x6. Multiplying all three brackets:
Application 2: Linear Inequalities via a Slack Variable§
How do we solve an inequality such as x1+x2+⋯+xr≤n using generating functions? Just as in Section 07, introduce a non-negative slack variables=n−(x1+x2+⋯+xr)≥0, converting the inequality into the exact equation:
x1+x2+⋯+xr+s=n,s≥0
Since s≥0 has no upper bound, it simply multiplies the generating function by one extra factor 1−x1!
Example 8: Find the number of non-negative integer solutions to x1+x2+x3≤10 subject to 0≤x1≤4.
Solution: Introduce s≥0 so that x1+x2+x3+s=10. The variables contribute 1−x1−x5 for x1, and 1−x1 for each of x2,x3,s:
Application 3: Ordering Restrictions and Integer Partitions§
Suppose variables are constrained by an ordering such as 0≤x1≤x2≤x3. At first glance, the variables seem coupled—you cannot write independent brackets for x1,x2,x3 directly.
The key idea is to switch to non-negative differences (gaps):
d1=x1≥0,d2=x2−x1≥0,d3=x3−x2≥0
Expressing x1,x2,x3 in terms of the independent variables d1,d2,d3:
x1=d1,x2=d1+d2,x3=d1+d2+d3
Now the sum x1+x2+x3=n transforms into a weighted equation in independent non-negative variables:
Example 9 (Ordered Triples and Integer Partitions): Find the number of integer solutions to x1+x2+x3=9 with 0≤x1≤x2≤x3. (Equivalently, count the number of ways to distribute 9 identical balls into 3 identical boxes—the integer partitions of 9 into at most 3 parts from Section 09!)
Solution: Substituting x1=d1,x2=d1+d2,x3=d1+d2+d3 turns the problem into 3d1+2d2+d3=9 with d1,d2,d3≥0. Its generating function is:
[x9](1−x)(1−x2)(1−x3)1
Expand 1−x31=1+x3+x6+x9+… (ignoring powers >9) and apply our Lemma [xm](1−x)(1−x2)1=⌊m/2⌋+1:
Connection to Section 09 (Euler's Generating Function for Integer Partitions):
An unrestricted integer partition of n chooses c1≥0 parts of size 1, c2≥0 parts of size 2, c3≥0 parts of size 3, and so on, such that 1⋅c1+2⋅c2+3⋅c3+⋯=n. Hence the OGF for the total partition number p(n) is Euler's famous infinite product: ∑n=0∞p(n)xn=∏k=1∞1−xk1.
One of the most striking uses of generating functions is counting distinct (non-congruent) triangles with integer side lengths and perimeter n, denoted T(n). The sequence T(0),T(1),T(2),… 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=n
For (a,b,c) to form a genuine (non-degenerate) triangle, it must also satisfy the Triangle Inequality. Since a≤b≤c, the inequalities a+c>b and b+c>a hold automatically; the only extra condition we need is:
a+b>c⟺a+b−c≥1
(because a,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) 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≥0
Now solve for a,b,c in terms of u,v,w. From v=b−a and w=c−b, we have b=a+v and c=b+w=a+v+w. Substituting into u=a+b−c−1:
u=a+(a+v)−(a+v+w)−1=a−w−1⟹a=u+w+1
Hence:
a=u+w+1,b=u+v+w+1,c=u+v+2w+1
Verify the bijection in one glance: for every choice of non-negative integers (u,v,w)≥0, we automatically get a≥1, b−a=v≥0, c−b=w≥0, and a+b−c=u+1≥1. Conversely, every valid triangle (a,b,c) determines a unique triple (u,v,w)≥0.
Now substitute a,b,c into the perimeter equation a+b+c=n:
Notice that every power of x in (1−x2)(1−x4)(1−x6)1 is even! Thus:
The first term (1−x2)(1−x4)(1−x6)x3 supplies all odd-perimeter termsT(3),T(5),T(7),…
The second term (1−x2)(1−x4)(1−x6)x6 supplies all even-perimeter termsT(6),T(8),T(10),…
This immediately reveals two remarkable facts:
1. Parity Symmetry: For every odd integer n≥1, the coefficient of xn in the first term equals the coefficient of xn+3 in the second term:
T(n)=T(n+3)(for every odd n≥1)
(Geometric reason: adding 1 to every side maps (a,b,c)↦(a+1,b+1,c+1), giving a bijection between odd-perimeter triangles of perimeter n and even-perimeter triangles of perimeter n+3! In reverse, if a+b+c is even, then a+b−c is also even and thus ≥2, and a≥2 automatically, so subtracting 1 from every side always keeps a valid triangle.)
2. Direct Link to Partitions into at Most 3 Parts: Setting t=x2 inside (1−x2)(1−x4)(1−x6)1 turns it into (1−t)(1−t2)(1−t3)1—the exact generating function from Application 3! Letting P3(k)=[tk](1−t)(1−t2)(1−t3)1:
T(2m)=P3(m−3)(m≥3),T(2m−3)=P3(m−3)(m≥3)
Step 3: Alcuin's Closed-Form Formula
We can find a closed formula for P3(k)—and hence for T(n)—using only elementary algebra!
Theorem (Nearest-Integer Formula for P3(k)): For every integer k≥0:
P3(k)=[tk](1−t)(1−t2)(1−t3)1=round(12(k+3)2)
where round(y) denotes the integer nearest to y.
Proof: Multiply ∑k=0∞P3(k)tk=(1−t)(1−t2)(1−t3)1 by (1−t6). Factor 1−t6=(1−t3)(1+t3), cancel (1−t3), then factor 1+t3=(1+t)(1−t+t2) and 1−t2=(1−t)(1+t) to cancel (1+t):
Since (1−t)−2=∑j=0∞(j+1)tj, multiplying by t gives (1−t)2t=∑k=1∞ktk. Comparing [tk] on both sides for every k≥6 yields the step-6 recurrence:
P3(k)−P3(k−6)=k(k≥6)
Now test the quadratic function Q(k)=12(k+3)2. Its step-6 difference is:
Q(k)−Q(k−6)=12(k+3)2−(k−3)2=1212k=k
Because P3(k) and Q(k) grow by the exact same amount k whenever k increases by 6, their difference E(k)=Q(k)−P3(k) satisfies E(k)=E(k−6) for all k≥6—it repeats periodically every 6 steps! Check the first 6 values directly (computing P3(k) via our Lemma as in Example 9):
k
0
1
2
3
4
5
P3(k)
1
1
2
3
4
5
Q(k)=(k+3)2/12
9/12
16/12
25/12
36/12
49/12
64/12
Error ∣Q(k)−P3(k)∣
1/4
1/3
1/12
0
1/12
1/3
For every k∈{0,1,2,3,4,5}—and therefore for every integer k≥0—the error satisfies ∣Q(k)−P3(k)∣≤31<21. Hence P3(k) is always the unique integer nearest to 12(k+3)2. ■
Substituting k=2n−3 (so k+3=2n) for even n, and k=2n−3 (so k+3=2n+3) for odd n, gives Alcuin's Theorem immediately (and checking n=1,2,3,4 shows it holds for all n≥1):
Theorem (Alcuin's Formula for Distinct Integer Triangles): The number T(n) of non-congruent triangles with integer side lengths and perimeter n≥1 is:
T(n)=⎩⎨⎧round(48n2)round(48(n+3)2)if n is even,if n is odd.
Example 10 (Counting Distinct Integer Triangles): Find the number of non-congruent triangles with integer side lengths having perimeter: (a)n=15, (b)n=20.
Solution:
(a) Perimeter n=15 (odd):
Method 1 (Direct Coefficient Extraction): Since n=15 is odd, write 15=2m−3⟹m=9, so k=m−3=6:
(Indeed, the 7 triangles are (1,7,7),(2,6,7),(3,5,7),(3,6,6),(4,4,7),(4,5,6),(5,5,5).)
(b) Perimeter n=20 (even): Applying Alcuin's Formula directly:
T(20)=round(48202)=round(48400)=round(8.33…)=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 xr for every r≥0. Comparing [xr] 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,r, prove that:
k=0∑r(km)(r−kn)=(rm+n)
Proof: Start from the elementary polynomial identity:
(1+x)m(1+x)n=(1+x)m+n
Compare [xr] on both sides:
Right-hand side: By the Binomial Theorem, [xr](1+x)m+n=(rm+n).
Left-hand side: Expand both factors using the Binomial Theorem:
(1+x)m(1+x)n=(k=0∑m(km)xk)(j=0∑n(jn)xj)
To obtain xr by picking one term from each bracket, pick (km)xk from the first bracket (for any 0≤k≤r) and the matching term (r−kn)xr−k from the second bracket (with the convention (qp)=0 if q>p). Summing over all k=0,1,…,r gives:
[xr](1+x)m(1+x)n=k=0∑r(km)(r−kn)
Equating the two expressions for [xr] completes the proof. ■
(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 n (and all shifted variables non-negative), translate each variable's condition into its exact generating factor:
Variable Condition
Allowed Exponents
Exact Factor
Notes
xi≥0 (no upper bound)
0,1,2,…
1−x1
Natural bound n; safe to extend to ∞
xi≥ai (ai≥0, no upper bound)
ai,ai+1,…
1−xxai
Lowers remaining budget to n′=n−∑aj
xi≥−ci (negative lower bound)
Shift yi=xi+ci≥0
1−x1 (for yi)
Always shift first before extending to ∞
0≤xi≤bi (bi<n, active)
0,1,…,bi
1−x1−xbi+1
Must stop at xbi; cannot extend to ∞
0≤xi≤bi (bi≥n, redundant)
0,1,…,n,…
1−x1
Natural bound n already enforces xi≤bi
ai≤xi≤bi (0≤ai≤bi)
ai,ai+1,…,bi
xai1−x1−xbi−ai+1
Active only when span bi−ai<n′
xi≥0 even
0,2,4,…
1−x21
Step size 2, starting at 0
xi≥1 odd
1,3,5,…
1−x2x
Step size 2, starting at 1
xi≥0 multiple of k (or weight kxi)
0,k,2k,…
1−xk1
Used for divisibility and weighted sums
xi∈S (finite set)
Elements of S
∑s∈Sxs
Direct list of allowed exponents
Inequality x1+⋯+xr≤n
Add slack s≥0
Multiply by 1−x1
Converts ≤n into =n
Section 11 of 11 · Combinatorics
Mark this section complete when you have worked through its proofs.
Type any topic, theorem, or concept to jump directly to the section.