Inclusion-Exclusion Principle
One-line statement: The size of a union of finite sets equals the alternating sum of the sizes of all possible intersections of those sets. Key result in words: Add the sizes of individual sets, subtract pairwise overlaps, add back triple overlaps, and so on, alternating signs, to count a union without double-counting. Where it applies: Combinatorics, probability, number theory (the Euler Totient Function and Sieve Methods), and counting problems with overlapping conditions. Who/when: Formalized by Abraham de Moivre (1718) and named after work by J. J. Sylvester and Henri Poincaré in the 19th century.The inclusion–exclusion principle is a counting technique that computes the cardinality of a union of finite sets by alternately adding and subtracting the cardinalities of their intersections. In its simplest form, , it corrects the naive overcount that occurs when overlapping elements are counted more than once. The principle generalizes to any finite number of sets and underlies a vast range of combinatorial identities, including the counting of derangements, surjections, and integers coprime to a given number. A surprising fact is that the same alternating-sum structure appears in probability (the formula for the probability of a union of events), in the Euler characteristic of topology, and in the Möbius inversion formula over the Boolean lattice — all manifestations of a single algebraic skeleton.
The Core Insight
When you count elements belonging to at least one of several sets, an element lying in of them is counted times if you simply add the individual set sizes. The fix is systematic correction by overlaps: subtract every pairwise intersection, which over-corrects elements in three or more sets, then add back triple intersections, and continue. The miracle is that the coefficients work out so that an element in exactly sets is counted with net multiplicity , regardless of . The entire principle is the combinatorial identity in disguise.
Formal Statement
Setup and Notation
Let be finite sets. For a nonempty subset of indices, write
The quantity depends only on which sets are intersected, and the principle expresses in terms of all these intersection sizes.
Inclusion–Exclusion Principle (Union Form)
For finite sets ,
Equivalently, expanding by intersection size:
The first few terms read , where is the sum of all -fold intersection sizes.
Complementary Form
Equivalently, counting elements in none of the sets within a universe of size :
This form is the one used in sieve arguments: encodes "having property ," and the left side counts objects with no listed property.
Why It Holds / Derivation
Indicator-Function / Element-Counting Proof
We prove equation [2] by showing each element of the union contributes exactly to both sides.
Step 1 — Fix an element. Let , and let be the number of sets containing . The left side of [2] counts exactly once. Step 2 — Count 's contributions on the right. An intersection contains if and only if is a subset of the indices whose sets contain . The number of such index sets of size is . Step 3 — Sum the signed contributions. Element contributes to the right sideInductive Proof
Base case : , since elements in the overlap are added twice and removed once. Inductive step. Assume [2] holds for sets. Write . ThenNow , so apply the inductive hypothesis to both and ; collecting terms reproduces [2] for sets, with each -fold intersection appearing exactly once with the correct sign.
Abraham de Moivre | 1667–1754
A French-born Huguenot mathematician who fled to England after the revocation of the Edict of Nantes, de Moivre worked largely as a private tutor and consultant on games of chance. In his 1718 The Doctrine of Chances, he gave an early systematic treatment of the inclusion–exclusion formula in the context of probability problems — notably the "problème des rencontres" (the matching/derangement problem). His work tied the combinatorial identity to practical questions of dice, lotteries, and annuities. The principle's later refinement and naming owe much to J. J. Sylvester and Henri Poincaré, but de Moivre's recognition that overcounting must be corrected by alternating subtraction is the historical seed.
Building Intuition
Imagine three overlapping circular spotlights on a stage, lighting up actors. If you ask each operator "how many actors does your beam touch?" and add the three numbers, an actor standing where two beams overlap gets counted twice, and one in the central three-way overlap gets counted three times. To find how many actors are lit at all, you subtract the pairwise-overlap counts — but this removes the central actor one time too many (counted , subtracted , leaving ). So you add back the triple overlap, restoring her to a single count. The alternating add/subtract pattern is precisely the bookkeeping needed so every lit actor ends up counted exactly once, no matter how many beams reach her.
Three-set inclusion–exclusion: the alternating correction of overlaps
Worked Examples
Counting integers divisible by 2, 3, or 5 up to 100
Given: Count integers with divisible by , , or .Let = multiples of 2, = multiples of 3, = multiples of 5, within .
Step 1 — Single counts (): , , . So . Step 2 — Pairwise counts (): , , . So . Step 3 — Triple count (): . Step 4 — Apply [3]: .(As a check, the number coprime to 30 in this range, via [4], is .)
The derangement problem $D_n$ for $n = 4$
Given: Count permutations of with no fixed point (no element maps to itself) — these are derangements.Let = permutations fixing position . We want permutations in none of the , so use complementary form [4] with .
Step 1 — Intersection sizes. A permutation fixing a chosen set of positions permutes the remaining freely, giving permutations. There are ways to choose which positions are fixed. Step 2 — Build the alternating sum (from [4]):- :
- :
- :
- :
- :
This matches the closed form , giving .
Common Misconceptions
Signs and stopping points
Three frequent errors:
- Forgetting to add back the triple overlap. Subtracting all pairwise intersections over-removes elements in three or more sets; the principle is not "add singles, subtract pairs" — it continues with alternating signs all the way to the -fold intersection.
- Mixing up (union form [2]) with (complement form [4]). The sign on the leading single-set term is for the union but the term carries no negative in the complement form.
- Assuming intersection sizes are products. is false in general for cardinalities; it holds for probabilities only under independence. For counting, you must determine each intersection size directly.
Naive subtraction fails for three or more sets
Take , a single shared element. Then .
If you (incorrectly) used only "singles minus pairs":
Connections
Inclusion–exclusion is a special case of Möbius inversion on the Boolean lattice of subsets, where the alternating signs are exactly the Möbius function values; see Mobius Inversion Formula. In probability it becomes the formula , foundational in Probability Theory. Its number-theoretic incarnation is the Sieve of Eratosthenes and the formula for the Euler Totient Function . The Bonferroni inequalities arise from truncating the alternating sum, giving alternating upper and lower bounds. Topologically, the same alternating structure governs the additivity of the Euler Characteristic under unions of cells.
Real-World Applications
- Sieve of Eratosthenes & prime counting — estimating how many integers up to survive removal of all multiples of small primes uses [4] directly; this is the root of analytic Sieve Methods.
- Euler's totient function — counting integers coprime to applies inclusion–exclusion over the distinct prime divisors of .
- Network reliability — computing the probability that at least one of several redundant paths in a communications network functions, where paths share components (events are not independent).
- Database query optimization — estimating the number of records satisfying "at least one of several filter conditions" requires correcting for records matching multiple conditions.
- Cryptographic collision counting — bounding the number of hash inputs colliding on at least one of several outputs.
- Surjection and onto-map enumeration — counting functions from an -set onto an -set (used in occupancy/balls-in-boxes problems and Stirling numbers) is a direct inclusion–exclusion over "missed targets."
- Coupon collector and matching problems — derangement-based scenarios such as the hat-check problem and probability of a perfect mismatch in secret-Santa assignments.
Historical Development
- 1718 — Abraham de Moivre, in The Doctrine of Chances, treats the matching problem (rencontres) using alternating-sum corrections, an early probabilistic inclusion–exclusion.
- 1779 — Leonhard Euler develops the totient function and uses product-over-primes reasoning equivalent to inclusion–exclusion.
- 1854 — Daniel da Silva states a general form of the principle in a Portuguese memoir, sometimes giving the result the name "da Silva's formula."
- 1867 — J. J. Sylvester independently formulates and applies the principle in combinatorics; the name "Sylvester's sieve" is sometimes used.
- 1883 — H. Poincaré states the probabilistic union formula in his work on probability, lending it the alternative name "Poincaré's formula."
- 1936 — C. E. Bonferroni publishes the inequalities obtained by truncating the alternating series, central to multiple-comparison statistics.
- 1964 — Gian-Carlo Rota, in On the Foundations of Combinatorial Theory I, unifies inclusion–exclusion as Möbius inversion over partially ordered sets, revealing its deep algebraic structure.
- 20th c. onward — The principle becomes standard in textbooks of enumerative combinatorics (Riordan, Stanley) and a workhorse of analytic number theory's sieve methods (Brun, Selberg).
Subtleties & Limits
Inclusion–exclusion is exact for finitely many sets, but practically it can require summing terms, which is computationally infeasible for large — exact application is #P-hard for general systems (e.g., reliability polynomials). This motivates sieve theory's central tension: how to extract good bounds from truncated or weighted versions of the alternating sum. The Bonferroni inequalities give crude bounds; the deeper achievements of Brun's sieve, the Selberg sieve, and the large sieve replace the rigid signs of pure inclusion–exclusion with optimized weights to tame error terms. The famous "parity problem" of sieve theory — the inability of classical sieves to distinguish numbers with an even versus odd number of prime factors — is fundamentally a limitation on how much the inclusion–exclusion structure can detect, and remains a guiding obstacle in attacks on problems like the twin prime conjecture and Goldbach's conjecture.