The Inclusion-Exclusion Principle
Consider a two finite sets $A$ and $B$. Suppose that we want to determine the number of elements in $A \cup B$. If $A$ and $B$ are disjoint sets then we know by The Addition and Subtraction Principles that $\lvert A \cup B \rvert = \lvert A \rvert + \lvert B \rvert$, so what do we do if $A$ and $B$ are not disjoint?
To explain this, consider the following venn-diagram representing the sets $A$ and $B$. If we count the number of elements in set $A$ which is $\lvert A \rvert$ and then add it to the number of elements in set $B$ which is $\lvert B \rvert$ then the sum $\lvert A \rvert + \lvert B \rvert$ over counts the total number of elements in $A \cup B$. In fact, as we can see in the diagram below, the number of elements in $A \cap B$ is counted twice:
It's not hard to therefore see that thus the total number of elements in $A \cup B$ is given by the formula:
(1)Note that the addition principle is simply a case of the formula above. If $A$ and $B$ are disjoint sets then $A \cap B = \emptyset$ and $\lvert A \cap B \rvert = \lvert \emptyset \rvert = 0$.
Now consider three finite sets and suppose once again we want to determine the number of elements in $A \cup B \cup C$. Once again, the sum $\lvert A \rvert + \lvert B \rvert + \lvert C \rvert$ over counts the total number of elements in this set. If we subtract the number of elements in the intersections between every set, i.e, subtraction $\lvert A \cap B \rvert$, $\lvert A \cap C$, and $\lvert B \cap C$ then we will need to add back the number of elements in $A \cap B \cap C$ as shown in the following venn diagram.
Therefore the total number of elements in $A \cup B \cup$ is given by:
(2)If we now consider four finite sets $A_1, A_2, A_3, A_4$ and we want to determine the number of elements in $A_1 \cup A_2 \cup A_3 \cup A_4$, then it's not hard to see by drawing a venn diagram that:
(3)The inclusion-exclusion principle given in the theorem below generalizes the pattern we have seen above for the number of elements in the union of a finite collection $A_1$, $A_2$, …, $A_n$ of finite sets.
Theorem 1 (The Inclusion-Exclusion Principle): Let $A_1, A_2, ..., A_n$ all be finite sets. Then $\displaystyle{\biggr \lvert \bigcup_{i=1}^{n} A_i \biggr \rvert = \sum_{i=1}^{n} \lvert A_i \rvert - \sum_{1 \leq p_1 < p_2 \leq n} \lvert A_{p_1} \cap A_{p_2} \rvert + \sum_{1 \leq p_1 < p_2 < p_3 \leq n} \lvert A_{p_1} \cap A_{p_2} \cap A_{p_3} \rvert - ... + (-1)^{n+1} \sum_{1 \leq p_1 < p_2 < ... < p_n \leq n} \lvert A_{p_1} \cap A_{p_2} \cap ... \cap A_{p_n} \rvert}$. |
A more compact way to write the formula above is by noting that the inner sum below for $j$ ranging from $1$ to $k$ is over all of the subsets $A_{i_1}, A_{i_2}, ..., A_{i_k}$ where $i_k \in \{ 1, 2, ..., n \}$ so that:
(4)