← Combinatorics
CombinatoricsSection 12 of 1217 min read

Multinomial Theorem and Exponential Generating Functions

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:

  1. When we expand (x1+x2+⋯+xr)n(x_1 + x_2 + \dots + x_r)^n by picking one term from each bracket, what is the exact coefficient of x1a1x2a2⋯xrarx_1^{a_1} x_2^{a_2} \cdots x_r^{a_r}? This gives the Multinomial Theorem.
  2. What if order matters—such as counting 44-letter words from MISSISSIPPI, nn-digit strings with parity rules, or distributing nn distinct balls into rr distinct boxes? Answering this leads directly to Exponential Generating Functions (EGFs).

The Multinomial Theorem§

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)(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=273 \times 3 \times 3 = 27 raw products.

Now ask: how many of these 2727 raw products simplify to a2ba^2 b?

To get a2ba^2 b, 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 ⟶\longrightarrow raw word aab ⟶a2b\longrightarrow a^2 b,
  • Bracket 1: a, Bracket 2: b, Bracket 3: a ⟶\longrightarrow raw word aba ⟶a2b\longrightarrow a^2 b,
  • Bracket 1: b, Bracket 2: a, Bracket 3: a ⟶\longrightarrow raw word baa ⟶a2b\longrightarrow a^2 b.

There are exactly 33 ways—because forming a2ba^2 b is identical to arranging the 33-letter multiset {2⋅a,  1⋅b}\{2 \cdot a,\; 1 \cdot b\} across the 33 numbered brackets! By the Multiset Permutation Theorem (Section 06), this count is 3!2! 1!=3\frac{3!}{2!\,1!} = 3.

Why the Coefficient of a2b in (a+b+c)3 Equals 3!/(2!1!) = 3

Similarly, to get abcabc, we pick one a, one b, and one c across the 33 brackets (abc, acb, bac, bca, cab, cba), giving 3!1! 1! 1!=6\frac{3!}{1!\,1!\,1!} = 6 ways.

Statement and Proof of the Multinomial Theorem§

The exact same reasoning works for rr variables raised to any positive integer power nn.

Theorem (The Multinomial Theorem): For any positive integer nn and variables x1,x2,…,xrx_1, x_2, \dots, x_r:

(x1+x2+⋯+xr)n=∑a1+a2+⋯+ar=na1,a2,…,ar≥0n!a1! a2!⋯ar! x1a1x2a2⋯xrar(x_1 + x_2 + \dots + x_r)^n = \sum_{\substack{a_1 + a_2 + \dots + a_r = n \\ a_1, a_2, \dots, a_r \ge 0}} \frac{n!}{a_1!\,a_2!\cdots a_r!}\, x_1^{a_1} x_2^{a_2} \cdots x_r^{a_r}

Proof: Write (x1+x2+⋯+xr)n(x_1 + x_2 + \dots + x_r)^n as the product of nn identical numbered brackets:

(x1+x2+⋯+xr)(x1+x2+⋯+xr)⋯(x1+x2+⋯+xr)⏟n brackets\underbrace{(x_1 + x_2 + \dots + x_r)(x_1 + x_2 + \dots + x_r)\cdots(x_1 + x_2 + \dots + x_r)}_{n \text{ brackets}}

Every raw product picks one variable from each of the nn brackets, so the sum of its exponents must equal nn: a1+a2+⋯+ar=na_1 + a_2 + \dots + a_r = n with each ai≥0a_i \ge 0.

Fix one exponent tuple (a1,a2,…,ar)(a_1, a_2, \dots, a_r) summing to nn. A raw product equals x1a1x2a2⋯xrarx_1^{a_1} x_2^{a_2} \cdots x_r^{a_r} if and only if we pick x1x_1 from a1a_1 brackets, x2x_2 from a2a_2 brackets, …\dots, and xrx_r from ara_r brackets. Recording which variable is picked from Bracket 11, Bracket 22, …\dots, Bracket nn creates an exact bijection with all distinct linear permutations of the multiset {a1⋅x1,  a2⋅x2,  …,  ar⋅xr}\{a_1 \cdot x_1,\; a_2 \cdot x_2,\; \dots,\; a_r \cdot x_r\}.

By the Multiset Permutation Theorem (Section 06), the number of such permutations—and hence the coefficient of x1a1x2a2⋯xrarx_1^{a_1} x_2^{a_2} \cdots x_r^{a_r}—is n!a1! a2!⋯ar!\frac{n!}{a_1!\,a_2!\cdots a_r!}. Summing over all valid tuples (a1,…,ar)(a_1, \dots, a_r) completes the proof. ■\blacksquare

The number n!a1! a2!⋯ar!\frac{n!}{a_1!\,a_2!\cdots a_r!} is called a multinomial coefficient and is often written:

(na1,  a2,  …,  ar)=n!a1! a2!⋯ar!\binom{n}{a_1,\; a_2,\; \dots,\; a_r} = \frac{n!}{a_1!\,a_2!\cdots a_r!}

Notice three immediate consequences:

1. Special case r=2r = 2 (Binomial Theorem): Setting r=2r = 2 with a1=ka_1 = k and a2=n−ka_2 = n - k gives (nk,  n−k)=n!k! (n−k)!=(nk)\binom{n}{k,\; n - k} = \frac{n!}{k!\,(n - k)!} = \binom{n}{k}, recovering (x1+x2)n=∑k=0n(nk)x1kx2n−k(x_1 + x_2)^n = \sum_{k=0}^{n} \binom{n}{k} x_1^k x_2^{n - k}.

2. Sum of all multinomial coefficients: Setting x1=x2=⋯=xr=1x_1 = x_2 = \dots = x_r = 1 yields:

∑a1+⋯+ar=nai≥0n!a1! a2!⋯ar!=rn\sum_{\substack{a_1 + \dots + a_r = n \\ a_i \ge 0}} \frac{n!}{a_1!\,a_2!\cdots a_r!} = r^n

(Combinatorial meaning: partitioning all rnr^n ways of placing nn distinct balls into rr distinct boxes by the exact box sizes (a1,…,ar)(a_1, \dots, a_r) from Section 09!)

3. Number of distinct terms: Each distinct term corresponds to one non-negative integer solution of a1+a2+⋯+ar=na_1 + a_2 + \dots + a_r = n, so (x1+x2+⋯+xr)n(x_1 + x_2 + \dots + x_r)^n has exactly (n+r−1r−1)\binom{n + r - 1}{r - 1} distinct terms (matching Section 07).

Example 1: Find the coefficient of x3y2z2x^3 y^2 z^2 in the expansion of (2x−y+3z)7(2x - y + 3z)^7.

Solution: Apply the Multinomial Theorem with x1=2xx_1 = 2x, x2=−yx_2 = -y, x3=3zx_3 = 3z, and n=7n = 7. The general term is:

7!a1! a2! a3! (2x)a1(−y)a2(3z)a3=7!a1! a2! a3! 2a1(−1)a23a3 xa1ya2za3\frac{7!}{a_1!\,a_2!\,a_3!}\,(2x)^{a_1} (-y)^{a_2} (3z)^{a_3} = \frac{7!}{a_1!\,a_2!\,a_3!}\,2^{a_1} (-1)^{a_2} 3^{a_3}\, x^{a_1} y^{a_2} z^{a_3}

For x3y2z2x^3 y^2 z^2, we need a1=3a_1 = 3, a2=2a_2 = 2, a3=2a_3 = 2 (check: 3+2+2=73 + 2 + 2 = 7). Substituting these values gives:

7!3! 2! 2!⋅23⋅(−1)2⋅32=210×8×1×9=15,120\frac{7!}{3!\,2!\,2!} \cdot 2^3 \cdot (-1)^2 \cdot 3^2 = 210 \times 8 \times 1 \times 9 = 15{,}120

Example 2 (Multiple Tuples Contributing to the Same Power): Find the coefficient of x4x^4 in the expansion of (1+2x−x2)5(1 + 2x - x^2)^5.

Solution: Be careful! Because xx appears in more than one term inside the bracket, different exponent tuples can produce the same power x4x^4. Write the general term using a1+a2+a3=5a_1 + a_2 + a_3 = 5 (a1,a2,a3≥0a_1, a_2, a_3 \ge 0):

5!a1! a2! a3! (1)a1(2x)a2(−x2)a3=5!a1! a2! a3! 2a2(−1)a3 xa2+2a3\frac{5!}{a_1!\,a_2!\,a_3!}\,(1)^{a_1} (2x)^{a_2} (-x^2)^{a_3} = \frac{5!}{a_1!\,a_2!\,a_3!}\,2^{a_2} (-1)^{a_3}\, x^{a_2 + 2a_3}

We need all non-negative integer triples (a1,a2,a3)(a_1, a_2, a_3) satisfying both a1+a2+a3=5a_1 + a_2 + a_3 = 5 and a2+2a3=4a_2 + 2a_3 = 4. List by a3∈{0,1,2}a_3 \in \{0, 1, 2\}:

  • a3=0  ⟹  a2=4,  a1=1a_3 = 0 \implies a_2 = 4,\; a_1 = 1: 5!1! 4! 0! 24(−1)0=5×16=80\frac{5!}{1!\,4!\,0!}\,2^4 (-1)^0 = 5 \times 16 = 80.
  • a3=1  ⟹  a2=2,  a1=2a_3 = 1 \implies a_2 = 2,\; a_1 = 2: 5!2! 2! 1! 22(−1)1=30×4×(−1)=−120\frac{5!}{2!\,2!\,1!}\,2^2 (-1)^1 = 30 \times 4 \times (-1) = -120.
  • a3=2  ⟹  a2=0,  a1=3a_3 = 2 \implies a_2 = 0,\; a_1 = 3: 5!3! 0! 2! 20(−1)2=10×1=10\frac{5!}{3!\,0!\,2!}\,2^0 (-1)^2 = 10 \times 1 = 10.

Summing all three contributions gives the coefficient of x4x^4:

80−120+10=−3080 - 120 + 10 = -30

Why Ordinary Generating Functions Fail for Ordered Arrangements§

Now turn to our second question. In Section 06, we counted 44-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}\{2 \cdot \text{A},\; 1 \cdot \text{B}\}, how many distinct 22-letter words can we form?

By direct listing, there are 33 distinct 22-letter words: AA, AB, and BA.

Now see what happens if we naively try an OGF from Section 11:

  • Bracket for A (at most 22 copies): (1+x+x2)(1 + x + x^2).
  • Bracket for B (at most 11 copy): (1+x)(1 + x).

Multiplying these brackets gives:

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

The coefficient of x2x^2 is 22, not 33! Why did the OGF undercount? Look at the two raw picks that produced x2x^2:

  • x2⋅x0x^2 \cdot x^0 (two A's, zero B's) gave weight 11, which is correct because {2⋅A}\{2 \cdot \text{A}\} forms only 2!2! 0!=1\frac{2!}{2!\,0!} = 1 word (AA).
  • x1⋅x1x^1 \cdot x^1 (one A, one B) ALSO gave weight 11, even though {1⋅A,  1⋅B}\{1 \cdot \text{A},\; 1 \cdot \text{B}\} forms 2!1! 1!=2\frac{2!}{1!\,1!} = 2 distinct words (AB and BA)!

The Root Cause: An OGF counts every allowed frequency tuple (a1,a2,…,ar)(a_1, a_2, \dots, a_r) summing to nn with weight 11—it counts unordered selections. To count ordered words, each tuple (a1,a2,…,ar)(a_1, a_2, \dots, a_r) summing to nn must instead be weighted by the multinomial coefficient n!a1! a2!⋯ar!\frac{n!}{a_1!\,a_2!\cdots a_r!}!


Building Exponential Generating Functions§

How can we make bracket multiplication automatically attach the weight n!a1! a2!⋯ar!\frac{n!}{a_1!\,a_2!\cdots a_r!} to every tuple (a1,a2,…,ar)(a_1, a_2, \dots, a_r)?

Look at the structure of the multinomial coefficient:

n!a1! a2!⋯ar!=n!⋅(1a1!⋅1a2!⋯1ar!)\frac{n!}{a_1!\,a_2!\cdots a_r!} = n! \cdot \left(\frac{1}{a_1!} \cdot \frac{1}{a_2!} \cdots \frac{1}{a_r!}\right)

This factorization is the entire secret! The numerator n!n! depends only on the final word length nn, while the denominator splits cleanly into one independent factor 1ai!\frac{1}{a_i!} for each letter type!

Therefore, inside each letter's bracket, instead of writing xkx^k when that letter is used kk times, we write:

xkk!\frac{x^k}{k!}

Watch what happens when we pick xa1a1!\frac{x^{a_1}}{a_1!} from Bracket 11, xa2a2!\frac{x^{a_2}}{a_2!} from Bracket 22, …\dots, and xarar!\frac{x^{a_r}}{a_r!} from Bracket rr, and multiply them:

xa1a1!⋅xa2a2!⋯xarar!=1a1! a2!⋯ar! xa1+a2+⋯+ar\frac{x^{a_1}}{a_1!} \cdot \frac{x^{a_2}}{a_2!} \cdots \frac{x^{a_r}}{a_r!} = \frac{1}{a_1!\,a_2!\cdots a_r!}\,x^{a_1 + a_2 + \dots + a_r}

When a1+a2+⋯+ar=na_1 + a_2 + \dots + a_r = n, this raw product contributes 1a1! a2!⋯ar!\frac{1}{a_1!\,a_2!\cdots a_r!} to the coefficient of xnx^n. Now multiply the final coefficient [xn][x^n] by n!n!:

n!⋅[xn] E(x)=∑a1+a2+⋯+ar=nai allowedn!a1! a2!⋯ar!n! \cdot [x^n]\,E(x) = \sum_{\substack{a_1 + a_2 + \dots + a_r = n \\ a_i \text{ allowed}}} \frac{n!}{a_1!\,a_2!\cdots a_r!}

Every allowed frequency tuple (a1,…,ar)(a_1, \dots, a_r) is now weighted by its exact number of ordered arrangements!

Testing the Fix on Our Small Multiset§

Return to {2⋅A,  1⋅B}\{2 \cdot \text{A},\; 1 \cdot \text{B}\} using our new xkk!\frac{x^k}{k!} brackets:

  • Bracket for A (0,1,0, 1, or 22 copies): (1+x1!+x22!)\left(1 + \frac{x}{1!} + \frac{x^2}{2!}\right).
  • Bracket for B (00 or 11 copy): (1+x1!)\left(1 + \frac{x}{1!}\right).

Multiply them out carefully:

(1+x+x22)(1+x)=1+2x+32x2+12x3\left(1 + x + \frac{x^2}{2}\right)(1 + x) = 1 + 2x + \frac{3}{2}x^2 + \frac{1}{2}x^3

Rewrite every term in the form an⋅xnn!a_n \cdot \frac{x^n}{n!} (equivalently, multiply each coefficient of xnx^n by n!n!):

1+2⋅x1!+3⋅x22!+3⋅x33!1 + 2\cdot\frac{x}{1!} + 3\cdot\frac{x^2}{2!} + 3\cdot\frac{x^3}{3!}

Check every single length nn against direct counting:

  • n=0n = 0: 0!⋅1=10! \cdot 1 = 1 (the empty word).
  • n=1n = 1: 1!⋅2=21! \cdot 2 = 2 (A, B).
  • n=2n = 2: 2!⋅32=32! \cdot \frac{3}{2} = 3 (AA, AB, BA).
  • n=3n = 3: 3!⋅12=33! \cdot \frac{1}{2} = 3 (AAB, ABA, BAA).

Every single word count is exact!

Comparing OGF and EGF Bracket Multiplication on the Multiset {2A, 1B}

Formal Definition and Notation§

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

E(x)=a0+a1x1!+a2x22!+a3x33!+⋯=∑n=0∞anxnn!E(x) = a_0 + a_1 \frac{x}{1!} + a_2 \frac{x^2}{2!} + a_3 \frac{x^3}{3!} + \dots = \sum_{n=0}^{\infty} a_n \frac{x^n}{n!}

We write [xnn!]E(x)\left[\frac{x^n}{n!}\right] E(x) for the coefficient of xnn!\frac{x^n}{n!} in E(x)E(x). Since the coefficient of xnx^n is ann!\frac{a_n}{n!}, we always extract ana_n by:

an=[xnn!]E(x)=n! [xn] E(x)a_n = \left[\frac{x^n}{n!}\right] E(x) = n!\,[x^n]\,E(x)

Natural Bound vs. Infinity Still Applies!
Just as in Section 11, because all exponents are non-negative, adding higher terms xn+1(n+1)!+xn+2(n+2)!+…\frac{x^{n+1}}{(n+1)!} + \frac{x^{n+2}}{(n+2)!} + \dots to any bracket never changes [xn][x^n]. Therefore, whenever a letter has no upper bound (or an upper bound bi≥nb_i \ge n, which is redundant for length nn), we extend its bracket all the way to ∞\infty!


Standard Exponential Series Factors§

Why are these called exponential generating functions? Because when an unrestricted bracket extends to ∞\infty, it becomes the famous series expansion of exe^x!

Recall the standard exponential series:

ex=1+x1!+x22!+x33!+x44!+⋯=∑n=0∞xnn!e^x = 1 + \frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \dots = \sum_{n=0}^{\infty} \frac{x^n}{n!}

Replacing xx by cxcx (for any constant cc) gives the master extraction formula for EGFs:

ecx=∑n=0∞(cx)nn!=∑n=0∞cnxnn!  ⟹  [xnn!]ecx=cne^{cx} = \sum_{n=0}^{\infty} \frac{(cx)^n}{n!} = \sum_{n=0}^{\infty} c^n \frac{x^n}{n!} \implies \left[\frac{x^n}{n!}\right] e^{cx} = c^n

(For c=0c = 0, e0⋅x=1e^{0 \cdot x} = 1, so [xnn!]1=0\left[\frac{x^n}{n!}\right] 1 = 0 for every n≥1n \ge 1 and 11 for n=0n = 0.)

As an instant check, if rr distinct letters are available in unlimited supply, each bracket is exe^x, so their product is (ex)r=erx(e^x)^r = e^{rx}, and [xnn!]erx=rn\left[\frac{x^n}{n!}\right] e^{rx} = r^n—immediately recovering Section 06's formula for nn-permutations with unlimited repetition!

Now derive every standard restricted EGF factor directly from exe^x:

1. Unlimited supply (k≥0k \ge 0):

1+x1!+x22!+x33!+⋯=ex1 + \frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \dots = e^x

2. Appears at least once (k≥1k \ge 1): Remove the k=0k = 0 term (11) from exe^x:

x1!+x22!+x33!+⋯=ex−1\frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \dots = e^x - 1

3. Appears at least aa times (k≥ak \ge a): Remove the first aa terms (k=0,1,…,a−1k = 0, 1, \dots, a - 1) from exe^x:

xaa!+xa+1(a+1)!+⋯=ex−(1+x1!+x22!+⋯+xa−1(a−1)!)\frac{x^a}{a!} + \frac{x^{a+1}}{(a+1)!} + \dots = e^x - \left(1 + \frac{x}{1!} + \frac{x^2}{2!} + \dots + \frac{x^{a - 1}}{(a - 1)!}\right)

4. Appears at most bb times (0≤k≤b0 \le k \le b): If b<nb < n (active bound), stop the bracket at xbb!\frac{x^b}{b!}:

1+x1!+x22!+⋯+xbb!1 + \frac{x}{1!} + \frac{x^2}{2!} + \dots + \frac{x^b}{b!}

(If b≥nb \ge n, the cap is redundant and may be replaced cleanly by exe^x!)

5. Even or odd number of occurrences: Write exe^x and e−xe^{-x} side by side:

ex=1+x1!+x22!+x33!+x44!+…e^x = 1 + \frac{x}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \dots e−x=1−x1!+x22!−x33!+x44!−…e^{-x} = 1 - \frac{x}{1!} + \frac{x^2}{2!} - \frac{x^3}{3!} + \frac{x^4}{4!} - \dots

Adding the two series cancels every odd power, and dividing by 22 leaves only even powers (k∈{0,2,4,… }k \in \{0, 2, 4, \dots\}):

1+x22!+x44!+⋯=ex+e−x21 + \frac{x^2}{2!} + \frac{x^4}{4!} + \dots = \frac{e^x + e^{-x}}{2}

Subtracting e−xe^{-x} from exe^x cancels every even power, and dividing by 22 leaves only odd powers (k∈{1,3,5,… }k \in \{1, 3, 5, \dots\}):

x1!+x33!+x55!+⋯=ex−e−x2\frac{x}{1!} + \frac{x^3}{3!} + \frac{x^5}{5!} + \dots = \frac{e^x - e^{-x}}{2}

Worked Examples and Unifying Connections§

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 44-letter words can be formed from the letters of MISSISSIPPI?

Solution: The available multiset is {1⋅M,  4⋅I,  4⋅S,  2⋅P}\{1 \cdot \text{M},\; 4 \cdot \text{I},\; 4 \cdot \text{S},\; 2 \cdot \text{P}\}, and our target word length is n=4n = 4. Write one EGF bracket per letter type:

  • M (at most 11, active since 1<41 < 4): (1+x)(1 + x).
  • P (at most 22, active since 2<42 < 4): (1+x+x22!)\left(1 + x + \frac{x^2}{2!}\right).
  • I and S (at most 44 each): notice 4≥n=44 \ge n = 4! Since the upper bound 44 is redundant for 44-letter words, we can safely extend both brackets to exe^x!

Multiplying all four brackets gives:

E(x)=(1+x)(1+x+x22)ex⋅ex=(1+2x+32x2+12x3)e2xE(x) = (1 + x)\left(1 + x + \frac{x^2}{2}\right) e^x \cdot e^x = \left(1 + 2x + \frac{3}{2}x^2 + \frac{1}{2}x^3\right) e^{2x}

Now extract [x4] E(x)[x^4]\,E(x) using e2x=∑k=0∞2kk!xke^{2x} = \sum_{k=0}^{\infty} \frac{2^k}{k!} x^k. Pair each term of the polynomial with the matching power from e2xe^{2x} so the exponents sum to 44:

[x4] E(x)=1⋅244!+2⋅233!+32⋅222!+12⋅211![x^4]\,E(x) = 1 \cdot \frac{2^4}{4!} + 2 \cdot \frac{2^3}{3!} + \frac{3}{2} \cdot \frac{2^2}{2!} + \frac{1}{2} \cdot \frac{2^1}{1!} =1624+166+32(2)+12(2)=23+83+3+1=103+4=223= \frac{16}{24} + \frac{16}{6} + \frac{3}{2}(2) + \frac{1}{2}(2) = \frac{2}{3} + \frac{8}{3} + 3 + 1 = \frac{10}{3} + 4 = \frac{22}{3}

Finally, multiply by 4!=244! = 24:

Total 4-letter words=4!⋅[x4] E(x)=24×223=176\text{Total 4-letter words} = 4! \cdot [x^4]\,E(x) = 24 \times \frac{22}{3} = 176

Notice how extending the redundant caps on I and S to exe^x replaced all five manual cases from Section 06 with a single three-line calculation!


2. Strings with Parity Constraints§

Example 4 (nn-Digit Strings with Even and Odd Digit Counts): How many nn-digit strings (n≥1n \ge 1, leading zeros allowed) can be formed from the digits {0,1,2,3}\{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 44 digits has an unlimited supply, except 0 must occur an even number of times:

  • Digit 0 (even): ex+e−x2\frac{e^x + e^{-x}}{2}.
  • Digits 1, 2, 3 (unrestricted): exe^x each.

Multiply the four brackets:

E(x)=(ex+e−x2)ex⋅ex⋅ex=e4x+e2x2E(x) = \left(\frac{e^x + e^{-x}}{2}\right) e^x \cdot e^x \cdot e^x = \frac{e^{4x} + e^{2x}}{2}

Extract [xnn!]\left[\frac{x^n}{n!}\right] term by term using [xnn!]ecx=cn\left[\frac{x^n}{n!}\right] e^{cx} = c^n:

an=4n+2n2a_n = \frac{4^n + 2^n}{2}

(Check n=1n = 1: 4+22=3\frac{4 + 2}{2} = 3, namely 1, 2, 3. Check n=2n = 2: 16+42=10\frac{16 + 4}{2} = 10, namely 00 plus all 32=93^2 = 9 strings with no 0.)

(b) Now digit 0 is even, digit 1 is odd, and digits 2 and 3 are unrestricted:

E(x)=(ex+e−x2)(ex−e−x2)ex⋅ex=e2x−e−2x4⋅e2x=e4x−14E(x) = \left(\frac{e^x + e^{-x}}{2}\right)\left(\frac{e^x - e^{-x}}{2}\right) e^x \cdot e^x = \frac{e^{2x} - e^{-2x}}{4} \cdot e^{2x} = \frac{e^{4x} - 1}{4}

For every n≥1n \ge 1, the constant term −1-1 contributes 00 to [xnn!]\left[\frac{x^n}{n!}\right], leaving:

an=4n4=4n−1a_n = \frac{4^n}{4} = 4^{n - 1}

(Check n=1n = 1: 40=14^0 = 1, namely 1. Check n=2n = 2: 41=44^1 = 4, namely 12, 21, 13, 31!)


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 nn distinct balls (Ball 1, Ball 2, …\dots, Ball n) into rr distinct boxes (Box 1, Box 2, …\dots, Box r) really is! Writing down which box receives Ball 1, which receives Ball 2, …\dots, and which receives Ball n creates an nn-letter ordered word over the rr-letter alphabet {Box 1,…,Box r}\{\text{Box 1}, \dots, \text{Box } r\}!

  • Box i receives aia_i balls   ⟺  \iff the symbol Box i appears aia_i times in the nn-letter word.
  • Therefore, distributing nn distinct balls into rr distinct boxes with box-size restrictions is 100% identical to forming nn-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 nn distinct balls into rr distinct boxes so that no box is empty (equivalently, the number of surjective/onto functions r! S(n,r)r!\,S(n, r)) is:

∑j=0r(−1)j(rj)(r−j)n\sum_{j=0}^{r} (-1)^j \binom{r}{j} (r - j)^n

Proof: Each of the rr distinct boxes must receive at least 11 ball, so each box contributes the EGF factor (ex−1)(e^x - 1). Multiplying all rr brackets and expanding by the Binomial Theorem gives:

E(x)=(ex−1)r=∑j=0r(−1)j(rj)(ex)r−j=∑j=0r(−1)j(rj)e(r−j)xE(x) = (e^x - 1)^r = \sum_{j=0}^{r} (-1)^j \binom{r}{j} (e^x)^{r - j} = \sum_{j=0}^{r} (-1)^j \binom{r}{j} e^{(r - j)x}

Now extract [xnn!]\left[\frac{x^n}{n!}\right] term by term using [xnn!]e(r−j)x=(r−j)n\left[\frac{x^n}{n!}\right] e^{(r - j)x} = (r - j)^n:

r! S(n,r)=∑j=0r(−1)j(rj)(r−j)n■r!\,S(n, r) = \sum_{j=0}^{r} (-1)^j \binom{r}{j} (r - j)^n \qquad \blacksquare

(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 nn distinct gifts (n≥1n \ge 1) be distributed among three children—Asha, Kabir, and Meera—so that Asha receives at least 11 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:

  • Asha (≥1\ge 1): (ex−1)(e^x - 1).
  • Kabir (even): ex+e−x2\frac{e^x + e^{-x}}{2}.
  • Meera (any): exe^x.

Multiply the three factors:

E(x)=(ex−1)(ex+e−x2)ex=12(ex−1)(e2x+1)=12(e3x−e2x+ex−1)E(x) = (e^x - 1)\left(\frac{e^x + e^{-x}}{2}\right) e^x = \frac{1}{2}(e^x - 1)(e^{2x} + 1) = \frac{1}{2}\left(e^{3x} - e^{2x} + e^x - 1\right)

For every n≥1n \ge 1, the constant −1-1 contributes 00 to [xnn!]\left[\frac{x^n}{n!}\right], giving:

an=3n−2n+1n2=3n−2n+12a_n = \frac{3^n - 2^n + 1^n}{2} = \frac{3^n - 2^n + 1}{2}

(Check n=2n = 2: 9−4+12=3\frac{9 - 4 + 1}{2} = 3. Indeed, labeling each of the 22 gifts by recipient gives AA, AM, MA—exactly 33 distributions!)


4. Bonus Connection: Derangements via EGFs (Section 08)§

Recall Property 4 of Derangements from Section 08: partitioning all n!n! permutations of nn objects by the exact number kk of objects in their original positions gave:

n!=∑k=0n(nk)D(n−k)=∑k=0nn!k! (n−k)! D(n−k)n! = \sum_{k=0}^{n} \binom{n}{k} D(n - k) = \sum_{k=0}^{n} \frac{n!}{k!\,(n - k)!}\,D(n - k)

Divide both sides by n!n!:

1=∑k=0n1k!⋅D(n−k)(n−k)!1 = \sum_{k=0}^{n} \frac{1}{k!} \cdot \frac{D(n - k)}{(n - k)!}

Look at the right-hand side! It is literally the coefficient of xnx^n in the product of ex=∑k=0∞xkk!e^x = \sum_{k=0}^{\infty} \frac{x^k}{k!} and the EGF of derangements ED(x)=∑m=0∞D(m)xmm!E_D(x) = \sum_{m=0}^{\infty} D(m)\frac{x^m}{m!}!

Example 7 (Deriving the Derangement Formula via EGF): Let ED(x)=∑n=0∞D(n)xnn!E_D(x) = \sum_{n=0}^{\infty} D(n)\frac{x^n}{n!}. From the identity above, every coefficient [xn][x^n] of ex⋅ED(x)e^x \cdot E_D(x) equals 11, so:

ex⋅ED(x)=1+x+x2+x3+⋯=11−xe^x \cdot E_D(x) = 1 + x + x^2 + x^3 + \dots = \frac{1}{1 - x}

Divide both sides by exe^x:

ED(x)=e−x1−x=(∑k=0∞(−1)kk!xk)(1+x+x2+x3+… )E_D(x) = \frac{e^{-x}}{1 - x} = \left(\sum_{k=0}^{\infty} \frac{(-1)^k}{k!} x^k\right)\left(1 + x + x^2 + x^3 + \dots\right)

To get xnx^n from this product, pick (−1)kk!xk\frac{(-1)^k}{k!} x^k from the first bracket (for any 0≤k≤n0 \le k \le n) and the matching power 1⋅xn−k1 \cdot x^{n - k} from the second bracket. Thus [xn] ED(x)=∑k=0n(−1)kk![x^n]\,E_D(x) = \sum_{k=0}^{n} \frac{(-1)^k}{k!}, and multiplying by n!n! immediately recovers the Derangement Formula from Section 08:

D(n)=n! [xn] ED(x)=n!∑k=0n(−1)kk!D(n) = n!\,[x^n]\,E_D(x) = n!\sum_{k=0}^{n} \frac{(-1)^k}{k!}

Choosing Between OGF and EGF: Master Comparison§

Students often ask: "How do I immediately know whether a problem needs an OGF or an EGF?" Look at whether order / object distinctness matters:

Feature Ordinary Generating Function (OGF) Exponential Generating Function (EGF)
Series form ∑n=0∞anxn\sum_{n=0}^{\infty} a_n x^n ∑n=0∞anxnn!\sum_{n=0}^{\infty} a_n \dfrac{x^n}{n!}
How to extract ana_n [xn] G(x)[x^n]\,G(x) [xnn!]E(x)=n! [xn] E(x)\left[\dfrac{x^n}{n!}\right] E(x) = n!\,[x^n]\,E(x)
Typical problems Unordered selections, integral equations x1+⋯+xr=nx_1 + \dots + x_r = n, coin change, integer partitions Ordered words / strings with repetition, multiset rr-permutations
Balls-and-boxes model Identical balls into distinct boxes Distinct balls into distinct boxes
No upper bound (k≥0k \ge 0) 11−x\dfrac{1}{1 - x} exe^x
At least one (k≥1k \ge 1) x1−x\dfrac{x}{1 - x} ex−1e^x - 1
At most bb (0≤k≤b<n0 \le k \le b < n) 1+x+⋯+xb=1−xb+11−x1 + x + \dots + x^b = \dfrac{1 - x^{b+1}}{1 - x} 1+x1!+x22!+⋯+xbb!1 + \dfrac{x}{1!} + \dfrac{x^2}{2!} + \dots + \dfrac{x^b}{b!}
Even count (0,2,4,…0, 2, 4, \dots) 11−x2\dfrac{1}{1 - x^2} ex+e−x2\dfrac{e^x + e^{-x}}{2}
Odd count (1,3,5,…1, 3, 5, \dots) x1−x2\dfrac{x}{1 - x^2} ex−e−x2\dfrac{e^x - e^{-x}}{2}
Section 12 of 12 · Combinatorics

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