Again start with the total number of functions:
\(3^5\) (as each of the five elements of the domain can go to any of three elements of the codomain). Now we count the functions that are
not surjective.
Start by excluding
\(a\) from the range. Then we have two choices (
\(b\) or
\(c\)) for where to send each of the five elements of the domain. Thus there are
\(2^5\) functions that exclude
\(a\) from the range. Similarly, there are
\(2^5\) functions that exclude
\(b\text{,}\) and another
\(2^5\) that exclude
\(c\text{.}\) Now have we counted all functions that are not surjective? Yes, but in fact, we have counted some multiple times. For example, the function which sends everything to
\(c\) was one of the
\(2^5\) functions we counted when we excluded
\(a\) from the range, and also one of the
\(2^5\) functions we counted when we excluded
\(b\) from the range. We must subtract out all the functions which specifically exclude two elements from the range. There is 1 function when we exclude
\(a\) and
\(b\) (everything goes to
\(c\)), one function when we exclude
\(a\) and
\(c\text{,}\) and one function when we exclude
\(b\) and
\(c\text{.}\)
We are using PIE: To count the functions that are not surjective, we added up the functions that exclude \(a\text{,}\) \(b\text{,}\) and \(c\) separately; then subtracted the functions that exclude pairs of elements. We would then add back in the functions that exclude groups of three elements, except that there are no such functions. We find that the number of functions that are not surjective is
\begin{equation*}
2^5 + 2^5 + 2^5 - 1 - 1 - 1 + 0 \text{.}
\end{equation*}
Perhaps a more descriptive way to write this is
\begin{equation*}
{3 \choose 1}2^5 - {3 \choose 2}1^5 + {3 \choose 3}0^5 \text{.}
\end{equation*}
since each of the \(2^5\)βs was the result of choosing 1 of the 3 elements of the codomain to exclude from the range; each of the three \(1^5\)βs was the result of choosing 2 of the 3 elements of the codomain to exclude. Writing \(1^5\) instead of 1 makes sense too: We have 1 choice of where to send each of the 5 elements of the domain.
Now we can finally count the number of surjective functions:
\begin{equation*}
3^5 - \left[{3 \choose 1}2^5 - {3 \choose 2}1^5\right] = 150 \text{.}
\end{equation*}