ConceptComplete

Inclusion-Exclusion Principle

The inclusion-exclusion principle is a fundamental counting technique that allows us to calculate the cardinality of the union of sets by systematically adding and subtracting intersections. This principle corrects for overcounting when elements belong to multiple sets.

DefinitionInclusion-Exclusion Principle

Let A1,A2,,AnA_1, A_2, \ldots, A_n be finite sets. The cardinality of their union is: i=1nAi=i=1nAi1i<jnAiAj+1i<j<knAiAjAk+(1)n+1A1A2An\left|\bigcup_{i=1}^n A_i\right| = \sum_{i=1}^n |A_i| - \sum_{1 \leq i < j \leq n} |A_i \cap A_j| + \sum_{1 \leq i < j < k \leq n} |A_i \cap A_j \cap A_k| - \cdots + (-1)^{n+1}|A_1 \cap A_2 \cap \cdots \cap A_n|

More compactly, this can be written as: i=1nAi=S[n](1)S+1iSAi\left|\bigcup_{i=1}^n A_i\right| = \sum_{\emptyset \neq S \subseteq [n]} (-1)^{|S|+1} \left|\bigcap_{i \in S} A_i\right| where [n]={1,2,,n}[n] = \{1, 2, \ldots, n\}.

The principle works by first counting all elements (possibly multiple times), then removing those counted twice, adding back those removed too many times, and so forth. The alternating signs ensure that each element is counted exactly once in the final sum.

ExampleDerangements

A derangement is a permutation where no element appears in its original position. The number of derangements DnD_n of nn elements can be computed using inclusion-exclusion.

Let AiA_i be the set of permutations where element ii is in position ii. Then: Dn=n!i=1nAiD_n = n! - \left|\bigcup_{i=1}^n A_i\right|

We have Ai=(n1)!|A_i| = (n-1)!, AiAj=(n2)!|A_i \cap A_j| = (n-2)!, and generally iSAi=(nS)!\left|\bigcap_{i \in S} A_i\right| = (n-|S|)!.

Therefore: Dn=n!(n1)(n1)!+(n2)(n2)!+(1)n(nn)0!D_n = n! - \binom{n}{1}(n-1)! + \binom{n}{2}(n-2)! - \cdots + (-1)^n\binom{n}{n}0! =n!(111!+12!13!++(1)nn!)= n!\left(1 - \frac{1}{1!} + \frac{1}{2!} - \frac{1}{3!} + \cdots + \frac{(-1)^n}{n!}\right)

This approaches n!/en!/e for large nn, meaning approximately 1/e36.8%1/e \approx 36.8\% of all permutations are derangements.

DefinitionSurjective Function Counting

The number of surjective functions from an nn-element set to a kk-element set can be computed using inclusion-exclusion. Let f:[n][k]f: [n] \to [k] be a function. We want to count surjections (onto functions).

Let AiA_i be the set of functions that do not have ii in their range. Then: \text{# surjections} = k^n - \left|\bigcup_{i=1}^k A_i\right|

By inclusion-exclusion: =kn(k1)(k1)n+(k2)(k2)n+(1)k1(kk1)1n= k^n - \binom{k}{1}(k-1)^n + \binom{k}{2}(k-2)^n - \cdots + (-1)^{k-1}\binom{k}{k-1}1^n =j=0k(1)kj(kj)jn= \sum_{j=0}^k (-1)^{k-j}\binom{k}{j}j^n

Remark

The inclusion-exclusion principle has a natural generalization to probability theory. For events E1,,EnE_1, \ldots, E_n in a probability space: P(i=1nEi)=i=1nP(Ei)i<jP(EiEj)++(1)n+1P(E1En)P\left(\bigcup_{i=1}^n E_i\right) = \sum_{i=1}^n P(E_i) - \sum_{i<j} P(E_i \cap E_j) + \cdots + (-1)^{n+1}P(E_1 \cap \cdots \cap E_n)

This probabilistic version is known as the Bonferroni inequalities when truncated at various stages.

ExampleEuler's Totient Function

The Euler totient function ϕ(n)\phi(n) counts integers in [1,n][1,n] that are coprime to nn. If n=p1a1p2a2pkakn = p_1^{a_1} p_2^{a_2} \cdots p_k^{a_k}, let AiA_i be the set of integers in [1,n][1,n] divisible by pip_i.

By inclusion-exclusion: ϕ(n)=ni=1kAi=n(11p1)(11p2)(11pk)\phi(n) = n - \left|\bigcup_{i=1}^k A_i\right| = n\left(1 - \frac{1}{p_1}\right)\left(1 - \frac{1}{p_2}\right) \cdots \left(1 - \frac{1}{p_k}\right)

For example, ϕ(12)=12(11/2)(11/3)=121/22/3=4\phi(12) = 12(1 - 1/2)(1 - 1/3) = 12 \cdot 1/2 \cdot 2/3 = 4, corresponding to {1,5,7,11}\{1, 5, 7, 11\}.

The principle extends to more abstract settings through Möbius inversion on posets, providing a systematic framework for "inverting" summation formulas in combinatorics and number theory.