Misplaced Pages

Inclusion–exclusion principle

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Inclusion–exclusion) Counting technique in combinatorics
Venn diagram showing the union of sets A and B as everything not in white

In combinatorics, the inclusion–exclusion principle is a counting technique which generalizes the familiar method of obtaining the number of elements in the union of two finite sets; symbolically expressed as

| A B | = | A | + | B | | A B | {\displaystyle |A\cup B|=|A|+|B|-|A\cap B|}

where A and B are two finite sets and |S| indicates the cardinality of a set S (which may be considered as the number of elements of the set, if the set is finite). The formula expresses the fact that the sum of the sizes of the two sets may be too large since some elements may be counted twice. The double-counted elements are those in the intersection of the two sets and the count is corrected by subtracting the size of the intersection.

The inclusion-exclusion principle, being a generalization of the two-set case, is perhaps more clearly seen in the case of three sets, which for the sets A, B and C is given by

| A B C | = | A | + | B | + | C | | A B | | A C | | B C | + | A B C | {\displaystyle |A\cup B\cup C|=|A|+|B|+|C|-|A\cap B|-|A\cap C|-|B\cap C|+|A\cap B\cap C|}

This formula can be verified by counting how many times each region in the Venn diagram figure is included in the right-hand side of the formula. In this case, when removing the contributions of over-counted elements, the number of elements in the mutual intersection of the three sets has been subtracted too often, so must be added back in to get the correct total.

Inclusion–exclusion illustrated by a Venn diagram for three sets

Generalizing the results of these examples gives the principle of inclusion–exclusion. To find the cardinality of the union of n sets:

  1. Include the cardinalities of the sets.
  2. Exclude the cardinalities of the pairwise intersections.
  3. Include the cardinalities of the triple-wise intersections.
  4. Exclude the cardinalities of the quadruple-wise intersections.
  5. Include the cardinalities of the quintuple-wise intersections.
  6. Continue, until the cardinality of the n-tuple-wise intersection is included (if n is odd) or excluded (n even).

The name comes from the idea that the principle is based on over-generous inclusion, followed by compensating exclusion. This concept is attributed to Abraham de Moivre (1718), although it first appears in a paper of Daniel da Silva (1854) and later in a paper by J. J. Sylvester (1883). Sometimes the principle is referred to as the formula of Da Silva or Sylvester, due to these publications. The principle can be viewed as an example of the sieve method extensively used in number theory and is sometimes referred to as the sieve formula.

As finite probabilities are computed as counts relative to the cardinality of the probability space, the formulas for the principle of inclusion–exclusion remain valid when the cardinalities of the sets are replaced by finite probabilities. More generally, both versions of the principle can be put under the common umbrella of measure theory.

In a very abstract setting, the principle of inclusion–exclusion can be expressed as the calculation of the inverse of a certain matrix. This inverse has a special structure, making the principle an extremely valuable technique in combinatorics and related areas of mathematics. As Gian-Carlo Rota put it:

"One of the most useful principles of enumeration in discrete probability and combinatorial theory is the celebrated principle of inclusion–exclusion. When skillfully applied, this principle has yielded the solution to many a combinatorial problem."

Formula

In its general formula, the principle of inclusion–exclusion states that for finite sets A1, ..., An, one has the identity

| i = 1 n A i | = i = 1 n | A i | 1 i < j n | A i A j | + 1 i < j < k n | A i A j A k | + ( 1 ) n + 1 | A 1 A n | . {\displaystyle \left|\bigcup _{i=1}^{n}A_{i}\right|=\sum _{i=1}^{n}|A_{i}|-\sum _{1\leqslant i<j\leqslant n}|A_{i}\cap A_{j}|+\sum _{1\leqslant i<j<k\leqslant n}|A_{i}\cap A_{j}\cap A_{k}|-\cdots +(-1)^{n+1}\left|A_{1}\cap \cdots \cap A_{n}\right|.} (1)
Each term of the inclusion–exclusion formula gradually corrects the count until finally each portion of the Venn diagram is counted exactly once.

This can be compactly written as

| i = 1 n A i | = k = 1 n ( 1 ) k + 1 ( 1 i 1 < < i k n | A i 1 A i k | ) {\displaystyle \left|\bigcup _{i=1}^{n}A_{i}\right|=\sum _{k=1}^{n}(-1)^{k+1}\left(\sum _{1\leqslant i_{1}<\cdots <i_{k}\leqslant n}|A_{i_{1}}\cap \cdots \cap A_{i_{k}}|\right)}

or

| i = 1 n A i | = J { 1 , , n } ( 1 ) | J | + 1 | j J A j | . {\displaystyle \left|\bigcup _{i=1}^{n}A_{i}\right|=\sum _{\emptyset \neq J\subseteq \{1,\ldots ,n\}}(-1)^{|J|+1}\left|\bigcap _{j\in J}A_{j}\right|.}

In words, to count the number of elements in a finite union of finite sets, first sum the cardinalities of the individual sets, then subtract the number of elements that appear in at least two sets, then add back the number of elements that appear in at least three sets, then subtract the number of elements that appear in at least four sets, and so on. This process always ends since there can be no elements that appear in more than the number of sets in the union. (For example, if n = 4 , {\displaystyle n=4,} there can be no elements that appear in more than 4 {\displaystyle 4} sets; equivalently, there can be no elements that appear in at least 5 {\displaystyle 5} sets.)

In applications it is common to see the principle expressed in its complementary form. That is, letting S be a finite universal set containing all of the Ai and letting A i ¯ {\displaystyle {\bar {A_{i}}}} denote the complement of Ai in S, by De Morgan's laws we have

| i = 1 n A i ¯ | = | S i = 1 n A i | = | S | i = 1 n | A i | + 1 i < j n | A i A j | + ( 1 ) n | A 1 A n | . {\displaystyle \left|\bigcap _{i=1}^{n}{\bar {A_{i}}}\right|=\left|S-\bigcup _{i=1}^{n}A_{i}\right|=|S|-\sum _{i=1}^{n}|A_{i}|+\sum _{1\leqslant i<j\leqslant n}|A_{i}\cap A_{j}|-\cdots +(-1)^{n}|A_{1}\cap \cdots \cap A_{n}|.}

As another variant of the statement, let P1, ..., Pn be a list of properties that elements of a set S may or may not have, then the principle of inclusion–exclusion provides a way to calculate the number of elements of S that have none of the properties. Just let Ai be the subset of elements of S which have the property Pi and use the principle in its complementary form. This variant is due to J. J. Sylvester.

Notice that if you take into account only the first m<n sums on the right (in the general form of the principle), then you will get an overestimate if m is odd and an underestimate if m is even.

Examples

Counting derangements

A more complex example is the following.

Suppose there is a deck of n cards numbered from 1 to n. Suppose a card numbered m is in the correct position if it is the m card in the deck. How many ways, W, can the cards be shuffled with at least 1 card being in the correct position?

Begin by defining set Am, which is all of the orderings of cards with the m card correct. Then the number of orders, W, with at least one card being in the correct position, m, is

W = | m = 1 n A m | . {\displaystyle W=\left|\bigcup _{m=1}^{n}A_{m}\right|.}

Apply the principle of inclusion–exclusion,

W = m 1 = 1 n | A m 1 | 1 m 1 < m 2 n | A m 1 A m 2 | + + ( 1 ) p 1 1 m 1 < < m p n | A m 1 A m p | + {\displaystyle W=\sum _{m_{1}=1}^{n}|A_{m_{1}}|-\sum _{1\leqslant m_{1}<m_{2}\leqslant n}|A_{m_{1}}\cap A_{m_{2}}|+\cdots +(-1)^{p-1}\sum _{1\leqslant m_{1}<\cdots <m_{p}\leqslant n}|A_{m_{1}}\cap \cdots \cap A_{m_{p}}|+\cdots }

Each value A m 1 A m p {\displaystyle A_{m_{1}}\cap \cdots \cap A_{m_{p}}} represents the set of shuffles having at least p values m1, ..., mp in the correct position. Note that the number of shuffles with at least p values correct only depends on p, not on the particular values of m {\displaystyle m} . For example, the number of shuffles having the 1st, 3rd, and 17th cards in the correct position is the same as the number of shuffles having the 2nd, 5th, and 13th cards in the correct positions. It only matters that of the n cards, 3 were chosen to be in the correct position. Thus there are ( n p ) {\textstyle {n \choose p}} equal terms in the p summation (see combination).

W = ( n 1 ) | A 1 | ( n 2 ) | A 1 A 2 | + + ( 1 ) p 1 ( n p ) | A 1 A p | + {\displaystyle W={n \choose 1}|A_{1}|-{n \choose 2}|A_{1}\cap A_{2}|+\cdots +(-1)^{p-1}{n \choose p}|A_{1}\cap \cdots \cap A_{p}|+\cdots }

| A 1 A p | {\displaystyle |A_{1}\cap \cdots \cap A_{p}|} is the number of orderings having p elements in the correct position, which is equal to the number of ways of ordering the remaining n − p elements, or (n − p)!. Thus we finally get:

W = ( n 1 ) ( n 1 ) ! ( n 2 ) ( n 2 ) ! + + ( 1 ) p 1 ( n p ) ( n p ) ! + = p = 1 n ( 1 ) p 1 ( n p ) ( n p ) ! = p = 1 n ( 1 ) p 1 n ! p ! ( n p ) ! ( n p ) ! = p = 1 n ( 1 ) p 1 n ! p ! {\displaystyle {\begin{aligned}W&={n \choose 1}(n-1)!-{n \choose 2}(n-2)!+\cdots +(-1)^{p-1}{n \choose p}(n-p)!+\cdots \\&=\sum _{p=1}^{n}(-1)^{p-1}{n \choose p}(n-p)!\\&=\sum _{p=1}^{n}(-1)^{p-1}{\frac {n!}{p!(n-p)!}}(n-p)!\\&=\sum _{p=1}^{n}(-1)^{p-1}{\frac {n!}{p!}}\end{aligned}}}

A permutation where no card is in the correct position is called a derangement. Taking n! to be the total number of permutations, the probability Q that a random shuffle produces a derangement is given by

Q = 1 W n ! = p = 0 n ( 1 ) p p ! , {\displaystyle Q=1-{\frac {W}{n!}}=\sum _{p=0}^{n}{\frac {(-1)^{p}}{p!}},}

a truncation to n + 1 terms of the Taylor expansion of e. Thus the probability of guessing an order for a shuffled deck of cards and being incorrect about every card is approximately e or 37%.

A special case

The situation that appears in the derangement example above occurs often enough to merit special attention. Namely, when the size of the intersection sets appearing in the formulas for the principle of inclusion–exclusion depend only on the number of sets in the intersections and not on which sets appear. More formally, if the intersection

A J := j J A j {\displaystyle A_{J}:=\bigcap _{j\in J}A_{j}}

has the same cardinality, say αk = |AJ|, for every k-element subset J of {1, ..., n}, then

| i = 1 n A i | = k = 1 n ( 1 ) k 1 ( n k ) α k . {\displaystyle \left|\bigcup _{i=1}^{n}A_{i}\right|=\sum _{k=1}^{n}(-1)^{k-1}{\binom {n}{k}}\alpha _{k}.}

Or, in the complementary form, where the universal set S has cardinality α0,

| S i = 1 n A i | = α 0 k = 0 n ( 1 ) k 1 ( n k ) α k . {\displaystyle \left|S\smallsetminus \bigcup _{i=1}^{n}A_{i}\right|=\alpha _{0}-\sum _{k=0}^{n}(-1)^{k-1}{\binom {n}{k}}\alpha _{k}.}

Formula generalization

Given a family (repeats allowed) of subsets A1, A2, ..., An of a universal set S, the principle of inclusion–exclusion calculates the number of elements of S in none of these subsets. A generalization of this concept would calculate the number of elements of S which appear in exactly some fixed m of these sets.

Let N = = {1,2,...,n}. If we define A = S {\displaystyle A_{\emptyset }=S} , then the principle of inclusion–exclusion can be written as, using the notation of the previous section; the number of elements of S contained in none of the Ai is:

J [ n ] ( 1 ) | J | | A J | . {\displaystyle \sum _{J\subseteq }(-1)^{|J|}|A_{J}|.}

If I is a fixed subset of the index set N, then the number of elements which belong to Ai for all i in I and for no other values is:

I J ( 1 ) | J | | I | | A J | . {\displaystyle \sum _{I\subseteq J}(-1)^{|J|-|I|}|A_{J}|.}

Define the sets

B k = A I { k }  for  k N I . {\displaystyle B_{k}=A_{I\cup \{k\}}{\text{ for }}k\in N\smallsetminus I.}

We seek the number of elements in none of the Bk which, by the principle of inclusion–exclusion (with B = A I {\displaystyle B_{\emptyset }=A_{I}} ), is

K N I ( 1 ) | K | | B K | . {\displaystyle \sum _{K\subseteq N\smallsetminus I}(-1)^{|K|}|B_{K}|.}

The correspondence KJ = IK between subsets of N \ I and subsets of N containing I is a bijection and if J and K correspond under this map then BK = AJ, showing that the result is valid.

In probability

In probability, for events A1, ..., An in a probability space ( Ω , F , P ) {\displaystyle (\Omega ,{\mathcal {F}},\mathbb {P} )} , the inclusion–exclusion principle becomes for n = 2

P ( A 1 A 2 ) = P ( A 1 ) + P ( A 2 ) P ( A 1 A 2 ) , {\displaystyle \mathbb {P} (A_{1}\cup A_{2})=\mathbb {P} (A_{1})+\mathbb {P} (A_{2})-\mathbb {P} (A_{1}\cap A_{2}),}

for n = 3

P ( A 1 A 2 A 3 ) = P ( A 1 ) + P ( A 2 ) + P ( A 3 ) P ( A 1 A 2 ) P ( A 1 A 3 ) P ( A 2 A 3 ) + P ( A 1 A 2 A 3 ) {\displaystyle \mathbb {P} (A_{1}\cup A_{2}\cup A_{3})=\mathbb {P} (A_{1})+\mathbb {P} (A_{2})+\mathbb {P} (A_{3})-\mathbb {P} (A_{1}\cap A_{2})-\mathbb {P} (A_{1}\cap A_{3})-\mathbb {P} (A_{2}\cap A_{3})+\mathbb {P} (A_{1}\cap A_{2}\cap A_{3})}

and in general

P ( i = 1 n A i ) = i = 1 n P ( A i ) i < j P ( A i A j ) + i < j < k P ( A i A j A k ) + + ( 1 ) n 1 i < . . . < n P ( i = 1 n A i ) , {\displaystyle \mathbb {P} \left(\bigcup _{i=1}^{n}A_{i}\right)=\sum _{i=1}^{n}\mathbb {P} (A_{i})-\sum _{i<j}\mathbb {P} (A_{i}\cap A_{j})+\sum _{i<j<k}\mathbb {P} (A_{i}\cap A_{j}\cap A_{k})+\cdots +(-1)^{n-1}\sum _{i<...<n}\mathbb {P} \left(\bigcap _{i=1}^{n}A_{i}\right),}

which can be written in closed form as

P ( i = 1 n A i ) = k = 1 n ( ( 1 ) k 1 I { 1 , , n } | I | = k P ( A I ) ) , {\displaystyle \mathbb {P} \left(\bigcup _{i=1}^{n}A_{i}\right)=\sum _{k=1}^{n}\left((-1)^{k-1}\sum _{I\subseteq \{1,\ldots ,n\} \atop |I|=k}\mathbb {P} (A_{I})\right),}

where the last sum runs over all subsets I of the indices 1, ..., n which contain exactly k elements, and

A I := i I A i {\displaystyle A_{I}:=\bigcap _{i\in I}A_{i}}

denotes the intersection of all those Ai with index in I.

According to the Bonferroni inequalities, the sum of the first terms in the formula is alternately an upper bound and a lower bound for the LHS. This can be used in cases where the full formula is too cumbersome.

For a general measure space (S,Σ,μ) and measurable subsets A1, ..., An of finite measure, the above identities also hold when the probability measure P {\displaystyle \mathbb {P} } is replaced by the measure μ.

Special case

If, in the probabilistic version of the inclusion–exclusion principle, the probability of the intersection AI only depends on the cardinality of I, meaning that for every k in {1, ..., n} there is an ak such that

a k = P ( A I )  for every  I { 1 , , n }  with  | I | = k , {\displaystyle a_{k}=\mathbb {P} (A_{I}){\text{ for every }}I\subset \{1,\ldots ,n\}{\text{ with }}|I|=k,}

then the above formula simplifies to

P ( i = 1 n A i ) = k = 1 n ( 1 ) k 1 ( n k ) a k {\displaystyle \mathbb {P} \left(\bigcup _{i=1}^{n}A_{i}\right)=\sum _{k=1}^{n}(-1)^{k-1}{\binom {n}{k}}a_{k}}

due to the combinatorial interpretation of the binomial coefficient ( n k ) {\textstyle {\binom {n}{k}}} . For example, if the events A i {\displaystyle A_{i}} are independent and identically distributed, then P ( A i ) = p {\displaystyle \mathbb {P} (A_{i})=p} for all i, and we have a k = p k {\displaystyle a_{k}=p^{k}} , in which case the expression above simplifies to

P ( i = 1 n A i ) = 1 ( 1 p ) n . {\displaystyle \mathbb {P} \left(\bigcup _{i=1}^{n}A_{i}\right)=1-(1-p)^{n}.}

(This result can also be derived more simply by considering the intersection of the complements of the events A i {\displaystyle A_{i}} .)

An analogous simplification is possible in the case of a general measure space ( S , Σ , μ ) {\displaystyle (S,\Sigma ,\mu )} and measurable subsets A 1 , , A n {\displaystyle A_{1},\dots ,A_{n}} of finite measure.

There is another formula used in point processes. Let S {\displaystyle S} be a finite set and P {\displaystyle P} be a random subset of S {\displaystyle S} . Let A {\displaystyle A} be any subset of S {\displaystyle S} , then

P ( P = A ) = P ( P A ) j 1 S A P ( P A j 1 ) + j 1 , j 2 S A   j 1 j 2 P ( P A j 1 , j 2 ) + + ( 1 ) | S | | A | P ( P S ) = A J S ( 1 ) | J | | A | P ( P J ) . {\displaystyle {\begin{aligned}\mathbb {P} (P=A)&=\mathbb {P} (P\supset A)-\sum _{j_{1}\in S\setminus A}\mathbb {P} (P\supset A\cup {j_{1}})\\&+\sum _{j_{1},j_{2}\in S\setminus A\ j_{1}\neq j_{2}}\mathbb {P} (P\supset A\cup {j_{1},j_{2}})+\dots \\&+(-1)^{|S|-|A|}\mathbb {P} (P\supset S)\\&=\sum _{A\subset J\subset S}(-1)^{|J|-|A|}\mathbb {P} (P\supset J).\end{aligned}}}

Other formulas

The principle is sometimes stated in the form that says that if

g ( A ) = S A f ( S ) {\displaystyle g(A)=\sum _{S\subseteq A}f(S)}

then

f ( A ) = S A ( 1 ) | A | | S | g ( S ) {\displaystyle f(A)=\sum _{S\subseteq A}(-1)^{|A|-|S|}g(S)} (2)

The combinatorial and the probabilistic version of the inclusion–exclusion principle are instances of (2).

Proof

Take m _ = { 1 , 2 , , m } {\displaystyle {\underline {m}}=\{1,2,\ldots ,m\}} , f ( m _ ) = 0 {\displaystyle f({\underline {m}})=0} , and

f ( S ) = | i m _ S A i i S A i |  and  f ( S ) = P ( i m _ S A i i S A i ) {\displaystyle f(S)=\left|\bigcap _{i\in {\underline {m}}\smallsetminus S}A_{i}\smallsetminus \bigcup _{i\in S}A_{i}\right|{\text{ and }}f(S)=\mathbb {P} \left(\bigcap _{i\in {\underline {m}}\smallsetminus S}A_{i}\smallsetminus \bigcup _{i\in S}A_{i}\right)}

respectively for all sets S {\displaystyle S} with S m _ {\displaystyle S\subsetneq {\underline {m}}} . Then we obtain

g ( A ) = | i m _ A A i | , g ( m _ ) = | i m _ A i |  and  g ( A ) = P ( i m _ A A i ) ,     g ( m _ ) = P ( i m _ A i ) {\displaystyle g(A)=\left|\bigcap _{i\in {\underline {m}}\smallsetminus A}A_{i}\right|,\quad g({\underline {m}})=\left|\bigcup _{i\in {\underline {m}}}A_{i}\right|{\text{ and }}g(A)=\mathbb {P} \left(\bigcap _{i\in {\underline {m}}\smallsetminus A}A_{i}\right),~~g({\underline {m}})=\mathbb {P} \left(\bigcup _{i\in {\underline {m}}}A_{i}\right)}

respectively for all sets A {\displaystyle A} with A m _ {\displaystyle A\subsetneq {\underline {m}}} . This is because elements a {\displaystyle a} of i m _ A A i {\displaystyle \cap _{i\in {\underline {m}}\smallsetminus A}A_{i}} can be contained in other A i {\displaystyle A_{i}} ( A i {\displaystyle A_{i}} with i A {\displaystyle i\in A} ) as well, and the {\displaystyle \cap \smallsetminus \cup } -formula runs exactly through all possible extensions of the sets { A i i m _ A } {\displaystyle \{A_{i}\mid i\in {\underline {m}}\smallsetminus A\}} with other A i {\displaystyle A_{i}} , counting a {\displaystyle a} only for the set that matches the membership behavior of a {\displaystyle a} , if S {\displaystyle S} runs through all subsets of A {\displaystyle A} (as in the definition of g ( A ) {\displaystyle g(A)} ).

Since f ( m _ ) = 0 {\displaystyle f({\underline {m}})=0} , we obtain from (2) with A = m _ {\displaystyle A={\underline {m}}} that

m _ T ( 1 ) | T | 1 g ( m _ T ) = S m _ ( 1 ) m | S | 1 g ( S ) = g ( m _ ) {\displaystyle \sum _{{\underline {m}}\supseteq T\supsetneq \varnothing }(-1)^{|T|-1}g({\underline {m}}\smallsetminus T)=\sum _{\varnothing \subseteq S\subsetneq {\underline {m}}}(-1)^{m-|S|-1}g(S)=g({\underline {m}})}

and by interchanging sides, the combinatorial and the probabilistic version of the inclusion–exclusion principle follow.

If one sees a number n {\displaystyle n} as a set of its prime factors, then (2) is a generalization of Möbius inversion formula for square-free natural numbers. Therefore, (2) is seen as the Möbius inversion formula for the incidence algebra of the partially ordered set of all subsets of A.

For a generalization of the full version of Möbius inversion formula, (2) must be generalized to multisets. For multisets instead of sets, (2) becomes

f ( A ) = S A μ ( A S ) g ( S ) {\displaystyle f(A)=\sum _{S\subseteq A}\mu (A-S)g(S)} (3)

where A S {\displaystyle A-S} is the multiset for which ( A S ) S = A {\displaystyle (A-S)\uplus S=A} , and

  • μ(S) = 1 if S is a set (i.e. a multiset without double elements) of even cardinality.
  • μ(S) = −1 if S is a set (i.e. a multiset without double elements) of odd cardinality.
  • μ(S) = 0 if S is a proper multiset (i.e. S has double elements).

Notice that μ ( A S ) {\displaystyle \mu (A-S)} is just the ( 1 ) | A | | S | {\displaystyle (-1)^{|A|-|S|}} of (2) in case A S {\displaystyle A-S} is a set.

Proof of (3)

Substitute g ( S ) = T S f ( T ) {\displaystyle g(S)=\sum _{T\subseteq S}f(T)} on the right hand side of (3). Notice that f ( A ) {\displaystyle f(A)} appears once on both sides of (3). So we must show that for all T {\displaystyle T} with T A {\displaystyle T\subsetneq A} , the terms f ( T ) {\displaystyle f(T)} cancel out on the right hand side of (3). For that purpose, take a fixed T {\displaystyle T} such that T A {\displaystyle T\subsetneq A} and take an arbitrary fixed a A {\displaystyle a\in A} such that a T {\displaystyle a\notin T} .

Notice that A S {\displaystyle A-S} must be a set for each positive or negative appearance of f ( T ) {\displaystyle f(T)} on the right hand side of (3) that is obtained by way of the multiset S {\displaystyle S} such that T S A {\displaystyle T\subseteq S\subseteq A} . Now each appearance of f ( T ) {\displaystyle f(T)} on the right hand side of (3) that is obtained by way of S {\displaystyle S} such that A S {\displaystyle A-S} is a set that contains a {\displaystyle a} cancels out with the one that is obtained by way of the corresponding S {\displaystyle S} such that A S {\displaystyle A-S} is a set that does not contain a {\displaystyle a} . This gives the desired result.

Applications

The inclusion–exclusion principle is widely used and only a few of its applications can be mentioned here.

Counting derangements

Main article: Derangement

A well-known application of the inclusion–exclusion principle is to the combinatorial problem of counting all derangements of a finite set. A derangement of a set A is a bijection from A into itself that has no fixed points. Via the inclusion–exclusion principle one can show that if the cardinality of A is n, then the number of derangements is where denotes the nearest integer to x; a detailed proof is available here and also see the examples section above.

The first occurrence of the problem of counting the number of derangements is in an early book on games of chance: Essai d'analyse sur les jeux de hazard by P. R. de Montmort (1678 – 1719) and was known as either "Montmort's problem" or by the name he gave it, "problème des rencontres." The problem is also known as the hatcheck problem.

The number of derangements is also known as the subfactorial of n, written !n. It follows that if all bijections are assigned the same probability then the probability that a random bijection is a derangement quickly approaches 1/e as n grows.

Counting intersections

The principle of inclusion–exclusion, combined with De Morgan's law, can be used to count the cardinality of the intersection of sets as well. Let A k ¯ {\displaystyle {\overline {A_{k}}}} represent the complement of Ak with respect to some universal set A such that A k A {\displaystyle A_{k}\subseteq A} for each k. Then we have

i = 1 n A i = i = 1 n A i ¯ ¯ {\displaystyle \bigcap _{i=1}^{n}A_{i}={\overline {\bigcup _{i=1}^{n}{\overline {A_{i}}}}}}

thereby turning the problem of finding an intersection into the problem of finding a union.

Graph coloring

The inclusion exclusion principle forms the basis of algorithms for a number of NP-hard graph partitioning problems, such as graph coloring.

A well known application of the principle is the construction of the chromatic polynomial of a graph.

Bipartite graph perfect matchings

The number of perfect matchings of a bipartite graph can be calculated using the principle.

Number of onto functions

Given finite sets A and B, how many surjective functions (onto functions) are there from A to B? Without any loss of generality we may take A = {1, ..., k} and B = {1, ..., n}, since only the cardinalities of the sets matter. By using S as the set of all functions from A to B, and defining, for each i in B, the property Pi as "the function misses the element i in B" (i is not in the image of the function), the principle of inclusion–exclusion gives the number of onto functions between A and B as:

j = 0 n ( n j ) ( 1 ) j ( n j ) k . {\displaystyle \sum _{j=0}^{n}{\binom {n}{j}}(-1)^{j}(n-j)^{k}.}

Permutations with forbidden positions

A permutation of the set S = {1, ..., n} where each element of S is restricted to not being in certain positions (here the permutation is considered as an ordering of the elements of S) is called a permutation with forbidden positions. For example, with S = {1,2,3,4}, the permutations with the restriction that the element 1 can not be in positions 1 or 3, and the element 2 can not be in position 4 are: 2134, 2143, 3124, 4123, 2341, 2431, 3241, 3421, 4231 and 4321. By letting Ai be the set of positions that the element i is not allowed to be in, and the property Pi to be the property that a permutation puts element i into a position in Ai, the principle of inclusion–exclusion can be used to count the number of permutations which satisfy all the restrictions.

In the given example, there are 12 = 2(3!) permutations with property P1, 6 = 3! permutations with property P2 and no permutations have properties P3 or P4 as there are no restrictions for these two elements. The number of permutations satisfying the restrictions is thus:

4! − (12 + 6 + 0 + 0) + (4) = 24 − 18 + 4 = 10.

The final 4 in this computation is the number of permutations having both properties P1 and P2. There are no other non-zero contributions to the formula.

Stirling numbers of the second kind

Main article: Stirling numbers of the second kind

The Stirling numbers of the second kind, S(n,k) count the number of partitions of a set of n elements into k non-empty subsets (indistinguishable boxes). An explicit formula for them can be obtained by applying the principle of inclusion–exclusion to a very closely related problem, namely, counting the number of partitions of an n-set into k non-empty but distinguishable boxes (ordered non-empty subsets). Using the universal set consisting of all partitions of the n-set into k (possibly empty) distinguishable boxes, A1, A2, ..., Ak, and the properties Pi meaning that the partition has box Ai empty, the principle of inclusion–exclusion gives an answer for the related result. Dividing by k! to remove the artificial ordering gives the Stirling number of the second kind:

S ( n , k ) = 1 k ! t = 0 k ( 1 ) t ( k t ) ( k t ) n . {\displaystyle S(n,k)={\frac {1}{k!}}\sum _{t=0}^{k}(-1)^{t}{\binom {k}{t}}(k-t)^{n}.}

Rook polynomials

Main article: Rook polynomial

A rook polynomial is the generating function of the number of ways to place non-attacking rooks on a board B that looks like a subset of the squares of a checkerboard; that is, no two rooks may be in the same row or column. The board B is any subset of the squares of a rectangular board with n rows and m columns; we think of it as the squares in which one is allowed to put a rook. The coefficient, rk(B) of x in the rook polynomial RB(x) is the number of ways k rooks, none of which attacks another, can be arranged in the squares of B. For any board B, there is a complementary board B {\displaystyle B'} consisting of the squares of the rectangular board that are not in B. This complementary board also has a rook polynomial R B ( x ) {\displaystyle R_{B'}(x)} with coefficients r k ( B ) . {\displaystyle r_{k}(B').}

It is sometimes convenient to be able to calculate the highest coefficient of a rook polynomial in terms of the coefficients of the rook polynomial of the complementary board. Without loss of generality we can assume that nm, so this coefficient is rn(B). The number of ways to place n non-attacking rooks on the complete n × m "checkerboard" (without regard as to whether the rooks are placed in the squares of the board B) is given by the falling factorial:

( m ) n = m ( m 1 ) ( m 2 ) ( m n + 1 ) . {\displaystyle (m)_{n}=m(m-1)(m-2)\cdots (m-n+1).}

Letting Pi be the property that an assignment of n non-attacking rooks on the complete board has a rook in column i which is not in a square of the board B, then by the principle of inclusion–exclusion we have:

r n ( B ) = t = 0 n ( 1 ) t ( m t ) n t r t ( B ) . {\displaystyle r_{n}(B)=\sum _{t=0}^{n}(-1)^{t}(m-t)_{n-t}r_{t}(B').}

Euler's phi function

Main article: Euler's totient function

Euler's totient or phi function, φ(n) is an arithmetic function that counts the number of positive integers less than or equal to n that are relatively prime to n. That is, if n is a positive integer, then φ(n) is the number of integers k in the range 1 ≤ kn which have no common factor with n other than 1. The principle of inclusion–exclusion is used to obtain a formula for φ(n). Let S be the set {1, ..., n} and define the property Pi to be that a number in S is divisible by the prime number pi, for 1 ≤ ir, where the prime factorization of

n = p 1 a 1 p 2 a 2 p r a r . {\displaystyle n=p_{1}^{a_{1}}p_{2}^{a_{2}}\cdots p_{r}^{a_{r}}.}

Then,

φ ( n ) = n i = 1 r n p i + 1 i < j r n p i p j = n i = 1 r ( 1 1 p i ) . {\displaystyle \varphi (n)=n-\sum _{i=1}^{r}{\frac {n}{p_{i}}}+\sum _{1\leqslant i<j\leqslant r}{\frac {n}{p_{i}p_{j}}}-\cdots =n\prod _{i=1}^{r}\left(1-{\frac {1}{p_{i}}}\right).}

Dirichlet hyperbola method

Main article: Dirichlet hyperbola method
An example of the Dirichlet hyperbola method with n = 10 , {\displaystyle n=10,} a 2.7 , {\displaystyle a\approx 2.7,} and b 3.7. {\displaystyle b\approx 3.7.}

The Dirichlet hyperbola method re-expresses a sum of a multiplicative function f ( n ) {\displaystyle f(n)} by selecting a suitable Dirichlet convolution f = g h {\displaystyle f=g\ast h} , recognizing that the sum

F ( n ) = k = 1 n f ( k ) = k = 1 n x y = k g ( x ) h ( y ) {\displaystyle F(n)=\sum _{k=1}^{n}f(k)=\sum _{k=1}^{n}\sum _{xy=k}^{}g(x)h(y)}

can be recast as a sum over the lattice points in a region bounded by x 1 {\displaystyle x\geq 1} , y 1 {\displaystyle y\geq 1} , and x y n {\displaystyle xy\leq n} , splitting this region into two overlapping subregions, and finally using the inclusion–exclusion principle to conclude that

F ( n ) = k = 1 n f ( k ) = k = 1 n x y = k g ( x ) h ( y ) = x = 1 a y = 1 n / x g ( x ) h ( y ) + y = 1 b x = 1 n / y g ( x ) h ( y ) x = 1 a y = 1 b g ( x ) h ( y ) . {\displaystyle F(n)=\sum _{k=1}^{n}f(k)=\sum _{k=1}^{n}\sum _{xy=k}^{}g(x)h(y)=\sum _{x=1}^{a}\sum _{y=1}^{n/x}g(x)h(y)+\sum _{y=1}^{b}\sum _{x=1}^{n/y}g(x)h(y)-\sum _{x=1}^{a}\sum _{y=1}^{b}g(x)h(y).}

Diluted inclusion–exclusion principle

See also: Bonferroni inequalities

In many cases where the principle could give an exact formula (in particular, counting prime numbers using the sieve of Eratosthenes), the formula arising does not offer useful content because the number of terms in it is excessive. If each term individually can be estimated accurately, the accumulation of errors may imply that the inclusion–exclusion formula is not directly applicable. In number theory, this difficulty was addressed by Viggo Brun. After a slow start, his ideas were taken up by others, and a large variety of sieve methods developed. These for example may try to find upper bounds for the "sieved" sets, rather than an exact formula.

Let A1, ..., An be arbitrary sets and p1, ..., pn real numbers in the closed unit interval [0, 1]. Then, for every even number k in {0, ..., n}, the indicator functions satisfy the inequality:

1 A 1 A n j = 1 k ( 1 ) j 1 1 i 1 < < i j n p i 1 p i j 1 A i 1 A i j . {\displaystyle 1_{A_{1}\cup \cdots \cup A_{n}}\geq \sum _{j=1}^{k}(-1)^{j-1}\sum _{1\leq i_{1}<\cdots <i_{j}\leq n}p_{i_{1}}\dots p_{i_{j}}\,1_{A_{i_{1}}\cap \cdots \cap A_{i_{j}}}.}

Proof of main statement

Choose an element contained in the union of all sets and let A 1 , A 2 , , A t {\displaystyle A_{1},A_{2},\dots ,A_{t}} be the individual sets containing it. (Note that t > 0.) Since the element is counted precisely once by the left-hand side of equation (1), we need to show that it is counted precisely once by the right-hand side. On the right-hand side, the only non-zero contributions occur when all the subsets in a particular term contain the chosen element, that is, all the subsets are selected from A 1 , A 2 , , A t {\displaystyle A_{1},A_{2},\dots ,A_{t}} . The contribution is one for each of these sets (plus or minus depending on the term) and therefore is just the (signed) number of these subsets used in the term. We then have:

| { A i 1 i t } | | { A i A j 1 i < j t } | + + ( 1 ) t + 1 | { A 1 A 2 A t } | = ( t 1 ) ( t 2 ) + + ( 1 ) t + 1 ( t t ) . {\displaystyle {\begin{aligned}|\{A_{i}\mid 1\leqslant i\leqslant t\}|&-|\{A_{i}\cap A_{j}\mid 1\leqslant i<j\leqslant t\}|+\cdots +(-1)^{t+1}|\{A_{1}\cap A_{2}\cap \cdots \cap A_{t}\}|={\binom {t}{1}}-{\binom {t}{2}}+\cdots +(-1)^{t+1}{\binom {t}{t}}.\end{aligned}}}

By the binomial theorem,

0 = ( 1 1 ) t = ( t 0 ) ( t 1 ) + ( t 2 ) + ( 1 ) t ( t t ) . {\displaystyle 0=(1-1)^{t}={\binom {t}{0}}-{\binom {t}{1}}+{\binom {t}{2}}-\cdots +(-1)^{t}{\binom {t}{t}}.}

Using the fact that ( t 0 ) = 1 {\displaystyle {\binom {t}{0}}=1} and rearranging terms, we have

1 = ( t 1 ) ( t 2 ) + + ( 1 ) t + 1 ( t t ) , {\displaystyle 1={\binom {t}{1}}-{\binom {t}{2}}+\cdots +(-1)^{t+1}{\binom {t}{t}},}

and so, the chosen element is counted only once by the right-hand side of equation (1).

Algebraic proof

An algebraic proof can be obtained using indicator functions (also known as characteristic functions). The indicator function of a subset S of a set X is the function

1 S : X { 0 , 1 } 1 S ( x ) = { 1 x S 0 x S {\displaystyle {\begin{aligned}&\mathbf {1} _{S}:X\to \{0,1\}\\&\mathbf {1} _{S}(x)={\begin{cases}1&x\in S\\0&x\notin S\end{cases}}\end{aligned}}}

If A {\displaystyle A} and B {\displaystyle B} are two subsets of X {\displaystyle X} , then

1 A 1 B = 1 A B . {\displaystyle \mathbf {1} _{A}\cdot \mathbf {1} _{B}=\mathbf {1} _{A\cap B}.}

Let A denote the union i = 1 n A i {\textstyle \bigcup _{i=1}^{n}A_{i}} of the sets A1, ..., An. To prove the inclusion–exclusion principle in general, we first verify the identity

1 A = k = 1 n ( 1 ) k 1 I { 1 , , n } | I | = k 1 A I {\displaystyle \mathbf {1} _{A}=\sum _{k=1}^{n}(-1)^{k-1}\sum _{I\subset \{1,\ldots ,n\} \atop |I|=k}\mathbf {1} _{A_{I}}} (4)

for indicator functions, where:

A I = i I A i . {\displaystyle A_{I}=\bigcap _{i\in I}A_{i}.}

The following function

( 1 A 1 A 1 ) ( 1 A 1 A 2 ) ( 1 A 1 A n ) = 0 , {\displaystyle \left(\mathbf {1} _{A}-\mathbf {1} _{A_{1}}\right)\left(\mathbf {1} _{A}-\mathbf {1} _{A_{2}}\right)\cdots \left(\mathbf {1} _{A}-\mathbf {1} _{A_{n}}\right)=0,}

is identically zero because: if x is not in A, then all factors are 0−0 = 0; and otherwise, if x does belong to some Am, then the corresponding m factor is 1−1=0. By expanding the product on the left-hand side, equation (4) follows.

To prove the inclusion–exclusion principle for the cardinality of sets, sum the equation (4) over all x in the union of A1, ..., An. To derive the version used in probability, take the expectation in (4). In general, integrate the equation (4) with respect to μ. Always use linearity in these derivations.

See also

Notes

  1. ^ Roberts & Tesman 2009, pg. 405
  2. Mazur 2010, pg. 94
  3. van Lint & Wilson 1992, pg. 77
  4. van Lint & Wilson 1992, pg. 77
  5. Stanley 1986, pg. 64
  6. Rota, Gian-Carlo (1964), "On the foundations of combinatorial theory I. Theory of Möbius functions", Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 2 (4): 340–368, doi:10.1007/BF00531932, S2CID 121334025
  7. Brualdi 2010, pp. 167–8
  8. Cameron 1994, pg. 78
  9. Graham, Grötschel & Lovász 1995, pg. 1049
  10. van Lint & Wilson 1992, pp. 77-8
  11. Björklund, Husfeldt & Koivisto 2009
  12. Gross 2008, pp. 211–13
  13. Gross 2008, pp. 208–10
  14. Mazur 2010, pp.84-5, 90
  15. Brualdi 2010, pp. 177–81
  16. Brualdi 2010, pp. 282–7
  17. Roberts & Tesman 2009, pp.419–20
  18. van Lint & Wilson 1992, pg. 73
  19. (Fernández, Fröhlich & Alan D. 1992, Proposition 12.6)

References

This article incorporates material from principle of inclusion–exclusion on PlanetMath, which is licensed under the Creative Commons Attribution/Share-Alike License.

Categories: