the principle of inclusion and exclusionlyuu/dm/2014/20140501.pdfthe principle of inclusion and...
TRANSCRIPT
The Principle of Inclusion and Exclusion
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 385
If I am I because you are you,
and if you are you because I am I,
then I am not I,
and you are not you.
— Hassidic rabbi
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 386
The Example on P. 26 Revisited
How many ways are there to arrange TALLAHASSEE with
no adjacent As?
• Rearrange the characters as AAAEEHLLSST.
• AAAEEHLLSST has 11 characters, among which there
are 3 As.
• There are11!
3! 2! 1! 2! 2! 1!= 831, 600
ways to arrange the 11 characters by Eq. (2) on p. 16.
• But some of them are invalid.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 387
The Example on P. 26 Revisited (continued)
• First, treat AA as a single, new character.
• The 10-character string (AA)AEEHLLSST can be
arranged in
10!
1! 1! 2! 1! 2! 2! 1!= 453, 600
ways.
• But some arrangements of (AA)AEEHLLSST may
contain 3 consecutive As.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 388
The Example on P. 26 Revisited (concluded)
• To count them, as before, treat AAA as a single, new
character.
• The 9-character string (AAA)EEHLLSST can be
arranged in9!
1! 2! 1! 2! 2! 1!= 45, 360
ways.
• The desired number is hence
831, 600− 453, 600 + 45, 360 = 423, 360,
matching the earlier result.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 389
The Setup
• Let S be a set with |S| = N .
• Let c1, c2, . . . , ct be conditions on the elements of S.
• N(a b c · · · ) denotes the number of elements of S that
satisfy
a ∧ b ∧ c ∧ · · · .
• N(c1 c2 · · · ct) denotes the number of elements of S that
satisfy none of the conditions ci.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 390
The Principle of Inclusion and Exclusion (1854, 1883)a
N(c1 c2 · · · ct) = N −∑
1≤i≤t
N(ci)
+∑
1≤i<j≤t
N(cicj)
−∑
1≤i<j<k≤t
N(cicjck) + · · ·
+(−1)tN(c1c2 · · · ct)
=t∑
k=0
(−1)k∑
1≤i1<i2<···<ik≤t
N(ci1ci2 · · · cik).
aDa Silva and James Joseph Sylvester (1814–1897).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 391
The Proof
• If x ∈ S satisfies none of the conditions ci, then x should
contribute one to N(c1 c2 · · · ct).– Indeed, it is counted once, in N .
• If x ∈ S satisfies 1 ≤ r ≤ t of the conditions ci, then x
should contribute zero to N(c1 c2 · · · ct).– It is counted once in N , r times in
∑1≤i≤t N(ci),
(r2
)times in
∑1≤i<j≤t N(cicj), . . ., and
(rr
)times in
N(ci1ci2 · · · cir ).– By the binomial theorem (p. 53), the total is
1− r +
(r
2
)−(r
3
)+ · · ·+ (−1)r
(r
r
)= (1− 1)r = 0,
as desired.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 392
The Proof (concluded)
• We have exhausted all cases for x.a
aContributed by Mr. Cheng-Chang Liu (B01902009) on April 18, 2013.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 393
Simplification of the Notation
• Define
S0 = N,
S1 = N(c1) +N(c2) + · · ·+N(ct),
S2 = N(c1c2) +N(c1c3) + · · ·+N(ct−1ct),
...
Sk =∑
1≤i1<i2<···<ik≤t
N(ci1ci2 · · · cik).
– Observe that Sk has(tk
)terms.
• The principle of inclusion and exclusion becomes
N(c1 c2 · · · ct) = S0 − S1 + S2 − · · ·+ (−1)tSt. (43)
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 394
A Corollary
• By DeMorgan’s law,
c1 ∨ c2 ∨ · · · ∨ ct = ¬(¬c1 ∧ ¬c2 ∧ · · · ∧ ¬ct).
• Hence the number of elements in S that satisfy at least
one of the conditions ci equals
N(c1 ∨ c2 ∨ · · · ∨ ct) = N −N(c1 c2 · · · ct).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 395
A Corollary (concluded)
• By the inclusion-exclusion principle (43) on p. 394,
N(c1 ∨ c2 ∨ · · · ∨ ct) =∑
1≤i≤t
N(ci)
−∑
1≤i<j≤t
N(cicj)
+∑
1≤i<j<k≤t
N(cicjck)
− · · ·+ (−1)t−1N(c1c2 · · · ct)
= S1 − S2 + · · ·+ (−1)t−1St.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 396
Number of Onto Functions Revisited
• Let A = {a1, a2, . . . , am} and B = {b1, b2, . . . , bn}.
• Let ci be the condition that bi is not in the range of
f : A → B.
• N(c1 c2 · · · cn) is the number of onto f : A → B.
• N(ci1ci2 · · · cik) is the number of
f : A → B − { bi1 , bi2 , . . . , bik }.
• Clearly
N(ci1ci2 · · · cik) = (n− k)m
for distinct i1, i2, . . . , ik.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 397
Number of Onto Functions Revisited (concluded)
• By the principle of inclusion and exclusion,
N(c1 c2 · · · cn) =
n∑k=0
(−1)k∑
1≤i1<i2<···<ik≤n
N(ci1ci2 · · · cik)
=n∑
k=0
(−1)k(n
k
)(n− k)m
= n!S(m,n), (44)
confirming again Eq. (31) on p. 270.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 398
A Useful Combinatorial Identity
Lemma 62 For m ≤ r ≤ n,(n−m
r −m
)=
m∑k=0
(−1)k(m
k
)(n− k
r
).
• In how many ways can we pick r numbers out of
{1, 2, . . . , n} and 1, 2, . . . ,m must be picked?
• The number is clearly (n−m
r −m
).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 399
The Proof (continued)
• Alternatively, let ci denote the condition that i is not
picked, 1 ≤ i ≤ m.
• Clearly, N(c1 c2 · · · cm) is our goal.
• Now,
N(ci) =
(n− 1
r
),
N(cicj) =
(n− 2
r
), i ̸= j,
...
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 400
The Proof (concluded)
• By the inclusion-exclusion principle (43) on p. 394, the
desired number equals
N(c1 c2 · · · cm)
=n∑
k=0
(−1)k∑
1≤i1<i2<···<ik≤m
N(ci1ci2 · · · cik)
=
m∑k=0
(−1)k(m
k
)(n− k
r
).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 401
Euler’s Phi Function
• Let ϕ(n) denote the number of positive integers
m ∈ {1, 2, . . . , n} such that gcd(m,n) = 1, where n ≥ 2.
– ϕ(p) = p− 1 for prime p.
– ϕ(1) = 1 by convention.
• It is a computationally hard problem without the
knowledge of n’s factorization.
– Related to the security of some cryptographical
systems such as RSA.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 402
Euler’s Phi Function: The Formula
Theorem 63 Let n = pe11 pe22 · · · pett be the prime
factorization of n. Then ϕ(n) = n∏t
i=1(1−1pi).
• Let ci be the condition that a number from {1, 2, . . . , n}is divisible by pi.
• The desired number is
ϕ(n) = N(c1 c2 · · · ct).
• For distinct i1, i2, . . . , ik,
N(ci1ci2 · · · cik) =n
pi1pi2 · · · pik.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 403
The Proof (concluded)
• By the principle of inclusion and exclusion,
ϕ(n)
= N(c1 c2 · · · ct)
=
t∑k=0
(−1)k∑
1≤i1<···<ik≤t
n
pi1pi2 · · · pik
= n
t∏i=1
(1− 1
pi
). (45)
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 404
Euler’s Phi Function: An Alternative Proof
• Let n = pe11 pe22 · · · pett be the prime factorization of n.
• Start with {1, 2, . . . , n}.
• The prime p1 will kill off every p1th number from the set.
• The prime p2 will kill off every p2th number from the
remaining set, etc.
• In the end, we end up with a set of size
n
(1− 1
p1
)(1− 1
p2
)· · ·
(1− 1
pt
)= ϕ(n).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 405
An Example
• Suppose n = pe11 pe22 pe33 .
• Then
ϕ(n)
= n
(1− 1
p1
)(1− 1
p2
)(1− 1
p3
)= n
[1−
(1
p1+
1
p2+
1
p3
)+
(1
p1p2+
1
p1p3+
1
p2p3
)− 1
p1p2p3
].
• This may help convince you that Eq. (45) on 404 is
correct.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 406
Application: ϕ(2n)
ϕ(2n)
= 2n∏
p | 2n,p prime
(1− 1
p
)
= 2n(1− 1
2
)= 2n−1.
Indeed, the only numbers in {1, 2, . . . , 2n} relatively prime
with 2 are the 2n/2 = 2n−1 odd numbers.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 407
��� ��� ��� ��� Q
���
���
���
���
���I+Q/
HXOHUSKL�QE �
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 408
Euler’s Phi Function Is Multiplicative
• Let n = m1m2, where gcd(m1,m2) = 1.
• Let m1 = pe11 pe22 · · · pess be the prime factorization of m1.
• Let m2 = pes+1
s+1 pes+2
s+2 · · · pett be the prime factorization of
m2.
• From the formula on p. 403,
ϕ(m1m2) = ϕ(n)
= n
t∏i=1
(1− 1
pi)
= m1
s∏i=1
(1− 1
pi) m2
t∏i=s+1
(1− 1
pi)
= ϕ(m1)ϕ(m2).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 409
A Loose Lower Bound for the Phi Functiona
Theorem 64 (Hardy and Wright (1979))
ϕ(n) > n/(6 ln lnn) for n > 3.
aGodfrey Harold Hardy (1877–1947) and Edward Maitland Wright
(1906–2005).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 410
Godfrey Harold Hardy (1877–1947)
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 411
Permutations without Fixed Points
• Write a permutation f on {1, 2, . . . , n} as 1 2 · · · n
f(1) f(2) · · · f(n)
• There are n! permutations.
• Permutation f has a fixed point at i if f(i) = i.
– i is invariant under f .
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 412
Number of Permutations without Fixed Points
What is the number of permutations without fixed points?
• Let SX be the number of permutations that fix all i ∈ X.
• By the principle of inclusion and exclusion, the desired
number isa ∑X⊆{1,2,...,n}
(−1)|X|SX .
• SX = (n− |X|)! as those numbers not in X form a
permutation.
aLet ci denote the condition that i is a fixed
point. Then the desired number is N(c1 c2 · · · cn) =∑nk=0(−1)k
∑1≤i1<i2<···<ik≤n N(ci1ci2 · · · cik ) =∑n
k=0(−1)k∑
{ i1,i2,...,ik } S{ i1,i2,...,ik } =∑
X⊆{1,2,...,n}(−1)|X|SX .
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 413
The Proof (concluded)
• The desired number is∑X⊆{1,2,...,n}
(−1)|X|(n− |X|)! =
n∑k=0
(−1)k(n
k
)(n− k)!
= n!
n∑k=0
(−1)k
k!(46)
≈ n!
e,
where e = 2.71828 . . . .
• A constant fraction of permutations have no fixed points!
• Or, if one picks a random permutation, with roughly
40% chance, that permutation will have no fixed points!
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 414
Derangements (Also p. 412)
• A derangement is a permutation of 1, 2, . . . , n in which
1 is not in the first place, 2 is not in the second place,
etc.a
• How many derangements of 1, 2, . . . , n are there?
• Let ci denote the condition that i is in the ith place.
• The desired number is N(c1 c2 · · · cn), which equals
dn ≡n∑
i=0
(−1)i(n
i
)(n− i)! = n!
n∑i=0
(−1)i1
i!≈ n!
e(47)
by the principle of inclusion and exclusion (43) on p. 394.
aJust a permutation without no fixed points!
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 415
A Combinatorial Identity for dn
• Let dk denote the number of derangements of 1, 2, . . . , k.
• By convention, d0 = 1.
• Any permutation of 1, 2, . . . , n can have n− k fixed
points for some k, with the rest being deranged.
• There are(
nn−k
)=
(nk
)choices for the fixed points.
• Hence
n! =n∑
k=0
(n
k
)dk. (48)
• Alternatively,
1 =
n∑k=0
dkk! (n− k)!
.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 416
The Proof (concluded)
• With the help of Eq. (47) on p. 415, the following
complex identity is obtained:
n!
=n∑
k=0
(n
k
)k!
k∑i=0
(−1)i1
i!
= n!
n∑k=0
1
(n− k)!
k∑i=0
(−1)i1
i!.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 417
An Example
One can numerically verify identity (48) on p. 416 with the
following data:
d0 = 1, d1 = 0,
d2 = 1, d3 = 2,
d4 = 9, d5 = 44,
d6 = 265,
d7 = 1854,
d8 = 14833,
d9 = 133496,
d10 = 1334961.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 418
A Variation on Derangement
• How many permutations of 1, 2, . . . , n are there such
that i is not in the (i− 1)st place for 2 ≤ i ≤ n?
– For example, 12345 (but not 23451).
• Let ci denote the condition that i is in the (i−1)st place.
• Now N(ci) = (n− 1)!, N(cicj) = (n− 2)! with i ̸= j, etc.
• The desired number N(c2 c3 · · · cn) equals
n!−(n− 1
1
)(n− 1)! +
(n− 1
2
)(n− 2)!− · · ·
by the principle of inclusion and exclusion.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 419
A Variation on Derangement (continued)
n−1∑i=0
(−1)i(n− 1
i
)(n− i)!
=
n−1∑i=0
(−1)i(n− 1)! (n− i)
i!
= n! +
n−1∑i=1
(−1)i(n− 1)! (n− i)
i!
= n! +
n−1∑i=1
(−1)in!
i!−
n−1∑i=1
(−1)i(n− 1)!
(i− 1)!
=
n−1∑i=0
(−1)in!
i!−
n−1∑i=1
(−1)i(n− 1)!
(i− 1)!
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 420
A Variation on Derangement (concluded)
=
n−1∑i=0
(−1)in!
i!+
n−2∑i=0
(−1)i(n− 1)!
i!
=
n−1∑i=0
(−1)in!
i!+
n−2∑i=0
(−1)i(n− 1)!
i!
+
[(−1)n
n!
n!+ (−1)n−1 (n− 1)!
(n− 1)!
]=
n∑i=0
(−1)in!
i!+
n−1∑i=0
(−1)i(n− 1)!
i!
= dn + dn−1 (49)
from Eq. (47) on p. 415.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 421
A Simpler Proof
• Again, how many permutations of 1, 2, . . . , n are there
such that i is not in the (i− 1)st place for 2 ≤ i ≤ n?
• Consider a permutation of 1, 2, . . . , n, where
1. i is not in the (i− 1)st place for 2 ≤ i ≤ n.
2. 1 is not in the nth place.
• There are dn of such permutations as they are but
derangements with the location restrictions shifted.
• The 2nd condition that 1 is not in the nth place is extra.
• So we need to add to dn the number of permutations
that satisfy condition 1 but not condition 2.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 422
A Simpler Proof (concluded)
• So consider permutations of 1, 2, . . . , n such that
1. i is not in the (i− 1)st place for 2 ≤ i ≤ n.
2. 1 is in the nth place.
• Remove 1 and rename i as i− 1 for 2 ≤ i ≤ n.
• The results are permutations of 1, 2, . . . , n− 1 such that
i is not in the ith place for 1 ≤ i ≤ n− 1.
• They are simply derangements of 1, 2, . . . , n− 1.
• Their count is dn−1, as desired.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 423
Another Variation on Derangement
• Let A ⊆ { 1, 2, . . . , n }.
• How many permutations of 1, 2, . . . , n induce a
derangement of A?
– The original derangement has A = { 1, 2, . . . , n }.
• Assume A = { 1, 2, . . . ,m }, where m ≤ n, without loss
of generality.
• Let ci denote the condition that i is in the ith place.
• The desired number is N(c1 c2 · · · cm), which equals
m∑i=0
(−1)i(m
i
)(n− i)!
by the principle of inclusion and exclusion.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 424
Integer Solutions of a Linear Equation with Upper Bounds
Theorem 65 The number of integer solutions of
x1 + x2 + · · ·+ xn = r, where 0 ≤ x1, x2, . . . , xn < b, is
⌊r/b⌋∑m=0
(−1)m(n
m
)(n+ r −mb− 1
r −mb
). (50)
• The number of integer solutions of x1+x2+ · · ·+xn = r,
where 0 ≤ x1, x2, . . . , xn, is N ≡(n+r−1
r
)(recall p. 82).
• Now impose upper bounds
0 ≤ x1, x2, . . . , xn < b.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 425
The Proof (continued)
• Let ci denote the condition that b ≤ xi.
• N(ci): The number of solutions satisfying ci equals(n+ r − b− 1
r − b
)as we are solving x1 + x2 + · · ·+ xn = r − b for
nonnegative integer solutions.
• N(cicj): The number of solutions satisfying ci ∧ cj with
i ̸= j equals (n+ r − 2b− 1
r − 2b
)as we are solving x1 + x2 + · · ·+ xn = r − 2b.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 426
The Proof (continued)
• And so on.
• Of course, there cannot be more than ⌊r/b⌋ conditions
ci.
• Our goal is
N(c1 c2 · · · c⌊r/b⌋).
• Recall the inclusion-exclusion principle (43) on p. 394:a
N(c1 c2 · · · c⌊r/b⌋) =⌊r/b⌋∑m=0
(−1)mSm.
aThe definition of Sm appeared on p. 394.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 427
The Proof (concluded)
• The number of N(ci) terms in S1 is(n1
).
• The number of N(cicj) terms in S2 is(n2
).
• And so on.
• Finally,
N(c1 c2 · · · c⌊r/b⌋) =
⌊r/b⌋∑m=0
(−1)mSm
=
⌊r/b⌋∑m=0
(−1)m(n
m
)(n+ r −mb− 1
r −mb
).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 428
An Example
• What is the number of positive integers x, where
x ≤ 999, whose sum of the digits equals 20?
– E.g., 389 and 776.
• Use xi to denote x’s ith digit.
• Now the problem is equivalent to x1 + x2 + x3 = 20,
where 0 ≤ xi < 10.
• Equation (50) on p. 425 says the answer is(30
)(3+20−1
20
)−
(31
)(3+20−10−1
20−10
)+(32
)(3+20−20−1
20−20
)= 36.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 429
Generalized Principle of Inclusion and Exclusion Em
• Let Em denote the number of elements in S that satisfy
exactly m of the t conditions.
– The principle of inclusion and exclusion corresponds
to E0.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 430
Generalized Principle of Inclusion and Exclusion Em
(concluded)
• Thena
Em = Sm −(m+ 1
1
)Sm+1 +
(m+ 2
2
)Sm+2
− · · ·+ (−1)t−m
(t
t−m
)St
=t∑
k=m
(−1)k−m
(k
k −m
)Sk
=t∑
k=m
(−1)k−m
(k
m
)Sk. (51)
aThe definition of Sk appeared on p. 394.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 431
The Proof
• If x ∈ S satisfies fewer than m conditions, then x should
contribute zero to Em.
– Indeed, it contributes zero to
Sm, Sm+1, . . . , St.
• If x ∈ S satisfies exactly m conditions, then x should
contribute one to Em.
– Indeed, it contributes one to Sm and zero to
Sm+1, Sm+2, . . . , St.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 432
The Proof (continued)
• If x ∈ S satisfies m < r ≤ t of the conditions ci, then x
should contribute zero to Em.
• Indeed, it is counted(rm
)times in Sm,
(r
m+1
)times in
Sm+1, . . .,(rr
)times in Sr, and zero times for all terms
beyond Sr.
• The total count is
r∑k=m
(−1)k−m
(k
m
)(r
k
).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 433
The Proof (concluded)
By Newton’s identity (p. 29),
r∑k=m
(−1)k−m
(k
m
)(r
k
)=
r∑k=m
(−1)k−m
(r
m
)(r −m
k −m
)
=r−m∑k=0
(−1)k(r
m
)(r −m
k
)
=
(r
m
) r−m∑k=0
(−1)k(r −m
k
)=
(r
m
)(1− 1)r−m = 0.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 434
Permutations with m Fixed Points
• Recall from p. 412 that a bijective function f on
{1, 2, . . . , n} has a fixed point at i if f(i) = i.
• What is the number of permutations with m fixed
points?
• Let ci denote the condition that i is a fixed point.
• Then
Sk =
(n
k
)(n− k)! =
n!
k!. (52)
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 435
The Proof (concluded)
• From Eq. (51) on p. 431,
Em =n∑
k=m
(−1)k−m
(k
k −m
)Sk
=n∑
k=m
(−1)k−m
(k
k −m
)n!
k!
=n!
m!
n∑k=m
(−1)k−m 1
(k −m)!.
• For example, En−2 = n(n− 1)/2 (permutations with
n− 2 fixed points).
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 436
Generalized Principle of Inclusion and Exclusion Lm
• Let Lm denote the number of elements in S that satisfy
at least m of the t conditions.
• Then
Lm = Sm −(
m
m− 1
)Sm+1 +
(m+ 1
m− 1
)Sm+2
− · · ·+ (−1)t−m
(t− 1
m− 1
)St
=t∑
k=m
(−1)k−m
(k − 1
m− 1
)Sk. (53)
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 437
The Proof
• By definition,
Lm − Lm+1 = Em
for m < t by definition.
• Now we prove the identity by induction on m.
• First note that Et = Lt = St.
• Inductively, assume that
Lm+1 =
t∑k=m+1
(−1)k−(m+1)
(k − 1
m
)Sk.
• Also Em =∑t
k=m(−1)k−m(km
)Sk from (51) on p. 431.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 438
The Proof (concluded)
• Finally, Lm equals
Lm+1 + Em
=
t∑k=m+1
(−1)k−(m+1)
(k − 1
m
)Sk +
t∑k=m
(−1)k−m
(k
m
)Sk
= Sm +
t∑k=m+1
(−1)k−m
[−
(k − 1
m
)+
(k
m
)]Sk
= Sm +
t∑k=m+1
(−1)k−m
(k − 1
m− 1
)Sk by Lemma 2 on p. 28
=t∑
k=m
(−1)k−m
(k − 1
m− 1
)Sk.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 439
Permutations with Fixed Points
• Consider permutations on {1, 2, . . . , n}.
• Let ci stand for the condition that i is a fixed point.
• From Eq. (53) on p. 437, the number of permutations
with at least one fixed point is
L1 =t∑
k=1
(−1)k−1Sk.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 440
The Proof (concluded)
• Recall that Eq. (52) on p. 435 says
Sk =n!
k!.
• Hencea
L1 =
n∑k=1
(−1)k−1Sk
= n!n∑
k=1
(−1)k−1 1
k!(54)
≈ n!
(1− 1
e
).
aAn alternative proof is via Eq. (46) on p. 414.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 441
Checking for Consistency
• The sum of the number of permutations without fixed
points (E0) and those with fixed points (L1) should be
n!.
• Indeed, from Eq. (46) on p. 414 for E0 and Eq. (54) on
p. 441 for L1,
n!n∑
k=0
(−1)k
k!+ n!
n∑k=1
(−1)k−1
k!= n!.
• Note that E0 is dn, the number of derangements.
c⃝2014 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 442