ma3210 lecture 8: the pigeonhole principle ima3210 lecture 8: the pigeonhole principle i1 erik e....

35
MA3210 Lecture 8: The Pigeonhole Principle I 1 Erik E. Westlund The Pigeonhole Principle (simple): If n + 1, or more objects are placed into n boxes, then at least one box will contain two or more objects. Proof. If not, then maximum number of objects is n z }| { 1+1+ ··· +1 <n + 1, a contradiction. Note: we don’t know which box contains more than 2 elements, only that one exists. (Non-constructive existence proof.) Also called Dirichlet drawer principle or Shoebox principle. Ex. Among any group of 367 people, there are at least two with the same birthday. Ex. At any given time, there are at least two people in California who were born on the same second of the year. There are (365)(24)(60)(60) = 31,536,000 seconds and at least 36,000,000 people in California. Ex. At any given time, there are at least two people in London that have the exact same number of hairs on their heads. Roughly 125,000 hairs on average head, so in no case more than 1,000,000 hairs. London has more than 1,000,000 people. Ex. You need only select n + 1 people out a set of n married couples to guarantee a married couple has been selected. There exists no injection ϕ : A B on finite sets such that the codomain is smaller than the domain. If |A| = |B| and ϕ is injective, then ϕ is surjective, i.e., “If n objects are put into n boxes and no box gets more than one object, then each box has an object in it.” If |A| = |B| and ϕ is surjective, then ϕ is injective, i.e., “If n objects are put into n boxes and no box is empty, then each box has an object in it.” 1 Updated: May 26, 2009. 1

Upload: others

Post on 11-Feb-2020

40 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 8: The Pigeonhole Principle I1

Erik E. Westlund

The Pigeonhole Principle (simple): If n + 1, or more objects are placedinto n boxes, then at least one box will contain two or more objects.

Proof. If not, then maximum number of objects is

n︷ ︸︸ ︷1 + 1 + · · ·+ 1 < n + 1,

a contradiction.

Note: we don’t know which box contains more than 2 elements, only thatone exists. (Non-constructive existence proof.)

Also called Dirichlet drawer principle or Shoebox principle.

Ex. Among any group of 367 people, there are at least two with the samebirthday.

Ex. At any given time, there are at least two people in California who wereborn on the same second of the year.

There are (365)(24)(60)(60) = 31,536,000 seconds and at least 36,000,000people in California.

Ex. At any given time, there are at least two people in London that have theexact same number of hairs on their heads.

Roughly 125,000 hairs on average head, so in no case more than 1,000,000hairs. London has more than 1,000,000 people.

Ex. You need only select n + 1 people out a set of n married couples toguarantee a married couple has been selected.

• There exists no injection ϕ : A → B on finite sets such that thecodomain is smaller than the domain.• If |A| = |B| and ϕ is injective, then ϕ is surjective, i.e., “If n objects

are put into n boxes and no box gets more than one object, then eachbox has an object in it.”• If |A| = |B| and ϕ is surjective, then ϕ is injective, i.e., “If n objects

are put into n boxes and no box is empty, then each box has an objectin it.”

1Updated: May 26, 2009.

1

Page 2: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. Does there exist a perfect cover of a chessboard pruned by cutting outtwo diagonally opposite corners?

Solution. There are a total of 62 squares, w.l.o.g., 32 black and 30 white.Let A be the black and B be the white squares. Each domino covers both ablack and white square. The dominoes induce a 1-1 correspondence betweenwhite and black squares. But Pigeonhole forbids an injection ϕ : A→ B.

Ex. During a 30-day month, a baseball team plays at least 1 game a day, butno more than 45 games. Prove that there exists a succession of consecutivedays during which the team will have played exactly 14 games.

Proof. Let aj = # games played on or prior to jth day. a1, a2, . . . , a30is an increasing sequence of distinct positive integers and 1 6 aj 6 45 for1 6 j 6 30. Also,

a1 + 14, a2 + 14, . . . , a30 + 14

is an increasing sequence of distinct positive integers, where 15 6 aj+14 6 59.The elements of the 60-set

{a1, . . . , a30, a1 + 14, . . . , a30 + 14}are all less than or equal to 59. By Pigeonhole Principle, ∃ i, j with 1 6 i, j 630 such that ai = aj + 14, i.e., exact 14 games where played from day j + 1to day i.

Ex. Prove that among any n + 1 positive integers not exceeding 2n, theremust be an integer that divides one of the others.

Proof. Let {a1, a2, . . . , an+1} ⊆ Z, where 1 6 ai 6 2n for 1 6 i 6 n + 1.Factor out as many 2’s as possible, i.e., aj = 2kjqj, where kj ∈ Z+ and qj isodd. Clearly, {q1, . . . , qn+1} are odd positive integers and qj < 2n. As thereare only n odd positive integers less than 2n, by the Pigeonhole Principle,qi = qj = q for some i, j, so that ai = 2kiq and aj = 2kjq. If ki < kj ⇒ ai | aj

and if kj < ki, then aj | ai.

(Note: this is optimal in the sense that having chosen only 10 integers notexceeding 2·10 = 20, e.g., {11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, then no integerdivides one of the others. With 11 integers, we are guaranteed one that dividesthe other.)

2

Page 3: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. The Chinese Remainder Theorem (simple): if m and n are rela-tively prime positive integers, then ∃ x ∈ Z+ such that x ≡ a (mod m) andx ≡ b (mod n). (In fact, x is unique modulo mn.)

E.g., If m = 4, n = 9, then gcd(4, 9) = 1. Pick a = 3 and b = 2, then an xthat satisfies x ≡ 3 (mod 4) and x ≡ 2 (mod 9) is x = 11.

Proof. Consider S = {a, m + a, 2m + a, . . . , (n − 1)m + a}. If for some0 6 i < j < n, we have

im + a ≡ jm + a ≡ r (mod n)⇔ im + a = qin + r and jm + a = qjn + r,

so that (j − i)m = (qi − qj)n⇒ n | (j − i)m⇒ n | (j − i), as gcd(n, m) = 1.But 0 < j − i 6 n − 1, so n - (j − i), a contradiction, hence all elements inS must have different remainders when divided by n. Hence, by PigeonholePrinciple, each of 0, 1, . . . , n− 1 occurs as a remainder, and so b is a remain-der. Let x = qkm + a be the number that has b as its remainder. Hence,x = pn + b, so that x ≡ a (mod m) and x ≡ b (mod n).

Ex. Let {(xi, yi, zi) : 1 6 i 6 9, and xi, yi, zi ∈ Z} be a set of nine pointsin xyz-space. Prove that the midpoint of at least one pair of points also hasinteger coordinates.

Proof. Let (xi, yi, zi) and (xj, yj, zj) be two points where 1 6 i < j 6 9. Themidpoint has coordinates(

xi + xj

2,yi + yj

2,zi + zj

2

).

These will be integer coordinates if and only if xi, xj have same parity, yi, yj

have same parity, and zi, zj have same parity. There are 23 possible triplesfor parity, e.g. (Even, Odd, Odd) or (Even, Odd, Even), etc. By Pigeonhole,at least two points must have the same parity triple.

Ex. In a room with 10 people, whose ages (in whole numbers) are between 1and 60 inclusive, prove that we can always find two disjoint groups of peoplewhose ages sum to the same number.

Proof. There are 210 − 1 = 1023 ways to select a non-empty subset of 10people. The largest the age sum can be is 10×60 = 600, thus by Pigeonhole,at least two groups must have the same age. If they intersect, remove thecommon people, to get disjoint sets with the same age sum.

3

Page 4: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 9: The Pigeonhole Principle II1

Erik E. Westlund

Pigeonhole Principle (Strong). For some positive integers, q1, q2, . . . , qn,if

q1 + q2 + · · ·+ qn − n + 1

objects are placed into n boxes, then either the first box contains at least q1objects, ...., or the nth box contains at least qn objects.

Proof. If not, then we have no more thann∑

i=1

(qi − 1) = n− 1 objects total, a contradiction.

If qi = 2 for all 1 6 i 6 n, we get the Pigeonhole Principle (Simple).

If qi = r for all 1 6 i 6 n, we get the Generalized Pigeonhole Principle:if n(r − 1) + 1 objects are placed into n boxes, then at least one box willcontain at least r objects.

Alternatively, if D objects are placed into n boxes, then at least one box willcontain at least dD/ne objects.

Proof. If not, then the number of objects is at most

n

(⌈D

n

⌉− 1

)< n

((D

n+ 1

)− 1

)= D

(We can get the Generalized Pigeonhole Principle by setting D = n(r−1)+1.)

Ex. Among 100 people, there are at least d100/12e = 9 that were born onthe same month.

Ex. What is the least number of area-codes needed to guarantee that the 25million phones in a state have distinct numbers (NXX-NXX-XXXX) whereN ∈ {2, . . . , 9}?There are (8)(106) = 8, 000, 000 numbers of the form NXX-XXXX. There-fore, at least d25, 000, 000/8, 000, 000e = 4 of them are identical, so we needat least 4 area codes.

1Updated: May 26, 2009.

1

Page 5: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. Suppose I have 7 blue and 12 black socks in my drawer, it’s completelydark, and I need to pack for a conference. What is the minimum number ofsocks I need to take out the drawer to guarantee I have

(1) at least one matching pair?(2) six socks of one color?(3) six black socks?(4) three matched pairs (possibly including pairs of each color)?

(1) I need to pick at least three.(2) I need to pick D = 2(r − 1) + 1 objects so some box gets at least r = 6,thus D = 2(5) + 1 = 11 socks.(3) Pigeonhole doesn’t apply, so we take worst-case scenario, i.e. all 7 bluesocks are chosen. Thus, we need 13 socks drawn.(4) Three socks gets one matched pair, another three gets another matchedpair. The two leftovers may not be matched, so we need a seventh sock.

Ramsey Theory. In every group of 6 people, there are always at least threepeople who all know each other, or all don’t know each other.

Proof. Let P = A, B, C, D, E, F be the people. Out of {B, C,D, E, F} ei-ther three or more know A or three or more don’t know A. (Putting D = 5objects into n = 2 boxes, at least one box contains d5/2e = 3 objects.) If, sayB, C,D know A and any pair know each other, then we’re done. Otherwise,B, C,D are three non-aquaintances.

If a1, a2, . . . , aN is a sequence of length n, then ai1, ai2, . . . , aik is a subse-quence, provided that 1 6 i1 < i2 < · · · < ik 6 N , and is increasing ifai1 6 ai2 6 · · · 6 aik or decreasing if ai1 > ai2 > · · · > aik.

Ex. Every sequence of n2 + 1 real numbers contains either an increasingsubsequence or a decreasing subsequence of n + 1 numbers.

E.g. 8, 11, 9, 1, 4, 6, 12, 10, 5, 7 is a sequence of 10 = 32 + 1 real numbers. 1,4, 6, 12 is an increasing subsequence, 11, 9, 6, 5 is a decreasing subsequence.

Proof. Let a1, a2, . . . , an2+1 be a sequence and let mk > 1 be the length ofthe longest increasing subsequence that starts with ak:

ak = ai1 6 ai2 6 · · · 6 aimk,

2

Page 6: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

where 1 6 k 6 n2 + 1. If mk > n + 1, for some k, we’re done. Otherwise,suppose that ∀ 1 6 k 6 n2+1, we have 1 6 mk 6 n. By Pigeonhole Principle,at least n + 1 of the numbers m1, m2 . . . , mn2+1 are equal, call them

mk1= mk2

= · · · = mkn+1,

where 1 6 k1 < k2 < · · · < kn+1 6 n2 + 1. If for some 1 6 i 6 n, we haveaki

< aki+1, then mki

> mki+1, a contradiction. Hence, aki

> aki+1, so that

ak1> ak2

> · · · > akn+1

is a decreasing subsequence of length n + 1.

3

Page 7: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 16: The Multinomial Theorem and Newton’sBinomial Theorem1

Erik E. Westlund

Goal: establish a generalization of the Binomial Theorem to multinomials.

Recall: The Binomial Theorem, for n ∈ N,

(x+ y)n =n∑i=0

(n

i

)xiyn−i =

n∑i=0

(n

n− i

)xiyn−i =

n∑i=0

(n

i

)xn−iyi

But, what about expanding (x+ y + z)n? (x1 + x2 + · · ·xk)n?

Revisit permutations of multisets: if S = {n1 · s1, n2 · s2} is a multiset of twodifferent types, then for n = n1 + n2, the # of permutations of S is

n!

n1!n2!=

n!

n1!(n− n1)!=

(n

n1

)=

(n

n2

).

I.e.,(nn1

)is the # of n1-subsets of an n-set, and the # of permutations of S.

If n1, n2, . . . , nk are non-negative integers, and n1 + n2 + · · · + nk = n, thenthe multinomial coefficient is:(

n

n1 n2 · · · nk

)=

n!

n1!n2! · · ·nk!.

E.g., for n, k ∈ N,

(n

k

)=

(n

k n− k

)=

(n− 1

k n− k − 1

)+

(n− 1

k − 1 n− k

).

Therefore, the Binomial Theorem may be rewritten as

(x+ y)n =∑

n1+n2=n

(n

n1 n2

)xn1yn2

Pascal’s Formula for Multinomial Coefficients: ∀ n, k, n1, n2, . . . , nk ∈N, where n1 + · · ·+ nk = n, we have(

n

n1 · · · nk

)=

k∑i=1

(n− 1

n1 · · · ni−1 ni − 1 ni+1 · · · nk

)1Updated: June 9, 2009.

1

Page 8: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Proof.k∑i=1

(n− 1

n1 · · · ni−1 ni − 1 ni+1 · · · nk

)=

k∑i=1

(n− 1)!

n1! · · ·ni−1!(ni − 1)!ni+1! · · ·nk!

=k∑i=1

ni(n− 1)!

n1! · · ·ni! · · ·nk!

=(n− 1)!

n1!n2! · · ·nk!

k∑i=1

ni

=(n− 1)!

n1!n2! · · ·nk!· n

=n!

n1!n2! · · ·nk!

Ex. Expand (x1 + x2 + x3)2 out and combine like terms.

(x1 + x2 + x3)(x1 + x2 + x3) = x21 + x2

2 + x23 + 2x1x2 + 2x1x3 + 2x2x3

The Multinomial Theorem. Let n, k ∈ Z, n, k > 1. The for all x1, x2, . . . , xk,

(x1 + x2 + · · ·+ xk)n =

∑n1+···+nk=n

(n

n1 n2 · · · nk

)xn1

1 xn22 · · ·x

nk

k ,

where ni ∈ N for all 1 6 i 6 k.

Inductive Proof. Too complicated. Double induction on k and n, or induc-tion and use of multi-index notation. For a fixed k, say k = 3, we can userepeated application of The Binomial Theorem. Here’s the idea:

(x1 + x2 + x3)n = ((x1 + x2) + x3)

n =∑

n1+n2=n

(n

n1 n2

)(x1 + x2)

n1xn23

Applying the Binomial Theorem again to (x1 + x2)n1,

(x1 + x2 + x3)n =

∑n1+n2=n

(n

n1 n2

)[ ∑k1+k2=n1

(n1

k1 k2

)xk1

1 xk22

]xn2

3

Pulling everything into the interior sum,∑n1+n2=n

∑k1+k2=n1

(n

n1 n2

)(n1

k1 k2

)xk1

1 xk22 x

n23 =

∑k1+k2+n2=n

(n

k1 k2 n2

)xk1

1 xk22 x

n23

2

Page 9: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Combinatorial Proof. Write (x1 + · · ·+ xk)n as the product of n factors:

(x1 + · · ·+ xk)n = (x1 + · · ·+ xk)(x1 + · · ·+ xk) · · · (x1 + · · ·+ xk)︸ ︷︷ ︸

n termsEvery monomial is formed by selecting one of the xis from each of the nterms. Hence, we form kn monomial terms, and each term can be arrangedin the form xn1

1 xn22 · · ·x

nk

k , where ni ∈ N, and n1 + · · ·+ nk = n. An arbitrarymonomial term is obtained by picking x1 in n1 of the factors, x2 in n2 of then−n1 remaining factors, ..., and xk in nk of the remaining n−n1−· · ·−nk−1 =nk factors. Thus, the # of ways to do this is:(

n

n1

)(n− n1

n2

)· · ·(n− n1 − · · · − nk

nk

)=

n!

n1!n2! · · ·nk!.

Ex. Find the expansion of (x1 + x2 + x3)3 using the Multinomial Theorem.

(x1 + x2 + x3)3 =

∑n1+n2+n3=3

(3

n1 n2 n3

)xn1

1 xn22 x

n33

The total # of terms is 33 = 27. The # of distinct monomials xn11 x

n22 x

n33 is

equivalent to the number of non-negative integral solutions to n1+n2+n3 = 3,for which there are

(3+3−13

)=(53

)= 10.

n1 n2 n3( 3n1 n2 n3

)3 0 0 12 1 0 32 0 1 31 2 0 31 1 1 61 0 2 30 3 0 10 2 1 30 1 2 30 0 3 1

x31 + 3x2

1x2 + 3x21x3 + 3x1x

22 + 6x1x2x3 + 3x1x

23 + x3

2 + 3x22x3 + 3x2x

23 + x3

3.

3

Page 10: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. What is the coefficient of x121 x

22x5x

106 in the expansion of

(x1 + x2 + x3 + x4 + x5 + x6 + x7)25?

Now, x121 x

22x5x

106 = x12

1 x22x

03x

04x

15x

106 x

07, so the coefficient is(

25

12 2 0 0 1 10 0

)=

25!

12!2!1!10!= 4, 461, 857, 400

There are a total of 725 = 1, 341, 068, 619, 663, 964, 900, 807 terms.

Ex. What is the coefficient of x21x

22x

23x5 in the expansion of

(2x1 − 3x2 + 5x3 + x4 − x5)7?

Note:

(2x1−3x2+5x3+x4−x5)7 =

∑(7

n1 n2 n3 n4 n5

)(2x1)

n1(−3x2)n2(5x3)

n3xn44 (−x5)

n5

Hence, the coefficient is:(7

2 2 2 0 1

)· 22 · (−3)2 · 52 · −1 = −567, 000

If r ∈ R, and k ∈ Z, then define(r

k

)=

r(r−1)···(r−k+1)

k! if k > 1

1 if k = 0

0 if k 6 −1

The expression r(r − 1) · · · (r − k + 1) is a falling factorial, denoted (r)k.

Pascal’s formula holds for general(rk

)as well, e.g.,(

5√

2

3

)=

(5√

2)(5√

2− 1)(5√

2− 2)

3!=

(5√

2− 1

2

)+

(5√

2− 1

3

)Right around the time the Black Plague was raging in London, Isaac Newton(1643-1727) generalized the Binomial Theorem as follows:

Generalized Binomial Theorem. If α, x, y ∈ R, where |x| < |y|, then

(x+ y)α =∞∑k=0

k

)xkyα−k

4

Page 11: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Equivalently, if z = x/y, then (x + y)α = yα(z + 1)α, and so for any z ∈ R,with |z| < 1, we have

(1 + z)α =∞∑k=0

k

)zk

Proof Sketch. Form the Taylor series centered at z = 0 for f(z) = (1 + z)α

(as f(z) has derivatives at all orders at z = 0) using∞∑k=0

f (k)(0)

k!zk = 1 + αz +

α(α− 1)

2!z2 +

α(α− 1)(α− 2)

3!z3 + · · ·

Using the Ratio Test, it can be shown f has radius of convergence R = 1, i.e.the Taylor series for f converges to some function on (−1, 1). Use Taylor’sTheorem to show it actually converges to f on this interval. Hence, as |z| < 1,we are inside the radius of convergence, and the result holds.

Ex.√

1.12 = (1 + 0.12)1/2, and as |z| = |0.12| < 1, we have

√1.2 =

∞∑k=0

(0.5

k

)(0.12)k = 1 +

0.12

2− (0.12)2

8+

(0.12)3

16− (0.12)4

128+ · · ·

If α = −n, for some n ∈ Z+, then for all |z| < 1

(1 + z)−n =∞∑k=0

(−nk

)zk

=∞∑k=0

(−n)(−n− 1) · · · (−n− k + 1)

k!zk

=∞∑k=0

(−1)k(n)(n+ 1) · · · (n+ k − 1)

k!zk

=∞∑k=0

(−1)k(n+ k − 1

k

)zk =

1

(1 + z)n

A few useful corollaries, for |z| < 1

• (1− z)−n =1

(1− z)n=

∞∑k=0

(n+ k − 1

k

)zk

1Updated: June 9, 2009.

5

Page 12: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

• 1

1 + z=

∞∑k=0

(−1)kzk = 1− z + z2 − z3 + z4 − · · ·

• 1

1− z=

∞∑k=0

zk = 1 + z + z2 + z3 + z4 + · · ·

The last two are infinite geometric series, and recall for a, r 6= 0, and |r| < 1,we have ∞∑

i=0

ari = a+ ar + ar2 + ar3 + · · · = a

1− r.

6

Page 13: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 17: The Principle of Inclusion-Exclusion1

Erik E. Westlund

How many elements are in A ∪B? If A ∩B = ∅, then |A ∪B| = |A|+ |B|.What if A ∩B 6= ∅?Clearly, |A|+ |B| will count the elements in A ∩B two times, hence,

|A ∪B| = |A|+ |B| − |A ∩B|

Ex. A discrete mathematics class consists of 25 math majors, 13 c.s. majors,and 8 joint math/c.s. majors. If every student in the class is either a mathmajor, c.s. major, or joint major, how many students are in the class?

Let A := { math majors} and B := { c.s. majors}. We seek |A ∪B|.|A ∪B| = |A|+ |B| − |A ∩B| = 25 + 13− 8 = 30.

Ex. How many positive integers not exceeding 1000 are divisible by 7 or 11?

Let A := {x ∈ Z+ : x 6 1000, 7 | x} and B := {x ∈ Z+ : x 6 1000, 11 | x}.We seek |A∪B|. Now, |A| =

⌊10007

⌋= 142, |B| =

⌊100011

⌋= 90, and if 7 | x and

11 | x, then lcm(7, 11) | x⇒ 77 | x, i.e. |A ∩B| =⌊1000

77

⌋= 12. Therefore,

|A ∪B| = 142 + 90− 12 = 220.

Ex. Suppose there are 1,807 freshmen at your school. Of these, 453 aretaking a course in C.S., 567 are taking a course in Math, and 299 are takingcourses in both C.S. and Math. How many freshmen are not taking a coursein either Math or C.S.?

Let A := { freshmen in a Math course}, B := { freshmen in a C.S. course},so that |A| = 567, |B| = 453, and |A∩B| = 299. We seek |A∩B| = |A ∪B|,the number of freshmen neither in A nor B. By Subtraction Principle,

|A∩B| = |S|−|A∪B| = |S|−|A|−|B|+|A∩B| = 1807−567−453+299 = 1086

If A1 and A2 are subsets of objects of S having properties P1 and P2, re-spectively, then A1 ∪A2 is the subset of objects having both properties, andA1 ∩ A2 is the subset of objects having neither property.

|A1 ∪ A2| = |A1 ∩ A2| = |S| − |A1| − |A2|+ |A1 ∩ A2|

1Updated: June 9, 2009.

1

Page 14: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

What about A1 ∪ A2 ∪ A3? What about A1 ∪ A2 ∪ · · · ∪ Ak?

The sum |A1|+ |A2|+ |A3| counts objects

• in exactly one of the three sets once,• in exactly two of the three sets twice,• in all three sets three times.

The sum |A1|+ |A2|+ |A3| − |A1 ∩A2| − |A1 ∩A3| − |A2 ∩A3| counts objects

• in exactly one of the three sets once,• in exactly two of the three sets once,• in all three sets zero times.

Finally, we add back in the elements in all three sets.

|A1∪A2∪A3| = |A1|+|A2|+|A3|−|A1∩A2|−|A1∩A3|−|A2∩A3|+|A1∩A2∩A3|.

Ex. 1232 students have taken a course in Spanish (S), 879 have taken a coursein French (F), and 114 have taken a course in Russian (R). Further, 103 havetaken S and F, 23 have taken S and R, and 14 have taken F and R. If 2092students have taken at least one course in S, F, or R, how many studentshave taken a course in all three?

Note, |S| = 1232, |F | = 879, and |R| = 114, and |S ∩F | = 103, |S ∩R| = 23,and |F ∩R| = 14. Also, |S ∪ F ∪R| = 2092, so

2092 = 1232 + 879 + 114− 103− 23− 14 + |S ∩ F ∩R| ⇒ |S ∩ F ∩R| = 7.

Ex. Find the number of integers between 1 and 10,000 that are neither perfectsquares nor perfect cubes.

Let A1 = {x ∈ Z : 1 6 x 6 10000, x = y2 ∃ y ∈ Z}, the set of perfect squares.

Let A2 = {x ∈ Z : 1 6 x 6 10000, x = y3 ∃ y ∈ Z}, the set of perfect cubes.

As√

10000 = 100, the squares of the numbers {1, 2, . . . , 100} are less than10,000, so |A1| = 100. Likewise, as 213 = 9261, and 223 = 10, 648, the cubesof the numbers {1, 2, . . . , 21} are all less than 10,000, so |A2| = 21. Now, ifx ∈ A1 ∩ A2, then x = y2 = z3, for some y, z ∈ Z, and so x = t6, and so xis a perfect 6th power. As 46 = 4096, and 56 = 15, 625, the 6th powers of thenumbers {1, 2, 3, 4} are all less than 10,000, i.e., |A1 ∩ A2| = 4. Hence, thereare 10000− 100− 21 + 4 = 9883 integers of the required form.

2

Page 15: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

The Principle of Inclusion-Exclusion. Let A1, A2, . . . , Am be finite sets.Then,

|A1 ∪ A2 ∪ · · · ∪ Am| =∑

16i6m

|Ai| −∑

16i<j6m

|Ai ∩ Aj|+∑

16i<j<k6m

|Ai ∩ Aj ∩ Ak|

− · · ·+ (−1)m+1|A1 ∩ A2 ∩ · · · ∩ Am|

Proof. Let a ∈ A1∪A2∪· · ·∪Am and suppose that a is a member of exactlyr of the sets Ai, where 1 6 r 6 m. Now, in evaluating the summations onthe RHS, we see a is counted

(r1

)times in

∑16i6m |Ai|, a is counted

(r2

)times

in∑

16i<j6m |Ai ∩ Aj|, a is counted(

r3

)times in

∑16i<j<k6m |Ai ∩ Aj ∩ Ak|,

and in general, for 1 6 t 6 r, a is counted(rt

)times in the sum involving the

summations of intersections of t of the sets Ai. Therefore, the element a iscounted exactly (

r

1

)−(

r

2

)+

(r

3

)− · · ·+ (−1)r+1

(r

r

)times by the RHS. But, we have(

r

0

)−(

r

1

)+

(r

2

)− · · ·+ (−1)r

(r

r

)= 0,

so

1 =

(r

0

)=

(r

1

)−(

r

2

)+ · · · − (−1)r

(r

r

).

Hence, a is counted exactly once by the RHS.

Ex. Give a formula for the number of elements in the union of four sets.

|A1 ∪ A2 ∪ A3 ∪ A4| = |A1|+ |A2|+ |A3|+ |A4|−|A1 ∩ A2| − |A1 ∩ A3| − |A1 ∩ A4|−|A2 ∩ A3| − |A2 ∩ A4| − |A3 ∩ A4|+|A1 ∩ A2 ∩ A3|+ |A1 ∩ A2 ∩ A4|+|A1 ∩ A3 ∩ A4|+ |A2 ∩ A3 ∩ A4|−|A1 ∩ A2 ∩ A3 ∩ A4|

Furthermore, if there is a universal set S, then

|A1 ∩ A2 ∩ · · · ∩ Am| = |A1 ∪ A2 ∪ · · · ∪ Am| = |S| − |A1 ∪ A2 ∪ · · · ∪ Am|.

3

Page 16: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. How many of the permutations of the 26 letters of the English alphabetdo not contain any of the strings FISH, RAT, or BIRD?

Let

S = { permutations of the alphabet }A1 = { permutations that contain FISH }A2 = { permutations that contain RAT }A3 = { permutations that contain BIRD }

We seek |A1 ∩A2 ∩A3|. Clearly, |S| = 26!. Elements in A1 are permutationsof the symbol FISH, and the 22 other letters, i.e., |A1| = 23!. Similarly,|A2| = 24!, and |A3| = 23!. Elements in A1 ∩ A2 are permutations of thesymbols, FISH, RAT , and the 19 other letters, i.e. |A1 ∩ A2| = 21!. Next,|A1 ∩ A3| = |A2 ∩ A3| = 0, for FISH and BIRD share an I, and RAT andBIRD share an R. For the same reason, |A1 ∩A2 ∩A3| = 0. Hence, there are

26!−(23!+24!+23!)+(21!+0+0)−0 = 402, 619, 359, 782, 336, 797, 900, 800, 000

permutations.

4

Page 17: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 18: Applications of the Principle ofInclusion-Exclusion1

Erik E. Westlund

Goal: present and discuss some interesting applications of The Principle ofInclusion-Exclusion.

Application 1: The Euler-Phi Function

The following function ϕ(n) is ubiquitous to number theory and algebra:

ϕ : N→ N defined by ϕ(n) = |{m ∈ N : m 6 n and gcd(n, m) = 1}|(The number of positive integers less than n that are relatively prime to n.)

Let n = pa11 pa2

2 · · · pak

k be the prime factorization of a positive integer n. For1 6 i 6 k, let Ai := {m ∈ N : m 6 n and pi | m}. Clearly, x ∈ A1 ∪ A2 ∪· · · ∪ Ak ⇔ gcd(n, x) 6= 1. Thus,

ϕ(n) = |A1 ∩ A2 ∩ · · · ∩ Ak|.

|Ai| =

⌊n

pi

⌋=

n

pi

|Ai ∩ Aj| =

⌊n

pipj

⌋=

n

pipj

|Ai ∩ Aj ∩ A`| =

⌊n

pipjp`

⌋=

n

pipjp`

......

|A1 ∩ A2 ∩ · · · ∩ Ak| =

⌊n

p1p2 · · · pk

⌋=

n

p1p2 · · · pk

Hence,∣∣∣∣∣k⋂

i=1

Ai

∣∣∣∣∣ = n−k∑

i=1

n

pi+

∑16i<j6k

n

pipj−∑

16i<j<`6k

n

pipjp`+ · · ·+ (−1)k n

p1p2 · · · pk

= n

1−k∑

i=1

1

pi+

∑16i<j6k

1

pipj−∑

16i<j<`6k

1

pipjp`+ · · ·+ (−1)k 1

p1p2 · · · pk

= n

k∏i=1

(1− 1

pi

)1Updated: June 14, 2009.

1

Page 18: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

The last equality follows from the fact that for all xi ∈ R, we have

n∏i=1

(1− xi) = 1−n∑

i=1

xi +∑

16i<j6n

xixj −∑

16i<j<k6n

xixjxk + · · ·+ (−1)nx1x2 · · ·xn.

(You can quickly prove this using induction!)

Application 2: Counting Prime Numbers

Count the number of primes between 1 and a fixed positive integer n.

Note: if m is composite, then m = ab with 1 < a 6 b ⇒ a2 6 m ⇒ a 6√m ⇒ there exists a prime p | m and p 6

√m. Hence, every composite

integer m 6 n has a prime factor p 6√

m 6√

n, so excluding these numberswill remove all composite numbers from {1, 2, . . . , n}.Ex. Let n = 120, then every composite integer 1 < m 6 120 has a primefactor p 6

√120 ≈ 10.95, i.e. p ∈ {p1 = 2, p2 = 3, p3 = 5, p4 = 7}. Let

Ai = {x ∈ Z : x 6 n and pi | x}. Hence,

|A1 ∩ A2 ∩ A3 ∩ A4| = 120− (60 + 40 + 24 + 17) + (20 + 12 + 8 + 8 + 5 + 3)

−(4 + 2 + 1 + 1) + 0 = 27

However, we haven’t counted the primes, 2, 3, 5, and 7 and we have countedthe nonprime 1. So, the number is 27− 1 + 4 = 30.

Application 3: The Number of Surjective Functions

We know that for X and Y , where |X| = m and |Y | = n.

1. The number of functions f : X → Y is nm.2. The number of injective functions f : X → Y is{

0 if m > n

n(n− 1) · · · (n−m + 1) if m 6 n

3. The number of bijective functions f : X → Y is{0 if m 6= n

n! if m = n

Question: What is the number of surjective functions f : X → Y ?

2

Page 19: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Let Y = {y1, y2, . . . , yn}, and let Ai be the set of all functions f : X → Y suchthat yi is not in the range of f . Any function g /∈

⋃ni=1 Ai is surjective, and

vice versa. Now |Ai| = (n−1)m, |Ai∩Aj| = (n−2)m, |Ai∩Aj∩Ak| = (n−3)m.In general, for 1 6 t 6 n

|Ai1 ∩ Ai2 ∩ · · · ∩ Ait| = (n− t)m,

hence∣∣∣∣∣n⋂

i=1

Ai

∣∣∣∣∣ = nm −(

n

1

)(n− 1)m +

(n

2

)(n− 2)m − · · ·+ (−1)n−1

(n

n− 1

)1m

The number of surjective functions f : X → Y is0 if m < n

nm +n−1∑i=1

(−1)i

(n

i

)(n− i)m if m > n

Application 4: Combinations with Repetition

Let S = {n1 · s1, n2·, . . . , nk · sk} be a multiset with k different types.

The # of r-combinations of S =

(

n

r

)if ni = 1 for all 1 6 i 6 k(

r + k − 1

r

)if ni > r for all 1 6 i 6 k

What if 1 < ni < r? I.e., what are the # of r-combinations for generalrepetition numbers?

Ex. Determine the number of 12-combinations of the multiset

S = {4 · s1, 3 · s2, 4 · s3, 5 · s4}.

Consider the multiset S∗ = {12 · s1, 12 · s2, 12 · s3, 12 · s4}. For 1 6 i 6 4, letAi be subsets of 12-combinations of S∗ where elements in A1 have more than4 s1’s, elements in A2 have more than 3 s2’s, elements in A3 have more than4 s3’s, and elements in A4 have more than 5 s4’s. We seek

|A1 ∩ A2 ∩ A3 ∩ A4| = |T | − |A1 ∪ A2 ∪ A3 ∪ A4|,where T is the set of all

(12+4−112

)= 455 12-combinations of S∗. Note |A1| is the

number of 12-combinations that have at least 5 s1’s, so |A1| =(7+4−1

7

)= 120.

Similarly,

|A2| =(8+4−1

8

)= 165, |A3| =

(7+4−17

)= 120, and |A4| =

(6+4−16

)= 84.

3

Page 20: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Now, |A1 ∩ A2| is the number of 12-combinations of S∗ that have at least 5s1’s and at least 4 s2’s, i.e. we can complete this 12-combination in exactly(3+4−1

3

)= 20 ways. Similarly,

|A1∩A3| =(2+4−1

2

)= 10, |A1∩A4| =

(1+4−11

)= 4, and |A2∩A3| =

(3+4−13

)= 20,

and

|A2 ∩ A4| =(2+4−1

2

)= 10, and |A3 ∩ A4| =

(1+4−11

)= 4.

Furthermore, A1 ∩A2 ∩A3 is the set of 12-combinations that have at least 5s1’s, at least 4 s2’s, and at least 5 s3’s, a contradiction, thus |A1∩A2∩A3| = 0.Similarly, |A1 ∩ A2 ∩ A4| = 0, |A1 ∩ A3 ∩ A4| = 0, and |A2 ∩ A3 ∩ A4| = 0.Finally, |A1 ∩ A2 ∩ A3 ∩ A4| = 0. Hence,

455−(120+165+120+84)+(20+10+4+20+10+4)−(0+0+0+0)+0 = 34

Using the above technique, we may now determine the number of integralsolutions to

x1 + x2 + · · ·+ xk = r,

where for all 1 6 i 6 k, we have 0 6 xi 6 ni for non-negative integers ni.

Ex. Find the number of integral solutions to

x1 + x2 + x3 = 17

that satisfy −2 6 x1 6 5, 0 6 x2 6 4, and 5 6 x3 6 11.

By letting y1 = x1 + 2, y2 = x2, and y3 = x3 − 5, this is the same as thenumber of integral solutions to

y1 + y2 + y3 = 17 + 2− 5 = 14

that satisfy 0 6 y1 6 7, 0 6 y2 6 4, and 0 6 y3 6 6. Let S be the set of allnon-negative solutions to the above, so

|S| =(

14 + 3− 1

14

)=

(16

2

)= 120.

Let A1 = { non-negative solutions to y1 + y2 + y3 = 14 where y1 > 8}.Let A2 = { non-negative solutions to y1 + y2 + y3 = 14 where y2 > 5}.Let A3 = { non-negative solutions to y1 + y2 + y3 = 14 where y3 > 7}.Note, |A1| is the number of non-negative solutions to

z1 + z2 + z3 = 14− 8 = 6,4

Page 21: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

by letting z1 = y1 − 8, z2 = y2, and z3 = y3. Hence,

|A1| =(

6 + 3− 1

6

)=

(8

2

)= 28.

Similarly,

|A2| =(

9 + 3− 1

9

)=

(11

2

)= 55 and |A3| =

(7 + 3− 1

7

)=

(9

2

)= 36.

Now, |A1 ∩ A2| is the number of non-negative solutions to

u1 + u2 + u3 = 14− 8− 5 = 1

by letting u1 = y1 − 8, u2 = y2 − 5, and u3 = y3. Hence,

|A1 ∩ A2| =(

1 + 3− 1

1

)= 3.

Similarly,

|A1 ∩ A3| = 0 and |A2 ∩ A3| =(

2 + 3− 1

2

)= 6

Finally, |A1 ∩ A2 ∩ A3| = 0, so by the Principle of Inclusion-Exclusion, wehave the number of integral solutions to our original linear equation is

|A1 ∩ A2 ∩ A3| = 120− (28 + 55 + 36) + (3 + 0 + 6)− 0 = 10.

5

Page 22: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 19: Derangements1

Erik E. Westlund

Goal: discuss permutations that have no fixed points.

Suppose a lazy professor gives his 44 students a quiz, collects them, mixesthem up, and then randomly passes the quizzes back out to be graded bythe students. What is the probability that no student grades their own quiz?(D44/44!)

In rencontres, an old French card game, the 52 cards of a deck are laid out,and the cards of a second deck are laid out with one on top of each of theprevious deck. The score is determined by the number of matched cards onefrom each deck. What is the probability of getting a score of zero? (D52/52!)

How many anagrams of a word leave no letters fixed?

Problems of this kind deal with permutations that are completely out of order.

A derangement of {1, 2, . . . , n} is a permutation i1i2 · · · in such that ij 6= jfor all 1 6 j 6 n. More generally, a derangement of a set S is a bijectionϕ : S → S such that ϕ(x) 6= x for all x ∈ S.

Ex. The permutation 21453 is a derangement of {1, 2, 3, 4, 5}, but 21354 isnot, because 3 is in its “natural position.”

Ex. List all derangements of ABCD.

BADC, BCDA, BDAC, CADB, CDAB, CDBA, DABC, DCAB, DCBA.

Let Dn be the number of derangements of {1, 2, . . . , n}. Dn is also called thenth subfactorial, denoted !n.

Theorem. For n > 1,

Dn = n!

(1− 1

1!+

1

2!− 1

3!+ · · ·+ (−1)n 1

n!

)Proof. Let X be the set of all n! permutations of {1, 2, . . . , n}. For all1 6 j 6 n, let Aj := {σ = i1i2 · · · in ∈ X : ij = j}. Then

Dn = |A1 ∩ A2 ∩ · · · ∩ An|.

1Updated: June 17, 2009.

1

Page 23: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

It is easily seen that, for all 1 6 k 6 n,

|At1 ∩ At2 ∩ · · · ∩ Atk| = (n− k)!,

where {t1, t2, · · · , tk} is any k-subset of {1, 2, . . . , n}. By the Principle ofInclusion-Exclusion, we have

Dn = n!−(n

1

)(n− 1)! +

(n

2

)(n− 2)!− · · ·+ (−1)n

(n

n

)0!

Dn = n!− n!

1!+n!

2!− · · ·+ (−1)nn!

n!

Ex. The number of derangements of ABCD is

D4 = 4!

(1− 1

1!+

1

2!− 1

3!+

1

4!

)= 24 · 3

8= 9.

Ex. Determine the number of permutations of {1, 2, . . . , 8} in which exactlyfour integers are in their natural positions.

This is the # of permutations in which exactly four integers are not in theirnatural positions. There are

(84

)ways to pick the integers, and D4 ways to

derange them, so(84

)D4 = 630 permutations.

From calculus, we have

e−1 = 1− 1

1!+

1

2!− 1

3!+

1

4!− · · ·

Recall the Lagrange Error Bound: if f and all of its derivatives are con-tinuous, and Pn(x) is the nth Taylor polynomial of f about x = a, then

|f(x)− Pn(x)| 6 max |f (n+1)(z)|(n+ 1)!

|x− a|n+1, where z is in between x and a.

Note: if Pn(x) is the nth MacLaurin polynomial of f(x) = ex, then Dn =n!Pn(−1), and

|ex − Pn(x)| 6 1

(n+ 1)!|x|n+1 ⇒

∣∣∣∣e−1 − Dn

n!

∣∣∣∣ 61

(n+ 1)!

Note: e−1 = 0.367879441171442 . . . and Dn is the closest integer to n!e−1.2

Page 24: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

n Dn |e−1 −Dn/n!| 1/(n+ 1)!1 0 0.36787 0.52 1 0.13212 0.166673 2 0.03454 0.041664 9 0.00712 0.008335 44 0.00121 0.001386 265 0.00017 0.00019

So, for n > 6, e−1 and Dn/n! agree to at least three decimal places.

Therefore, if |E| = Dn, then

Prob(E) =Dn

n!≈ e−1, for n > 6.

Ex. A new employee checks the hats of n people at a restaurant, forgettingto put claim check numbers on the hats. What is the probability that uponleaving, no customer receives the correct hat?

Using the aforementioned, formula, we see that the probability is Dn/n! ≈0.36, and this probability is essentially the same for 10 customers as it is for1 billion customers!

Theorem. The derangement numbers satisfy the linear recurrence relation:

Dn = (n− 1)(Dn−2 +Dn−1) for n > 3.

Let X be the set of derangements of {1, . . . , n}, and let σ = σ1σ2 · · · σn ∈ X.Let dni

= # of derangements where σ1 = i. Clearly, σi = σj for all 1 6 i, j 6n, and let dn be the common value. Hence, Dn = (n− 1)dn. Partition the dn

derangements σ = 2σ2σ3 · · ·σn according to whether σ2 = 1 or σ2 6= 1. I.e.,let

A = {2σ2σ3 · · ·σn : σj 6= j, σ2 = 1} and B = {2σ2σ3 · · ·σn : σj 6= j, σ2 6= 1}

Thus, dn = |A|+|B|, and clearly, |A| is the # of derangements of {3, 4, . . . , n},and |B| is the # of derangements of {1, 3, 4, . . . , n}. Thus, Dn = (n−1)(|A|+|B|) = (n− 1)(Dn−2 +Dn−1).

3

Page 25: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Dn − nDn−1 = (−1)[Dn−1 − (n− 1)Dn−2]

= (−1)2[Dn−2 − (n− 2)Dn−3]

= (−1)3[Dn−3 − (n− 3)Dn−4]

= · · ·= (−1)n−2[D2 − 2D1] = (−1)n−2 = (−1)n

Hence, Dn = nDn−1 + (−1)n for all n > 2.

Ex. Prove that Dn is even if and only if n is odd.

Proof. If Dn is even, then Dn ± 1 = nDn−1 is odd, hence n is odd. If n isodd, then Dn−1 is odd, for otherwise, n − 1 is odd, a contradiction. Hence,nDn−1 = Dn + (−1)n is odd, so that Dn is even.

4

Page 26: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 21: Ordinary Generating Functions I1

Erik E. Westlund

Goal: discuss the importance and basic operations of generating functions,and how they are applied to counting problems.

Analogy: A generating function for a sequence can be thought of as a

“clothesline for displaying a sequence”.

We want a way to concisely represent sequences and manipulate them.

The formal power series of a sequence {an}∞n=0 is

A(x) =∞∑

n=0

anxn = a0 + a1x + a2x

2 + a3x3 + · · ·+ anx

n + · · ·

The coefficients of A(x) are the terms in the sequence (an), and A(x) is calledthe ordinary generating function, or GF, of (an).

Generating functions transform problems about sequences to problems aboutalgebraic functions.

Comments:

• Unlike calculus, we usually don’t care about issues of convergence!• A(x) is not a function of x in the natural sense of domain and codomain.• A(x) may be regarded as a purely algebraic object that can be manip-

ulated as such.• A(x) may be expressed in closed form as a function of a formal argument

x, using the notion of a function and its power series expansion.• xn is essentially a placeholder for an.• GF’s for finite sequences, i.e., sequences with only finitely many nonzero

terms, (an) = 〈a0, a1, . . . , an, 0, 0, . . .〉, as just polynomials.

Ex. The GF’s for the sequences (an), with an = 4, an = n + 1, and an = 2n,are

∑∞n=0 4xn,

∑∞n=0(n + 1)xn, and

∑∞n=0 2nxn, respectively.

Ex. The GF of (an) = 〈1, 1, 1, 1, . . . , 1, . . .〉, is

A(x) = 1 + x + x2 + x3 + · · ·+ xn + · · · = 1

1− xif |x| < 1.

1Updated: June 21, 2009.

1

Page 27: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. The GF of (an) = 〈1, a, a2, a3, . . . , an, . . .〉 is

A(x) = 1+ax+a2x2+· · ·+anxn+· · · = 1+(ax)+(ax)2+· · ·+(ax)n+· · · = 1

1− ax

if |ax| < 1⇒ |x| < 1/|a|.

Properties: If A(x) =∑∞

n=0 anxn and B(x) =

∑∞n=0 bnx

n, are GF’s for (an)and (bn), respectively, then

• A(x)+B(x) =∞∑

n=0

(an + bn)xn = (a0 + b0)+(a1 + b2)x+(a2 + b2)x2 + · · ·

is the GF for

(an + bn) = 〈a0 + b0, a1 + b1, a2 + b2, . . . , an + bn, . . .〉• xkA(x) =

∑∞n=0 anx

n+k = a0xk +a1x

k+1 +a2xk+2 + · · · , called the right

translation, is the GF for

〈0, 0, . . . , 0︸ ︷︷ ︸k

, a0, a1, . . . , an, . . .〉

• cA(x) =∑∞

n=0 canxn = ca0+ca1x+ca2x

2+· · · , is the GF for the scaledsequence,

(can) = 〈ca0, ca1, . . . , can, . . .〉

• A′(x) =d

dx[A(x)] =

∞∑n=1

nanxn−1 = a1 + 2a2x + 3a3x

2 + 4a4x3 + · · · ,

called the formal derivative, is the GF for

〈a1, 2a2, 3a3, . . . nan︸︷︷︸n−1st term

, . . .〉

• A(x)B(x) =∞∑

n=0

(n∑

k=0

akbn−k

)xn, called the discrete convolution.

Ex. Find the sequence whose GF is C(x) =1

(1− x)2 .

C(x) =1

1− x· 1

1− x=

( ∞∑n=0

xn

)( ∞∑n=0

xn

)=

∞∑n=0

(n∑

k=0

1 · 1

)xn =

n∑n=0

(n+1)xn

Hence, (cn) = 〈1, 2, 3, 4, . . .〉, the natural number sequence starting at 1, isthe corresponding sequence.

2

Page 28: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Alternatively, we could use differentiation:

1

(1− x)2 =d

dx

[1

1− x

]=

∞∑n=1

nxn−1

Ex. The GF for (ak) =⟨(

n0

),(n1

),(n2

), . . . ,

(nk

), . . .

⟩, for n, k ∈ Z+ is:

A(x) =∞∑

k=0

(n

k

)xk =

(n

0

)+

(n

1

)x +

(n

2

)x2 + · · · =

n∑k=0

(n

k

)xk = (1 + x)n

Notation: If A(x) is the GF for the sequence (an) = 〈a0, a1, a2, . . . , an, . . .〉,we will write:

A(x)↔ 〈a0, a1, a2, . . . , an, . . .〉.

Ex. Find the GF for the sequence of perfect squares (an) = 〈0, 1, 4, 9, . . . , n2, . . .〉.Consider:

A(x) =∞∑

n=0

xn =1

1− x↔ 〈1, 1, 1, . . . , 1, . . . , 〉

A′(x) =∞∑

n=1

nxn−1 =1

(1− x)2 ↔ 〈1, 2, 3, . . . , n + 1, . . . , 〉

xA′(x) =∞∑

n=0

nxn =x

(1− x)2 ↔ 〈0, 1, 2, 3, . . . , n, . . .〉

d

dx[xA′(x)] =

∞∑n=1

n2xn−1 =1 + x

(1− x)3 ↔ 〈1, 4, 9, . . . , (n + 1)2, . . .〉

xd

dx[xA′(x)] =

∞∑n=0

n2xn =x(1 + x)

(1− x)3 ↔ 〈0, 1, 4, 9, . . . , n2, . . .〉

3

Page 29: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

MA3210 Lecture 22: Ordinary Generating Functions II1

Erik E. Westlund

Ex. Find the GF for (fn), the Fibonacci number sequence.

We need to find F (x) = f0 + f1x + f2x2 + · · · + fnx

n + · · · , a GF for thesequence (fn) = 0, 1, f1 + f0, f2 + f1, f3 + f2, . . .

0, 1, 0, 0, 0, . . . ↔ x0, f0, f1, f2, f3, . . . ↔ xF (x)

+ 0, 0, f0, f1, f2, . . . ↔ x2F (x)0, 1 + f0, f1 + f0, f2 + f1, f3 + f2, . . . ↔ x+ xF (x) + x2F (x)

Hence,

F (x) = x+xF (x)+x2F (x)⇒ F (x) =x

1− x− x2 = x+x2+2x3+3x4+5x5+· · ·

I.e., the coefficients in the power series expansion of F (x) are exactly theFibonacci numbers!

Question: How can we use generating functions to count?

Given a set A, let A(x) = a0 + a1x + a2x2 + · · · , where the coefficient of xn

is the # of ways to select n objects from A. More generally, given a taskthat depends on a parameter n, let the coefficient of xn be the # of ways toperform the task for n.

Convolution Rule: Let A(x) be the GF for selecting objects from a set A,and let B(x) be the GF for selecting objects from a set B. If A∩B = ∅, thenthe GF for selecting objects from A ∪B is A(x)B(x).

Note: to count the # of ways to select n objects from A∪B, we can select kobjects from A and n− k objects from B, where 0 6 k 6 n. As A ∩ B = ∅,the total is

a0bn + a1bn−1 + a2bn−2 + · · ·+ anb0

This is the coefficient of xn in A(x)B(x).

1Updated: June 22, 2009. Selected examples from Course Notes written by Prof. Albert R. Meyer and Prof. RonittRubinfeld, MIT 2005.

1

Page 30: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Ex. Find the generating function for the sequence (an), where an is thenumber ways to choose n objects from a multiset with k types, each availablein unlimited supply.

Let S = {∞ · s1,∞ · s2, . . . ,∞ · sk}. The GF for selecting the s1’s is:

1

1− x= 1 + x+ x2 + x3 + · · ·+,

for there is one way to select zero s1’s, one way to select 1 s1, one way toselect two s1’s, etc, and we may replace s1 with any of the si’s and get thesame GF. Hence, the GF for selecting objects from S is:

1

(1− x)k=

(1

1− x

)(1

1− x

)· · ·(

1

1− x

)=

( ∞∑n=0

xn

)( ∞∑n=0

xn

)· · ·

( ∞∑n=0

xn

)

=∞∑

n=0

( ∑n1+···+nk=n

1k

)xn =

∞∑n=0

(n+ k − 1

n

)xn

The coefficient of xn is the number of nonnegative integral solutions to x1 +x2 + · · ·+ xk = n. We could also derive the GF by using Newton’s BinomialTheorem.

Ex. Find the number of integral solutions of

y1 + y2 + y3 = 17

satisfying 2 6 y1 6 5, 3 6 y2 6 6, and 4 6 y3 6 7.

Let S = {∞ · s1,∞ · s2,∞ · s3} and let yi be the # of si’s we pick. TheGF for selecting the s1’s is S1(x) = x2 + x3 + x4 + x5, because there is zeroways to pick y1 s1’s for 0 6 y1 6 1, and 6 6 y2, and one way to pick y1 s1’sfor each 2 6 y1 6 5. Similarly, the GFs for picking the s2’s and s3’s are,S2(x) = x3 + x4 + x5 + x6, and S3(x) = x4 + x5 + x6 + x7. Hence, the numberof ways to pick 17 objects from S, subject to the constraints, is the coefficentof x17 in the expansion of

S(x) = S1(x)S2(x)S3(x) = (x2+x3+x4+x5)(x3+x4+x5+x6)(x4+x5+x6+x7)

S(x) = x9 + 3x10 + 6x11 + 10x12 + 12x13 + 12x14 + 10x15 + 6x16 + 3x17 + x18,2

Page 31: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

so there are 3 solutions. Furthermore, the coefficient of xn in S(x) is exactlythe # of integer solutions to y1 + y2 + y3 = n that satisfy the constraints.

Ex. Determine the generating function for the number of bags of fruit thatcontain an even number of apples, at most four oranges, at most one pear,and the number of bananas is a multiple of 5, and no other fruits.

We use the Convolution Rule. The GF for selecting apples is

A(x) = 1 + x2 + x4 + x6 + · · · = 1

1− x2

The GF for selecting oranges is

O(x) = 1 + x+ x2 + x3 + x5 =1− x5

1− xThe GF for selecting pears is

P (x) = 1 + x

The GF for selecting bananas is

B(x) = 1 + x5 + x10 + x15 + · · · = 1

1− x5

Hence, the GF for selecting objects among the four fruits, subject to theconstraints is:

G(x) = A(x)O(x)P (x)B(x) =

(1

1− x2

)(1− x5

1− x

)(1+x)

(1

1− x5

)=

1

(1− x)2 .

I.e., G(x) = 1 + 2x + 3x2 + 4x3 + · · · . Hence, there are hn = n + 1 bags ofn fruits that meet the requirements. (Note: the above counting problem wasanswered purely through algebraic manipulation!)

Ex. In how many ways can you make change for a dollar, using pennies,nickels, dimes, and quarters?

This is equivalent to the number of non-negative integral solutions to

x1 + 5x2 + 10x3 + 25x4 = 100

If P (x), N(x), D(x), and Q(x) denote the generating functions to choosingpennies, nickels, dimes, and quarters, then

P (x) = 1 + x+ x2 + · · · = 1

1− x3

Page 32: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

N(x) = 1 + x5 + x10 + · · · = 1

1− x5

N(x) = 1 + x10 + x20 + · · · = 1

1− x10

N(x) = 1 + x25 + x50 + · · · = 1

1− x25

So, the # of solutions to the problem is the coefficient of x100 in

G(x) =1

1− x· 1

1− x5 ·1

1− x10 ·1

1− x25

Using Mathematica, we see G(x) = 1 + x+ x2 + x3 + x4 + 2x5 + 2x6 + 2x7 +2x8 +2x9 +4x10 +4x11 +4x12 +4x13 +4x14 +6x15 +6x16 +6x17 +6x18 +6x19 +9x20 + 9x21 + 9x22 + 9x23 + 9x24 + 13x25 + 13x26 + 13x27 + 13x28 + 13x29 +18x30 +18x31 +18x32 +18x33 +18x34 +24x35 +24x36 +24x37 +24x38 +24x39 +31x40 +31x41 +31x42 +31x43 +31x44 +39x45 +39x46 +39x47 +39x48 +39x49 +49x50 +49x51 +49x52 +49x53 +49x54 +60x55 +60x56 +60x57 +60x58 +60x59 +73x60 +73x61 +73x62 +73x63 +73x64 +87x65 +87x66 +87x67 +87x68 +87x69 +103x70 + 103x71 + 103x72 + 103x73 + 103x74 + 121x75 + 121x76 + 121x77 +121x78 + 121x79 + 141x80 + 141x81 + 141x82 + 141x83 + 141x84 + 163x85 +163x86 + 163x87 + 163x88 + 163x89 + 187x90 + 187x91 + 187x92 + 187x93 +187x94 + 213x95 + 213x96 + 213x97 + 213x98 + 213x99 + 242x100 + · · · .Again, G(x) answers more than we asked for. The coefficient of xn in G(x) isthe # of ways to make n cents out of pennies, nickels, dimes, and quarters.

Theorem. Let A(x) = 11−x , be the generating function for the geometric

sequence. Then

A(xe1)A(xe2) · · ·A(xer) =∞∑

n=0

Tnxn

is the generating function where Tn is the # of non-negative integral solutionsto e1x1 + e2x2 + · · ·+ erxr = n.

Note: there is no closed, short formula in general.

4

Page 33: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

We can use generating functions to solve linear recurrence relations.

A sequence (an) is said to have a linear recurrence relation of order k if

an = β1an−1 + β2an−2 + · · ·+ βkan−k + γn,

where n > k, βk 6= 0, and each of the βi and γn may depend on n.

Solving a linear recurrence relation means finding a closed-form expressionfor an, i.e., a formula that may depend on n, but not on an−i for any i < n.

Ex. Solve the recurrence relation an = 3an−1, for n > 1, where a0 = 2.

Let A(x) =∑∞

n=0 anxn be the GF for (an). Note that

xA(x) =∞∑

n=0

anxn+1 =

∞∑n=1

an−1xn

So,

A(x)− 3xA(x) =∞∑

n=0

anxn − 3

∞∑n=1

an−1xn = a0 +

∞∑n=1

(an − 3an−1)xn = 2.

Thus, (1 − 3x)A(x) = 2 ⇒ A(x) =2

1− 3x⇒ A(x) =

∞∑n=0

(2 · 3n)xn, so that

an = 2 · 3n for n > 0.

Ex. Derive a closed-form for the nth Fibonacci number fn, where n > 1.

Recall F (x) =x

1− x− x2 is the GF for (fn). Using Partial Fraction Decom-

position, we have

F (x) =x

1− x− x2 =A

1− ϕx+

B

1− ϕx,

where ϕ = 1+√

52 and ϕ = 1−

√5

2 . It’s easy to find that

A =1

ϕ− ϕ=

1√5

and B =−1

ϕ− ϕ= − 1√

5.

Hence,

F (x) =1√5

(1

1− ϕx− 1

1− ϕx

),

F (x) =1√5

(1 + ϕx+ (ϕx)2 + · · · )− (1 + ϕx+ (ϕx)2 + · · · )5

Page 34: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Hence,

F (x) =1√5

((ϕ− ϕ)x+ (ϕ2 − ϕ2)x2 + · · ·+ (ϕn − ϕn)xn + · · · ),

i.e.,

fn =ϕn − ϕn

√5

=1√5

((1 +√

5

2

)n

(1−√

5

2

)n).

Ex. Find a recurrence relation for Cn, then number of ways to evaluate amatrix product A1, A2, . . . , An+1, for n > 0, by adding various parenthesesand determine a closed formula for Cn.

E.g. C0 = C1 = 1, C2 = 2, they are: A1(A2A3), (A1A2)A3. C3 = 5, they are:

((A1A2)A3)A4, (A1(A2A3))A4, (A1A2)(A3A4), A1((A2A3)A4), A1(A2(A3A4))

In evaluating Cn+1, the matrix product A1A2 · · ·An+2 ends with the finaloperator between Ak+1 and Ak+2, for some 0 6 k 6 n.

(A1 · · ·Ak+1︸ ︷︷ ︸Ck

)(Ak+2 · · ·An+2︸ ︷︷ ︸Cn−k

)

Thus,

Cn+1 =n∑

k=0

CkCn−k, for n > 1.

Let C(x) =∞∑

n=0

Cnxn be the GF of (Cn). Now

C(x)2 =

( ∞∑n=0

Cnxn

)( ∞∑n=0

Cnxn

)=

∞∑n=0

(n∑

k=0

CkCn−k

)xn =

∞∑n=0

Cn+1xn

So, xC(x)2 =∞∑

n=1

Cnxn and C(x) = 1 +

∞∑n=1

Cnxn and so

xC(x)2 = C(x)− 1⇒ xC(x)2 − C(x) + 1 = 0

So

C(x) =1−√

1− 4x

2xNow, by Newton’s Binomial Theorem,

(1− 4x)1/2 =∞∑

n=0

(1/2

n

)(−4x)n = · · · = 1− 2

∞∑n=0

(2n)!

n!(n+ 1)!xn+1

6

Page 35: MA3210 Lecture 8: The Pigeonhole Principle IMA3210 Lecture 8: The Pigeonhole Principle I1 Erik E. Westlund The Pigeonhole Principle (simple): If n+1, or more objects are placed into

Hence,

C(x) =∞∑

n=0

(2n)!

n!(n+ 1)!xn =

∞∑n=0

1

n+ 1

(2n

n

)xn

Therefore, the sequence (Cn) is given by Cn = 1n+1

(2nn

), for n > 0. This

is called the Catalan sequence, and is an important counting sequence incombinatorics.

7