116. The Principle of Inclusion and Exclusion
116.1 Theorem
Let $A$ and $B$ be finite sets. Then
$$|A\cup B| =|A| +|B| - |A\cap B| \tag{116.1}$$
Proof This follows from the fact that the expression $|A| +|B|$ counts the elements which are in both sets twice, so to get the correct count for $|A\cup B|$, you have to subtract $|A\cap B|$.
116.1.1 Remark More generally, if $C$ and $D$ are also finite sets, then
$$|A\cup B \cup C| =|A| +|B| +|C| - |A\cap B| - |A\cap C| - |B \cap C| +|A\cap B \cap C| \tag{116.2}$$
and
$$\begin{aligned} |A\cup B \cup C\cup D| ={}& |A| +|B| +|C| +|D| \\ & -|A\cap B| - |A\cap C| - |A\cap D| \\ & -|B \cap C| - |B \cap D| - |C\cap D| \\ & +|A\cap B \cap C| +|A\cap B \cap D| \\ & +|A\cap C \cap D| +|B \cap C \cap D| \\ & -|A\cap B \cap C\cap D| \end{aligned} \tag{116.3}$$
116.1.2 The general principle Equations (116.1)–(116.3) are special cases of a general principle which requires some notation to state properly. Let $\mathcal{F}$ be a family of $n$ distinct finite sets. For each $k = 1, 2,\ldots ,n$, let $\mathcal{F}_{k}$ be the set of $k$-element subsets of $\mathcal{F}$. For example, if $\mathcal{F} =\{A,B,C,D\}$, then
$$\mathcal{F}_{3} =\{\{A,B,C\},\{A,B,D\},\{A,C,D\},\{B,C,D\}\}$$
Then we have:
116.2 Theorem: The Principle of Inclusion and Exclusion
Using the notation of Section 116.1.2,
$$\begin{aligned} |\cup \mathcal{F}| ={}& \sum_{X\in \mathcal{F}} |X| - \sum_{G\in \mathcal{F}_{2}} |\cap G| + \sum_{G\in \mathcal{F}_{3}} |\cap G| - \ldots \\ & -(- 1)^{k} \sum_{G\in \mathcal{F}_{k}} |\cap G| +\cdots - (- 1)^{n}|\cap \mathcal{F}| \end{aligned} \tag{116.4}$$
116.2.1 Remarks
a) The first sum is over the elements of $\mathcal{F}$ (which are themselves sets), whereas the others are over intersections of subfamilies $G$ of $\mathcal{F}$, with a plus sign for subfamilies with an odd number of elements and a minus sign for those with an even number of elements.
b) You should check that Equations (116.1)–(116.3) are special cases of this Principle.
c) The Principle of Inclusion and Exclusion will not be proved here, but you should be able to see with no trouble why it is true for families of three or four sets.
116.2.2 Example The Principle of Inclusion and Exclusion is stated as an equation, so you can solve for one of its terms if you know all the others.
For example, suppose there was a party with 9 people, including 5 Norwegians. There was only one man at the party who was neither a vegetarian nor a Norwegian. All the vegetarians were Norwegians and two of the women were Norwegians. Exactly one woman was a vegetarian. How many women were at the party?
To solve this, let $W$ be the set of women, $N$ the set of Norwegians, and $V$ the set of vegetarians. The party had 9 people, and only one was not in $W \cup$ $N \cup V$, so $|W \cup N \cup V|= 8$. We are given that $|N|= 5$. Since 2 of the women were Norwegians, $|W \cap N|= 2$, and since one woman was a vegetarian and every vegetarian was a Norwegian, we know $|W \cap V| =|W \cap N \cap V|= 1$ and also $|V|=$ $|N \cap V|$.
Thus in the sum
$$\begin{aligned} |W \cup N \cup V| ={}& |W| +|N| +|V | - \\ & |W \cap N| - |W \cap V| - |N \cap V | +|W \cap N \cap V| \end{aligned}$$
we have
$$8 =|W| + 5 +|V| - 2- |W \cap V | - |N \cap V| +|W \cap N \cap V|$$
or since $|V| =|N \cap V|$,
$$8 =|W| + 5- 2 =|W|+ 3$$
so that there were 5 women at the party.
116.2.3 Exercise You have a collection of American pennies. Three of them are zinc pennies and eight of them were minted before 1932. What do you have to know to determine the total number of pennies? Explain your answer! (Answer on page 249.)
116.2.4 Exercise $A, B$ and $C$ are finite sets with the following properties: $A\cup$ $B\cup C$ has 10 elements; $B$ has twice as many elements as $A$; $C$ has 5 elements; $B$ and $C$ are disjoint; and there is just one element in $A$ that is also in $B$. Show that $A$ has at least 2 elements.
116.2.5 Exercise Suppose that $A, B$ and $C$ are finite sets with the following properties:
(i) $B$ has one more element than $A$.
(ii) $C$ has one more element than $B$.
(iii) $A\cap B$ is twice as big as $A\cap C$.
(iv) $B$ and $C$ have no elements in common.
Prove that $|A\cup B \cup C|$ is divisible by 3.
116.2.6 Exercise Cornwall Computernut has 5 computers with hard disk drives and one without. Of these, several have speech synthesizers, including the one without hard disk. Several have Pascal, including all those with synthesizers. Exactly 3 of the computers with hard disk have Pascal. How many have Pascal?
Pages 178–180 of the book (PDF).