The principle of inclusion/exclusion
ProvedFamousTheorems.inclusion_exclusion_card_biUnionThe principle of inclusion–exclusion.
For a finite family of finite sets ,
Counting the union by adding the sizes overcounts every element lying in several ; subtracting the pairwise intersections overcorrects; adding back the triples overcorrects again, and so on. The alternating sum is exactly right because an element in precisely of the sets is counted time.
It is the fundamental counting identity of enumerative combinatorics: derangements, Euler's totient function, the surjection count, and the sieve of Eratosthenes are all one substitution away. Its analytic descendants are the Bonferroni inequalities (truncating the sum gives alternating bounds) and Brun's and Selberg's sieves.
De Moivre stated it in 1718; the modern general form is often credited to Sylvester and Poincaré.
Formalization note. The index runs over nonempty subsets of s, carried as a subtype so that
inf' — the intersection of a nonempty family — is well defined; the cardinality is cast to
so the alternating signs make sense. The result is Mathlib's Finset.inclusion_exclusion_card_biUnion.
import Mathlib
namespace FamousTheorems
theorem inclusion_exclusion_card_biUnion {ι α : Type*} [DecidableEq α] (s : Finset ι)
(S : ι → Finset α) :
(s.biUnion S).card = ∑ t : {t ∈ s.powerset | t.Nonempty},
(-1 : ℤ) ^ (t.1.card + 1) * (t.1.inf' (Finset.mem_filter.1 t.2).2 S).card := by sorry
end FamousTheorems