The Principle of Inclusion-Exclusion

How many integers from 11 to 10001000 are divisible by 33, 55, or 77? Naively adding the three counts overcounts numbers divisible by more than one of these. So we must correct for the overcounting — and then correct the correction. This simple tension between the Sum and Product Rules and overlapping sets is the seed of one of the most versatile counting tools in combinatorics: the Principle of Inclusion-Exclusion (PIE). PIE matters because most interesting counting problems are not about disjoint collections. Instead they involve unions and complements of overlapping conditions — numbers avoiding certain divisors, functions missing certain outputs, permutations avoiding certain fixed points, arrangements violating certain adjacency constraints. Whenever a problem can be phrased as "count the elements satisfying at least one of several properties," PIE helps. The same holds dually for "count the elements satisfying none." PIE turns that question into a computable alternating sum over intersections. Each of these is often far easier to count than the union directly. The big picture is that a finite set can be built from overlapping subsets. Their interactions form a Boolean lattice. PIE is precisely the Möbius-function calculation on that lattice, made elementary through a counting argument. It generalizes the humble observation that ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A \cup B| = |A| + |B| - |A \cap B| to arbitrarily many sets. As intersections deepen, the signs alternate between ++ and −-. This article develops PIE rigorously from the two-set and three-set cases up to the full nn-set alternating-sum theorem. It proves the theorem two independent ways, and works through asymmetric numeric examples. It also sets up the machinery — counting elements satisfying none of several properties. This machinery powers the classical theory of Derangements, the counting of surjective functions, and enumeration of restricted Integer Partitions.

Key takeaways
  • PIE computes ∣A1∪⋯∪An∣|A_1 \cup \cdots \cup A_n| as an alternating sum of sizes of all possible intersections of the sets.
  • The two-set case ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A\cup B|=|A|+|B|-|A\cap B| is the seed; three-set and nn-set versions add correction terms recursively.
  • The complementary form counts elements satisfying none of nn properties, which is the engine behind derangements and surjection counts.
  • The proof works by tracking, for each element, how many times it is counted at each stage — this reduces to a binomial identity.
  • PIE is a special case of Möbius inversion on the subset lattice, though it can be proved without that machinery.
  • Key idea: overcounting from overlaps is corrected by alternating +/−+/- terms indexed by the sizes of all subset intersections.

Where this lives today

Inclusion-exclusion is a working tool across mathematics and its applications. In enumerative combinatorics it underlies the count of Derangements (permutations with no fixed point), the formula for Counting Surjections used above, and the enumeration of integer solutions to equations under upper-bound constraints — a technique feeding directly into Integer Partitions with bounded part sizes. In elementary number theory, PIE proves the formula for Euler's totient function φ(n)\varphi(n) by excluding multiples of each prime factor of nn, and computes counts of integers free of specified divisors, exactly as in the worked example above. In probability theory, the same alternating sum (applied to probabilities instead of cardinalities) gives Bonferroni's inequalities, used to bound event probabilities when full inclusion-exclusion is computationally infeasible. In graph theory and algorithms, PIE underlies the chromatic polynomial computation via the deletion–contraction-adjacent "broken circuit" methods and dynamic-programming algorithms (such as the Held–Karp-style inclusion-exclusion algorithms for Hamiltonian cycles and graph coloring) achieving O(2npoly(n))O(2^n \mathrm{poly}(n)) running time. In cryptography and coding theory, sieve methods analogous to PIE estimate collision probabilities and counts of "bad" keys avoiding structural weaknesses. In statistical mechanics and combinatorial physics, inclusion-exclusion sums appear in cluster expansions and in computing partition-function corrections for interacting systems on lattices.

Ask the tutor: How does inclusion-exclusion combine with the Product Rule to count permutations avoiding several forbidden positions at once, as in the derangement problem?

DefinitionPrinciple of Inclusion-Exclusion

Let UU be a finite set and let A1,A2,…,An⊆UA_1, A_2, \dots, A_n \subseteq U be finite sets (subsets of a common finite universe, or simply finite sets in their own right). For a nonempty index set I⊆{1,…,n}I \subseteq \{1,\dots,n\}, write

AI  =  ⋂i∈IAi.A_I \;=\; \bigcap_{i \in I} A_i .

The Principle of Inclusion-Exclusion states:

∣⋃i=1nAi∣  =  ∑I⊆{1,…,n}I≠∅(−1)∣I∣+1 ∣AI∣  =  ∑k=1n(−1)k+1∑1≤i1<⋯<ik≤n∣Ai1∩⋯∩Aik∣.\left| \bigcup_{i=1}^n A_i \right| \;=\; \sum_{\substack{I \subseteq \{1,\dots,n\} \\ I \neq \varnothing}} (-1)^{|I|+1} \, |A_I| \;=\; \sum_{k=1}^{n} (-1)^{k+1} \sum_{1 \le i_1 < \cdots < i_k \le n} |A_{i_1} \cap \cdots \cap A_{i_k}|.

Equivalently, if UU is a finite universe containing all AiA_i, the complementary form counts elements in none of the sets:

∣U∖⋃i=1nAi∣  =  ∑I⊆{1,…,n}(−1)∣I∣∣AI∣,where A∅:=U.\left| U \setminus \bigcup_{i=1}^n A_i \right| \;=\; \sum_{I \subseteq \{1,\dots,n\}} (-1)^{|I|} |A_I|, \qquad \text{where } A_\varnothing := U.

Intuition

Picture three overlapping disks representing A1,A2,A3A_1, A_2, A_3. If you simply add ∣A1∣+∣A2∣+∣A3∣|A_1|+|A_2|+|A_3|, every point lying in exactly two disks gets counted twice, and every point lying in all three gets counted three times. Subtracting all pairwise intersections ∣A1∩A2∣+∣A1∩A3∣+∣A2∩A3∣|A_1\cap A_2| + |A_1\cap A_3| + |A_2\cap A_3| fixes the doubly-counted points, but it removes the triply-counted point three times (once per pair), on top of having added it three times originally — net effect zero, when it should count once. Adding back ∣A1∩A2∩A3∣|A_1\cap A_2\cap A_3| restores exactly one count for that region. This alternating add/subtract/add pattern is the whole idea; the theorem below shows it persists for any number of sets, and the proof shows why the arithmetic always lands on exactly 11 for every element of the union.

Figure
Venn diagram bookkeeping for three sets: each region's net multiplicity after inclusion-exclusion is exactly 1
A₁ A₂ A₃ only A₁: +1 only A₂: +1 only A₃: +1 A₁∩A₂: +2−1=1 A₁∩A₃: +2−1=1 A₂∩A₃: +2−1=1 A₁∩A₂∩A₃: +3−3+1=1

Theorem statement and proof

TheoremPrinciple of Inclusion-Exclusion, the nn-set case

Let A1,…,AnA_1, \dots, A_n be finite sets (contained in some common finite universe UU, or considered abstractly with all pairwise and multi-wise intersections finite). Then

∣⋃i=1nAi∣=∑k=1n(−1)k+1∑1≤i1<⋯<ik≤n∣Ai1∩⋯∩Aik∣.\left| \bigcup_{i=1}^n A_i \right| = \sum_{k=1}^n (-1)^{k+1} \sum_{1\le i_1 < \cdots < i_k \le n} |A_{i_1}\cap\cdots\cap A_{i_k}|.
LemmaBinomial alternating sum

For every integer m≥1m \ge 1,

∑k=0m(−1)k(mk)=0.\sum_{k=0}^{m} (-1)^k \binom{m}{k} = 0.
Proof

This is the binomial theorem applied to (1−1)m(1-1)^m: by the Binomial Theorem (an immediate consequence of the Combinations counting rule for choosing kk objects from mm),

0=0m=(1−1)m=∑k=0m(mk)1m−k(−1)k=∑k=0m(−1)k(mk).0 = 0^m = (1-1)^m = \sum_{k=0}^m \binom{m}{k} 1^{m-k}(-1)^k = \sum_{k=0}^m (-1)^k \binom{m}{k}.

■\blacksquare

∎
Proof

Technique: double counting — we show both sides count each element of ⋃i=1nAi\bigcup_{i=1}^n A_i exactly once, by comparing, for each fixed element xx, its contribution to the left side and to the right side.

Left side. Fix x∈⋃i=1nAix \in \bigcup_{i=1}^n A_i. The left side ∣⋃Ai∣\left|\bigcup A_i\right| counts xx exactly once, since it is a plain set cardinality and xx belongs to the union.

Right side. Let

S={ i∈{1,…,n}:x∈Ai }S = \{\, i \in \{1,\dots,n\} : x \in A_i \,\}

be the (nonempty, since xx is in the union) set of indices ii for which x∈Aix \in A_i, and let m=∣S∣≥1m = |S| \ge 1. We compute how many times xx is counted in the right-hand alternating sum. For a given kk with 1≤k≤n1 \le k \le n, and a given kk-subset {i1<⋯<ik}\{i_1 < \cdots < i_k\} of {1,…,n}\{1,\dots,n\}, the element xx contributes 11 to ∣Ai1∩⋯∩Aik∣|A_{i_1}\cap \cdots \cap A_{i_k}| exactly when xx belongs to every one of Ai1,…,AikA_{i_1},\dots,A_{i_k}, i.e. exactly when {i1,…,ik}⊆S\{i_1,\dots,i_k\} \subseteq S. Since ∣S∣=m|S|=m, the number of kk-subsets I⊆{1,…,n}I \subseteq \{1,\dots,n\} with I⊆SI \subseteq S equals the number of kk-subsets of SS, which is (mk)\binom{m}{k} by the definition of Combinations (and (mk)=0\binom{m}{k}=0 automatically when k>mk>m, since SS has no kk-subsets). Therefore, xx's total signed contribution to the right-hand side is

∑k=1n(−1)k+1(mk)=−∑k=1n(−1)k(mk)=−(∑k=0n(−1)k(mk)−(m0)).\sum_{k=1}^{n} (-1)^{k+1} \binom{m}{k} = -\sum_{k=1}^{n} (-1)^{k}\binom{m}{k} = -\left(\sum_{k=0}^{n} (-1)^k \binom{m}{k} - \binom{m}{0}\right).

Because m≤nm \le n, terms with k>mk > m vanish, so ∑k=0n(−1)k(mk)=∑k=0m(−1)k(mk)=0\sum_{k=0}^n (-1)^k\binom{m}{k} = \sum_{k=0}^m (-1)^k\binom{m}{k} = 0 by the Lemma (using m≥1m \ge 1). Also (m0)=1\binom{m}{0}=1. Substituting,

x’s contribution=−(0−1)=1.x\text{'s contribution} = -\bigl(0 - 1\bigr) = 1.

So every element of ⋃Ai\bigcup A_i contributes exactly 11 to the right-hand side, matching its contribution of 11 to the left-hand side. Elements outside the union lie in no AiA_i, hence in no intersection AIA_I for nonempty II either, so they contribute 00 to both sides. Since both sides are sums of 0/10/1 contributions over all elements of UU that agree elementwise, the two sides are equal as cardinalities. ■\blacksquare

∎
CorollaryComplementary / "none of the properties" form

Let UU be a finite universe and A1,…,An⊆UA_1,\dots,A_n \subseteq U. Then the number of elements of UU lying in none of the AiA_i is

∣U∖⋃i=1nAi∣=∑I⊆{1,…,n}(−1)∣I∣∣AI∣,A∅=U.\left| U \setminus \bigcup_{i=1}^n A_i \right| = \sum_{I \subseteq \{1,\dots,n\}} (-1)^{|I|} |A_I|, \qquad A_\varnothing = U.
Proof

By the Complement Rule, ∣U∖⋃Ai∣=∣U∣−∣⋃Ai∣\left|U \setminus \bigcup A_i\right| = |U| - \left|\bigcup A_i\right|. Substitute the theorem's formula for ∣⋃Ai∣|\bigcup A_i| and note ∣U∣=(−1)0∣A∅∣|U| = (-1)^0|A_\varnothing| is exactly the missing I=∅I = \varnothing term; the rest of the sum is −∑k≥1(−1)k+1∑∣I∣=k∣AI∣=∑k≥1(−1)k∑∣I∣=k∣AI∣-\sum_{k\ge1}(-1)^{k+1}\sum_{|I|=k}|A_I| = \sum_{k\ge 1}(-1)^k \sum_{|I|=k}|A_I|, which combines with the I=∅I=\varnothing term to give precisely ∑I⊆{1,…,n}(−1)∣I∣∣AI∣\sum_{I\subseteq\{1,\dots,n\}}(-1)^{|I|}|A_I|. ■\blacksquare

∎

Worked examples

Example 1 (asymmetric divisibility count). How many integers in {1,2,…,2000}\{1, 2, \dots, 2000\} are divisible by 66, by 1010, or by 1515? Let U={1,…,2000}U = \{1,\dots,2000\}, and let A1,A2,A3A_1, A_2, A_3 be the multiples of 6,10,156, 10, 15 respectively within UU. For any dd, the number of multiples of dd in UU is ⌊2000/d⌋\lfloor 2000/d \rfloor. Singles:

∣A1∣=⌊2000/6⌋=333,∣A2∣=⌊2000/10⌋=200,∣A3∣=⌊2000/15⌋=133.|A_1| = \lfloor 2000/6\rfloor = 333, \quad |A_2| = \lfloor 2000/10\rfloor = 200, \quad |A_3| = \lfloor 2000/15\rfloor = 133.

Pairwise intersections use least common multiples: lcm(6,10)=30\mathrm{lcm}(6,10)=30, lcm(6,15)=30\mathrm{lcm}(6,15)=30, lcm(10,15)=30\mathrm{lcm}(10,15)=30.

∣A1∩A2∣=⌊2000/30⌋=66,∣A1∩A3∣=66,∣A2∩A3∣=66.|A_1\cap A_2| = \lfloor 2000/30\rfloor = 66, \quad |A_1\cap A_3| = 66, \quad |A_2\cap A_3| = 66.

Triple intersection: lcm(6,10,15)=30\mathrm{lcm}(6,10,15) = 30, so

∣A1∩A2∩A3∣=⌊2000/30⌋=66.|A_1\cap A_2\cap A_3| = \lfloor 2000/30 \rfloor = 66.

By the theorem,

∣A1∪A2∪A3∣=(333+200+133)−(66+66+66)+66=666−198+66=534.|A_1\cup A_2\cup A_3| = (333+200+133) - (66+66+66) + 66 = 666 - 198 + 66 = 534.

So exactly 534534 integers from 11 to 20002000 are divisible by 66, 1010, or 1515. (Sanity check: since lcm(6,10,15)=30\mathrm{lcm}(6,10,15)=30 and all pairwise lcms also equal 3030, actually A1∩A2=A1∩A3=A2∩A3=A1∩A2∩A3A_1\cap A_2 = A_1\cap A_3 = A_2 \cap A_3 = A_1\cap A_2\cap A_3 exactly — every number divisible by any two of 6,10,156,10,15 is automatically divisible by 3030 and hence by all three. This is a genuine, slightly surprising numerical coincidence of this example, not a hidden symmetry of the method: it happens because 6=2⋅36=2\cdot3, 10=2⋅510=2\cdot5, 15=3⋅515=3\cdot5 pairwise "cover" all three primes 2,3,52,3,5.)

Example 2 (counting onto functions — foreshadowing surjections). How many functions f:{1,2,3,4,5}→{a,b,c}f : \{1,2,3,4,5\} \to \{a,b,c\} are surjective (i.e., hit every element of the codomain)? Let UU be the set of all functions from a 55-element domain to a 33-element codomain, so ∣U∣=35=243|U| = 3^5 = 243 by the Product Rule. For i∈{a,b,c}i \in \{a,b,c\}, let AiA_i be the set of functions that miss the value ii (i.e. ii is not in the image). A function is surjective exactly when it lies in none of Aa,Ab,AcA_a, A_b, A_c — so the complementary form of PIE applies directly. A function missing a specific set I⊆{a,b,c}I \subseteq \{a,b,c\} of values is the same as a function from a 55-element set into the remaining 3−∣I∣3-|I| values, and there are (3−∣I∣)5(3-|I|)^5 such functions by the Product Rule; this quantity depends only on ∣I∣|I|, so

∣AI∣=(3−∣I∣)5.|A_I| = (3-|I|)^5.

Applying the corollary with n=3n=3 properties (missing aa, missing bb, missing cc):

#{surjections}=∑I⊆{a,b,c}(−1)∣I∣(3−∣I∣)5=∑k=03(−1)k(3k)(3−k)5.\#\{\text{surjections}\} = \sum_{I \subseteq \{a,b,c\}} (-1)^{|I|} (3-|I|)^5 = \sum_{k=0}^{3} (-1)^k \binom{3}{k} (3-k)^5.

Compute term by term:

  • k=0k=0: (30)(3)5=1⋅243=243\binom{3}{0}(3)^5 = 1 \cdot 243 = 243.
  • k=1k=1: −(31)(2)5=−3⋅32=−96-\binom{3}{1}(2)^5 = -3\cdot 32 = -96.
  • k=2k=2: (32)(1)5=3⋅1=3\binom{3}{2}(1)^5 = 3 \cdot 1 = 3.
  • k=3k=3: −(33)(0)5=−1⋅0=0-\binom{3}{3}(0)^5 = -1\cdot 0 = 0.

Sum: 243−96+3−0=150243 - 96 + 3 - 0 = 150. So there are exactly 150150 surjective functions from a 55-element set onto a 33-element set. (This matches the general surjection-count formula that PIE produces for Counting Surjections in general: ∑k=0m(−1)k(mk)(m−k)n\sum_{k=0}^{m}(-1)^k\binom{m}{k}(m-k)^n surjections from an nn-set onto an mm-set — here m=3m=3, n=5n=5.)

Counterexamplewhy finiteness of the sets is needed

Drop the hypothesis that A1,…,AnA_1,\dots,A_n are finite and the theorem collapses, because the individual cardinalities ∣Ai∣|A_i|, ∣AI∣|A_I| may be infinite (or, for infinite cardinal arithmetic, may fail to combine via ordinary subtraction at all). Concretely, let U=ZU = \mathbb{Z}, and let

A1={ x∈Z:x≥0 },A2={ x∈Z:x≤0 }.A_1 = \{\, x \in \mathbb{Z} : x \ge 0 \,\}, \qquad A_2 = \{\, x \in \mathbb{Z} : x \le 0 \,\}.

Both are infinite, and A1∪A2=ZA_1 \cup A_2 = \mathbb{Z} is infinite, while A1∩A2={0}A_1 \cap A_2 = \{0\} is finite with ∣A1∩A2∣=1|A_1\cap A_2| = 1. The formula

∣A1∪A2∣∣A1∣+∣A2∣−∣A1∩A2∣|A_1 \cup A_2| \stackrel{?}{=} |A_1| + |A_2| - |A_1\cap A_2|

would require assigning a numeric value to ∣A1∣+∣A2∣|A_1|+|A_2| and subtracting 11 from it to recover ∣A1∪A2∣|A_1\cup A_2|, but ∣A1∣|A_1| and ∣A2∣|A_2| are both the cardinal ℵ0\aleph_0, and "ℵ0+ℵ0−1\aleph_0 + \aleph_0 - 1" is not well-defined as ordinary subtraction (cardinal arithmetic has ℵ0+ℵ0=ℵ0\aleph_0+\aleph_0=\aleph_0, and there is no unique inverse operation). The proof above crucially used the finiteness of S={i:x∈Ai}S = \{i : x \in A_i\} (needed to invoke the binomial lemma with a well-defined finite mm) and used ordinary integer subtraction throughout, both of which require finite cardinalities. Without finiteness the entire double-counting argument, and the algebra it rests on, breaks down.

Scope, edge cases & common traps

SituationWhat happens
n=2n=2 setsReduces to ∣A∪B∣=∣A∣+∣B∣−∣A∩B∣|A\cup B| = |A|+|B|-|A\cap B|, the classical two-set case.
Some AiA_i pairwise disjointAll higher intersections vanish; PIE reduces to the plain Sum and Product Rules additive count.
All AiA_i equalFormula still holds but is wasteful; direct reasoning is simpler.
Infinite index set n=∞n=\inftyTheorem as stated does not apply; requires measure-theoretic or probabilistic analogues (Bonferroni-type inequalities), beyond this scope.
Complementary formRequires an ambient finite universe UU containing all AiA_i; without it "none of the properties" is undefined.

The mathematician behind it

Origins · 1 minAbraham de Moivre and how this was discovered
AD
Abraham de Moivre
1667–1754 · early probability and combinatorics in England

De Moivre, a French Huguenot mathematician who emigrated to England after the revocation of the Edict of Nantes, developed early inclusion-exclusion-type arguments in his work on probability, particularly in The Doctrine of Chances (1718), where he analyzed the probability that at least one of several events occurs. The systematic algebraic formulation of the principle for arbitrarily many sets — with the modern alternating-sum notation — was consolidated over the following two centuries, with contributions from Daniel da Silva, J. J. Sylvester, and Henri Poincaré, and is sometimes called Da Silva's formula or the Sylvester–Poincaré formula in older European texts.

History
- 1708 — De Moivre begins publishing work on games of chance involving compound event probabilities.
- 1718 — The Doctrine of Chances appears, containing early sieve-type arguments for "at least one" events.
- 1854 — Daniel da Silva publishes a rigorous general statement of the sieve formula for finite sets.
- 1883 — J. J. Sylvester writes on the combinatorial "method of exclusion" in the modern algebraic style.
- 1896 — Henri Poincaré applies inclusion-exclusion reasoning within a general combinatorial and probabilistic framework.
Is inclusion-exclusion only for two or three sets, or does it really work for any number nn?

It works for any finite n≥1n \ge 1. The two- and three-set cases are just small instances of the same general alternating-sum formula proved above. For general nn, the formula sums over all 2n−12^n - 1 nonempty subsets of indices, with the sign of each term determined solely by the size of that subset: odd-sized index sets get a ++ sign, even-sized get a −- sign. The proof by double counting (tracking how many times a fixed element is counted) works uniformly in nn, using the binomial identity ∑k=0m(−1)k(mk)=0\sum_{k=0}^m (-1)^k \binom{m}{k}=0, which holds for every m≥1m \ge 1 regardless of how large nn is.

How is this related to the Möbius function or Möbius inversion?

Inclusion-exclusion is exactly Möbius inversion on the lattice of subsets of {1,…,n}\{1,\dots,n\}, ordered by inclusion. The Möbius function of this lattice is μ(I,J)=(−1)∣J∣−∣I∣\mu(I,J) = (-1)^{|J|-|I|} for I⊆JI \subseteq J, and the general Möbius inversion formula, when specialized to this lattice and to the function I↦∣AI∣I \mapsto |A_I|, produces precisely the alternating-sum formula proved here. The combinatorial proof given in this article, however, is self-contained and does not require developing the general theory of Möbius functions on posets — it only needs elementary counting and one binomial identity.

Can PIE be used to compute probabilities instead of counts?

Yes. If A1,…,AnA_1,\dots,A_n are events in a finite (or more generally discrete) probability space, dividing every term in the theorem by the size of the sample space (or working directly with probability measure instead of counting measure) gives

P(⋃i=1nAi)=∑k=1n(−1)k+1∑i1<⋯<ikP(Ai1∩⋯∩Aik).P\Bigl(\bigcup_{i=1}^n A_i\Bigr) = \sum_{k=1}^n (-1)^{k+1}\sum_{i_1<\cdots<i_k} P(A_{i_1}\cap\cdots\cap A_{i_k}).

This is the standard probabilistic form of inclusion-exclusion, and truncating the alternating sum after kk terms gives the Bonferroni inequalities, useful upper and lower bounds when computing every intersection probability is impractical.

Why does the complementary "none of the properties" form include an I=∅I = \varnothing term equal to ∣U∣|U|?

The empty intersection over zero sets is conventionally defined to be the entire universe UU (the intersection of no constraints excludes nothing), so A∅:=UA_\varnothing := U by convention. This convention makes the corollary's formula uniform: summing (−1)∣I∣∣AI∣(-1)^{|I|}|A_I| over all subsets II, including the empty one, automatically starts from ∣U∣|U| and then subtracts, adds back, and so on — exactly matching ∣U∣−∣⋃Ai∣|U| - |\bigcup A_i| once you expand the union formula from the main theorem and combine terms.

What is the connection between PIE and counting derangements?

A derangement of {1,…,n}\{1,\dots,n\} is a permutation with no fixed point. Let UU be the set of all n!n! permutations, and let AiA_i be the set of permutations fixing position ii (so ∣Ai∣=(n−1)!|A_i| = (n-1)!, and more generally ∣AI∣=(n−∣I∣)!|A_I| = (n-|I|)! for ∣I∣|I| fixed positions). Derangements are exactly the permutations in none of the AiA_i, so the complementary form of PIE gives the derangement count Dn=∑k=0n(−1)k(nk)(n−k)!=n!∑k=0n(−1)kk!D_n = \sum_{k=0}^n (-1)^k \binom{n}{k}(n-k)!= n!\sum_{k=0}^n \frac{(-1)^k}{k!}, the classical formula developed fully under Derangements.

Does the order in which the sets A1,…,AnA_1,\dots,A_n are listed affect the formula?

No. The formula sums over all subsets II of the index set {1,…,n}\{1,\dots,n\}, and set intersection is commutative and associative, so AI=⋂i∈IAiA_I = \bigcap_{i\in I} A_i does not depend on any ordering of the elements of II. Relabeling or reordering the sets A1,…,AnA_1,\dots,A_n permutes the terms of the sum but does not change its value, since addition is also commutative. The formula is intrinsically defined in terms of the sets themselves, not any sequence in which they are presented.

Is there a version of PIE for more than two "overlapping conditions" phrased without sets, e.g. directly with logical predicates?

Yes — PIE is often stated for a finite set UU together with nn properties P1,…,PnP_1,\dots,P_n that elements of UU may or may not satisfy. Letting Ai={x∈U:x has property Pi}A_i = \{x \in U : x \text{ has property } P_i\} recovers the set formulation exactly, so the two phrasings are identical in content. This predicate phrasing is often more natural when properties are combinatorial conditions (e.g., "the permutation fixes position ii," or "the assignment violates constraint jj") rather than naturally-occurring subsets, and it is the phrasing most commonly used when applying PIE to derangements, surjections, and constraint-satisfaction counting problems.

Before this

Where this leads