\documentstyle[11pt,twoside,amsfonts,amstex,psfig]{article}
\input{macros-course-lectures}

\newtheorem{falsethm}[theorem]{False Theorem}
\newtheorem{guess}{Guess}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{method}{Method}
\newtheorem{axiom}{Axiom}

\begin{document}

\lecture{notes15}{Lecture Notes}{23 Oct 97}

In the last lecture, we saw a variety of techniques for counting
elements in a finite set: the Sum Rule, Inclusion-Exclusion, the
Product Rule, tree diagrams, etc.  In this lecture we introduce a new
counting tool called the {\em Division Rule} and use it to find a
formula for the number of {\em $r$-combinations} of a set.  One common
pitfall in counting problems is mixing up $r$-combinations with
$r$-permutations; try keep track of which is which!

\section{The Division Rule}

We will state the Division Rule twice, once informally and then again
with more precise notation.

\begin{theorem}[Division Rule]
If $B$ is a finite set and $f:A \mapsto B$ maps precisely $k$ items of
$A$ to every item of $B$, then $A$ has $k$ times as many items as $B$.
\end{theorem}

For example, suppose $A$ is a set of students, $B$ is a set of
recitations, and $f$ defines the assignment of students to
recitations.  If 15 students are assigned to every recitation, then
the Division Rule says that there are 15 times as many students as
recitations.

The following two definitions permit a more precise statement of the
Division Rule.

\begin{defin*}
If $f : A \mapsto B$ is a function, then $f^{-1}(b) = \{ a \in A \mid
f(a) = b \}$.
\end{defin*}

That is, $f^{-1}(b)$ is the set of items in $A$ that are mapped to the
item $b \in B$.  In the preceding example, $f^{-1}(b)$ is the set of
students assigned to recitation $b$.

This notation can be confusing, since $f^{-1}$ normally denotes the
inverse of the function $f$.  With our definition, however,
$f^{-1}(b)$ can be a set, not just a single value.  For exampe, if $f$
assigns no items in $A$ to some element $b \in B$, then $f^{-1}(b)$ is
actually the empty set.  In the special case where $f$ is a bijection,
$f^{-1}(b)$ is always a single value, and so $f^{-1}$ by our
definition is just the ordinary inverse of $f$.

%  Well, not really, since we define f^{-1} to be a SET...

\begin{defin*}
A function $f:A \mapsto B$ is {\em $k$-to-1} if for all $b \in B$,
$|f^{-1}(b)| = k$.
\end{defin*}

For example, if $f$ assigns exactly 15 students to each recitation,
then $f$ is 15-to-1.  Assuming $k$ is non-zero, a $k$-to-1 function is
always a surjection; every element of the range is mapped to by $k >
0$ elements of the domain.

We can now restate the Division Rule more precisely:

\begin{theorem*}[Division Rule, restatement]
If $B$ is a finite set and $f : A \mapsto B$ is $k$-to-1, then $|A| =
k |B|$.
\end{theorem*}

\begin{proof}
Since $B$ is finite, we can let $n = |B|$ and let $B = \{ b_1, b_2,
\ldots, b_n \}$.  Then we have:

\[
A = f^{-1}(b_1) \cup f^{-1}(b_2) \cup \ldots \cup f^{-1}(b_n)
\]

Equality holds because each side contains the other.  The left side
contains the right because every set $f^{-1}(b_i)$ is contained in $A$
by the definition of $f^{-1}(b_i)$.  The right side contains the left,
since every item in $a$ maps to some $b_i$, and therefore is contained
in the set $f^{-1}(b_i)$.

Furthermore, all of the sets $f^{-1}(b_i)$ are disjoint.  The proof is
by contradiction.  Assume for the purpose of contradiction that $a \in
f^{-1}(b_i)$ and $a \in f^{-1}(b_j)$ for some $i \neq j$.  The first
inclusion implies $f(a) = b_i$, but the second inclusion implies that
$f(a) = b_j$.  This is a contradiction since $f(a)$ denotes a unique
item.

Since the sets $f^{-1}(b_i)$ are disjoint, we can compute the
cardinality of their union with the Sum Rule.  Note that each set
$f^{-1}(b_i)$ has size $k$, since $f$ is $k$-to-1.

\begin{eqnarray*}
|A| & = & |f^{-1}(b_1)| + |f^{-1}(b_2)| + \ldots + |f^{-1}(b_n)| \\
    & = & \underbrace{k + k + \ldots + k}_{n = |B| \mbox{ terms}} \\
    & = & k |B|
\end{eqnarray*}
\end{proof}

\subsection{Seating at a Round Table}

In how many ways can King Arthur seat $n$ knights at his round table?
Two seatings are considered equivalent if one can be obtained from the
other by rotation.  For example, if Arthur has only four knights, then
there are six possibilities as shown in Figure~\ref{fig:knights}.
Hereafter, we denote a seating arrangement in text by listing knights
in square brackets in clockwise order, starting at an arbitrary point.
For example, $[1234]$ and $[4123]$ are equivalent.

\begin{figure}[htbp]
\centerline{\psfig{figure=knights.eps,height=2.0in}}
\caption{\em These are the 6 different ways that King Arthur can
seat 4 knights at his round table.  Two seatings differing only by
rotation are considered equivalent.  We denote a seating arrangement
in text by listing knights in square brackets in clockwise order,
starting at an arbitrary point.  For example, the seatings in the top
row can be denoted $[1234]$, $[2413]$, and $[3421]$.}
\label{fig:knights}
\end{figure}

\begin{claim}
Arthur can seat $n$ knights at his round table in $(n-1)$! ways.
\end{claim}

In particular, the claim says that for $n = 4$ knights there are
$(4-1)! = 3! = 6$ orderings, which is consistent with the example in
Figure~\ref{fig:knights}.

\begin{proof}
The proof uses the Division Rule.  Let $A$ be the set of orderings of
$n$ knights in a line.  Let $B$ be the set of orderings of $n$ knights
in a ring.  Define $f: A \mapsto B$ by $f((x_1, x_2, \ldots, x_n)) =
[x_1 x_2 \ldots x_n]$.

The function $f$ is $n$-to-1.  In particular:

\begin{eqnarray*}
f^{-1}([x_1 x_2 \ldots x_n]) & = \{ &
	(x_1, x_2, x_3, \ldots, x_n), \\
    & & (x_n, x_1, x_2, \ldots, x_{n-1}) \\
    & & (x_{n-1}, x_n, x_1, \ldots, x_{n-2}), \\
    & &  \ldots\mbox{$x_1$ appears in $n$ different places}\ldots \\
    & & (x_2, x_3, x_4, \ldots, x_1) \}
\end{eqnarray*}

By the Division Rule, $|A| = n |B|$.  This gives:

\begin{eqnarray*}
|B| & = & \frac{|A|}{n} \\
    & = & \frac{n!}{n} \\
    & = & (n-1)!
\end{eqnarray*}

The second equality holds, because the number of orderings of $n$
items in a line is $n!$, as we showed last lecture.
\end{proof}

\subsection{$r$-Combinations of a Set}

The Division Rule can be used to count the $r$-combinations of a set,
which are defined as follows.

\begin{defin*}
An {\em $r$-combination} of a set is a subset of size $r$.
\end{defin*}

For example, there are three 2-combinations of the set $\{ A, B, C
\}$:

\[
\begin{array}{ccc}
\{ A, B \} & \{ A, C \} & \{ B, C \}
\end{array}
\]

Understanding the distinction between $r$-combinations and
$r$-permutations is important.  The $r$-combinations of a set are
different from $r$-permutations in that order does not matter.  For
example, the above set has six 2-permutations:

\[
\begin{array}{ccc}
(A, B) & (A, C) & (B, C) \\
(B, A) & (C, A) & (C, B)
\end{array}
\]

The number of $r$-combinations of an $n$-element set comes up in many
problems.  The quantity is important enough to merit two notations.
The first is $C(n, r)$; this is analogous to the notation $P(n, r)$
from last lecture for the number of $r$ permutations of an $n$-element
set.  The second notation is $\binom{n}{r}$, read ``$n$ choose $r$''.
The values $\binom{n}{r}$ or $C(n, r)$ are often called {\em binomial
coefficients} because of their prominent role in the Binomial Theorem,
which we will cover shortly.

The following theorem gives a closed form for $\binom{n}{r}$.  This
theorem is used all the time; remember it!

\begin{theorem}\label{th:comb}
\[
\binom{n}{r} = \frac{n!}{(n-r)! \ r!}
\]
\end{theorem}

The theorem says, for example, that the number of 2-combinations of
the three element set $\{ A, B, C \}$ is $\frac{3!}{(3-2)! 2!} = 3$ as
we saw above.

\begin{proof}
The proof uses the Division Rule.  Let $X$ be a set with $n$ elements.
Let $A$ be the set of $r$-permutations of $X$, and let $B$ be the set
of $r$-combinations of $X$.  Our goal is to compute $|B|$.  To this
end, let $f: A \mapsto B$ be the function mapping $r$-permutations to
$r$-combinations that is defined by:

\[
f(\underbrace{(x_1, x_2, \ldots, x_r)}_{
\begin{array}{cc}
{\mbox{order matters}} \\
{\mbox{(permutation)}}
\end{array}
})
   = \underbrace{ \{ x_1, x_2, \ldots, x_r \} }_{
\begin{array}{cc}
{\mbox{order does not matter}} \\
{\mbox{(combination)}}
\end{array}
}
\]

The function $f$ is $r!$-to-1.  In particular:

\begin{eqnarray*}
f^{-1}( \{ x_1, x_2, \ldots, x_r \} ) & = \{ &
	( x_1, x_2, x_3, x_4, \ldots, x_r), \\
& &	( x_2, x_1, x_3, x_4, \ldots, x_r), \\
& &	\ldots \mbox{all $r!$ permutations} \ldots \ \}
\end{eqnarray*}

By the Division Rule, $|A| = r! |B|$.  Now we can compute the number
of $r$-combinations of an $n$-element set, $|B|$, as follows:

\begin{eqnarray*}
|B| & = & \frac{|A|}{r!} \\
    & = & \frac{P(n, r)}{r!} \\
    & = & \frac{n!}{(n-r)! \ r!}
\end{eqnarray*}
\end{proof}

Binomial coefficients are important enough that some special values of
$\binom{n}{r}$ are worth remembering:

\begin{eqnarray*}
\binom{n}{0} = \frac{n!}{n! \ 0!} = 1 & &
	\mbox{There is a single 0-element subset of an $n$-set.}\\
\binom{n}{n} = \frac{n!}{0! \ n!} = 1 & &
	\mbox{This is a single $n$-element subset of an $n$-set.}\\
\binom{n}{1} = \frac{n!}{(n-1)! \ 1!} = n & &
	\mbox{These are $n$ 1-element subsets of an $n$-set.}
\end{eqnarray*}

Recall that $0!$ is defined to be 1, not zero.

\section{Examples Involving $r$-Combinations}

There is a card game called Five-Card Draw.  In this game, each player
is dealt a hand consisting of 5 cards from a deck of 52 cards.  Each
card in the deck has a suit (clubs $\clubsuit$, hearts $\heartsuit$,
diamonds $\diamondsuit$, or spades $\spadesuit$) and a value ($A$, 1,
2, $\ldots$, $9$, $J$, $Q$, or $K$).  The order in which cards are
dealt does not matter.  We will count various types of hands in
Five-Card Draw to show how to use the formula for $r$-combinations
given in Theorem~\ref{th:comb}.

\subsubsection*{Five-Card Hands}

How many different hands are possible in Five-Card Draw?  A hand is
just a 5-card subset of the 52-card deck.  Therefore, the possible
hands in Five-Card Draw are exactly the 5-combinations of a 52-element
set.  By Theorem~\ref{th:comb}, there are $\binom{52}{5} =
\frac{52!}{47! \ 5!} = 2,598,960$ possible hands.

Confusion between combinations and permutations is a common source of
error in counting problems.  For example, one might erroneously count
the number of 5-card hands as follows.  There are 52 choices for the
first card, 51 choice for the second card given the first, $\ldots$,
and 48 choices for the fifth card given the first four.  This totals
$52 \cdot 51 \cdot 50 \cdot 49 \cdot 48$ possible hands.  The problem
with this way of counting is that a hand is counted once for every
ordering of the five cards; that is, each hand is counted $5! = 120$
times.  We accidentally counted $r$-permutations instead of
$r$-combinations!  To get the number of 5-combinations, we would have
to divide by 120.

\subsubsection*{Hands with Four-of-a-Kind}

How many hands are there with four-of-a-kind?  For example, $9
\spadesuit \ 4 \diamondsuit \ 9 \clubsuit \ 9 \heartsuit \ 9 \diamondsuit$
has a four-of-a-kind, because there are four 9's.

First we must choose one value to appear in all four suits from the
set of 13 possible values.  This can be done in $\binom{13}{1} = 13$
ways.  Then we have to choose one more card from the remaining set of
48.  This can be done in $\binom{48}{1} = 48$ ways.  In total, there
are $13 \cdot 48 = 624$ hands with four-of-a-kind.  The situation is
illustrated by the tree diagram in Figure~\ref{fig:fourkind}.

\begin{figure}[htbp]
\centerline{\psfig{figure=fourkind.eps,height=2.0in}}
\caption{\em This (incomplete) tree diagram counts the number of hands
with four-of-a-kind.  There are 13 choices for the value appearing in
all four suits.  The fifth card in the hand can be any of the 48 cards
remaining in the deck.  This gives a total of $13 \cdot 48 = 624$
possible hands.}
\label{fig:fourkind}
\end{figure}

Here is a way to interpret the result that uses probabilty.  If all
$\binom{52}{5}$ hands are equally likely, then the probability that we
are dealt a four-of-a-kind is $624 / \binom{52}{5} = 1/4165$.  In
other words, we can only expect to get four-of-a-kind only once in
every 4165 games of Five-Card Draw!  (This is just a passing
observation; we will talk about probabilty ``for real'' in a few
weeks.)

Mistakes are easy to make in counting problems.  It is a good idea to
check a result by counting the same thing in another way.  For
example, we could also count the number of hands with a four-of-a-kind
as follows.  First, there are 52 ways to choose the ``extra'' card.
Given this, there are 12 ways to choose the value that appears in all
four suits.  (We can not choose the value of the first card.)  The
possibilities are illustrated by the tree diagram in
Figure~\ref{fig:fourkind2}.  By this method, we find that there are
$52 \cdot 12 = 624$ four-of-a-kind hands.  This is consistent with our
first answer.

\begin{figure}[htbp]
\centerline{\psfig{figure=fourkind2.eps,height=2.0in}}
\caption{\em This tree diagram shows another way to count the number of
hands with a four-of-a-kind.  There are 52 choices for the ``extra''
card and then 12 choices for the value appearing in all four suits.
This gives $52 \cdot 12 = 624$ hands, the same answer as before.}
\label{fig:fourkind2}
\end{figure}

\subsubsection*{Hands with a Full House}

A full house is a hand with both a three-of-a-kind and a
two-of-a-kind.  For example, the hand $7 \spadesuit \ 7 \diamondsuit \
J \clubsuit \ J \heartsuit \ J \diamondsuit$ is a full house because
there are three jacks and two sevens.  How many different full houses
are there?

We can choose the value that appears three times in 13 ways.  Then we
can pick any three of the four cards in the deck with this value; this
can be done in $\binom{4}{3} = 4$ ways.  There are then 12 remaining
choices for the value that appears two times.  We can pick any two of
the four cards with this value; this can be done in $\binom{4}{2} = 6$
ways.

The total number of full house hands is therefore $13 \cdot 4 \cdot 12
\cdot 6 = 3744$.  This is 6 times greater than the number of
hands with a four-of-a-kind.  Since a four-of-a-kind is more rare, it
is worth more in poker!

\subsubsection*{Hands with Two Pairs}

How many hands are there with two pairs, but no three- or
four-of-a-kind?

{\em Incorrect count. } There are 13 choices for the value of the
cards in the first pair.  There are then $\binom{4}{2} = 6$ ways to
choose two of the four cards in the deck that have this value.  Next,
there are 12 choices for the value of the cards in the second pair,
and $\binom{4}{2} = 6$ ways to choose two of the four cards with this
value.  Finally, the fifth card can be any one of the 48 cards
remaining in the deck.  Alltogether there are $13
\cdot 6 \cdot 12 \cdot 6 \cdot 48$ hand with just two pairs.

There are actually {\em two} bugs in this argument.  The first is that
the fifth card can {\em not} be any one of the 48 remaining cards; in
particular, it can not have the same value as a card already selected.
(Otherwise, there would be a three-of-a-kind.)  This rules out 4 of
the 48 cards, leaving only 44 choices for the fifth card.

The second bug is that every hand has been counted twice!  For
example, a pair of kings and a pairs of queens is counted once with
the kings as the first pair and a second time with the queens as the
first pair.  The references in the argument to a ``first pair'' and a
``second pair'' signal danger; these terms imply an ordering that is
not part of the problem.  To fix the second bug, we can apply the
Division Rule.  There is a 2-to-1 mapping from the set of hands we
counted to the set of hands with two pairs.  Therefore, the set of
hands with two pairs is half as large as our initial count:

\begin{eqnarray*}
\mbox{hands with two pairs}
	& = & \frac{13 \cdot 6 \cdot 12 \cdot 6 \cdot 44}{2} \\
	& = & 123,552 \\
\end{eqnarray*}

Why did this factor of 2 arise in counting pairs, but not in counting
full houses?  The reason is that pairs are interchangable, but a pair
and a triple are not.  For example, a pair of 2's and a pair of 9's is
the same as a pair of 9's and a pair of 2's.  On the other hand, a
pair of 2's and a triple of 9's is very different from a pair of 9's
and a triple of 2's!

To check our result, we can count the number of hands with two pairs
in a completely different way.  The number of ways to choose the
values for the two pairs is $\binom{13}{2}$.  We can choose suits for
each pair in $\binom{4}{2} = 6$ ways, and we can choose the remaining
card in 44 ways as before.  This gives:

\[
\binom{13}{2} \cdot 6 \cdot 6 \cdot 44 = 123,552
\]

This is the same answer as before.  Two pairs turn out to be 33 times
more likely than a full house; as one would expect, a full house beats
two pairs in poker!

\subsubsection*{Hands with No Pairs}

How many hands are there with no pairs?

{\em First count. } There are 52 choices for the first card, 48
choices for the second card given the first, 44 choices for the third
given the first two, etc.  After each card, the number of remaining
choices drops by four, since we can not subsequently pick the card
just taken or any of the other three cards with the same value.  This
gives $52 \cdot 48
\cdot 44
\cdot 40 \cdot 36$ hands with no pair.  Is this answer right?

The references to ``first card'', ``second card'', $\ldots$ are a
warning signal that we may be inadvertantly counting an ordered set.
To be sure, we can check how many times a particular hand is counted.
Consider the hand $A \heartsuit \ K \spadesuit \ Q \clubsuit \ J \clubsuit
\ 10 \heartsuit$.  We could have obtained this hand by drawing cards in
the order listed, but we could also have drawn them in another order.
In fact, we counted this hand once for every possible ordering of the
five cards; that is, each hand is counted $5! = 120$ times!  We can
correct our initial answer by applying the Division Rule.  This gives:

\begin{eqnarray*}
\mbox{hands with no pairs}
	& = & \frac{52 \cdot 48 \cdot 44 \cdot 40 \cdot 36}{120} \\
        & = & 1,317,888
\end{eqnarray*}

{\em Second count. } There is another way to count the hands with no
pairs that avoids this confusion.  Since there are no pairs, no two
cards have the same value.  This means that we could first choose 5
distinct values from the set of 13 possibilites.  Then we could choose
one of the four suits for each of the five cards.  This gives:

\begin{eqnarray*}
\mbox{hands with no pairs}
	& = & \binom{13}{5} \cdot 4^5 \\
        & = & \frac{13 \cdot 12 \cdot 11 \cdot 10 \cdot 9}
                   {5 \cdot 4 \cdot 3 \cdot 2 \cdot 1} \cdot 4^5 \\
	& = & 1,317,888
\end{eqnarray*}

This is the same answer as before.  Notice that the number of hands
with no pairs is more than half of all the hands.  This means that in
more than half our games of Five-Card Draw, we will not even have one
pair!

\subsubsection*{Hands with Every Suit}

How many hands contain one card of every suit?  Such a hand must
contain two cards from one suit and one card from each of the other
three suits.  Again, we can count in two ways.

{\em First count. } Pick one card from each suit.  This can be done in
$13^4$ ways.  Then pick any one of the remaining 48 cards.  This gives
a total of $13^4 \cdot 48$ hands.  However, we have overcounted by
two, since the two cards with the same suit could be picked in either
order.  Accounting for this, there are $\frac{13^4
\cdot 48}{2} = 685,464$ hands.

{\em Second count } First, we can pick the suit that contains two
cards in four ways.  Then we can pick values for these two cards in
$\binom{13}{2}$ ways.  Finally, we can pick a card from each of the
other three suits in $13^3$ ways.  This gives:

\begin{eqnarray*}
\mbox{hands with all suits}
	& = & 4 \binom{13}{2} \binom{13}{1}^3 \\
	& = & 4 \cdot \frac{13 \cdot 12}{2} \cdot 13 \cdot 13 \cdot 13 \\
	& = & 685,464
\end{eqnarray*}

More than a quarter of all Five-Card Draw hands contain all suits.

\subsubsection*{Reminders}

To make sure that you get the right answer when counting:

\begin{enumerate}
\item Look at a sample 5-card hand (or a sample of whatever you are
counting) and make sure that it is covered once and only once in your
count.
\item Try counting by two different ways and check that you get the same
answer.
\end{enumerate}

For example, when we first counted the number of hands with no pairs,
we discovered that we had masively overcounted; a sample hand was
actually covered 120 times by our count!  We corrected this answer by
applying the Division Rule, {\em and} we counted the same thing again in a
different way as a double-check.

\section{The Magic Trick}

Counting has many applications in computer science.  For example, we
have proved upper and lower bounds on the run time of algorithms,
proved that some functions are not computable, etc.  Counting also has
applications in information theory.  Here is a fun one!

There is a magician and an assistant.  The assistant goes into the
audience with a deck of 52 cards while the magician looks away.  Five
audience members are asked to select one card each from the deck.  The
assistant then gathers up the five cards and announces four of them to
the magician.  The magician thinks for a time and then correctly names
the secret, fifth card!

\subsection{How the Trick Works}

The assistant has somehow communicated the secret card to the magician
just by naming the other four cards.  In particular, the assistant has
two ways to communicate.  First, he can announce the four cards in any
order.  The number of orderings of four cards is $4! = 24$, so this
alone is insufficient to identify which of the remaining 48 cards is
the secret one.  Second, the assistant can choose which four of the
five cards to reveal.  The amount of information that can be conveyed
this way is harder to pin down.  The assistant has $\binom{5}{4} = 5$
ways to choose the four cards revealed, but the magician can not
determine which of these five possibilities the assistant selected,
since he does not know the secret card!  Nevertheless, these two forms
of communication allow the assistant to covertly reveal the secret
card to the magician.

Here is an overview of how the trick works.  The secret card has the
same suit as the first card announced.  Furthermore, the value of the
secret card is offset from the value of the first card announced by
between 1 and 6.  See Figure~\ref{fig:cardcycle}.  This offset is
communicated by the order of the last three cards.

\begin{figure}[htbp]
\centerline{\psfig{figure=cardcycle.eps,height=2.5in}}
\caption{\em The 13 possible card values can be ordered in a cycle.  For
any two distinct values, one is offset between 1 and 6 clockwise steps
from the other.  In this diagram, $3$ is offset five steps from $J$.
In the card trick, the value of the secret card is offset between 1
and 6 steps from the first card announced.  This offset is
communicated by the order of the last three cards named by the
assistant.}
\label{fig:cardcycle}
\end{figure}

Here are the details.  The audience selects five cards and there are
only 4 suits in the deck.  Therefore, by the Pigeonhole Principle, the
assistant can always pick out two cards with the same suit.  One of
these will become the secret card, and the other will be the first
card that he announces.

Here is how he decides which is which.  Note that for any two card
numbers, one is at most six clockwise steps away from the other in
Figure~\ref{fig:cardcycle}.  For example, if the card numbers are $2$
and $Q$, then $2$ is three clockwise steps away from $Q$.  The
assistant ensures that the value of the secret card is offset between
1 and 6 clockwise steps from the first card he announces.

The offset is communicated by the order that the assistant announces
the last three cards.  The magician and assistant agree in advance on
an order for all 52 cards.  For example, they might use:

\[
A \ \clubsuit, 2 \ \clubsuit, \ldots, K \ \clubsuit, A \ \diamondsuit,
\ldots, K \ \diamondsuit, A \ \heartsuit, \ldots, K \ \heartsuit, A \
\spadesuit, \ldots, K \ \spadesuit
\]

With this order, one of the last three cards announced is the
smallest ($S$), one is largest ($L$), and the other is medium ($M$).
The offset is encoded by the order of these three:

\[
\begin{array}{ccc}
SML = 1 & SLM = 2 & MSL = 3 \\
MLS = 4 & LSM = 5 & LMS = 6
\end{array}
\]

For example, suppose that the audience selects $3 \heartsuit \ 8
\diamondsuit \ A \spadesuit \ J \heartsuit \ 6 \diamondsuit$.  The
assistant picks out two cards with the same suit, say $3 \heartsuit$
and $J \heartsuit$.  The $3 \heartsuit$ is five clockwise steps from
$J \heartsuit$ in Figure~\ref{fig:cardcycle}.  So the assistant makes
$3 \heartsuit$ the secret card, announces $J \heartsuit$ first, and
then encodes the number 5 by the order in which he announces the last
three cards: $A \spadesuit \ 6 \diamondsuit \ 8 \diamondsuit = LSM =
5$.

\subsection{Same Trick with 4 Cards?}

Could the same magic trick work with just 4 cards?  That is, if the
audience picks four cards, and the assistant reveals three, then can
the magician determine the fourth card?  The answer turns out to be
``no''.  The proof relies on the Pigeonhole Principle.

\begin{theorem}
The magic trick is not possible with 4 cards.
\end{theorem}

\begin{proof}
The audience can select any 4-combination of cards; let $A$ be the set
of all such 4-combinations.  The assistant can announce any
3-permutation of cards; let $B$ be the set of all such 3-permutations.
The formulas for $r$-combinations and $r$-permutations give the
following sizes for $A$ and $B$:

\begin{eqnarray*}
|A| & = & C(n, r) \\
    & = & \frac{52!}{48! \ 4!} \\
    & = & 270,725 \\
|B| & = & P(n, r) \\
    & = & \frac{52!}{49!} \\
    & = & 132,600
\end{eqnarray*}

The assistant sees a 4-combination of cards selected by the audience
and must announce a 3-permutation to the magician.  Let $f: A \mapsto
B$ be the function that the assistant uses in mapping one to the
other.  Since $|A| > |B|$, the Pigeonhole Principle implies that $f$
maps at least two 4-combinations to the same 3-permutation.  That is,
there are two different sets of four cards that the audience can pick
for which the assistant says exactly the same thing to the magician.

For these two sets of four cards, three cards must be the same (since
the assistant announces the same three cards in both cases) and one
card must be different (since the two sets are different).  For
example, these might be the two sets of four cards for which the
assistant says exactly the same thing to the magician:

\begin{eqnarray*}
3 \heartsuit \ 8 \diamondsuit \ A \spadesuit \ J \heartsuit \\
3 \heartsuit \ 8 \diamondsuit \ A \spadesuit \ K \diamondsuit
\end{eqnarray*}

In this case, the assistant announces $3 \heartsuit \ 8 \diamondsuit \
A \spadesuit$ in some order.  The magician is now stuck; he can not
determine whether the remaining card is $J \heartsuit$ or $K
\diamondsuit$.
\end{proof}

There are many variants of the magic trick.  For example, if the
audience picks 8 cards, then revealing 6 to the magician is enough to
let him determine the other two.  This sort of subtle transmission of
information is important in the security business where one wants to
prevent information from leaking out in undetected ways.  This is
actually a whole field of study, but this trick is all we'll see in
6.042.

\end{document}
