\documentclass[12pt,twoside]{article}
\usepackage{amsmath}
\usepackage{graphics}
\input{macros-course}
\begin{document}

\handout{lec6-sup}{Supplement to Lecture 6}{October 8, 1998}

\newcommand{\rank}{\text{rank}}
\newcommand{\pref}{\text{pref}}
\newcommand{\curboy}{\text{cur-boy}}
\newcommand{\best}{\text{best}}
\newcommand{\bestgirl}{\text{best-girl}}
\newcommand{\cur}{\text{cur}}
\newcommand{\pos}{\text{Poss}}
\newcommand{\comment}[1]{}
\newtheorem{invariant}{Invariant}
\newtheorem{thrm}{Theorem}
%\newtheorem{claim}{Claim}


\section{The Dating Game}

Suppose that there are an equal number of boys and girls in a town.
We want to find a good matching; that is, a good pairing of boys and
girls into dating couples.  We suppose that each boy has a ranking of
all the girls according to how much he likes them, and each girl has a
similar ranking of all the boys.  If a boy and a girl that we do not
match-up each ranks the other above his or her current date, then they
are called a {\em rogue couple}.  A matching with no rogue couples is
called a {\em stable matching}.  Our goal is to devise and analyze an
algorithm that takes the boys' and girls' rankings as input and
produces a stable matching as output.

The following notation will be used throughout the lecture.  There are
$N$ girls and $N$ boys.  The set of girls is called $G$, and the set
of boys is called $B$.  A {\em matching} is a set of pairs $(g, b)$,
where $g \in G$ and $b \in B$, such that every girl and boy appears in
exactly one pair in the set.

We define $\rank_b(g)$ to be the rank that boy $b$ assigns to girl
$g$.  For example, if $\rank_b(g) = 2$, then girl $g$ is boy $b$'s
second favorite.  Similarly, $\rank_g(b)$ indicates the rank that girl
$g$ assigns to boy $b$.  (This notation may be confusing because a boy
assigns the numerically highest rank to his least-favorite girl.)  In
addition, we define $\pref_b(k)$ to be boy $b$'s $k$-th favorite girl,
and $\pref_g(k)$ to be girl $g$'s $k$-th favorite boy.

With this notation, a pair $(g, b)$ is called a rogue couple in a
matching $M$ if $(g, b') \in M$, $(b, g') \in M$, and the following
two conditions hold:

\begin{eqnarray*}
\rank_{g}(b)	& < &	\rank_{g}(b') \\
\rank_{b}(g)	& < &	\rank_{b}(g')
\end{eqnarray*}

\section{The Algorithm}

We will use the following algorithm to generate a matching.  The input
is the set of all boys' and girls' rankings.  In general terms, each
girl pursues one boy at a time, and each boy rejects pursuers that he
does not want to date.

More precisely, a girl always pursues the boy that she ranks best
among those boys that have not yet rejected her.  If a boy is
currently pursued by more than one girl, then he may reject any of his
pursuers other than his favorite among them.  The algorithm terminates
when no more rejections are possible.  (We will show that this implies
that the algorithm terminates when every boy has a single pursuer.)
The output is the matching that pairs each boy with his final pursuer.

Note that this algorithm is underspecified.  One boy may swiftly
reject all pursuers other than his favorite, while another boy tries
to amass as large a pool of pursuers as possible before issuing any
rejections.  One might suppose that by carefully timing his
rejections, a boy might better his odds of ending up with the girl of
his dreams.  We will show that this is not the case; the output of the
algorithm is independent of the timing of rejections.

\section{A State Machine Model}

We can model the dating game with a state machine as follows.

Let $\cur_g$ be the rank that girl $g$ assigns to the boy that she is
currently pursuing.  As a special case, if the girl has been rejected
by all the boys and is pursuing no one, then we let $\cur_g = N + 1$.
A state of the state machine corresponds to a particular assignment to
all of the variables $\cur_g$.  For example, the initial state
corresponds setting all of the $\cur_g$ variables equal to 1.

Before describing the transitions of the state machine, we introduce
some derived variables.

\begin{itemize}

\item For each girl $g$, let $\curboy_g$ be the boy that girl $g$ is
currently pursuing, namely $\pref_g(\cur_g)$.  If the girl $g$ has
been rejected by all suitors, and thus $\cur_g = N + 1$, then
$\curboy_g$ is defined to be the null value $\Lambda$.

\item For each boy $b$, we define $\best_b$ to be the rank that boy
$b$ assigns to his favorite current pursuer.  If boy $b$ currently has
no pursuers, then $best_b$ is defined to be $N+1$.

\item For each boy $b$, we define $\bestgirl_b$ to be boy $b$'s
favorite current pursuer.  That is, $\bestgirl_b = \pref_b(\best_b)$.
If boy $b$ is not pursued by any girl, then $\bestgirl_b$ is defined
to be $\Lambda$.

\end{itemize}

Each state machine transition corresponds to a boy rejecting one of
his pursuers other than his favorite among them.  Formally, from each
state where $\curboy_g = b$ and $\bestgirl_b \neq g$, there is a
transition to the state the differs only in that $\cur_g$ is
incremented by 1.  Intuitively, this means that if girl $g$ is
pursuing boy $b$ and boy $b$'s favorite pursuer is someone else, then
he can reject her, forcing her to move down to the next guy on her
preference list.

\section{Basic Algorithm Properties}

We will prove a sequence of invariants about the matching algorithm.

\begin{invariant}
\label{inv:1}
If $\rank_g(b) < \cur_g$ then $\best_b < \rank_b(g)$.
\end{invariant}

%\item There exists a girl $g'$ such that $\cur_{g'} = b$
%and $\rank_{b}(g') < rank_b(g)$.

Intuitively, this says that if girl $g$ ranks boy $b$ better than the
boy that she is currently pursuing, then boy $b$ currently has a girl
$g'$ that he likes better than $g$.

\bigskip

\begin{proof}
The proof uses the Invariant Thorem.  The invariant holds in the start
state, because the hypothesis $\rank_g(b) < \cur_g$ is always false;
initially, every girl pursues her favorite boy, and so $\cur_g = 1$.
Now suppose that the invariant holds before a transition.  The
invariant can hold for one of two reasons: either the hypothesis is
false or else the conclusion is true.

First, suppose that the invariant holds prior to a transition because
the hypothesis is false; that is $\rank_g{b} \geq \cur_g$ prior to the
transition.  Note that $\rank_g{b}$ is the ranking that girl $g$
assigns boy $b$ and thus does not change.  If the hypothesis remains
false after the transition, then the invariant still holds after the
transition.  On the other hand, the hypothesis can only become true if
$\rank_g{b} = \cur_g$ prior to the transition (which implies that girl
$g$ is pursing boy $b$) and then $\cur_g$ is increased (which implies
that boy $b$ rejects girl $g$).  But boy $b$ can only reject girl $g$
if he has another pursuer that he likes better.  This implies that
$\best_b < \rank_b(g)$ both before and after the transition.
Therefore, the invariant is true after the transition because the
conclusion is true.

Second, suppose that the invariant holds prior to a transition because
the conclusion is true; that is, $\best_b < \rank_b(g)$.  Since boy
$b$ never rejects his favorite pursuer, $\best_b$ can never increase.
But $\rank_b(g)$ is just the rank that boy $b$ assigns to girl $g$ and
can not change.  Therefore, the invariant holds after the transition
because the conclusion remains true.

Since the invariant holds in the start state and is preserved under
all transitions, the invariant holds for all reachable states by the
Invariant Theorem.
\end{proof}

\begin{invariant}
\label{inv:2}
For each girl $g$, $cur_g \leq N$.
\end{invariant}

In other words, every girl is always pursing some boy; no girl is
ever rejected by all the boys and left with nothing to do.

\bigskip

\begin{proof}
\begin{tabbing}
xxx \= xxx \= xxx \= xxx \= xxx \kill
1. Assume not; that is, in some reachable state, $\cur_g = N+1$. \\
2. {\tt FALSE} \\
\> 1.1 For all boys $b$, $\rank_g(b) < \cur_g$ (because $\cur_g = N+1$). \\
\> 1.2 For all boys $b$, $\best_b < \rank_b(g)$ (by Invariant~\ref{inv:1}). \\
\> 1.3 For all boys $b$, $\bestgirl_b \not\in \{ g, \Lambda\}$
	(by previous step and definition of $\bestgirl_b$). \\
\> 1.4 For all pairs of distinct boys $b$ and $b'$,
	$\bestgirl_b \neq \bestgirl_{b'}$ (by definition of $\bestgirl$). \\
\> 1.5 Q. E. D. (there are $N$ boys, but only $N - 1$ girls). \\
3. Q. E. D. (by contradiction)
\end{tabbing}
\end{proof}

\begin{thrm}
The algorithm terminates.
\end{thrm}

\begin{proof}
The sum of the $\cur_g$ variable increases by 1 under each transtion.
The sum of these variables is initially $N$, and the maximum sum is
$N^2$.  Therefore, the maximum number of transitions before the
algorithm terminates is $N^2-N$.
\end{proof}

(To do this with a termination function, we would want a decreasing
derived variable.  We could always define the termination function to
be $N^2 - \sum_g \cur_g$.  Or we could just realize that this is a
variation on the notion of a termination function that also works.)

Now we show that when the algorithm terminates, everyone is paired.
Recall that the algorithm terminates when no more rejections are
possible; that is, every boy is pursued by at most one girl.

\begin{invariant}
\label{inv:3}
If a reachable state is terminating, then:

\begin{enumerate}
\item For every girl $g$, $\curboy_g \neq \Lambda$.
\item For every boy $b$, $\bestgirl_b \neq \Lambda$
\end{enumerate}
\end{invariant}

\begin{proof}
By Invariant~\ref{inv:2}, $\cur_g$ is always at most $N$.  The first
assertion then followed from the definition of $\curboy$.  For the
second assertion, note that in a terminating state every boy is
pursued by at most one girl.  Since every girl is still pursuing some
boy by the first assertion, every boy must be paired with exactly one
girl.  Therefore, $\bestgirl_b \neq \Lambda$.
\end{proof}

Finally, we show that the algorithm creates a stable matching.

\begin{invariant}
\label{inv:4}
If a (reachable) state is terminating, then the pairing defined by
$\curboy_g$ and $\bestgirl_b$ is stable.
\end{invariant}

\begin{proof}
\begin{enumerate}
\item Assume not; that is, there exist $b, b' \in B$ and $g, g' \in G$ such
that $\bestgirl_b = g$, $\curboy_g = b$, $\bestgirl_{b'} = g'$,
$\curboy_{g'} = b'$, and $b$ and $g$ form a rogue couple.
\item {\tt FALSE}
\begin{enumerate}
\item $\rank_b(g') < \rank_b(g) = \best_b$ and $\rank_{g'}(b) <
\rank_{g'}(b') = \cur_{g'}$ (by definition of rogue couple).
\item $\best_b < rank_b(g')$ (by Invariant~\ref{inv:1} and second part of (a)).
\item $\best_b > \rank_b(g')$ (by first part of (a)).
\item Q. E. D. (by comparing 3 and 4)
\end{enumerate}
\item Q. E. D. (by contradiction)
\end{enumerate}
\end{proof}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Fairness}

This algorithm is totally biased in favor of the girls.  For a given
set of boys' and girls' preferences, there are many possible stable
matchings.  There is no stable matching in which any girl is paired
with a boy that she likes better than the one she is assigned by the
algorithm.  On the other hand, there is no stable matching in which
any boy is paired with a girl that he like less than the one is
assigned by the algorithm.  Thus, the algorithm is said to be
``optimal'' for the girls and ``pessimal'' for the boys.

Let $\pos$ be the set of all pairs $(b, g)$ such that there exists a
stable matching in which boy $b$ is paired with girl $g$.  Then the
claim that the algorithm is optimal for girls can be formulated as
follows.

\begin{claim}
If a girl $g$ prefers a boy $b$ to her match assigned to her by the
algorithm, than $b$ isn't even possible for her; that is $(b, g)
\notin \pos$.
\end{claim}

This claim is a consequence of the following invariant, which states
that girls only ever ``cross-off'' boys that they could never be
paired with anyway.

\begin{invariant}
\label{inv:5}
For every boy $b$ and every girl $g$, if $\rank_g(b) < \cur_g$, then
$(b, g) \notin \pos$.
\end{invariant}

\begin{proof}
By the invariant theorem:

\begin{enumerate}
\item The invariant holds vacuously in the start state, because
$\cur_g = 1$ for all $g$.
\item The invariant is preserved under all transitions.

  \begin{enumerate}

  \item Assume that the invariant is not preserved by some step.

  \item {\tt FALSE}

    \begin{enumerate}

    \item Fix a step that doesn't preserve it, so the invariant holds
before the step but not after.  Let $b$ and $g$ be the boy and girl
for which the invariant is false after the transition.

    \item This must be a step where boy $b$ rejects girl $g$, making
    $\cur_b$ greater than $\rank_g(b)$ even though $(b, g) \in \pos$.
         Fix $g'$ such that $b$ is rejecting $g$ in favor of $g'$.
         Fix a stable matching $M$, $(b,g) \in M$.
         Fix $b'$, the mate of $g'$ in $M$.

    \item $(b,g')$ form a rogue couple in $M$.

      \begin{enumerate}

      \item $b$ prefers $g'$ to $g$ (by ?).

      \item $g'$ prefers $b$ to $b'$.

%begin enumerate

        \item Assume not, that $g'$ prefers $b'$ to $b$, that is,
               $\ms{rank}_{g'}(b) < \ms{rank}_{g'}(b)$.
	\item $\ms{rank}_{g'}(b) = \ms{cur}_{g'}$ (before or after
               the transition).
               Because $g'$ is currently after $b$.

	\item $\ms{rank}_{g'}(b') < \ms{cur}_{g'}$.
               By previous two steps, 2.2.3.2.1 and 2.2.3.2.2

	\item $(b',g') \notin \ms{Poss}$.
               By the invariant applied to the pre-state.
            5. $(b',g') \notin P$
               By previous step and definition of $\ms{Poss}$.
            6. F, comparing 2.2.3.2.5 and 2.2.2
            7. QED, contradiction

%end enumerate

      \end{enumerate}
    \end{enumerate}
  \end{enumerate}
\end{enumerate}
         3. QED, definition of rogue pair
      4. QED, rogue pair (2.2.3) vs. good pairing (2.2.2).
   3. QED, Contradiction
3. QED, by Invariant Theorem

\end{proof}
%%%%%%%%%

\comment{
Pessimality for boys

[[[I stopped typing things in here]]]

My handwritten notes have what I think is a correct proof for this
case.
Be sure to use the LATEST version of those notes, p. 17, and 18 --
Joanne xeroxed them today (Wednesday).
In the proof in my notes, the key is

Invt 6:
For all $b,g$, if $\ms{rank}_b(g) > \ms{best}_b$ then $(b,g) \notin \ms{Poss}$.

The proof of this, on p. 18, doesn't use the invariant theorem, but
rather invariant 5 and a contradiction.
Still, there is a lot of repetition between this proof and the
optimality proof.  
I think the two arguments could be combined into one more economical
argument, though I'm not sure it's worth doing this for the notes.

E.g., I think we could probably replace Invt. 5 by:

Invt 5':
For all $b,g,g'$, 
if $\ms{cur}_g' = \ms{rank}_{g'}(b)$ (that is, $g'$ is chasing $b$)
and 
$\ms{rank}_b(g') < \ms{rank}_b(g)$ ($b$ likes $g'$ better than $g$)
then $(b,g) \notin \ms{Poss}$.

This seems to be to be provable using the Invariant theorem, with a proof
similar to the one above for Invt. 5.
Now the interesting transition seems to be the one where 
$g'$ is rejected by her previous choice and moves on to $b$. ???
(At the key step of the proof, before we invoke the inductive
hypothesis for $(b',g')$, I think we also have to use Invt 1 to get a
best-girl for b'. ???  Needs checking.)
Note that the base case now needs a little argument about a rogue pair
-- but maybe that can be a separate lemma.

Anyway, it seems that Invt 5' implies both invt 6 and invt 5
(the latter requiring invt 1).

I'm not sure of all this -- just thought of it quickly.
}
\end{document}