40.01.02 · combinatorics / enumeration-generating-functions

Inclusion-Exclusion and the Sieve

shipped3 tiersLean: none

Anchor (Master): Stanley 2012 *Enumerative Combinatorics, Volume 1* 2e §2.1-2.7 and Notes (inclusion-exclusion as Möbius inversion on the Boolean lattice, the involution principle, permanents and rook polynomials, sign-reversing involutions); Aigner 2007 *A Course in Enumeration* (Springer) §5; Rota 1964 *Amer. Math. Monthly* / *Z. Wahrscheinlichkeitstheorie* 2 (the Möbius-function programme placing the sieve inside poset theory); Bonferroni 1936 *Pubbl. R. Ist. Sup. Sci. Econ. Comm. Firenze* (the partial-sum inequalities)

Intuition Beginner

Suppose you want to count the students in a class who play neither soccer nor chess. You know how many play soccer, how many play chess, and how many play both. A first guess is to take the whole class and subtract the soccer players and the chess players. That over-corrects: anyone who plays both sports got subtracted twice, once in each list, even though they are a single person. To repair the count you add the both-players back in once. Subtract the two single lists, add back the overlap — that is the whole idea in miniature.

The principle of inclusion-exclusion is this repair carried out for any number of overlapping lists. You include everything, then exclude the pairwise overlaps you double-counted, then include the triple overlaps you over-excluded, and so on, with the signs alternating plus and minus. Each element of the universe gets counted exactly the right number of times once all the corrections are in. The alternating sum is not a clever trick pulled from nowhere; it is the unique bookkeeping that makes every element's net count come out to one if it should be counted and zero if it should not.

People reach for this principle whenever a set is easy to describe by the bad properties it should avoid rather than by the good properties it should have. "Arrangements where no one sits in their own seat", "numbers below a million sharing no factor with it", "ways to seat couples so no husband sits beside his wife" — each is a count of objects avoiding a list of forbidden conditions. Counting the avoiders directly is hard; counting how many objects have at least a given batch of forbidden conditions is easy, and the sieve assembles those easy counts into the hard one.

The pattern you should carry forward is the sieve: a fine-grained subtract-and-restore that strains out exactly the elements failing none of the conditions. The same alternating-sign signature reappears later as the Möbius function on the lattice of subsets, the deepest reason the signs are what they are.

Visual Beginner

Picture three overlapping circles in a rectangle: the rectangle is everyone, the circles are the soccer, chess, and tennis players. To count people inside at least one circle, add the three circle sizes, subtract the three pairwise lens-shaped overlaps, then add back the central region where all three meet.

The table tracks how many times a person in each region is counted as the corrections accumulate. A person in exactly one circle is counted once and never touched again. A person in exactly two circles is added twice, then subtracted once — net one. A person in all three is added three times, subtracted three times, then added once — net one.

region added by singles removed by pairs added by triple net
in one circle
in two circles
in all three
in no circle

Every row in the union nets to one, and the outsiders net to zero. That last column is the entire content of the principle: the alternating sum is the unique weighting that scores each element by whether it belongs.

Worked example Beginner

Count the derangements of three guests: the seatings of guests into chairs so that no guest sits in the chair matching their number. We do it by listing, then by the sieve.

Step 1. List all seatings, writing each as the chairs taken by guests in order. They are . A seating is a derangement when no position holds its own number.

Step 2. Strike the bad ones. fixes all three. fixes guest . fixes guest . fixes guest . That leaves and , where every guest avoids their own chair. So there are derangements by direct count.

Step 3. Now the sieve. Start from all seatings. Subtract those fixing at least one chosen guest. Fixing guest leaves the other two free: seatings; same for guests and , giving to subtract. But seatings fixing two guests got subtracted twice, so add them back: fixing guests and forces guest too, giving seating, and there are such pairs, so add . Finally subtract the one seating fixing all three.

Step 4. Assemble: . The sieve agrees with the list.

What this tells us: the alternating sum counts "at least one fixed guest" with the right multiplicities, and subtracting it from the total leaves exactly the seatings fixing nobody. The same recipe with guests gives , which we meet again in the formal sections.

Check your understanding Beginner

Formal definition Intermediate+

Let be a finite universe and let . For a subset write with the convention , and set , the number of elements lying in at least the sets indexed by .

Definition (inclusion-exclusion, union form). The cardinality of the union is the alternating sum $$ \Bigl|\bigcup_{i=1}^{n} A_i\Bigr| = \sum_{\varnothing \neq T \subseteq [n]} (-1)^{|T|+1},|A_T| = \sum_{i} |A_i| - \sum_{i<j}|A_i \cap A_j| + \sum_{i<j<k}|A_i \cap A_j \cap A_k| - \cdots . $$

Definition (complementary form). The number of elements of lying in none of the — equivalently with none of the corresponding properties — is $$ \Bigl|U \setminus \bigcup_{i=1}^n A_i\Bigr| = \sum_{T \subseteq [n]} (-1)^{|T|},N_{\supseteq T} = N_{\supseteq \varnothing} - \sum_i N_{\supseteq {i}} + \sum_{i<j} N_{\supseteq {i,j}} - \cdots . $$ This is the sieve formula: it strains down to the elements satisfying none of the listed conditions.

Definition (property-count refinement). Index by properties and let be the sum of intersection counts, so tallies, with multiplicity, the elements satisfying at least the properties in some -subset. Write for the number of elements satisfying exactly of the properties. The complementary form is the case ; the general refinement is $$ E_m = \sum_{k=m}^{n} (-1)^{k-m}\binom{k}{m} N_k , $$ the Sylvester-Whitney formula, and the truncations of these alternating sums are the Bonferroni inequalities [Bonferroni 1936].

Definition (Boolean-lattice viewpoint). The subsets of ordered by inclusion form the Boolean lattice . On any locally finite poset the zeta function has a convolution inverse, the Möbius function ; for one computes when and otherwise. The sieve is the assertion that the map and the map are related by , so ; reading off recovers . The general theory on an arbitrary poset is developed in 40.02.02; this unit owns the set-theoretic instance.

Counterexamples to common slips Intermediate+

  • " is the number of elements with exactly properties." It is not. counts pairs (element, -subset of its properties), so an element with properties is counted times. The exactly- count is , recovered from the by the Sylvester-Whitney sum, not by reading directly.

  • "Truncating the sieve early gives an approximation of unknown sign." The Bonferroni inequalities pin the sign: stopping the alternating sum for a union after a term gives an upper bound, after a term a lower bound. The error is controlled, not merely small.

  • "Inclusion-exclusion needs the to be disjoint or nested." It holds for arbitrary overlaps; the alternating signs exist precisely to handle arbitrary multiplicities of overlap. Disjointness collapses every intersection term to zero and reduces the formula to the sum rule.

  • "The signs are a convention one could flip." They are forced: is the Möbius function of the Boolean lattice, the unique inverse of the zeta function, so any other sign pattern fails to invert the over-counting.

Key theorem with proof Intermediate+

The signature theorem is the sieve formula itself, proved by the indicator-function identity that makes every element's net contribution equal one or zero.

Theorem (inclusion-exclusion / sieve). With notation as above, $$ \Bigl|U \setminus \bigcup_{i=1}^{n} A_i\Bigr| = \sum_{T \subseteq [n]} (-1)^{|T|},|A_T|, \qquad \Bigl|\bigcup_{i=1}^n A_i\Bigr| = \sum_{\varnothing \neq T \subseteq [n]} (-1)^{|T|+1},|A_T| . $$

Proof. Fix an element and let be the set of indices whose sets contain ; write . We show that contributes the value to the right-hand side of the first identity, where is when the bracketed statement holds and otherwise; summing over then gives the count of elements in no .

The element lies in exactly when . Its total contribution to is therefore $$ \sum_{T \subseteq P(x)} (-1)^{|T|} = \sum_{k=0}^{r} \binom{r}{k}(-1)^k = (1 - 1)^r = [r = 0], $$ using the binomial theorem at , which vanishes for and equals for . Hence each contributes and each contributes , so the right-hand side counts . Subtracting from and rearranging the term gives the union form.

Corollary (derangements). The number of permutations of with no fixed point is . Indeed, let be the permutations fixing ; an intersection over a -set fixes those points and permutes the rest freely, so and there are such . The sieve gives , and yields the second form. As the sum converges to , so a uniformly random permutation has no fixed point with limiting probability .

Bridge. This theorem is the foundational reason a count of "objects avoiding all of a list of properties" is always within reach: the alternating sum is the only weighting whose per-element total is the indicator , and the binomial collapse is exactly the Boolean-lattice shadow of the more general Möbius inversion. The sieve builds toward the poset Möbius theory, where is replaced by on an arbitrary locally finite poset; this is exactly the statement that and are mutually inverse in the incidence algebra, and the Boolean case generalises to chains, divisor lattices, and partition lattices alike. Putting these together, the derangement corollary is the prototype that appears again in the ménage problem and in every restricted-position count, where the forbidden positions index the properties and the central insight is that the permanent of a board complement is a single sieve in disguise. The bridge is that one indicator identity, summed over a universe, underwrites derangements, the totient, surjections, and the rook-polynomial machinery as a single mechanism.

Exercises Intermediate+

Advanced results Master

The sieve is the degree-zero case of Möbius inversion; its depth emerges once the index set carries a lattice structure, once the alternating sum is read as a permanent, and once the cancellation is made bijective by an involution.

Theorem 1 (sieve as Boolean Möbius inversion). On the Boolean lattice the incidence algebra carries the zeta function and its convolution inverse . For functions the inversion holds, and the complementary sieve is the case with , [Aigner 2007]. The arithmetic Möbius function on the divisor lattice 21.11.01 and the set-theoretic sign are two specialisations of the one poset Möbius function developed in 40.02.02; this unit owns the set-theoretic sieve, the divisor case is owned there, and the analytic sieve of 21.14.01 is the number-theoretic refinement that controls error terms rather than counting exactly.

Theorem 2 (the ménage problem). The number of ways to seat married couples around a circular table, men and women alternating, with no wife adjacent to her own husband, is $$ M_n = \sum_{k=0}^{n} (-1)^k \frac{2n}{2n-k}\binom{2n-k}{k}(n-k)! . $$ The factor is the rook number of the -cell board consisting of the two diagonals encoding the forbidden husband-left and husband-right adjacencies; counting non-attacking rook placements on a circular two-diagonal board is the Touchard-Kaplansky lemma. The ménage count is the headline application of the principle of restricted positions, and Wyman-Moser made the asymptotic precise.

Theorem 3 (permanents and restricted positions). For a matrix , the permanent counts the permutations with for all . Taking to be the complement of the forbidden board , the count of placements avoiding is , where is all-ones and the indicator of , and the inclusion-exclusion expansion of this permanent is exactly of Exercise 8. The permanent is -hard to compute in general (Valiant 1979), so the sieve trades an intractable permanent for the rook polynomial of , tractable when is sparse or structured.

Theorem 4 (the involution principle). The cancellation is realised bijectively: fixing any element (when ), the map is a sign-reversing involution on the subsets of with no fixed points, pairing each with one of opposite parity and equal weight. Garsia and Milne's involution principle generalises this: every inclusion-exclusion identity with non-negative refined counts can be upgraded to an explicit weight-preserving bijection between the surviving objects, turning a signed identity into a combinatorial one. This is the mechanism behind Franklin-style involutive proofs and the bijective proofs of restricted-partition identities.

Theorem 5 (Bonferroni inequalities, refined). The truncated sieve sums bracket the true count: for the union, partial sums ending on overestimate and those ending on underestimate, and analogously brackets as ranges over the parities. These inequalities make inclusion-exclusion usable as an estimation tool when the full alternating sum is intractable, and in probability they yield the Bonferroni and Galambos bounds on used throughout the second-moment method [Bonferroni 1936].

Synthesis. The principle of inclusion-exclusion is the foundational reason a single mechanism underlies derangements, the totient, surjections, the ménage seating, and every restricted-position count: each is a sieve for a suitable family of properties, and the alternating signs are not chosen but forced, being the Möbius function of the Boolean lattice. The central insight is that this Boolean Möbius function is one instance of the poset Möbius function of 40.02.02, so the set-theoretic sieve, the arithmetic Möbius inversion of 21.11.01, and the analytic sieves of 21.14.01 are the same inversion read on the subset lattice, the divisor lattice, and the integers with error control respectively. Putting these together, the permanent formulation shows the sieve trades a -hard count for the rook polynomial, the involution principle shows the signed cancellation is dual to an explicit bijection, and the Bonferroni truncations show the alternating sum degrades gracefully into two-sided bounds. This is exactly the bridge that builds toward analytic combinatorics and probabilistic sieve theory: the elementary subtract-and-restore of the Beginner tier generalises to the full incidence-algebra inversion that organises enumeration, where each refinement — exactly-, bounded truncation, bijective realisation, permanent evaluation — is a face of the one Möbius identity.

Full proof set Master

Proposition 1 (sieve via the indicator identity). For finite , the number of elements in none of the is , with .

Proof. Write for the indicator function of a set . For each with property set of size , the contribution of to is , since precisely when . This inner sum is , which equals if and if . Summing over counts exactly the with , the elements in no .

Proposition 2 (derangement closed form and limit). , and .

Proof. Let be the permutations of fixing . For , fixes the points of and permutes the complementary points arbitrarily, so ; there are subsets of size . Proposition 1 gives . Since , this is . The sum is the degree- truncation of the Taylor series of , whose tail is bounded by in absolute value, so .

Proposition 3 (Euler totient as a sieve). For with distinct prime divisors , .

Proof. Let , so and, for , because the are distinct primes and . The integers coprime to are exactly those in no , so Proposition 1 gives $$ \varphi(N) = \sum_{T\subseteq[r]}(-1)^{|T|}\frac{N}{\prod_{i\in T}p_i} = N\prod_{i=1}^r\Bigl(1 - \frac{1}{p_i}\Bigr), $$ the product expanding to the alternating sum over subsets . This recovers multiplicativity of and the divisor identity , both owned downstream by 21.11.01.

Proposition 4 (restricted positions and the rook polynomial). For a forbidden board with rook numbers , the number of permutations avoiding is .

Proof. Let property of a permutation hold when . The permutations avoiding satisfy none of the . For , a term counts permutations whose graph contains a chosen forbidden cell in each row of ; the chosen cells lie in distinct rows (the rows of ) and distinct columns (since is a bijection), so they form a non-attacking -rook placement on , and the remaining rows are filled by a bijection onto the remaining columns in ways. Each non-attacking -rook placement arises from exactly one choice of (the occupied rows), so . Proposition 1 in the form yields . When is the union of two diagonals on the seating cycle, by the Touchard-Kaplansky count, giving the ménage number .

Connections Master

  • The alternating sign that drives the sieve is the Möbius function of the Boolean lattice , and inclusion-exclusion is precisely Möbius inversion on that poset. The general theory — the incidence algebra of a locally finite poset, the zeta function and its inverse , and inversion on chains, divisor lattices, and partition lattices — is the co-produced unit 40.02.02, which this sieve is the elementary base case of. The foundational reason the signs invert the over-counting is that is the unique convolution inverse of .

  • The arithmetic Möbius function and Möbius inversion over the divisor lattice are owned by 21.11.01: the totient computation of this unit is the set-theoretic sieve specialised to the prime-divisor properties, whereas 21.11.01 develops the same inversion as a statement about Dirichlet convolution and multiplicative functions. The boundary is deliberate — this unit owns the finite set-theoretic sieve, that unit owns the number-theoretic Dirichlet form.

  • The analytic sieves of number theory — the Eratosthenes-Legendre sieve, Brun's sieve, and the large sieve — are the asymptotic descendants developed in 21.14.01, where the exact alternating sum is truncated and its error term estimated rather than evaluated. The Bonferroni inequalities of this unit are the elementary truncation bounds that those analytic sieves sharpen; this unit counts exactly, that unit controls error terms when exact evaluation is intractable.

  • The surjection count recovered here by sieving the codomain is the inclusion-exclusion half of the twelvefold way's signature theorem 40.01.01, where it was paired with the bijective identity . This unit isolates and generalises the sieve half of that argument into the abstract principle.

Historical & philosophical context Master

The principle was stated by Abraham de Moivre in his Doctrine of Chances (1718) and, in the form of the derangement count, by Pierre Rémond de Montmort, who in 1708 posed and solved the problème des rencontres — the matching game later named after him — obtaining . Nicholas Bernoulli and Euler returned to the derangement problem independently; Euler's 1779 treatment of the problème des ménages (in the form studied by Édouard Lucas in 1891 and solved by Jacques Touchard in 1934) established the restricted-position circle of ideas. James Joseph Sylvester gave the principle its general "exactly " form in the 1880s, the formula carried jointly with the later refinements of Whitney.

The modern viewpoint is Gian-Carlo Rota's. His 1964 paper On the foundations of combinatorial theory I [Aigner 2007] placed inclusion-exclusion inside the incidence algebra of a partially ordered set, identifying the alternating signs as the values of the Möbius function of the Boolean lattice and exhibiting inclusion-exclusion, Möbius number-theoretic inversion, and Euler-characteristic computations as instances of one inversion principle. Carlo Emilio Bonferroni's 1936 study of statistical classes [Bonferroni 1936] supplied the partial-sum inequalities that bound a union by truncated sieves, central to multiple-comparison statistics. Adriano Garsia and Stephen Milne's 1981 involution principle then closed the loop, showing that the signed cancellation underlying every sieve can be realised as an explicit weight-preserving bijection.

Bibliography Master

@book{stanley2012ec1,
  author    = {Stanley, Richard P.},
  title     = {Enumerative Combinatorics, Volume 1},
  series    = {Cambridge Studies in Advanced Mathematics},
  volume    = {49},
  edition   = {2},
  publisher = {Cambridge University Press},
  year      = {2012}
}

@book{aigner2007enumeration,
  author    = {Aigner, Martin},
  title     = {A Course in Enumeration},
  series    = {Graduate Texts in Mathematics},
  volume    = {238},
  publisher = {Springer},
  year      = {2007}
}

@article{rota1964mobius,
  author  = {Rota, Gian-Carlo},
  title   = {On the foundations of combinatorial theory I: Theory of M\"{o}bius functions},
  journal = {Zeitschrift f\"{u}r Wahrscheinlichkeitstheorie und verwandte Gebiete},
  volume  = {2},
  year    = {1964},
  pages   = {340--368}
}

@article{bonferroni1936teoria,
  author  = {Bonferroni, Carlo Emilio},
  title   = {Teoria statistica delle classi e calcolo delle probabilit\`{a}},
  journal = {Pubblicazioni del R. Istituto Superiore di Scienze Economiche e Commerciali di Firenze},
  volume  = {8},
  pages   = {3--62},
  year    = {1936}
}

@book{demoivre1718doctrine,
  author    = {de Moivre, Abraham},
  title     = {The Doctrine of Chances: or, A Method of Calculating the Probability of Events in Play},
  publisher = {W. Pearson},
  address   = {London},
  year      = {1718}
}

@article{touchard1934permutations,
  author  = {Touchard, Jacques},
  title   = {Sur un probl\`{e}me de permutations},
  journal = {Comptes Rendus de l'Acad\'{e}mie des Sciences (Paris)},
  volume  = {198},
  pages   = {631--633},
  year    = {1934}
}

@article{garsiamilne1981involution,
  author  = {Garsia, Adriano M. and Milne, Stephen C.},
  title   = {A Rogers-Ramanujan bijection},
  journal = {Journal of Combinatorial Theory, Series A},
  volume  = {31},
  number  = {3},
  pages   = {289--339},
  year    = {1981}
}

@article{valiant1979permanent,
  author  = {Valiant, Leslie G.},
  title   = {The complexity of computing the permanent},
  journal = {Theoretical Computer Science},
  volume  = {8},
  number  = {2},
  pages   = {189--201},
  year    = {1979}
}

@book{vanlintwilson2001,
  author    = {van Lint, J. H. and Wilson, R. M.},
  title     = {A Course in Combinatorics},
  edition   = {2},
  publisher = {Cambridge University Press},
  year      = {2001}
}