MAS334 Combinatorics

5. The inclusion-exclusion principle

Problem 5.1.

Consider a sports club in which people can play tennis or squash. Some members play both sports, some play only one, and some just drink at the bar. Suppose that 10 members play tennis (and maybe squash as well), 12 members play squash (and maybe tennis as well), and 3 members play both sports. How many members play at least one sport?

Solution.

Let Mt be the set of members who play tennis, and let Ms be the set of members who play squash. We are given that |Mt|=10 and |Ms|=12 and |MsMt|=3, and we need to find |MsMt|. For this, we need to fill in the numbers in the following Venn diagram:

Region 2 is MtMs, which has 3 elements, so we write 3 there. Regions 1 and 2 together make up Mt, which has 10 elements, so we need 10-3=7 elements in region 1 to make the total correct. Regions 2 and 3 together make up Ms, which has 12 elements, so we need 12-3=9 elements in region 3 to make the total correct. Now MtMs consists of regions 1, 2 and 3, so it has 7+3+9=19 elements in total. In other words, there are 19 members who play at least one sport.

Another way to describe the solution is as follows: we could just take |Mt|+|Ms|, but that would count the people who play both sports twice, once as members of Mt, and once more as members of Ms. To compensate for this, we need to subtract the number of people who play both sports, which is |MtMs|. This gives

|MtMs|=|Mt|+|Ms|-|MtMs|=10+12-3=19

as before.

Problem 5.2.

Now suppose instead that we have a club that offers tennis (t), squash (s) and badminton (b). We are given the following data:

10 members play t 5 members play t and s
15 members play s 4 members play t and b
12 members play b 3 members play s and b
2 members play t, s and b There are 40 members altogether.

How many members play no sport at all?

Solution.

This time we will give a more algebraic explanation. We write M for the set of all members, and m=|M|. We write Mt for the set of members who play t, and mt=|Mt| for the number of players who play t, and similarly for Ms, Mtb and so on. The initial data is then as follows:

mt =10 mts =5
ms =15 mtb =4
mb =12 msb =3
mtsb =2 m =40.

Now let Mt* be the set of members who play t and nothing else, and let Mts* be the set of members who play t and s and nothing else, and so on. To complete the pattern, we put Mtsb*=Mtsb, and we write M* for the set of members who play no sport at all, so our problem is to find |M*|. The people who play t can be divided into four groups:

  • Those that play t and nothing else

  • Those that play t and s but not b

  • Those that play t and b but not s

  • Those that play t and s and b.

From this we get Ms=Ms*Mts*Mtb*Mtsb*, and these sets do not overlap, so we get ms=ms*+mts*+mtb*+mtsb*. By a similar analysis, we get the following equations:

mtsb* =mtsb=2
mts*+mtsb* =mts=5
mtb*+mtsb* =mtb=4
msb*+mtsb* =msb=3
mt*+mst*+mtb*+mtsb* =mt=10
ms*+mst*+msb*+mtsb* =ms=15
mb*+mtb*+msb*+mtsb* =mb=12
m*+mt*+ms*+mb*+mts*+mtb*+msb*+mtsb* =m=40.

These equations are easily solved to give

mtsb* =mtsb=2
mts* =mts-mtsb=5-2=3
mtb* =mtb-mtsb=4-2=2
msb* =msb-mtsb=3-2=1
mt* =mt-mts-mtb+mtsb=10-5-4+2=3
ms* =ms-mts-msb+mtsb=15-5-3+2=9
mb* =mb-mtb-msb+mtsb=12-4-3+2=7
m* =m-mt-ms-mb+mts+mtb+msb-mtsb=40-10-15-12+5+4+3-2=13.

In particular, we have m*=13, so there are 13 members who play no sport; this answers the original question.

We now want to discuss the Inclusion-Exclusion Principle (IEP), which generalises the last two problems. Suppose we have a finite set B, together with a family of subsets BaB for each a in some set A of labels. (For example, in Problem 5.2 we have a set B=M, together with subsets Ms, Mt and Mb, indexed by the set A={s,t,b} of available sports.) We put

B ={bB|b lies in at least one of the sets Ba}
B* =BB={bB|b lies in none of the sets Ba}.

In the common case where A={1,,n}, this can be written as

B =B1B2Bn
B* =B(B1B2Bn).

The IEP tells us about |B| and |B*|. To formulate it, we use the following notation. Given a subset IA, we put BI=iIBi. This means that

B{i} =Bi
B{i,j} =BiBj
B{i,j,k} =BiBjBk

and so on. For the case I=, we interpret this as B=B. We will often abbreviate the notation, by writing Bijk for B{i,j,k} and so on.

Theorem 5.3.

For B and Bi as above, we have

|B*| =IA(-1)|I||BI|
|B| =I(-1)|I|+1|BI|.

In the case where A={1,,n}, this can be written as

|B*| =|B|-|B1|--|Bn|+|B12|++|Bn-1,n|-±|B12n|
|B| =|B1|++|Bn|-|B12|--|Bn-1,n|+|B12n|

There is a single video covering the statement and proof of the IEP, together with two lemmas required for the proof:

.

The equation for |B*| is called the negative form of the IEP, and the equation for |B| is called the positive form. Because B*=BB we have |B*|=|B|-|B|, which makes it easy to see that the two forms are equivalent. For n=2 and n=3 the equations are as follows:

|B1B2| =|B1|+|B2|-|B12|
|B(B1B2)| =|B|-|B1|-|B2|+|B12|
|B1B2B3| =|B1|+|B2|+|B3|-|B12|-|B13|-|B23|+|B123|
|B(B1B2)| =|B|-|B1|-|B2|-|B3|+|B12|+|B13|+|B23|-|B123|.

Problem 5.1 is just an example of the positive IEP with n=2. Problem 5.2 is an example of the negative IEP with n=3.

We will prove the IEP after some preliminary discussion.

Lemma 5.4.

Let I be a finite set, and consider the sum s=JI(-1)|J|. Then s=1 if I is empty, and s=0 if I is not empty.

Proof.

If I is empty, then the only term in the sum is for J=, and that term is (-1)0=1, so s=1. Suppose instead that I, and put n=|I|>0. Then there are (nk) possible choices of J with |J|=k, and this gives s=k(nk)(-1)k. This is just the binomial expansion of (1-1)n=0n=0, so s=0. Alternatively, we can choose an element aI, and put I=I{a}. For every JI we have a term (-1)|J| in s for J=J, and another term (-1)1+|J| for J=J{a}, and these terms cancel out. All the terms cancel in pairs in this way, so we are left with s=0. ∎

Definition 5.5.

In the context of the IEP, for an element bB, we put

Ab={aA|bBa}A.

For example, consider a member x of the club in Problem 5.2. Then Ax is just the set of sports that x plays. For example, if x plays tennis and badminton but not squash, then Ax={t,b}.

  • Consider the set I={t,s,b} and the corresponding set MI=Mtsb=MtMsMb. Member x does not lie in this set MI, because x does not play s. Here IAx={t,b}.

  • Consider instead the set I={t,s} and the corresponding set MI=Mts=MtMs. Member x does not lie in this set MI, because x does not play s. Here IAx={t,b}.

  • Now consider the set I={t,b} and the corresponding set MI=Mtb=MtMb. Member x does lie in this set MI, because x does not play both t and b. Here IAx={t,b}.

  • Similarly, if I={b} then x does lie in the set MI=Mb, and again IAx.

  • For an arbitrary subset IA={t,s,b} we find that xMI iff x plays all the sports in I iff IKx.

We record the obvious generalisation as a lemma:

Lemma 5.6.

Suppose we have a family of subsets (Ba)aA as before, and an element bB, and a subset IA. Then bBI iff IAb.

Proof.

By definition BI=iIBi, so bBI iff bBi for all iI. However, we have bBi iff iAb, by the definition of Ab. Thus, we can say that bBI iff for all iI, we have iAb. This is clearly equivalent to the condition IAb. ∎

Lemma 5.7.

Ab is empty iff bB*.

Proof.

We have iAb iff bBi. Thus Ab is empty iff the condition bBi is false for all i, which means that b lies in none of the sets Bi, which means that bB*. ∎

Proof of Theorem 5.3.

Put u=IA(-1)|I||BI|. We need to prove that this is the same as |B*|. We have |BI|=bBI1, so we can rewrite the definition of u as

u=IAbBI(-1)|I|.

Lemma 5.6 tells us that bBI iff IAb, so we can regroup this sum as

u=bBIAb(-1)|I|.

Now Lemma 5.4 tells us that IAb(-1)|I| is zero if Ab, but is 1 if Ab=. Using Lemma 5.7, we therefore see that IAb(-1)|I| is zero if bB*, but is 1 if bB*. We now have

u=bB*1=|B*|,

as required. This proves the negative form of the IEP. For the positive form, we note that

|B|=|B|-|B*|=|B|-IA(-1)|I||BI|.

The term for I= in the sum cancels out the extra term of |B| outside the sum. We can also bring the minus sign inside the sum to get

|B|=I(-1)|I|+1|BI|.

Definition 5.8.

Let Sn be the set of all permutations of the set N={1,,n}, so |Sn|=n!. A derangement of {1,,n} is a permutation σSn with the property that for all i we have σ(i)i. We write Dn for the set of derangements, so DnSn. We also write pn=|Dn|/|Sn| (which is the probability that a randomly chosen permutation is a derangement).

Example 5.9.

This picture lists all 24 possible permutations of the set N={1,2,3,4}. For example, the top right box contains 1432, which refers to the permutation sending 1, 2 3 and 4 to 1, 4, 3 and 2 respectively. (In disjoint cycle notation, this would be (2  4).) The numbers 1 and 3 are sent to themselves, so they are underlined. As some numbers are sent to themselves, this is not a derangement. However, in the bottom right box we have the permutation 4321. This does not send anything to itself, so no numbers are underlined, and we have a derangement. All the derangements are circled; there are 9 of them. Thus, the fraction of derangements is p4=9/24=3/8=0.375.

Example 5.10.

Suppose that n people arrive at a party, each wearing a hat. At the end of the party, no one can remember which hat they brought, so they pick one up at random. This means that guest i picks up the hat belonging to guest σ(i), for some randomly chosen permutation σ. This permutation is a derangement iff no one gets the right hat. Thus, the probability that no one gets the right hat is pn. How does this change as n increases? For any given guest, there are more hats to choose from, so the probability of getting the right hat goes down. On the other hand, as there are more guests, there are more chances for at least one guest to get the right hat. It is not obvious how these competing effects balance out, but the answer is given by our next result.

Proposition 5.11.

pn=k=0n(-1)k/k!, and this converges to e-10.368 as n.

Proof.

Put

N ={1,,n}
P =Sn={ all permutations of N}
Pi ={σP|σ(i)=i}={ permutations that fix i}.

Note that a permutation is a derangement iff it lies in none of the sets Pi, so Dn=P* in the usual notation of the IEP. We therefore have

|Dn| =|P*|=IN(-1)|I||PI|
pn =n!-1|Dn|=IN(-1)|I||PI|/n!.

Here PI is the set of permutations σ that fix all the elements of I, but are free to permute the remaining elements of NI in any way. If |I|=k we have |NI|=n-k so there are (n-k)! possible permutations of NI. This means that |PI|=(n-k)!. On the other hand, there are (nk) possible choices of I with |I|=k. Putting this together, we get

pn=k=0n(nk)(-1)k(n-k)!n!.

However, we also have

(nk)(n-k)!n!=n!k!(n-k)!(n-k)!n!=1k!,

so our previous expression simplifies to pn=k=0n(-1)k/k! as claimed. As n tends to infinity, this converges to k=0(-1)k/k!, which is e-1 by the standard Taylor series for ex. ∎

Problem 5.12.

Of the numbers 0,1,,41, how many are coprime with 42?

Solution.

Put D={0,,41}, and let U be the subset of numbers that are coprime with 42. We need to find |U|. Put P={2,3,7}, which is the set of primes that divide 42. For any pP, put

Dp={iD|i is divisible by p}.

In the standard notation for the IEP, we have U=D*, and so |U|=IP(-1)|I||DI|. We therefore need to understand |DI|. Let qI be the product of the primes in I (to be interpreted as qI=1 in the case I=). We note that qI divides 42, and DI is the set of multiples of qI in D, so DI={kqI| 0k<42/qI} and |DI|=42/qI. We now have

|U|=42IP(-1)IqI=42(1-12-13-17+12×3+12×7+13×7-12×3×7).

It is not hard to see that this factors as

|U|=42(1-12)(1-13)(1-17)=12.

Alternatively, we could say that the proportion of coprime numbers is |U|/|D|=(1-12)(1-13)(1-17)=2/7.

The following more general statement can be proved in the same way:

Proposition 5.13.

Consider an integer m>1, and let P be the set of primes that divide m. Put D={0,1,,m-1}, and let x be the proportion of numbers in D that are coprime with m. Then

x=pP(1-p-1).