In Section 11, we started from the basic rule of expanding algebraic brackets and built Ordinary Generating Functions (OGFs) to count unordered selections with repetition.
Now we ask two natural follow-up questions:
When we expand (x1+x2+⋯+xr)n by picking one term from each bracket, what is the exact coefficient of x1a1x2a2⋯xrar? This gives the Multinomial Theorem.
What if order matters—such as counting 4-letter words from MISSISSIPPI, n-digit strings with parity rules, or distributing n distinct balls into r distinct boxes? Answering this leads directly to Exponential Generating Functions (EGFs).
Return to the bracket-picking rule from Section 11, and look closely at the cube of a three-term sum:
(a+b+c)3=(a+b+c)(a+b+c)(a+b+c)
To form one raw product in this expansion, we pick exactly one letter from Bracket 1, one letter from Bracket 2, and one letter from Bracket 3, and multiply them together. Before combining like terms, there are 3×3×3=27 raw products.
Now ask: how many of these 27 raw products simplify to a2b?
To get a2b, we must pick a from two of the three brackets and b from the remaining one bracket. Listing every valid pick explicitly:
Bracket 1: a, Bracket 2: a, Bracket 3: b⟶ raw word aab⟶a2b,
Bracket 1: a, Bracket 2: b, Bracket 3: a⟶ raw word aba⟶a2b,
Bracket 1: b, Bracket 2: a, Bracket 3: a⟶ raw word baa⟶a2b.
There are exactly 3 ways—because forming a2b is identical to arranging the 3-letter multiset {2⋅a,1⋅b} across the 3 numbered brackets! By the Multiset Permutation Theorem (Section 06), this count is 2!1!3!=3.
Similarly, to get abc, we pick one a, one b, and one c across the 3 brackets (abc, acb, bac, bca, cab, cba), giving 1!1!1!3!=6 ways.
Proof: Write (x1+x2+⋯+xr)n as the product of n identical numbered brackets:
n brackets(x1+x2+⋯+xr)(x1+x2+⋯+xr)⋯(x1+x2+⋯+xr)
Every raw product picks one variable from each of the n brackets, so the sum of its exponents must equal n: a1+a2+⋯+ar=n with each ai≥0.
Fix one exponent tuple (a1,a2,…,ar) summing to n. A raw product equals x1a1x2a2⋯xrar if and only if we pick x1 from a1 brackets, x2 from a2 brackets, …, and xr from ar brackets. Recording which variable is picked from Bracket 1, Bracket 2, …, Bracket n creates an exact bijection with all distinct linear permutations of the multiset {a1⋅x1,a2⋅x2,…,ar⋅xr}.
By the Multiset Permutation Theorem (Section 06), the number of such permutations—and hence the coefficient of x1a1x2a2⋯xrar—is a1!a2!⋯ar!n!. Summing over all valid tuples (a1,…,ar) completes the proof. ■
The number a1!a2!⋯ar!n! is called a multinomial coefficient and is often written:
(a1,a2,…,arn)=a1!a2!⋯ar!n!
Notice three immediate consequences:
1. Special case r=2 (Binomial Theorem): Setting r=2 with a1=k and a2=n−k gives (k,n−kn)=k!(n−k)!n!=(kn), recovering (x1+x2)n=∑k=0n(kn)x1kx2n−k.
2. Sum of all multinomial coefficients: Setting x1=x2=⋯=xr=1 yields:
a1+⋯+ar=nai≥0∑a1!a2!⋯ar!n!=rn
(Combinatorial meaning: partitioning all rn ways of placing n distinct balls into r distinct boxes by the exact box sizes (a1,…,ar) from Section 09!)
3. Number of distinct terms: Each distinct term corresponds to one non-negative integer solution of a1+a2+⋯+ar=n, so (x1+x2+⋯+xr)n has exactly (r−1n+r−1) distinct terms (matching Section 07).
Example 1: Find the coefficient of x3y2z2 in the expansion of (2x−y+3z)7.
Solution: Apply the Multinomial Theorem with x1=2x, x2=−y, x3=3z, and n=7. The general term is:
For x3y2z2, we need a1=3, a2=2, a3=2 (check: 3+2+2=7). Substituting these values gives:
3!2!2!7!⋅23⋅(−1)2⋅32=210×8×1×9=15,120
Example 2 (Multiple Tuples Contributing to the Same Power): Find the coefficient of x4 in the expansion of (1+2x−x2)5.
Solution: Be careful! Because x appears in more than one term inside the bracket, different exponent tuples can produce the same power x4. Write the general term using a1+a2+a3=5 (a1,a2,a3≥0):
Summing all three contributions gives the coefficient of x4:
80−120+10=−30
Why Ordinary Generating Functions Fail for Ordered Arrangements§
Now turn to our second question. In Section 06, we counted 4-letter words formed from MISSISSIPPI by splitting into five separate cases. Can we use generating functions to count ordered words with repetition automatically?
Test an Ordinary Generating Function (OGF) on a tiny example first so we see exactly what goes wrong.
Test Problem: Using the multiset {2⋅A,1⋅B}, how many distinct 2-letter words can we form?
By direct listing, there are 3 distinct 2-letter words: AA, AB, and BA.
Now see what happens if we naively try an OGF from Section 11:
Bracket for A (at most 2 copies): (1+x+x2).
Bracket for B (at most 1 copy): (1+x).
Multiplying these brackets gives:
(1+x+x2)(1+x)=1+2x+2x2+x3
The coefficient of x2 is 2, not3! Why did the OGF undercount? Look at the two raw picks that produced x2:
x2⋅x0 (two A's, zero B's) gave weight 1, which is correct because {2⋅A} forms only 2!0!2!=1 word (AA).
x1⋅x1 (one A, one B) ALSO gave weight 1, even though {1⋅A,1⋅B} forms 1!1!2!=2 distinct words (AB and BA)!
The Root Cause: An OGF counts every allowed frequency tuple (a1,a2,…,ar) summing to n with weight 1—it counts unordered selections. To count ordered words, each tuple (a1,a2,…,ar) summing to n must instead be weighted by the multinomial coefficienta1!a2!⋯ar!n!!
How can we make bracket multiplication automatically attach the weight a1!a2!⋯ar!n! to every tuple (a1,a2,…,ar)?
Look at the structure of the multinomial coefficient:
a1!a2!⋯ar!n!=n!⋅(a1!1⋅a2!1⋯ar!1)
This factorization is the entire secret! The numerator n! depends only on the final word length n, while the denominator splits cleanly into one independent factor ai!1 for each letter type!
Therefore, inside each letter's bracket, instead of writing xk when that letter is used k times, we write:
k!xk
Watch what happens when we pick a1!xa1 from Bracket 1, a2!xa2 from Bracket 2, …, and ar!xar from Bracket r, and multiply them:
We write [n!xn]E(x) for the coefficient of n!xn in E(x). Since the coefficient of xn is n!an, we always extract an by:
an=[n!xn]E(x)=n![xn]E(x)
Natural Bound vs. Infinity Still Applies!
Just as in Section 11, because all exponents are non-negative, adding higher terms (n+1)!xn+1+(n+2)!xn+2+… to any bracket never changes[xn]. Therefore, whenever a letter has no upper bound (or an upper bound bi≥n, which is redundant for length n), we extend its bracket all the way to ∞!
Why are these called exponential generating functions? Because when an unrestricted bracket extends to ∞, it becomes the famous series expansion of ex!
Recall the standard exponential series:
ex=1+1!x+2!x2+3!x3+4!x4+⋯=n=0∑∞n!xn
Replacing x by cx (for any constant c) gives the master extraction formula for EGFs:
ecx=n=0∑∞n!(cx)n=n=0∑∞cnn!xn⟹[n!xn]ecx=cn
(For c=0, e0⋅x=1, so [n!xn]1=0 for every n≥1 and 1 for n=0.)
As an instant check, if r distinct letters are available in unlimited supply, each bracket is ex, so their product is (ex)r=erx, and [n!xn]erx=rn—immediately recovering Section 06's formula for n-permutations with unlimited repetition!
Now derive every standard restricted EGF factor directly from ex:
1. Unlimited supply (k≥0):
1+1!x+2!x2+3!x3+⋯=ex
2. Appears at least once (k≥1): Remove the k=0 term (1) from ex:
1!x+2!x2+3!x3+⋯=ex−1
3. Appears at least a times (k≥a): Remove the first a terms (k=0,1,…,a−1) from ex:
1. Partial Permutations of a Multiset (Fulfilling Section 06)§
Example 3 (Four-Letter Words from MISSISSIPPI): Re-solve Example 6 of Section 06 using an Exponential Generating Function: how many distinct 4-letter words can be formed from the letters of MISSISSIPPI?
Solution: The available multiset is {1⋅M,4⋅I,4⋅S,2⋅P}, and our target word length is n=4. Write one EGF bracket per letter type:
M (at most 1, active since 1<4): (1+x).
P (at most 2, active since 2<4): (1+x+2!x2).
I and S (at most 4 each): notice 4≥n=4! Since the upper bound 4 is redundant for 4-letter words, we can safely extend both brackets to ex!
Multiplying all four brackets gives:
E(x)=(1+x)(1+x+2x2)ex⋅ex=(1+2x+23x2+21x3)e2x
Now extract [x4]E(x) using e2x=∑k=0∞k!2kxk. Pair each term of the polynomial with the matching power from e2x so the exponents sum to 4:
Example 4 (n-Digit Strings with Even and Odd Digit Counts): How many n-digit strings (n≥1, leading zeros allowed) can be formed from the digits {0,1,2,3} such that:
(a) the digit 0 appears an even number of times?
(b) the digit 0 appears an even number of times and the digit 1 appears an odd number of times?
Solution:
(a) Each of the 4 digits has an unlimited supply, except 0 must occur an even number of times:
Digit 0 (even): 2ex+e−x.
Digits 1, 2, 3 (unrestricted): ex each.
Multiply the four brackets:
E(x)=(2ex+e−x)ex⋅ex⋅ex=2e4x+e2x
Extract [n!xn] term by term using [n!xn]ecx=cn:
an=24n+2n
(Check n=1: 24+2=3, namely 1, 2, 3. Check n=2: 216+4=10, namely 00 plus all 32=9 strings with no 0.)
(b) Now digit 0 is even, digit 1 is odd, and digits 2 and 3 are unrestricted:
3. Distinct Balls into Distinct Boxes (Unifying Sections 09 and 10)§
Why do distinct-ball-into-distinct-box distribution problems use Exponential Generating Functions?
Think carefully about what a distribution of n distinct balls (Ball 1, Ball 2, …, Ball n) into r distinct boxes (Box 1, Box 2, …, Box r) really is! Writing down which box receives Ball 1, which receives Ball 2, …, and which receives Ball n creates an n-letter ordered word over the r-letter alphabet {Box 1,…,Box r}!
Box i receives ai balls ⟺ the symbol Box i appears ai times in the n-letter word.
Therefore, distributing n distinct balls into r distinct boxes with box-size restrictions is 100% identical to forming n-letter words with letter-frequency restrictions!
Example 5 (Onto Functions and Non-Empty Boxes — Recovering Sections 09 and 10): Use an EGF to prove that the number of ways to distribute n distinct balls into r distinct boxes so that no box is empty (equivalently, the number of surjective/onto functions r!S(n,r)) is:
j=0∑r(−1)j(jr)(r−j)n
Proof: Each of the r distinct boxes must receive at least 1 ball, so each box contributes the EGF factor (ex−1). Multiplying all r brackets and expanding by the Binomial Theorem gives:
Now extract [n!xn] term by term using [n!xn]e(r−j)x=(r−j)n:
r!S(n,r)=j=0∑r(−1)j(jr)(r−j)n■
(Compare this three-line algebraic proof with the Principle of Inclusion–Exclusion proof in Section 09!)
Example 6 (Distinct Gifts with Mixed Conditions): In how many ways can n distinct gifts (n≥1) be distributed among three children—Asha, Kabir, and Meera—so that Asha receives at least 1 gift, Kabir receives an even number of gifts, and Meera receives any number of gifts?
Solution: Since both gifts and children are distinct, use an EGF:
For every n≥1, the constant −1 contributes 0 to [n!xn], giving:
an=23n−2n+1n=23n−2n+1
(Check n=2: 29−4+1=3. Indeed, labeling each of the 2 gifts by recipient gives AA, AM, MA—exactly 3 distributions!)
4. Bonus Connection: Derangements via EGFs (Section 08)§
Recall Property 4 of Derangements from Section 08: partitioning all n! permutations of n objects by the exact number k of objects in their original positions gave:
n!=k=0∑n(kn)D(n−k)=k=0∑nk!(n−k)!n!D(n−k)
Divide both sides by n!:
1=k=0∑nk!1⋅(n−k)!D(n−k)
Look at the right-hand side! It is literally the coefficient of xn in the product of ex=∑k=0∞k!xk and the EGF of derangements ED(x)=∑m=0∞D(m)m!xm!
Example 7 (Deriving the Derangement Formula via EGF): Let ED(x)=∑n=0∞D(n)n!xn. From the identity above, every coefficient [xn] of ex⋅ED(x) equals 1, so:
ex⋅ED(x)=1+x+x2+x3+⋯=1−x1
Divide both sides by ex:
ED(x)=1−xe−x=(k=0∑∞k!(−1)kxk)(1+x+x2+x3+…)
To get xn from this product, pick k!(−1)kxk from the first bracket (for any 0≤k≤n) and the matching power 1⋅xn−k from the second bracket. Thus [xn]ED(x)=∑k=0nk!(−1)k, and multiplying by n! immediately recovers the Derangement Formula from Section 08: