Home › Combinatorics › Lesson 3

Inclusion–Exclusion and Möbius Inversion

Lesson 3 of 13

Key idea of this section

|A₁ ∪ ⋯ ∪ Aₘ| = ∑ over nonempty I ⊆ [m] of (−1)|I|+1 |⋂ᵢ∈I Aᵢ|
Dₙ = n! ∑ⱼ₌₀ⁿ (−1)ʲ/j!

The principle

Theorem 3.1 (Inclusion–exclusion). Let A₁, …, Aₘ be subsets of a finite set X, and for I ⊆ [m] let AI = ⋂ᵢ∈I Aᵢ, with A_∅ = X. Then the number of elements of X lying in none of the Aᵢ is ∑ over I ⊆ [m] of (−1)|I| |AI|.

Proof. Consider an element x ∈ X, and let J be the set of indices i with x ∈ Aᵢ, with |J| = j. The element x is counted in |AI| exactly when I ⊆ J, so its total contribution to the right-hand side is ∑ over I ⊆ J of (−1)|I| = ∑ᵣ C(j, r)(−1)ʳ = (1 − 1)ʲ, which is 1 if j = 0 and 0 otherwise. ∎

Truncating the alternating sum gives the Bonferroni inequalities: stopping after a positive term gives an upper bound for the union, and stopping after a negative term gives a lower bound. In probability these yield the estimates Pr(⋃Aᵢ) ≤ ∑ Pr(Aᵢ) and Pr(⋃Aᵢ) ≥ ∑ Pr(Aᵢ) − ∑ Pr(Aᵢ ∩ Aⱼ).

Derangements

A derangement is a permutation with no fixed point. Let Aᵢ be the set of permutations of [n] fixing i. Then |AI| = (n − |I|)!, and inclusion–exclusion gives

Dₙ = ∑ⱼ (−1)ʲ C(n, j)(n − j)! = n! ∑ⱼ₌₀ⁿ (−1)ʲ / j!.

The first values are D₀, …, D₈ = 1, 0, 1, 2, 9, 44, 265, 1854, 14833. Since the tail of the alternating series for e⁻¹ is bounded by its first omitted term, |Dₙ − n!/e| < n!/(n + 1)! = 1/(n + 1), so for n ≥ 1, Dₙ is the integer nearest to n!/e, and the probability that a random permutation is a derangement tends to 1/e ≈ 0.3679. Two recurrences follow combinatorially: Dₙ = (n − 1)(Dₙ₋₁ + Dₙ₋₂) (look at where n goes and whether that image maps back to n) and Dₙ = n Dₙ₋₁ + (−1)ⁿ. The number of permutations of [n] with exactly j fixed points is C(n, j) Dₙ₋ⱼ.

Surjections and Euler's totient

Taking Aᵢ to be the set of functions [n] → [k] missing the value i gives the count of surjections, k!·S(n, k) = ∑ⱼ (−1)ʲ C(k, j)(k − j)ⁿ. Taking X = [N] and Aᵢ the multiples of the i-th prime divisor pᵢ of N gives Euler's product φ(N) = N ∏ (1 − 1/p) over primes p dividing N, since |AI| = N/∏ᵢ∈I pᵢ.

Upper bounds in stars and bars

Example 3.2. The number of solutions of x₁ + x₂ + x₃ = 15 with 0 ≤ xᵢ ≤ 7: let Aᵢ be the solutions with xᵢ ≥ 8. Then |Aᵢ| is the number of weak compositions of 7 into 3 parts, C(9, 2) = 36, and no two of the Aᵢ intersect because 16 > 15. Hence the count is C(17, 2) − 3 · 36 = 136 − 108 = 28.

Möbius inversion on posets

Inclusion–exclusion is the special case of a far more general principle. Let (P, ≤) be a locally finite partially ordered set (every interval [x, y] is finite). The Möbius function μ is defined recursively by μ(x, x) = 1 and μ(x, y) = −∑ over x ≤ z < y of μ(x, z) for x < y, and μ(x, y) = 0 unless x ≤ y.

Theorem 3.3 (Möbius inversion). Let f, g : P → ℂ, and suppose every principal ideal {y : y ≤ x} is finite. Then g(x) = ∑ over y ≤ x of f(y) for all x if and only if f(x) = ∑ over y ≤ x of μ(y, x) g(y) for all x.

Proof. Assume the first relation. Then ∑ over y ≤ x of μ(y, x) g(y) = ∑ over z ≤ x of f(z) ∑ over z ≤ y ≤ x of μ(y, x). The inner sum is 1 if z = x and 0 otherwise; this is the dual form of the defining recursion, which holds because the incidence algebra of P is an associative algebra in which μ is the two-sided inverse of the zeta function ζ(x, y) = [x ≤ y], and ζ has both a left inverse and a right inverse (each defined by an analogous recursion), which in an associative algebra must coincide. The converse is identical. ∎

Three posets recover classical results. For the Boolean lattice of subsets of [m], μ(S, T) = (−1)|T∖S|, which is inclusion–exclusion. For the positive integers ordered by divisibility, μ(d, n) = μ(n/d), the number-theoretic Möbius function, giving the classical inversion g(n) = ∑d|n f(d) ⟺ f(n) = ∑d|n μ(n/d) g(d). For the lattice of set partitions of [n] ordered by refinement, μ(0̂, 1̂) = (−1)ⁿ⁻¹(n − 1)!. Philip Hall and, decisively, Gian-Carlo Rota (On the Foundations of Combinatorial Theory I, 1964) made Möbius functions a central tool.

Exercise

  • (a)
    How many permutations of [7] have exactly 2 fixed points?
  • (b)
    Compute φ(360) by inclusion–exclusion.
  • (c)
    Using the recurrence Dₙ = n Dₙ₋₁ + (−1)ⁿ, compute D₉ from D₈ = 14833.
Show solution

Answers: (a) C(7, 2) D₅ = 21 · 44 = 924. (b) 360 = 2³·3²·5, so φ(360) = 360 · (1/2)(2/3)(4/5) = 96. (c) D₉ = 9 · 14833 − 1 = 133,496.

V.3.1