Definition
Inclusion-Exclusion Principle
Let be finite sets indexed by the index set . The inclusion–exclusion principle computes the number of elements in their union by alternately adding and subtracting the sizes of their intersections:
Terms involving one set are added, intersections of two sets are subtracted, intersections of three sets are added, and so on.
Two finite sets gives
Setting
Adding and counts each element of the intersection twice. Subtracting removes one copy, leaving every element of the union counted once.
Three finite sets gives
Setting
The pairwise intersections remove the double counts. Their common intersection is then added back because it was subtracted once for each of the three pairs.
Why the Signs Alternate
Fix an element that belongs to exactly of the sets. It appears in intersections of sets, so its total contribution to the right-hand side is
because . Thus every element of the union is counted exactly once.
Examples
3 Intersecting Sets
Include the individual sets
Begin with
This counts an element once for every set containing it. An element in exactly two sets is therefore counted twice, while an element in all three sets is counted three times.
Exclude the pairwise intersections
Subtract each pairwise overlap:
An element in exactly two sets belongs to one pairwise intersection, so its count becomes . An element in all three sets belongs to all three pairwise intersections, so its count becomes .
Include the triple intersection again
The central region must be restored once. Hence
The correction leaves every element counted exactly once.