Skip to main content
\(\newcommand{\set}[1]{\{1,2,\dotsc,#1\,\}} \newcommand{\ints}{\mathbb{Z}} \newcommand{\posints}{\mathbb{N}} \newcommand{\rats}{\mathbb{Q}} \newcommand{\reals}{\mathbb{R}} \newcommand{\complexes}{\mathbb{C}} \newcommand{\twospace}{\mathbb{R}^2} \newcommand{\threepace}{\mathbb{R}^3} \newcommand{\dspace}{\mathbb{R}^d} \newcommand{\nni}{\mathbb{N}_0} \newcommand{\nonnegints}{\mathbb{N}_0} \newcommand{\dom}{\operatorname{dom}} \newcommand{\ran}{\operatorname{ran}} \newcommand{\prob}{\operatorname{prob}} \newcommand{\Prob}{\operatorname{Prob}} \newcommand{\height}{\operatorname{height}} \newcommand{\width}{\operatorname{width}} \newcommand{\length}{\operatorname{length}} \newcommand{\crit}{\operatorname{crit}} \newcommand{\inc}{\operatorname{inc}} \newcommand{\HP}{\mathbf{H_P}} \newcommand{\HCP}{\mathbf{H^c_P}} \newcommand{\GP}{\mathbf{G_P}} \newcommand{\GQ}{\mathbf{G_Q}} \newcommand{\AG}{\mathbf{A_G}} \newcommand{\GCP}{\mathbf{G^c_P}} \newcommand{\PXP}{\mathbf{P}=(X,P)} \newcommand{\QYQ}{\mathbf{Q}=(Y,Q)} \newcommand{\GVE}{\mathbf{G}=(V,E)} \newcommand{\HWF}{\mathbf{H}=(W,F)} \newcommand{\bfC}{\mathbf{C}} \newcommand{\bfG}{\mathbf{G}} \newcommand{\bfH}{\mathbf{H}} \newcommand{\bfF}{\mathbf{F}} \newcommand{\bfI}{\mathbf{I}} \newcommand{\bfK}{\mathbf{K}} \newcommand{\bfP}{\mathbf{P}} \newcommand{\bfQ}{\mathbf{Q}} \newcommand{\bfR}{\mathbf{R}} \newcommand{\bfS}{\mathbf{S}} \newcommand{\bfT}{\mathbf{T}} \newcommand{\bfNP}{\mathbf{NP}} \newcommand{\bftwo}{\mathbf{2}} \newcommand{\cgA}{\mathcal{A}} \newcommand{\cgB}{\mathcal{B}} \newcommand{\cgC}{\mathcal{C}} \newcommand{\cgD}{\mathcal{D}} \newcommand{\cgE}{\mathcal{E}} \newcommand{\cgF}{\mathcal{F}} \newcommand{\cgG}{\mathcal{G}} \newcommand{\cgM}{\mathcal{M}} \newcommand{\cgN}{\mathcal{N}} \newcommand{\cgP}{\mathcal{P}} \newcommand{\cgR}{\mathcal{R}} \newcommand{\cgS}{\mathcal{S}} \newcommand{\bfn}{\mathbf{n}} \newcommand{\bfm}{\mathbf{m}} \newcommand{\bfk}{\mathbf{k}} \newcommand{\bfs}{\mathbf{s}} \newcommand{\bijection}{\xrightarrow[\text{onto}]{\text{$1$--$1$}}} \newcommand{\injection}{\xrightarrow[]{\text{$1$--$1$}}} \newcommand{\surjection}{\xrightarrow[\text{onto}]{}} \newcommand{\nin}{\not\in} \newcommand{\prufer}{\mbox{prüfer}} \DeclareMathOperator{\fix}{fix} \DeclareMathOperator{\stab}{stab} \DeclareMathOperator{\var}{var} \newcommand{\inv}{^{-1}} \newcommand{\lt}{ < } \newcommand{\gt}{ > } \newcommand{\amp}{ & } \)


We start this chapter with an elementary example.


Let \(X\) be the set of \(63\) students in an applied combinatorics course at a large technological university. Suppose there are \(47\) computer science majors and \(51\) male students. Also, we know there are \(45\) male students majoring in computer science. How many students in the class are female students not majoring in computer science?


Another type of problem where we can readily see how such a technique is applicable is a generalization of the problem of enumerating integer solutions of equations. In Chapter 2, we discussed how to count the number of solutions to an equation such as \begin{equation*} x_1 + x_2 + x_3 + x_4 = 100, \end{equation*} where \(x_1>0\), \(x_2, x_3 \geq 0\) and \(2\leq x_4\leq 10\). However, we steered clear of the situation where we add the further restriction that \(x_3\leq 7\). The previous example suggests a way of approaching this modified problem.

First, let's set up the problem so that the lower bound on each variable is of the form \(x_i\geq 0\). This leads us to the revised problem of enumerating the integer solutions to \begin{equation*} x_1' + x_2 + x_3 + x_4' = 97 \end{equation*} with \(x_1',x_2,x_3,x_4'\geq 0\), \(x_3\leq 7\), and \(x_4'\leq 8\). (We'll then have \(x_1 = x_1'+1\) and \(x_4 = x_4' + 2\) to get our desired solution.) To count the number of integer solutions to this equation with \(x_3\leq 7\) and \(x_4'\leq 8\), we must exclude any solution in which \(x_3 \gt 7\) or \(x_4' \gt 8\). There are \(C(92,3)\) solutions with \(x_3 \gt 7\), and the number of solutions in which \(x_4'\gt 8\) is \(C(91,3)\). At this point, it might be tempting to just subtract \(C(92,3)\) and \(C(91,3)\) from \(C(100,3)\), the total number of solutions with all variables nonnegative. However, care is required. If we did that, we would eliminate the solutions with both \(x_3\gt 7\) and \(x_4'\gt 8\) twice. To account for this, we notice that there are \(C(83,3)\) solutions with both \(x_3\gt 7\) and \(x_4'\gt 8\). If we add this number back in after subtracting, we've ensured that the solutions with both \(x_3\gt 7\) and \(x_4'\gt 8\) are not included in the total count and are not excluded more than once. Thus, the total number of solutions is \begin{equation*} \binom{100}{3} - \binom{92}{3} - \binom{91}{3} + \binom{83}{3} = 6516. \end{equation*}

From these examples, you should start to see a pattern emerging that leads to a more general setting. In full generality, we will consider a set \(X\) and a family \(\mathcal{P}=\{P_1,P_2,\dots,P_m\}\) of properties. We intend that for every \(x\in X\) and each \(i=1,2,\dots,m\), either \(x\) satisfies \(P_i\) or it does not. There is no ambiguity. Ultimately, we are interested in determining the number of elements of \(X\) which satisfy none of the properties in \(\mathcal{P}\). In Example 7.1, we could have made property \(P_1\) “is a computer science major” and property \(P_2\) “is male”. Then the number of students satisfying neither \(P_1\) nor \(P_2\) would be the number of female students majoring in something other than computer science, exactly the number we were asked to determine. What would the properties \(P_1\) and \(P_2\) be for Example 7.3?

Let's consider three examples of larger sets of properties. These properties will come back up during the remainder of the chapter as we apply inclusion-exclusion to some more involved situations. Recall that throughout this book, we use the notation \([n]\) for the set \(\{1,2,\dots,n\}\) when \(n\) is a positive integer.


Let \(m\) and \(n\) be fixed positive integers and let \(X\) consist of all functions from \([n]\) to \([m]\). Then for each \(i=1,2,\dots,m\), and each function \(f\in X\), we say that \(f\) satisfies \(P_i\) if there is no \(j\) so that \(f(j)=i\). In other words, \(i\) is not in the image or output of the function \(f\).

As a specific example, suppose that \(n=5\) and \(m=3\). Then the function given by the table below satisfies \(P_1\) but not \(P_2\) or \(P_3\).

\(i\) 1 2 3 4 5
\(f(i)\) 2 3 2 2 3

Let \(m\) be a fixed positive integer and let \(X\) consist of all bijections from \([m]\) to \([m]\). Elements of \(X\) are called permutations. Then for each \(i=1,2,\dots,m\), and each permutation \(\sigma\in X\), we say that \(\sigma\) satisfies \(P_i\) if \(\sigma(i)=i\).

For example, the permutation \(\sigma\) of \([5]\) given in by the table below satisfies \(P_3\) and \(P_5\) and no other \(P_i\).

\(i\) 1 2 3 4 5
\(\sigma(i)\) 2 4 3 1 5

Note that in the previous example, we could have said that \(\sigma\) satisfies property \(P_i\) if \(\sigma(i)\neq i\). But remembering that our goal is to count the number of elements satisfying none of the properties, we would then be counting the number of permutations satisfying \(\sigma(i)=i\) for each \(i=1,2,\dots,n\), and perhaps we don't need a lot of theory to accomplish this task—the number is one, of course.


Let \(m\) and \(n\) be fixed positive integers and let \(X=[n]\). Then for each \(i=1,2,\dots,m\), and each \(j\in X\), we say that \(j\) satisfies \(P_i\) if \(i\) is a divisor of \(j\). Put another way, the positive integers that satisfy property \(P_i\) are precisely those that are multiples of \(i\).

At first this may appear to be the most complicated of the sets of properties we've discussed thus far. However, being concrete should help clear up any confusion. Suppose that \(n=m=15\). Which properties does \(12\) satisfy? The divisors of \(12\) are \(1\), \(2\), \(3\), \(4\), \(6\), and \(12\), so \(12\) satisfies \(P_1\), \(P_2\), \(P_3\), \(P_4\), \(P_6\), and \(P_{12}\). On the other end of the spectrum, notice that \(7\) satisfies only properties \(P_1\) and \(P_7\), since those are its only divisors.