本帖最后由 hbghlyj 于 2022-6-27 08:36 编辑
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 $[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 . 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 ${\displaystyle {\overline {A_{k}}}}$ represent the complement of $A_k$ with respect to some universal set $A$ such that ${\displaystyle A_{k}\subseteq A}$ for each $k$. Then we have
$$\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 $P_i$ 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:
$$\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 $A_i$ be the set of positions that the element $i$ is not allowed to be in, and the property $P_i$ to be the property that a permutation puts element $i$ into a position in $A_i$, 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 $P_1$, $6 = 3!$ permutations with property $P_2$ and no permutations have properties $P_3$ or $P_4$ 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 $P_1$ and $P_2$. 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, $A_1, A_2, …, A_k$, and the properties $P_i$ meaning that the partition has box $A_i$ 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)={\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, $r_k(B)$ of $x_k$ 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'$ consisting of the squares of the rectangular board that are not in $B$. This complementary board also has a rook polynomial ${\displaystyle R_{B'}(x)}$ with coefficients ${\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 $n ≤ m$, so this coefficient is $r_n(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)\cdots (m-n+1).$$
Letting $P_i$ 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)=\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 ≤ 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 $P_i$ to be that a number in $S$ is divisible by the prime number $p_i$, for $1 ≤ i ≤ r$, where the prime factorization of
$$n=p_{1}^{{a_{1}}}p_{2}^{{a_{2}}}\cdots p_{r}^{{a_{r}}}.$$
Then,
$$ \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).$$ |