Inclusion--exclusion: why the alternating signs work
The inclusion--exclusion principle corrects for overcounting by alternately adding and subtracting intersection sizes. We prove the general formula using indicator functions, apply it to count derangements, and trace the thread forward to the Mobius inversion formula on partially ordered sets.
The inclusion–exclusion principle instructs us to add, subtract, add again, subtract again – an operation that seems almost whimsical. For two sets and a Venn diagram the logic is intuitive, but as the number of sets grows to three, four, or more, why does this alternating pattern of signs continue to yield the correct count? Where does the cancellation come from?
1 Two sets: the Venn diagram
A glance at a Venn diagram makes this self-evident. The sum counts every element of twice, so we subtract once to correct the overcount.
2 The general formula
Written out explicitly:
3 Proof via indicator functions
4 Derangements
5 A competitive-programming classic: integers coprime to given primes
6 A glimpse of Mobius inversion
7 Takeaway
Inclusion–exclusion ensures that every element is counted exactly once, with the cancellation guaranteed by the binomial identity .
Derangements provide a beautiful application: .
In competitive programming, the principle yields a standard method for counting integers satisfying divisibility constraints.
Inclusion–exclusion is a special case of Mobius inversion on partially ordered sets, opening the door to a far more general theory.
In the next article, we explore the idea of encoding a sequence as a function – the generating function – and discover how it transforms recurrences into algebra.
Mathematics "between the lines" — exploring the intuition textbooks leave out, written in LaTeX on Folio.