Inclusion–exclusion principle
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
- <math> |A \cup B| = |A| + |B| - |A \cap B| </math>
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
- <math>|A \cup B \cup C| = |A| + |B| + |C| - |A \cap B| - |A \cap C| - |B \cap C| + |A \cap B \cap C|</math>
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.
Generalizing the results of these examples gives the principle of inclusion–exclusion. To find the cardinality of the union of Template:Mvar sets:
- Include the cardinalities of the sets.
- Exclude the cardinalities of the pairwise intersections.
- Include the cardinalities of the triple-wise intersections.
- Exclude the cardinalities of the quadruple-wise intersections.
- Include the cardinalities of the quintuple-wise intersections.
- Continue, until the cardinality of the Template:Mvar-tuple-wise intersection is included (if Template:Mvar is odd) or excluded (Template:Mvar 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),<ref name="Roberts 2009 loc=pg. 405">Template:Harvnb</ref> although it first appears in a paper of Daniel da Silva (1854)<ref>Template:Harvnb</ref> and later in a paper by J. J. Sylvester (1883).<ref>Template:Harvnb</ref> 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.<ref>Template:Harvnb</ref>
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.<ref>Template:Harvnb</ref> 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:<ref>Template:Citation</ref>
"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."
FormulaEdit
In its general formula, the principle of inclusion–exclusion states that for finite sets Template:Math, one has the identity
This can be compactly written as
- <math>\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)</math>
or
- <math>\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|.</math>
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 <math>n = 4,</math> there can be no elements that appear in more than <math>4</math> sets; equivalently, there can be no elements that appear in at least <math>5</math> sets.)
In applications it is common to see the principle expressed in its complementary form. That is, letting Template:Mvar be a finite universal set containing all of the Template:Math and letting <math>\bar{A_i}</math> denote the complement of Template:Math in Template:Mvar, by De Morgan's laws we have
- <math>\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|.</math>
As another variant of the statement, let Template:Math be a list of properties that elements of a set Template:Mvar may or may not have, then the principle of inclusion–exclusion provides a way to calculate the number of elements of Template:Mvar that have none of the properties. Just let Template:Math be the subset of elements of Template:Mvar which have the property Template:Math and use the principle in its complementary form. This variant is due to J. J. Sylvester.<ref name="Roberts 2009 loc=pg. 405"/>
Notice that if you take into account only the first Template:Math sums on the right (in the general form of the principle), then you will get an overestimate if Template:Math is odd and an underestimate if Template:Math is even.
ExamplesEdit
Counting derangementsEdit
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 mth 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 mth card correct. Then the number of orders, W, with at least one card being in the correct position, m, is
- <math>W = \left|\bigcup_{m=1}^n A_m\right|.</math>
Apply the principle of inclusion–exclusion,
- <math>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</math>
Each value <math>A_{m_1} \cap \cdots \cap A_{m_p}</math> 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 <math>m</math>. 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 <math display="inline">{n \choose p}</math> equal terms in the pth summation (see combination).
- <math>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</math>
<math>|A_1 \cap \cdots \cap A_p|</math> 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:
- <math>\begin{align}
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{align}</math>
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
- <math>Q = 1 - \frac{W}{n!} = \sum_{p=0}^n \frac{(-1)^p}{p!}, </math>
a truncation to n + 1 terms of the Taylor expansion of e−1. Thus the probability of guessing an order for a shuffled deck of cards and being incorrect about every card is approximately e−1 or 37%.
A special caseEdit
The situation that appears in the derangement example above occurs often enough to merit special attention.<ref>Template:Harvnb</ref> 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
- <math>A_J:=\bigcap_{j\in J} A_j</math>
has the same cardinality, say αk = |AJ|, for every k-element subset J of {1, ..., n}, then
- <math>\left |\bigcup_{i=1}^n A_i\right| =\sum_{k=1}^n (-1)^{k-1}\binom nk \alpha_k.</math>
Or, in the complementary form, where the universal set S has cardinality α0,
- <math>\left |S \smallsetminus \bigcup_{i=1}^n A_i\right| =\alpha_0 - \sum_{k=0}^n (-1)^{k-1}\binom nk \alpha_k.</math>
Formula generalizationEdit
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 = [n] = {1,2,...,n}. If we define <math>A_{\emptyset} = S</math>, 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:
- <math> \sum_{J \subseteq [n]} (-1)^{|J|} |A_J|.</math>
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:<ref>Template:Harvnb</ref>
- <math> \sum_{I \subseteq J} (-1)^{|J| - |I|} |A_J|.</math>
Define the sets
- <math>B_k = A_{I \cup \{ k \}} \text{ for } k \in N \smallsetminus I.</math>
We seek the number of elements in none of the Bk which, by the principle of inclusion–exclusion (with <math>B_\emptyset = A_I</math>), is
- <math>\sum_{K \subseteq N \smallsetminus I} (-1)^{|K|}|B_K|.</math>
The correspondence K ↔ J = I ∪ K 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 probabilityEdit
In probability, for events A1, ..., An in a probability space <math>(\Omega,\mathcal{F},\mathbb{P})</math>, the inclusion–exclusion principle becomes for n = 2
- <math>\mathbb{P}(A_1\cup A_2)=\mathbb{P}(A_1)+\mathbb{P}(A_2)-\mathbb{P}(A_1\cap A_2),</math>
for n = 3
- <math>\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)</math>
and in general
- <math>\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} \mathbb{P}\left(\bigcap_{i=1}^n A_i\right),</math>
which can be written in closed form as
- <math>\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),</math>
where the last sum runs over all subsets I of the indices 1, ..., n which contain exactly k elements, and
- <math>A_I:=\bigcap_{i\in I} A_i</math>
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 <math>\mathbb{P}</math> is replaced by the measure μ.
Special caseEdit
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
- <math>a_k=\mathbb{P}(A_I) \text{ for every } I\subset\{1,\ldots,n\} \text{ with } |I|=k,</math>
then the above formula simplifies to
- <math>\mathbb{P}\left(\bigcup_{i=1}^n A_i\right) =\sum_{k=1}^n (-1)^{k-1}\binom n k a_k </math>
due to the combinatorial interpretation of the binomial coefficient <math display="inline">\binom nk</math>. For example, if the events <math>A_i</math> are independent and identically distributed, then <math>\mathbb{P}(A_i) = p</math> for all i, and we have <math>a_k = p^k</math>, in which case the expression above simplifies to
- <math>\mathbb{P}\left(\bigcup_{i=1}^n A_i\right) = 1 - (1-p)^n. </math>
(This result can also be derived more simply by considering the intersection of the complements of the events <math>A_i</math>.)
An analogous simplification is possible in the case of a general measure space <math>(S, \Sigma, \mu)</math> and measurable subsets <math>A_1, \dots, A_n</math> of finite measure.
There is another formula used in point processes. Let <math>S</math> be a finite set and <math>P</math> be a random subset of <math>S</math>. Let <math>A</math> be any subset of <math>S</math>, then
<math display="block">\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 \ne 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} </math>
Other formulasEdit
The principle is sometimes stated in the form<ref>Template:Harvnb</ref> that says that if
- <math>g(A)=\sum_{S \subseteq A}f(S)</math>
then Template:NumBlk
The combinatorial and the probabilistic version of the inclusion–exclusion principle are instances of (Template:EquationNote). Template:Math proof 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)</math>
respectively for all sets <math>A</math> with <math>A \subsetneq \underline{m}</math>. This is because elements <math>a</math> of <math>\cap_{i \in \underline{m} \smallsetminus A} A_i</math> can be contained in other <math>A_i</math> (<math>A_i</math> with <math>i \in A</math>) as well, and the Template:Nowrap runs exactly through all possible extensions of the sets <math>\{A_i \mid i \in \underline{m} \smallsetminus A\}</math> with other <math>A_i</math>, counting <math>a</math> only for the set that matches the membership behavior of <math>a</math>, if <math>S</math> runs through all subsets of <math>A</math> (as in the definition of <math>g(A)</math>).
Since <math>f(\underline{m}) = 0</math>, we obtain from (Template:EquationNote) with <math>A = \underline{m}</math> that
- <math>\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})</math>
and by interchanging sides, the combinatorial and the probabilistic version of the inclusion–exclusion principle follow. }}
If one sees a number <math>n</math> as a set of its prime factors, then (Template:EquationNote) is a generalization of Möbius inversion formula for square-free natural numbers. Therefore, (Template:EquationNote) 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, (Template:EquationNote) must be generalized to multisets. For multisets instead of sets, (Template:EquationNote) becomes
where <math>A - S</math> is the multiset for which <math>(A - S) \uplus S = A</math>, 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 <math>\mu(A - S)</math> is just the <math>(-1)^{|A|-|S|}</math> of (Template:EquationNote) in case <math>A - S</math> is a set.
ApplicationsEdit
The inclusion–exclusion principle is widely used and only a few of its applications can be mentioned here.
Counting derangementsEdit
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}
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 [n! / e] where [x] 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."<ref>Template:Harvnb</ref> 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 intersectionsEdit
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 <math>\overline{A_k}</math> represent the complement of Ak with respect to some universal set A such that <math>A_k \subseteq A</math> for each k. Then we have
- <math>\bigcap_{i=1}^n A_i = \overline{\bigcup_{i=1}^n \overline{A_i}}</math>
thereby turning the problem of finding an intersection into the problem of finding a union.
Graph coloringEdit
The inclusion exclusion principle forms the basis of algorithms for a number of NP-hard graph partitioning problems, such as graph coloring.<ref name="bhk">Template:Harvnb</ref>
A well known application of the principle is the construction of the chromatic polynomial of a graph.<ref>Template:Harvnb</ref>
Bipartite graph perfect matchingsEdit
The number of perfect matchings of a bipartite graph can be calculated using the principle.<ref>Template:Harvnb</ref>
Number of onto functionsEdit
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:<ref>Template:Harvnb</ref>
- <math>\sum_{j=0}^{n} \binom{n}{j} (-1)^j (n-j)^k.</math>
Permutations with forbidden positionsEdit
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.<ref>Template:Harvnb</ref>
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 kindEdit
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}
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:<ref>Template:Harvnb</ref>
- <math>S(n,k) = \frac{1}{k!}\sum_{t=0}^k (-1)^t \binom k t (k-t)^n.</math>
Rook polynomialsEdit
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}
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 xk 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 <math>B'</math> consisting of the squares of the rectangular board that are not in B. This complementary board also has a rook polynomial <math>R_{B'}(x)</math> with coefficients <math>r_k(B').</math>
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 n ≤ m, 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:
- <math>(m)_n = m(m-1)(m-2) \cdots (m-n+1).</math>
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:<ref>Template:Harvnb</ref>
- <math> r_n(B) = \sum_{t=0}^n (-1)^t (m-t)_{n-t} r_t(B'). </math>
Euler's phi functionEdit
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}
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 ≤ k ≤ n 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 ≤ i ≤ r, where the prime factorization of
- <math>n = p_1^{a_1} p_2^{a_2} \cdots p_r^{a_r}.</math>
Then,<ref>Template:Harvnb</ref>
- <math>\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 ).</math>
Dirichlet hyperbola methodEdit
{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}
The Dirichlet hyperbola method re-expresses a sum of a multiplicative function <math>f(n)</math> by selecting a suitable Dirichlet convolution <math>f = g \ast h</math>, recognizing that the sum
- <math>F(n) = \sum_{k=1}^n f(k) = \sum_{k=1}^n \sum_{xy=k}^{} g(x) h(y)</math>
can be recast as a sum over the lattice points in a region bounded by <math>x \geq 1</math>, <math>y \geq 1</math>, and <math>xy \leq n</math>, splitting this region into two overlapping subregions, and finally using the inclusion–exclusion principle to conclude that
- <math>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).</math>
Diluted inclusion–exclusion principleEdit
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 Template:Closed-closed. Then, for every even number k in {0, ..., n}, the indicator functions satisfy the inequality:<ref>Template:Harv</ref>
- <math>1_{A_1\cup\cdots\cup A_n} \ge \sum_{j=1}^k (-1)^{j-1}\sum_{1\le i_1<\cdots<i_j\le n} p_{i_1} \dots p_{i_j} \, 1_{A_{i_1} \cap \cdots \cap A_{i_j}}.</math>
Proof of main statementEdit
Choose an element contained in the union of all sets and let <math>A_1, A_2, \dots, A_t</math> be the individual sets containing it. (Note that t > 0.) Since the element is counted precisely once by the left-hand side of equation (Template:EquationNote), 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 <math>A_1, A_2, \dots, A_t</math>. 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:
- <math>\begin{align}
|\{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{align}</math>
By the binomial theorem,
- <math> 0 = (1-1)^t= \binom{t}{0} - \binom{t}{1} + \binom{t}{2} - \cdots + (-1)^t\binom{t}{t}.</math>
Using the fact that <math>\binom{t}{0} = 1</math> and rearranging terms, we have
- <math>1 = \binom{t}{1} - \binom{t}{2} + \cdots + (-1)^{t+1}\binom{t}{t},</math>
and so, the chosen element is counted only once by the right-hand side of equation (Template:EquationNote).
Algebraic proofEdit
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
- <math>\begin{align}
&\mathbf{1}_S: X \to \{0,1\} \\ &\mathbf{1}_S(x) = \begin{cases} 1 & x \in S\\ 0 & x \notin S \end{cases} \end{align}</math>
If <math>A</math> and <math>B</math> are two subsets of <math>X</math>, then
- <math>\mathbf{1}_A \cdot\mathbf{1}_B = \mathbf{1}_{A\cap B}.</math>
Let A denote the union <math display="inline">\bigcup_{i=1}^n A_i</math> of the sets A1, ..., An. To prove the inclusion–exclusion principle in general, we first verify the identity
for indicator functions, where:
- <math>A_I = \bigcap_{i\in I} A_i.</math>
The following function
- <math>\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,</math>
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 mth factor is 1−1=0. By expanding the product on the left-hand side, equation (Template:EquationNote) follows.
To prove the inclusion–exclusion principle for the cardinality of sets, sum the equation (Template:EquationNote) over all x in the union of A1, ..., An. To derive the version used in probability, take the expectation in (Template:EquationNote). In general, integrate the equation (Template:EquationNote) with respect to μ. Always use linearity in these derivations.
See alsoEdit
- Template:Annotated link
- Template:Annotated link
- Template:Annotated link
- Template:Annotated link
- Template:Annotated link
- Template:Annotated link
NotesEdit
ReferencesEdit
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Springer
- Template:Citation
- Template:Citation
- Template:Citation
- Template:Citation
{{#if: | This article incorporates material from the following PlanetMath articles, which are licensed under the Creative Commons Attribution/Share-Alike License: {{#if: | principle of inclusion–exclusion | {{#if: 2803 | principle of inclusion–exclusion | [{{{sourceurl}}} principle of inclusion–exclusion] }} }}, {{#if: | {{{title2}}} | {{#if: | {{{title2}}} | [{{{sourceurl2}}} {{{title2}}}] }} }}{{#if: | , {{#if: | {{{title3}}} | {{#if: | {{{title3}}} | [{{{sourceurl3}}} {{{title3}}}] }} }} }}{{#if: | , {{#if: | {{{title4}}} | {{#if: | {{{title4}}} | [{{{sourceurl4}}} {{{title4}}}] }} }} }}{{#if: | , {{#if: | {{{title5}}} | {{#if: | {{{title5}}} | [{{{sourceurl5}}} {{{title5}}}] }} }} }}{{#if: | , {{#if: | {{{title6}}} | {{#if: | {{{title6}}} | [{{{sourceurl6}}} {{{title6}}}] }} }} }}{{#if: | , {{#if: | {{{title7}}} | {{#if: | {{{title7}}} | [{{{sourceurl7}}} {{{title7}}}] }} }} }}{{#if: | , {{#if: | {{{title8}}} | {{#if: | {{{title8}}} | [{{{sourceurl8}}} {{{title8}}}] }} }} }}{{#if: | , {{#if: | {{{title9}}} | {{#if: | {{{title9}}} | [{{{sourceurl9}}} {{{title9}}}] }} }} }}. | This article incorporates material from {{#if: | principle of inclusion–exclusion | principle of inclusion–exclusion}} on PlanetMath, which is licensed under the Creative Commons Attribution/Share-Alike License. }}