Inclusion-Exclusion Principle
Statement
For finite sets :
For the two-set case this simplifies to:
Visualization
Venn diagram — two overlapping sets of integers:
Set A Set B
┌──────────┐ ┌──────────┐
│ 2 4 6 │ 8 10 │ 10 15 20 │
│ │◄──────►│ │
│ │ 8, 10 │ │
└──────────┘ └──────────┘
Let and .
| Quantity | Value | Count |
|---|---|---|
| 5 | ||
| 4 | ||
| 2 | ||
| 7 |
Formula check: . Correct.
Three-set example — students taking courses:
Math (M)
┌───────────────┐
│ 5 │
│ ┌──────┐ │
│ │ 3 │ 2 │
│ │ ┌───┼──┐ │
│ │ │ 1 │ │ │
│ └──┼───┘ │ │
└─────┼──────┘ │
CS (C) │ Physics (P)
└──────────┘
.
Proof Sketch
The key observation: each element (belonging to exactly of the sets) is counted times in the alternating sum. By the binomial theorem, this equals . So every element is counted exactly once.
For the two-set case: draw the Venn diagram, observe elements in are double-counted in , and subtract once.
Connections
- Pigeonhole PrinciplePigeonhole PrincipleIf n+1 objects are placed into n boxes, some box contains at least two objectsRead more → — a crude cousin: forces existence of a collision without counting precisely
- Catalan NumbersCatalan NumbersThe ubiquitous sequence counting balanced parentheses, binary trees, and Dyck pathsRead more → — the ballot problem uses complementary counting, an inclusion-exclusion variant
- Stirling NumbersStirling NumbersCounting partitions of n elements into k non-empty subsetsRead more → — the explicit formula for involves an inclusion-exclusion sum over
- Bell NumbersBell NumbersThe total number of partitions of a set of n elementsRead more → — accumulates Stirling numbers, each built on inclusion-exclusion
- Möbius InversionMöbius InversionIf g equals the Dirichlet convolution of f with the constant 1, then f recovers via the Möbius functionRead more → — the Möbius function on a poset is the categorical generalization of inclusion-exclusion
- Fermat's Little TheoremFermat's Little TheoremFor prime p, a^p is congruent to a mod pRead more → — Euler's totient is computed via inclusion-exclusion on prime factors
Lean4 Proof
import Mathlib.Data.Finset.Basic
/-- Two-set inclusion-exclusion: |A ∪ B| = |A| + |B| - |A ∩ B|.
Proved from `Finset.card_union_add_card_inter` using `omega`. -/
theorem inc_exc_two {α : Type*} [DecidableEq α] (s t : Finset α) :
(s ∪ t).card = s.card + t.card - (s ∩ t).card := by
have h := Finset.card_union_add_card_inter s t
omega
/-- The additive form is already in Mathlib as `Finset.card_union_add_card_inter`:
|(s ∪ t)| + |s ∩ t| = |s| + |t|. -/
theorem inc_exc_additive {α : Type*} [DecidableEq α] (s t : Finset α) :
(s ∪ t).card + (s ∩ t).card = s.card + t.card :=
Finset.card_union_add_card_inter s t
/-- Concrete check: {1,2,3} ∪ {2,3,4} has cardinality 4. -/
theorem inc_exc_example :
({1, 2, 3} ∪ {2, 3, 4} : Finset ℕ).card = 4 := by decideReferenced by
- Catalan NumbersCombinatorics
- Polya EnumerationCombinatorics
- Erdos-Ko-Rado TheoremCombinatorics
- Stirling NumbersCombinatorics
- Pigeonhole PrincipleCombinatorics
- Ramsey's TheoremCombinatorics
- Stirling's ApproximationCombinatorics
- Bell NumbersCombinatorics