# Told by Professor that this is PIE, but don't see how it's PIE. Help understanding what constitutes the sets, or alternative ways to solve?

So, basically, my professor has taught us the principle of inclusion and exclusion. We were given the basic formulation of the problem using set theory (A$$\cup$$B$$\cup$$C), and then launched into examples. I failed to see in any of the examples how it related to set theory, and he seemed to want us to learn through pattern matching (which has left me very confused).

An example of this: How many ways are there to assign five different jobs to four different employees if every employee is assigned at least one job?

$$4^5$$ - $$\binom{4}{1}3^5$$ + $$\binom{4}{2}2^5$$ - $$\binom{4}{3}1^5$$ He talked us through this somewhat, but I couldn't understand how or why it worked. It seemed very much intuition based, as though it changed with every circumstance, rather than following a rule that was unchanging through the various circumstances.

Calculating this, the answer is 240. I'm not good at pattern matching, and I don't really understand how the Professor chose the values that he did for the binomial coefficients, and I don't really understand what the sets constitute in this case (what does set A represent versus set B versus set C). My main question in this case is what do the sets represent, and what do the intersections being added and subtracted represent? I need more than a pattern in order to understand what's going on in this problem.

My Dad was helping me with this problem and he didn't understand what the professor was doing either. He attempted to solve the problem this way:

$$\binom{5}{4}\cdot$$4!$$\cdot\binom{4}{1}$$ The idea was to distribute one job to each of the four employees, determine the possible number of combinations, and then choose one employee for the remaining job.

The answer was twice that of the Professor's answer. Either my Dad over-counted somehow, or it just plain isn't the correct way to solve the problem. Which is unfortunate because at least with that method I could see what was going on. My second question is whether or not there is any amendment that could be made to my Dad's method in order to get the correct answer with these problems, or if there is some second method of solving PIE problems that do not involve pure pattern matching?

Thank you for taking the time to read this. I was trying to be as specific as possible, which was noted in the guidelines (vague questions get vague answers). I'm a first time poster, and so I would appreciate any additional feedback if there is something I can do to improve any future posts.

• Welcome to MSE and nice first post! I am going to bed soon so I will let someone else (in another time zone) tackle the PIE formula. Re: your dad, he double-counted. Suppose employee Pat got two jobs $A$ and $B$. Your dad counted once for the case when $A$ is the $5$th job (the one *not* chosen in the ${5 \choose 4}$), and once more for the case when $B$ is the $5$th job. This is true for every single case, luckily, so you just need to divide by 2. – antkam Mar 27 at 4:08
• One "dad style" way that is correct would be: Pick an unlucky employee to have $2$ jobs ($4$ ways), then arrange the other $3$ by height (they're distinguishable) and give the tallest person a job ($5$ ways), the next tallest a job ($4$ ways), the shortest a job ($3$ ways). The unlucky employee by necessity gets the last $2$ jobs. Total no. $=4 \times 5 \times 4 \times 3 = 240$. – antkam Mar 27 at 4:14
• This example is not the greatest for demonstrating the power of PIE, since it's so easy by multiplication principle (which in turn is due to only one pattern 5=2+1+1+1 occurring). To see why PIE is useful, do the same problem with, say, 8 jobs assigned to 4 people with everyone getting at least one job. – Ned Mar 27 at 11:35

The magic words which indicate a usage of PIE are at least.

• If counting objects having at least a number of properties is simple, but counting objects having exactly a number of properties is difficult, than PIE comes into play.

In our example we have five jobs $$\{J_1,\ldots,J_5\}$$ which have to be assigned to four employees so that every employee is assigned at least one job.

Step 1: $$4^5$$

• We start with the easy things and observe there are $$4$$ ways to assign $$J_1$$ to one of the four employees. To each of these possibilities we have $$4$$ ways to assign $$J_2$$ to one of the four employees, giving a total of $$4^2$$ possibilities. Continuing this way we find there is a total of $$4^5$$ ways to assign five jobs to four employees.

Here we did some overcounting, since we also count possibilities where one (or more) of the employees were not assigned a job. We are now going to compensate for this. We subtract the possibilities one employee was not assigned a job.

Step 2: $$\binom{4}{1}3^5$$

There are $$\binom{4}{1}$$ possibilities that one employee was not assigned a job. In each of these $$\binom{4}{1}$$ cases there are $$3^5$$ possibilities to assign the five jobs to the three remaining employees. Combined with step 1 we obtain a total of $$4^5-\binom{4}{1}3^5$$ ways.

But we have to be careful. What we really did when we subtracted $$\binom{4}{1}3^5$$ was to subtract the possibilities that at least one employee was not assigned a job. The $$3^5$$ ways which we have identified do also include cases where less than three employees were assigned the five jobs. So, we did some overcounting in the other direction and we have again to compensate for this.

Step 3: $$\binom{4}{2}2^5$$

There are $$\binom{4}{2}$$ possibilities that two employees were not assigned a job. In each of these $$\binom{4}{2}$$ cases there are $$2^5$$ possibilities to assign the five jobs to the two remaining employees. Combined with step 1 and step 2 we obtain a total of $$4^5-\binom{4}{1}3^5+\binom{4}{2}2^5$$ ways.

Again, we observe that $$2^5$$ possibilities to assign the five jobs to two remaining employees also include the (two) possibilities that one employee was assigned all five jobs. We have to compensate this also and obtain finally

\begin{align*} \color{blue}{4^5-\binom{4}{1}3^5+\binom{4}{2}2^5-\binom{4}{3}1^5} \end{align*}

• Thank you for the answer. I'm going to attempt to internalize the method so that I can apply the principle to not only this particular problem, but PIE problems in general. – Daniel Mar 27 at 15:46
• @Daniel: You're welcome. I appreciate your approach. The PIE method belongs to the so-called sieve methods. Maybe not yet but soon you might want to have a look at section 4.2 of H.S. Wilf's Generatingfunctionology which provides helpful information. – Markus Scheuer Mar 27 at 16:01

As usual @MarkusScheuer gave an excellent answer. Here I "supplement" his answer by showing how all this maps to set theory, what the sets are, etc.

PIE goes like this:

$$|\bigcup_i A_i| = \sum_i |A_i| - \sum_{i < j} |A_i \cap A_j| + \sum_{i < j < k} |A_i \cap A_j \cap A_k| - ...$$

Here $$\sum_{i means you are summing over all pairs (size $$2$$ subsets). We write $$i because then clearly $$(4,7)$$ and $$(7,4)$$ are not both included. (Whereas if we write $$\sum_{i \neq j}$$ then it can be a little ambiguous whether they are both included.)

Anyway, the LHS (left hand side), the thing you're trying to use PIE to count, is a union of sets. This is (almost?) always true of PIE: you are counting a union. So the first question is: for this problem, what union of what sets?

Now, "everybody gets at least $$1$$ job" sounds like an intersection (Peter gets a job AND Mary gets a job AND etc...), but then the complement would indeed be a union (Peter has no job OR Mary has no job OR etc...) So we are using PIE to count this complement.

In this problem, the individual sets are $$A_i=$$ assignments in which person $$i$$ gets no job. Then the "bad" assignments are: $$Bad = A_1 \cup A_2 \cup A_3 \cup A_4 = \bigcup_i A_i=$$ LHS, and your answer is all assignments minus the bad ones, i.e. $$4^5 - |Bad|$$. Now we can do the right hand side of PIE as follows:

• $$\sum_i |A_i|$$: There are $${4 \choose 1}$$ terms in the summation, but luckily for you, all $$|A_i|$$ are equal! $$A_i =$$ person $$i$$ gets no jobs, and so the $$5$$ jobs are distributed to $$3$$ people; no. of ways $$= 3^5$$. The whole thing is $${4 \choose 1} 3^5$$.

• $$\sum_{i: There are $${4 \choose 2}$$ terms in the summation, but again luckily for you, every term is equal! Each term is $$2^5$$ and the total is $${4\choose 2} 2^5$$.

• $$\sum_{i: There are $${4 \choose 3}$$ terms in the summation, but again luckily for you, every term is equal! Each term is $$1^5$$ and the total is $${4\choose 3} 1^5$$.

• $$\sum_{i: There is only $$1$$ term, $$|A_1 \cap A_2 \cap A_3 \cap A_4|$$, and it is zero since it is impossible for all $$4$$ to get no jobs.

Therefore: $$|Bad| = {4 \choose 1} 3^5 - {4\choose 2} 2^5 + {4\choose 3} 1^5$$ and your answer $$=4^5 - |Bad|$$.

P.S.: in this simple problem, in each summation all the terms are equal. For a more difficult problem this may not hold. While the PIE is still valid, the formula becomes more complicated to evaluate. See here for one of my other examples if you're interested.

• Nice and instructive answer. (+1). Your ref inspired me to also give an answer there. It is in fact also based upon PIE as indicated in this post. :-) – Markus Scheuer Mar 27 at 18:09

Your father did overcount by exactly a factor of two. That method is very prone to overcounting, but we're lucky in this case to be able to quantify the overcounting exactly.

Suppose you have employees $$\{A,B,C,D\}$$ and jobs $$\{P,Q,R,S,T\}.$$ One of the ways you can assign one job to each of the four employees is $$\{(A,P),(B,Q),(C,R),(D,S)\}.$$ You have one job, $$T,$$ still to assign, so assign it to $$D.$$

Another way to assign one job to each of the four employees is $$\{(A,P),(B,Q),(C,R),(D,T)\}.$$ You have one job, $$S,$$ still to assign, so assign it to $$D.$$

But each of those two different ways of following your father's procedure gives you the same set of job assignments: $$\{(A,P),(B,Q),(C,R),(D,S),(D,T)\}.$$

Since it turns out all job assignments follow essentially the same pattern--two jobs to one employee, one job to each other employee--all the overcounting follows the same pattern as well. The employee with two jobs can get them in one of two ways: one of the jobs is assigned to that employee in the first step (choose either of the two jobs that eventually will be assigned to that employee), and the other must be assigned in the second step. Hence every set of assignments you wanted to count gets counted exactly twice.

If you had seven jobs for the four employees, things would have been much messier: the "extra" jobs could all go to one employee, or two to one employee and one to a different employee, or one each to three separate employees. In each of those cases the unwanted distinction between "job assigned in the first step" and "jobs assigned in the second step" results in each set of assignments being overcounted a different number of times, and inclusion-exclusion starts to become a lot easier in comparison.