Read · 2 min
The Principle of Inclusion-Exclusion (PIE) is a theorem that allows one to calculate the number of elements in a union of multiple finite sets.
First, consider two sets, and . PIE states that: where denotes the cardinality of a set (the cardinality of a set is the number of elements in the set).
Why does this work? Well, the union of and can be thought of in terms of different regions: the elements in and not in , the elements in and not in , and the elements in both and . (These regions can be seen very clearly in a Venn diagram.)
As an example, take the elements in both and . When one adds and , these elements are counted twice; however, when is subtracted, these elements are removed once, so they are counted a total of once, as desired. Similarly, one can check that the elements in the other two regions are also counted exactly once each.
Now, consider three sets: , , and . PIE states that:
Consider the region containing elements in all sets. The first three terms count these elements times; the second three terms subtract these elements times; and the last term adds these elements once. In total, they are counted time, as desired. (One can check that the same holds for the other regions of the union of and .
PIE can be extended to any finite number of finite sets. To compute the cardinality of the union of finite sets:
-
Add the cardinalities of the sets.
-
Subtract the cardinalities of the pairwise intersections.
-
Add the cardinalities of the triple-wise intersections.
-
Subtract the cardinalities of the quadruple-wise intersections.
-
Continue, until the cardinality of the -tuple-wise intersection is added (if is odd) or subtracted ( even).
This can be written in terms of an equation, but it tends to be easier to understand the method explained above rather than the equation.
The union of sets has regions. Consider a region that contains the elements from exactly of the sets, where is an integer from to . Then, the first step counts these elements times. The second step excludes these elements times. This continues, until, on the th step, the elements are included (if is odd) or excluded (if is even) exactly time. Therefore, the number of times the elements are included (denoted ) is: where the second step follows from the Binomial Theorem. Thus, every element is counted exactly once, as desired!