\documentclass[numbers=enddot,12pt,final,onecolumn,notitlepage]{scrartcl}%
\usepackage[headsepline,footsepline,manualmark]{scrlayer-scrpage}
\usepackage[all,cmtip]{xy}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{framed}
\usepackage{comment}
\usepackage{color}
\usepackage{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{wasysym}
\usepackage{easytable}
\usepackage{ytableau}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Friday, November 17, 2023 13:45:29}
%TCIDATA{SuppressPackageManagement}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="SaveForMode" CONTENT="1">}
%TCIDATA{BibliographyScheme=Manual}
%TCIDATA{Language=American English}
%BeginMSIPreambleData
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
%EndMSIPreambleData
\usetikzlibrary{arrows.meta}
\usetikzlibrary{chains}
\newcounter{exer}
\numberwithin{exer}{subsection}
\theoremstyle{definition}
\newtheorem{theo}{Theorem}[subsection]
\newenvironment{theorem}[1][]
{\begin{theo}[#1]\begin{leftbar}}
{\end{leftbar}\end{theo}}
\newtheorem{lem}[theo]{Lemma}
\newenvironment{lemma}[1][]
{\begin{lem}[#1]\begin{leftbar}}
{\end{leftbar}\end{lem}}
\newtheorem{prop}[theo]{Proposition}
\newenvironment{proposition}[1][]
{\begin{prop}[#1]\begin{leftbar}}
{\end{leftbar}\end{prop}}
\newtheorem{defi}[theo]{Definition}
\newenvironment{definition}[1][]
{\begin{defi}[#1]\begin{leftbar}}
{\end{leftbar}\end{defi}}
\newtheorem{remk}[theo]{Remark}
\newenvironment{remark}[1][]
{\begin{remk}[#1]\begin{leftbar}}
{\end{leftbar}\end{remk}}
\newtheorem{coro}[theo]{Corollary}
\newenvironment{corollary}[1][]
{\begin{coro}[#1]\begin{leftbar}}
{\end{leftbar}\end{coro}}
\newtheorem{conv}[theo]{Convention}
\newenvironment{convention}[1][]
{\begin{conv}[#1]\begin{leftbar}}
{\end{leftbar}\end{conv}}
\newtheorem{quest}[theo]{Question}
\newenvironment{question}[1][]
{\begin{quest}[#1]\begin{leftbar}}
{\end{leftbar}\end{quest}}
\newtheorem{warn}[theo]{Warning}
\newenvironment{warning}[1][]
{\begin{warn}[#1]\begin{leftbar}}
{\end{leftbar}\end{warn}}
\newtheorem{conj}[theo]{Conjecture}
\newenvironment{conjecture}[1][]
{\begin{conj}[#1]\begin{leftbar}}
{\end{leftbar}\end{conj}}
\newtheorem{exam}[theo]{Example}
\newenvironment{example}[1][]
{\begin{exam}[#1]\begin{leftbar}}
{\end{leftbar}\end{exam}}
\newtheorem{exmp}[exer]{Exercise}
\newenvironment{exercise}[1][]
{\begin{exmp}[#1]\begin{leftbar}}
{\end{leftbar}\end{exmp}}
\newenvironment{statement}{\begin{quote}}{\end{quote}}
\newenvironment{fineprint}{\medskip \begin{small}}{\end{small} \medskip}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{warning}[1][Warning]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{teachingnote}[1][Teaching note]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\fi
\let\sumnonlimits\sum
\let\prodnonlimits\prod
\let\cupnonlimits\bigcup
\let\capnonlimits\bigcap
\renewcommand{\sum}{\sumnonlimits\limits}
\renewcommand{\prod}{\prodnonlimits\limits}
\renewcommand{\bigcup}{\cupnonlimits\limits}
\renewcommand{\bigcap}{\capnonlimits\limits}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\voffset=0cm
\hoffset=-0.7cm
\setlength\textheight{22.5cm}
\setlength\textwidth{15.5cm}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\newenvironment{teachingnote}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\excludecomment{teachingnote}
\newcommand{\CC}{\mathbb{C}}
\newcommand{\RR}{\mathbb{R}}
\newcommand{\QQ}{\mathbb{Q}}
\newcommand{\NN}{\mathbb{N}}
\newcommand{\ZZ}{\mathbb{Z}}
\newcommand{\KK}{\mathbb{K}}
\newcommand{\id}{\operatorname{id}}
\newcommand{\lcm}{\operatorname{lcm}}
\newcommand{\rev}{\operatorname{rev}}
\newcommand{\powset}[2][]{\ifthenelse{\equal{#2}{}}{\mathcal{P}\left(#1\right)}{\mathcal{P}_{#1}\left(#2\right)}}
\newcommand{\set}[1]{\left\{ #1 \right\}}
\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\tup}[1]{\left( #1 \right)}
\newcommand{\ive}[1]{\left[ #1 \right]}
\newcommand{\floor}[1]{\left\lfloor #1 \right\rfloor}
\newcommand{\lf}[2]{#1^{\underline{#2}}}
\newcommand{\underbrack}[2]{\underbrace{#1}_{\substack{#2}}}
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}
\newcommand{\are}{\ar@{-}}
\newcommand{\nnn}{\nonumber\\}
\newcommand{\sslash}{\mathbin{/\mkern-6mu/}}
\newcommand{\numboxed}[2]{\underbrace{\boxed{#1}}_{\text{box } #2}}
\newcommand{\ig}[2]{\includegraphics[scale=#1]{#2.png}}
\iffalse
\NOEXPAND{\today}{\today}
\NOEXPAND{\sslash}{\sslash}
\NOEXPAND{\numboxed}[2]{\numboxed}
\fi
\ihead{Math 235 Fall 2023, Worksheet 6, version \today}
\ohead{page \thepage}
\cfoot{Darij Grinberg}
\begin{document}
\setcounter{section}{5}

\section{Math 235 Fall 2023, Worksheet 6: Invariants and processes}

On this worksheet, we will discuss some techniques for analyzing
\emph{processes}. In particular, we will present \emph{invariants},
\emph{monovariants} (aka \emph{semi-invariants}) and \emph{working backwards}.
As with many other techniques, these are very simple ideas, but can be used in
many elegant and creative ways to obtain fairly surprising results.

These ideas appear in several texts on problem-solving: For example,
invariants and monovariants appear in \cite[\S 1.5]{GelAnd17}, \cite[Chapter
1]{Engel98}, \cite[\S 3.4]{Zeitz17}, \cite[Chapter 10]{StaRik08} and
\cite[Chapter 8]{20f}, whereas working backwards is discussed in \cite[\S 14.3
and elsewhere]{Engel98}. In particular, I recommend \cite[Chapter 8]{20f} as a
source of extra examples (as I have been deliberately avoiding a repetition of
the examples from \cite[Chapter 8]{20f} in the present worksheet).

As before, $\mathbb{N}$ means the set $\left\{  0,1,2,\ldots\right\}  $.

\subsection{Processes}

\subsubsection{What are they?}

Let me first informally define the concepts I will be using. For more
examples, see \cite[Chapter 8]{20f}.

Mathematicians frequently study \emph{processes} -- i.e., roughly speaking,
objects that change with time. For example, imagine an integer that increases
by $1$ every minute. For another example, imagine a tuple of integers that is
repeatedly extended by adding the last two of its entries together and
inserting the sum at the end of the tuple. (The former process is a clock,
while the latter is a way to compute the Fibonacci numbers, at least if you
start with the tuple $\left(  0,1\right)  $.) Processes do not have to be
deterministic; for example, a process can consist of an integer that increases
by $4$ or $6$ every minute, where the decision (whether to increase it by $4$
or by $6$) is made by whoever is performing the process. Thus, we have given
three examples of processes; you will soon see many more.

We restrict ourselves to processes that have a precisely defined set of
\emph{states} (which the object can have at any given time) and a precisely
defined set of \emph{moves} (i.e., ways in which the object can change from
one moment to the next; i.e., allowable transitions between states). The first
of our three above examples is thus a process whose states are the integers,
and whose moves are $i\mapsto i+1$ (that is, \textquotedblleft replace $i$ by
$i+1$\textquotedblright) for each integer $i$. Our second example is a process
whose states are the tuples $\left(  a_{1},a_{2},\ldots,a_{k}\right)  $ of
integers, and whose moves are $\left(  a_{1},a_{2},\ldots,a_{k}\right)
\mapsto\left(  a_{1},a_{2},\ldots,a_{k},a_{k-1}+a_{k}\right)  $. Note that
such moves are only allowed when $k\geq2$, since otherwise $a_{k-1}+a_{k}$
does not make sense. Thus, if our state is a $0$-tuple or a $1$-tuple, then we
cannot make a move. States from which no moves are possible are called
\emph{end states} or \emph{final states}. Finally, our third example is a
process whose states are the integers, and whose moves are $i\mapsto i+4$ and
$i\mapsto i+6$ for each integer $i$.

\subsubsection{Questions about processes}

Whenever you have a process, you can ask several natural questions:

\begin{itemize}
\item Given two states $a$ and $b$, is it possible to reach $b$ from $a$ by
making (the right) moves?

\item What states can be reached starting from a given state $a$ ?

\item Can the process go on forever, or will it necessarily reach a final
state after a (finite) number of moves?

\item Does the process exhibit periodic behavior (i.e., does it return to the
starting state after some number of moves)?

\item Is the process reversible? I.e., can we reconstruct a state from the
next state?

\item What things (quantities, statements) remain unchanged whenever we make a
move (and thus never change during the process)? These things are called the
\emph{invariants} (or \emph{conserved quantities}) of the process.

\item What things change only in one direction (i.e., only get smaller or only
get larger) whenever we make a move? These things are called the
\emph{monovariants} of the process.
\end{itemize}

These questions are related, and solving one can often help in solving
another. For instance, our first example of a process above has an obvious
monovariant (the number $i$ itself, which gets larger and larger as we keep
increasing it by $1$), and this immediately entails that the process cannot
exhibit periodic behavior. Likewise, our third example of a process has an
easily-found invariant: the parity of the number $i$, that is, the remainder
of $i$ upon division by $2$ (since this is clearly preserved if we increase
$i$ by $4$ or by $6$). Thus, all states reachable from $2$ (using the moves of
this process) are even integers (although not every even integer is reachable
from $2$). Hence, it is impossible to reach the state $7$ from the state $2$
by making moves of this process.

\subsubsection{\label{subsec.process.euclid}The cave-man's Euclidean
algorithm}

The examples so far were toy examples. A more interesting example of a process
is the famous \emph{Euclidean algorithm} for computing the greatest common
divisor $\gcd\left(  a,b\right)  $ of two nonnegative integers $a$ and $b$. In
the most elementary version of this algorithm\footnote{This might not be the
version that you are most familiar with. In fact, this is a rather slow
version, since it uses subtraction instead of division with remainder. But I
think it is best for illustrative purposes.}, we begin with the pair $\left(
a,b\right)  $ and progressively \textquotedblleft simplify\textquotedblright%
\ it by subtracting the smaller of its entries from the larger\footnote{If the
two entries are equal, we can freely choose which one to subtract from
which.}, as long as the smaller entry is nonzero. In other words, this is a
process whose states are the pairs $\left(  a,b\right)  \in\mathbb{N}%
\times\mathbb{N}$, and whose moves are%
\[
\left(  a,b\right)  \mapsto\left(  a-b,\ b\right)
\ \ \ \ \ \ \ \ \ \ \text{if }a\geq b>0
\]
and%
\[
\left(  a,b\right)  \mapsto\left(  a,\ b-a\right)
\ \ \ \ \ \ \ \ \ \ \text{if }b\geq a>0.
\]
For example, starting with $\left(  10,14\right)  $, it proceeds as follows:%
\[
\left(  10,14\right)  \mapsto\left(  10,4\right)  \mapsto\left(  6,4\right)
\mapsto\left(  2,4\right)  \mapsto\left(  2,2\right)  \mapsto\left(
2,0\right)
\]
(we could also go to $\left(  0,2\right)  $ from $\left(  2,2\right)  $
instead). The state $\left(  2,0\right)  $ reached here is an end state, since
no moves from it are possible. What do we notice about this process?

\begin{itemize}
\item A monovariant of this process is the sum $a+b$ of the two entries of the
state $\left(  a,b\right)  $. Indeed, this sum decreases with every move
(since $\left(  a-b\right)  +b$ and $a+\left(  b-a\right)  $ are both smaller
than $a+b$).

\item Hence, the process cannot keep running forever. Indeed, the sum $a+b$ is
a nonnegative integer, but a nonnegative integer can only decrease a finite
number of times until it becomes negative (or non-integer). Thus, after a
finite number of moves, we reach an end state.

\item An invariant of this process is the greatest common divisor $\gcd\left(
a,b\right)  $ of the two entries of the state $\left(  a,b\right)  $. Indeed,
this gcd\footnote{I abbreviate the word \textquotedblleft greatest common
divisor\textquotedblright\ as \textquotedblleft gcd\textquotedblright\ here
and in the following.} remains unchanged under every move, since $\gcd\left(
a-b,b\right)  =\gcd\left(  a,b\right)  $ and $\gcd\left(  a,b-a\right)
=\gcd\left(  a,b\right)  $.

\item From these observations, we can predict how the process will end: If we
start our process with a given pair $\left(  a,b\right)  \in\mathbb{N}%
\times\mathbb{N}$, then it will eventually (after finitely many moves) reach
an end state. This end state will have either the form $\left(  d,0\right)  $
or the form $\left(  0,d\right)  $ (since an end state must have a zero
entry), and moreover the gcd of this end state will equal the gcd of the
original state (since the gcd is an invariant). That is, $\gcd\left(
d,0\right)  $ (or, respectively, $\gcd\left(  0,d\right)  $) will equal
$\gcd\left(  a,b\right)  $. Since both $\gcd\left(  d,0\right)  $ and
$\gcd\left(  0,d\right)  $ equal $d$, this means that $d$ will equal
$\gcd\left(  a,b\right)  $. Thus, our process computes the gcd of $a$ and $b$.
\end{itemize}

Note that we have used both a monovariant (to prove that the process
terminates) and an invariant (to identify the end state to which it leads). A
similar analysis can be made for the \textquotedblleft
grown-up\textquotedblright\ Euclidean algorithm that uses division with
remainder instead of subtraction.

\subsection{Invariants}

We now come to more interesting problems. The first is a famous puzzle
(\href{https://www.cut-the-knot.org/blue/Chameleons.shtml}{the
\textquotedblleft chameleon problem\textquotedblright}):

\begin{exercise}
\label{exe.invars.chameleon1}An island has a population of chameleons.
Chameleons come in three colors (red, green and blue), but can change these
colors according to the following rule: When two chameleons of different
colors meet, they both change to the third color. (For example, if a red
chameleon meets a blue one, they both turn green.) This is the only situation
in which chameleons change colors. (Some fine print for the pedantic reader:
More than two chameleons never meet simultaneously. Also, a chameleon cannot
have more than one color at a time.)

At the beginning, the island has $13$ red, $15$ green and $17$ blue
chameleons. Can it happen that, after a while, all of the chameleons have
acquired the same color?

\flushright(Tournament of Towns 6.10)
\end{exercise}

\begin{proof}
[Solution idea.]As a warmup, let us solve an easier version of this exercise:
What if the island starts out with $1$ red, $4$ green and $5$ blue chameleons
instead? Then, the answer is \textquotedblleft yes\textquotedblright. For
example, we can first have a red-green pair meet and change colors, so that we
obtain $0$ red, $3$ green and $7$ blue chameleons. Then, a green-blue pair
meets and turns red, so we obtain $2$ red, $2$ green and $6$ blue chameleons.
Then, two red-green pairs meet (independently of each other), and ultimately
all chameleons become blue.

Unfortunately, this kind of reasoning can only prove a positive answer, and it
becomes increasingly cumbersome as the chameleon population grows.

So let us return to the exercise with a fresh mind. Obviously we are dealing
with a process. Its states are the possible distributions of colors on the
island. For the sake of convenience, we will encode such distributions as
triples $\left(  a,b,c\right)  \in\mathbb{N}^{3}$, where $a$ is the number of
red chameleons, $b$ is the number of green chameleons and $c$ is the number of
blue chameleons.

Hence, the states of our process are the triples $\left(  a,b,c\right)
\in\mathbb{N}^{3}$, and the moves are%
\begin{align*}
\left(  a,b,c\right)   &  \mapsto\left(  a-1,b-1,c+2\right)
\ \ \ \ \ \ \ \ \ \ \text{if }a\geq1\text{ and }b\geq1;\\
\left(  a,b,c\right)   &  \mapsto\left(  a-1,b+2,c-1\right)
\ \ \ \ \ \ \ \ \ \ \text{if }a\geq1\text{ and }c\geq1;\\
\left(  a,b,c\right)   &  \mapsto\left(  a+2,b-1,c-1\right)
\ \ \ \ \ \ \ \ \ \ \text{if }b\geq1\text{ and }c\geq1.
\end{align*}
(These moves correspond to a red-green meeting, a red-blue meeting and a
green-blue meeting, respectively.)

The end states are precisely the states in which all chameleons have the same
color. Thus, we are wondering if we can reach an end state starting from the
state $\left(  13,15,17\right)  $. Our warmup above shows that an end state
can be reached from the state $\left(  1,4,5\right)  $ via the moves%
\[
\left(  1,4,5\right)  \mapsto\left(  0,3,7\right)  \mapsto\left(
2,2,6\right)  \mapsto\left(  1,1,8\right)  \mapsto\left(  0,0,10\right)  .
\]
The starting state $\left(  13,15,17\right)  $ does not succumb to such a
simple move sequence, so we try to think more generally.

What invariants does our system have? Clearly, the total number of all
chameleons on the island never changes. In other words, the sum $a+b+c$ of a
state $\left(  a,b,c\right)  $ is an invariant. This shows that any sequence
of moves from $\left(  13,15,17\right)  $ to an end state must lead to an end
state whose sum is $13+15+17=45$. But this does not rule out that such a
sequence might exist.

However, there is another, subtler invariant that is helpful. Indeed, let us
\textquotedblleft work modulo $3$\textquotedblright, that is, consider the
remainders of $a,b,c$ upon division by $3$. Recall that the remainder of a
number $n$ upon division by $3$ is denoted by $n\%3$.

Modulo $3$, there is no difference between $x-1$ and $x+2$. Hence, all three
possible moves \textquotedblleft look like\textquotedblright\ $\left(
a,b,c\right)  \mapsto\left(  a-1,b-1,c-1\right)  $ modulo $3$, in the sense
that all three entries of a state decrease by $1$ modulo $3$ when we apply a
move. Hence, the difference $a-b$ between the numbers of red and of green
chameleons does not change modulo $3$ (that is, its remainder $\left(
a-b\right)  \%3$ does not change) when we make a move.\footnote{If you don't
like the above handwaving, you can check this directly: For instance, when we
make a move of the form $\left(  a,b,c\right)  \mapsto\left(
a-1,b+2,c-1\right)  $, the difference $a-b$ decreases by $3$ (since it becomes
$\left(  a-1\right)  -\left(  b+2\right)  =a-b-3$) and thus its remainder
$\left(  a-b\right)  \%3$ does not change. Similarly, the other two kinds of
moves don't change this remainder either.}

Hence, the remainder $\left(  a-b\right)  \%3$ constructed from a state
$\left(  a,b,c\right)  $ is an invariant of our process. Thus, for any state
$\left(  a^{\prime},b^{\prime},c^{\prime}\right)  $ that is reachable from
$\left(  a,b,c\right)  $, we will have
\begin{equation}
\left(  a^{\prime}-b^{\prime}\right)  \%3=\left(  a-b\right)  \%3.
\label{sol.invars.chameleon1.a-b}%
\end{equation}
Similarly, we can see that any such state will satisfy
\begin{align}
\left(  b^{\prime}-c^{\prime}\right)  \%3  &  =\left(  b-c\right)
\%3\ \ \ \ \ \ \ \ \ \ \text{and}\label{sol.invars.chameleon1.b-c}\\
\left(  c^{\prime}-a^{\prime}\right)  \%3  &  =\left(  c-a\right)  \%3.
\label{sol.invars.chameleon1.c-a}%
\end{align}


Now, let us assume that we can reach an end state starting from a state
$\left(  a,b,c\right)  $. This end state must have two zero entries (since all
chameleons must have the same color), so it has either the form $\left(
d,0,0\right)  $ or the form $\left(  0,d,0\right)  $ or the form $\left(
0,0,d\right)  $ for some $d\in\mathbb{N}$. Consider this $d$. Let us assume
that it has the form $\left(  d,0,0\right)  $ (the other two cases are
analogous). Thus, the equality (\ref{sol.invars.chameleon1.b-c}) (applied to
$\left(  a^{\prime},b^{\prime},c^{\prime}\right)  =\left(  d,0,0\right)  $)
yields $\left(  0-0\right)  \%3=\left(  b-c\right)  \%3$. Hence, $\left(
b-c\right)  \%3=\left(  0-0\right)  \%3=0\%3=0$, so that $b-c\equiv
0\operatorname{mod}3$. In other words, $b\equiv c\operatorname{mod}3$. Thus,
two of the three numbers $a,b,c$ are congruent modulo $3$. Similarly, we can
obtain the same conclusion in the other two cases.

Thus, we have shown that if we can reach an end state starting from a state
$\left(  a,b,c\right)  $, then two of the three numbers $a,b,c$ are congruent
modulo $3$. Taking the contrapositive, we conclude that if a state $\left(
a,b,c\right)  $ has no two entries that are congruent modulo $3$, then we
cannot reach an end state from it. Hence, in particular, we cannot reach an
end state from the state $\left(  13,15,17\right)  $ (since no two of the
entries $13,15,17$ are congruent modulo $3$). In other words, in Exercise
\ref{exe.invars.chameleon1}, the chameleons will never all end up having the
same color, no matter how they organize their meetings.
\end{proof}

Here is another illustrative exercise:

\begin{exercise}
\label{exe.invars.prodgame}You arrive at Heaven's gate, but it is closed.
Three glowing numbers appear on the wall in front of you: $a$ (the number of
times you have used the axiom of choice), $b$ (the number of times you have
denoted a function by the term for its value) and $c$ (the number of theorems
you have cited without knowing their proofs). Before you proceed, you must
play a game: You can pick any of the three numbers and decrease it by $1$,
unless it already equals $0$. When you do this, the product of the other two
numbers is added to the time (in years) that you have to spend in Purgatory.
When all three numbers become $0$, you serve your punishment, after which you
are set free.

How should you play to minimize your time in Purgatory?

\flushright(Tournament of Towns 28.2.1)
\end{exercise}

\begin{proof}
[Solution idea.]For the sake of brevity, we encode the three numbers $a,b,c$
on the wall as a triple $\left(  a,b,c\right)  $. Furthermore, we define the
\emph{punishment} to be the number of Purgatory-years accumulated so far
during the game. At the beginning of the game, this number is $0$, but every
move increases it by a certain product. You want to minimize the final
punishment (i.e., the punishment accumulated by the end of the game).

For a simple example, let us try to play this game with $a=2$ and $b=3$ and
$c=1$. Here is one way to do this:%
\begin{align*}
\left(  2,3,1\right)   &  \mapsto\left(  2,2,1\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{punishment increases by }2\cdot1=2\right) \\
&  \mapsto\left(  2,2,0\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{punishment
increases by }2\cdot2=4\right) \\
&  \mapsto\left(  2,1,0\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{punishment
increases by }2\cdot0=0\right) \\
&  \mapsto\left(  1,1,0\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{punishment
increases by }1\cdot0=0\right) \\
&  \mapsto\left(  0,1,0\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{punishment
increases by }1\cdot0=0\right) \\
&  \mapsto\left(  0,0,0\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{punishment
increases by }0\cdot0=0\right)  .
\end{align*}
Thus, we finish the game with a punishment of $2+4+0+0+0+0=6$. Try another way
(e.g., starting by decreasing the $1$ or the $2$ instead of the $3$).
Surprisingly perhaps, you will see that the final punishment is $6$ again!

Try a few more examples to check whether this might be a coincidence. What you
might notice is that the final punishment will not just be independent of how
you play, but in fact always equal to $abc$.

This looks like something that an invariant could be useful to prove. However,
care must be taken in defining the process. It is tempting to let the states
of the process to be the triples of the numbers on the wall; but this leads to
no useful invariants, since these numbers eventually all become $0$. Moreover,
such a definition would forget about the punishment, but this is the most
important feature of the problem!

Thus, we have to incorporate the punishment into the state. So we want the
states to be $4$-tuples $\left(  u,v,w,p\right)  $, where $u,v,w$ are the
three numbers on the wall (originally $a,b,c$, ultimately $0,0,0$), and $p$ is
the punishment accumulated so far (originally $0$). Thus, the states of our
process are the $4$-tuples $\left(  u,v,w,p\right)  \in\mathbb{N}^{4}$, and
the moves are%
\begin{align*}
\left(  u,v,w,p\right)   &  \mapsto\left(  u-1,v,w,p+vw\right)
\ \ \ \ \ \ \ \ \ \ \text{if }u\geq1;\\
\left(  u,v,w,p\right)   &  \mapsto\left(  u,v-1,w,p+uw\right)
\ \ \ \ \ \ \ \ \ \ \text{if }v\geq1;\\
\left(  u,v,w,p\right)   &  \mapsto\left(  u,v,w-1,p+uv\right)
\ \ \ \ \ \ \ \ \ \ \text{if }w\geq1.
\end{align*}
The end states are the states of the form $\left(  0,0,0,p\right)  $. The
initial state is $\left(  a,b,c,0\right)  $. Clearly, the game ends after
$a+b+c$ moves (why?), and we want to show that the end state is $\left(
0,0,0,abc\right)  $ (so that the total punishment incurred will be $abc$).

What invariants could our system have? We are looking for a quantity that is
preserved under each move. For instance, the move $\left(  u,v,w,p\right)
\mapsto\left(  u-1,v,w,p+vw\right)  $ decreases the first entry $u$ by $1$
while increasing the last entry $p$ by $vw$. In an invariant, these two
changes should balance each other out. We can achieve this by multiplying $u$
by $vw$. In other words, we take the sum $uvw+p$.

Thus, the quantity $uvw+p$ defined for a state $\left(  u,v,w,p\right)  $ is
unchanged under the move $\left(  u,v,w,p\right)  \mapsto\left(
u-1,v,w,p+vw\right)  $. Similarly, we can see that this quantity is unchanged
under the other two types of moves. Hence, this quantity is an invariant.

For the initial state $\left(  a,b,c,0\right)  $, this quantity is
$abc+0=abc$. For the final state $\left(  0,0,0,p\right)  $, it is
$0\cdot0\cdot0+p=p$. Since this quantity cannot change from the initial to the
final state (because it is unchanged under any move), we thus conclude that
$p=abc$. In other words, the final punishment will always be $abc$, no matter
how you play.
\end{proof}

\subsection{Monovariants}

Monovariants can be useful, too. We saw a simple example of their use in
Subsubsection \ref{subsec.process.euclid}. Here are two trickier applications
(see \cite[\S 8.2 and \S A.2.10 (First solution to Exercise 3.7.10)]{20f} for
other examples):

\begin{exercise}
\label{exa.monvars.SPmoves}Consider an $n$-tuple $\left(  a_{1},a_{2}%
,\ldots,a_{n}\right)  $ of real numbers. We are allowed to make the following
two kinds of moves:

\begin{itemize}
\item \textbf{S-moves:} We pick two adjacent entries $a_{i}$ and $a_{i+1}$
that are \textquotedblleft out of order\textquotedblright\ (i.e., satisfy
$a_{i}>a_{i+1}$), and swap them (i.e., replace them by $a_{i+1}$ and $a_{i}$,
respectively). This is called an \emph{S-move}.

\item \textbf{P-moves:} We pick two adjacent entries $a_{i}$ and $a_{i+1}$
that are \textquotedblleft out of order\textquotedblright\ (i.e., satisfy
$a_{i}>a_{i+1}$), and replace them by $a_{i+1}+1$ and $a_{i}+1$, respectively.
This is called a \emph{P-move}.
\end{itemize}

For instance, examples of S-moves are $\left(  4,3,1,2\right)  \mapsto\left(
3,4,1,2\right)  $ and $\left(  4,3,1,2\right)  \mapsto\left(  4,1,3,2\right)
$, while examples of P-moves are $\left(  4,3,1,2\right)  \mapsto\left(
4,5,1,2\right)  $ and $\left(  4,3,1,2\right)  \mapsto\left(  4,2,4,2\right)
$.

\begin{enumerate}
\item[\textbf{(a)}] Prove that if we keep applying S-moves to our $n$-tuple
(sequentially), then we eventually end up with a weakly increasing $n$-tuple
(i.e., the process terminates).

\item[\textbf{(b)}] Is the same true if we allow applying both P-moves and S-moves?

\item[\textbf{(c)}] Is the same true if we allow applying both P-moves and
S-moves, but require that all entries of our $n$-tuple are integers?
\end{enumerate}
\end{exercise}

\begin{proof}
[Solution idea.]Before we come to the solution, let me illustrate the
different moves and what they can lead to.

Starting with the $4$-tuple $\left(  3,1,3,2\right)  $, we can apply an S-move
to its first two entries (which are out of order), and obtain the $4$-tuple
$\left(  1,3,3,2\right)  $. Subsequently, we apply a further S-move to the
last two entries, obtaining $\left(  1,3,2,3\right)  $. Then, we apply one
more S-move to the middle two entries, obtaining $\left(  1,2,3,3\right)  $,
at which point the $4$-tuple has become weakly increasing and thus we cannot
apply any further moves. Thus, our process has stopped after three moves.
However, if we also allow P-moves, then we can keep making moves a bit longer:
For example, starting with a P-move (applied to the first two entries), we can
obtain%
\[
\left(  3,1,3,2\right)  \overset{\text{P-move}}{\mapsto}\left(
2,4,3,2\right)  \overset{\text{S-move}}{\mapsto}\left(  2,4,2,3\right)
\overset{\text{P-move}}{\mapsto}\left(  2,3,5,3\right)  \overset{\text{S-move}%
}{\mapsto}\left(  2,3,3,5\right)  .
\]
Other choices of moves lead to different results. Still, the process
terminates, no matter what we do. How can we prove this, and does this hold
for every possible initial state? \medskip

\textbf{(a)} This is a classical result (underlying various sorting
algorithms), see \cite[Exercise 8.2.1]{20f} for example. The following proof
is essentially the same as in \cite[Exercise 8.2.1]{20f}, but organized
somewhat differently.

We consider the \textquotedblleft S-process\textquotedblright\ -- i.e., the
process that successively applies S-moves to an $n$-tuple of real numbers.
(Its states are the $n$-tuples of real numbers, and its moves are the
S-moves.) We try to construct a monovariant that is a nonnegative integer and
decreases with every S-move. If we can find such a monovariant, then it will
automatically follow that the process will eventually terminate, since a
nonnegative integer cannot decrease endlessly.

To define our monovariant, we first introduce some notation:

\begin{itemize}
\item If $a$ is any $n$-tuple, and if $i\in\left\{  1,2,\ldots,n\right\}  $,
then $a_{i}$ shall denote the $i$-th entry of $a$. Thus, $a=\left(
a_{1},a_{2},\ldots,a_{n}\right)  $ for any $n$-tuple $a$.

\item If $a$ is any $n$-tuple, and if $i\in\left\{  1,2,\ldots,n\right\}  $,
then $a_{>i}$ shall denote the $\left(  n-i\right)  $-tuple $\left(
a_{i+1},a_{i+2},\ldots,a_{n}\right)  $. In other words, $a_{>i}$ is the part
of $a$ to the right of the $i$-th position. (In other words, $a_{>i}$ is what
remains if we remove the first $i$ entries from $a$.)

\item If $a$ is an $n$-tuple of real numbers, and if $i\in\left\{
1,2,\ldots,n\right\}  $, then $\ell_{i}\left(  a\right)  $ shall denote the
number of entries of $a_{>i}$ that are smaller than $a_{i}$. In other words,%
\[
\ell_{i}\left(  a\right)  :=\left(  \text{the number of }j\in\left\{
i+1,i+2,\ldots,n\right\}  \text{ such that }a_{j}<a_{i}\right)  .
\]
For example, if $a=\left(  4,2,4,1,3\right)  $, then $\ell_{1}\left(
a\right)  =3$ and $\ell_{2}\left(  a\right)  =1$ and $\ell_{3}\left(
a\right)  =2$ and $\ell_{4}\left(  a\right)  =0$ and $\ell_{5}\left(
a\right)  =0$.

We note that $\ell_{i}\left(  a\right)  $ is always a nonnegative integer and
is $\leq n-i$ (since the tuple $a_{>i}$ has only $n-i$ entries in total).

\item If $a$ is an $n$-tuple of real numbers, then we define the nonnegative
integer%
\begin{equation}
\ell\left(  a\right)  :=\ell_{1}\left(  a\right)  +\ell_{2}\left(  a\right)
+\cdots+\ell_{n}\left(  a\right)  . \label{sol.monvars.SPmoves.la=}%
\end{equation}
Thus, $\ell\left(  a\right)  $ is the number of all pairs $\left(  i,j\right)
$ of integers such that $1\leq i<j\leq n$ and $a_{j}<a_{i}$. (These pairs are
known as the \emph{inversions} of $a$.)

For example, if $a=\left(  4,2,4,1,3\right)  $, then $\ell\left(  a\right)
=3+1+2+0+0=6$.

We observe that $\ell\left(  a\right)  =0$ if and only if $a$ is weakly
increasing (why?).
\end{itemize}

Now, we shall show that this nonnegative integer $\ell\left(  a\right)  $
(where $a=\left(  a_{1},a_{2},\ldots,a_{n}\right)  $ is our state) is a
monovariant of the S-process. To do so, we must prove that if an S-move
transforms an $n$-tuple $a$ into an $n$-tuple $b$, then $\ell\left(  b\right)
<\ell\left(  a\right)  $.

Let us prove this. Let an S-move transform an $n$-tuple $a$ into an $n$-tuple
$b$. We must prove that $\ell\left(  b\right)  <\ell\left(  a\right)  $. We
will actually prove something more specific: namely, that $\ell\left(
b\right)  =\ell\left(  a\right)  -1$.

Recall that $a=\left(  a_{1},a_{2},\ldots,a_{n}\right)  $. Since $b$ is
obtained from $a$ by an S-move, we thus must have
\begin{equation}
b=\left(  \underbrace{a_{1},a_{2},\ldots,a_{i-1}}_{\text{same entries as in
}a},a_{i+1},a_{i},\underbrace{a_{i+2},a_{i+3},\ldots,a_{n}}_{\text{same
entries as in }a}\right)  \label{sol.monvars.SPmoves.a.b=}%
\end{equation}
for some $i\in\left\{  1,2,\ldots,n-1\right\}  $ satisfying $a_{i}>a_{i+1}$
(because an S-move swaps two consecutive entries $a_{i}$ and $a_{i+1}$ that
satisfy $a_{i}>a_{i+1}$). Consider this $i$. Thus, $b_{i}=a_{i+1}$ and
$b_{i+1}=a_{i}$.

Now, let us see how the numbers $\ell_{k}\left(  a\right)  $ differ from the
respective numbers $\ell_{k}\left(  b\right)  $:

\begin{itemize}
\item For each $k\in\left\{  1,2,\ldots,i-1\right\}  $, we have%
\begin{equation}
\ell_{k}\left(  b\right)  =\ell_{k}\left(  a\right)  .
\label{sol.monvars.SPmoves.a.1}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.a.1}):}\footnote{I am spelling out
this argument in much more detail than you would need on any exam. You could
just claim (\ref{sol.monvars.SPmoves.a.1}) to be obvious. The same applies to
the equalities (\ref{sol.monvars.SPmoves.a.2}), (\ref{sol.monvars.SPmoves.a.3}%
) and (\ref{sol.monvars.SPmoves.a.4}), except that you should perhaps point
out that $a_{i}>a_{i+1}$ is used in the proofs of
(\ref{sol.monvars.SPmoves.a.2}) and (\ref{sol.monvars.SPmoves.a.3}).} Let
$k\in\left\{  1,2,\ldots,i-1\right\}  $. Then, the $n$-tuples $a$ and $b$ have
the same $k$-th entries (since they differ only in their $i$-th and $\left(
i+1\right)  $-st positions). In other words, $b_{k}=a_{k}$. Furthermore the
entries of $b$ after the $k$-th position are the same as the entries of $a$
after the $k$-th position, up to a permutation (because the S-move only swaps
the entries at the $i$-th and $\left(  i+1\right)  $-st positions, and both of
these positions are to the right of the $k$-th position). In other words, the
entries of $b_{>k}$ are the same as the entries of $a_{>k}$, up to a permutation.

However, the definition of $\ell_{k}\left(  b\right)  $ yields%
\begin{align*}
\ell_{k}\left(  b\right)   &  =\left(  \text{the number of entries of }%
b_{>k}\text{ that are smaller than }b_{k}\right) \\
&  =\left(  \text{the number of entries of }b_{>k}\text{ that are smaller than
}a_{k}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since }b_{k}%
=a_{k}\right) \\
&  =\left(  \text{the number of entries of }a_{>k}\text{ that are smaller than
}a_{k}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{since the entries of }b_{>k}\text{ are the same as}\\
\text{the entries of }a_{>k}\text{, up to a permutation}%
\end{array}
\right) \\
&  =\ell_{k}\left(  a\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by the
definition of }\ell_{k}\left(  a\right)  \right)  .
\end{align*}
This proves (\ref{sol.monvars.SPmoves.a.1}).]

\item We have
\begin{equation}
\ell_{i}\left(  b\right)  =\ell_{i+1}\left(  a\right)  .
\label{sol.monvars.SPmoves.a.2}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.a.2}):} The definition of
$\ell_{i}\left(  b\right)  $ yields%
\begin{align*}
\ell_{i}\left(  b\right)   &  =\left(  \text{the number of entries of }%
b_{>i}\text{ that are smaller than }b_{i}\right) \\
&  =\left(  \text{the number of entries of }b_{>i}\text{ that are smaller than
}a_{i+1}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since }b_{i}%
=a_{i+1}\right) \\
&  =\left(  \text{the number of entries among }a_{i},a_{i+2},a_{i+3}%
,\ldots,a_{n}\text{ that are smaller than }a_{i+1}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{since the entries of }b_{>i}\text{ are }a_{i},a_{i+2},a_{i+3}%
,\ldots,a_{n}\\
\text{(because (\ref{sol.monvars.SPmoves.a.b=}) yields }b_{>i}=\left(
a_{i},a_{i+2},a_{i+3},\ldots,a_{n}\right)  \text{)}%
\end{array}
\right) \\
&  =\left(  \text{the number of entries among }a_{i+2},a_{i+3},\ldots
,a_{n}\text{ that are smaller than }a_{i+1}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{here, we removed }a_{i}\text{ from the list, since }a_{i}\\
\text{is not smaller than }a_{i+1}\text{ (in fact, }a_{i}>a_{i+1}\text{)}%
\end{array}
\right) \\
&  =\left(  \text{the number of entries of }a_{>i+1}\text{ that are smaller
than }a_{i+1}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since }%
a_{i+2},a_{i+3},\ldots,a_{n}\text{ are the entries of }a_{>i+1}\right) \\
&  =\ell_{i+1}\left(  a\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by the
definition of }\ell_{i+1}\left(  a\right)  \right)  .
\end{align*}
This proves (\ref{sol.monvars.SPmoves.a.2}).]

\item We have%
\begin{equation}
\ell_{i+1}\left(  b\right)  =\ell_{i}\left(  a\right)  -1.
\label{sol.monvars.SPmoves.a.3}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.a.3}):} The definition of
$\ell_{i+1}\left(  b\right)  $ yields%
\begin{align}
\ell_{i+1}\left(  b\right)   &  =\left(  \text{the number of entries of
}b_{>i+1}\text{ that are smaller than }b_{i+1}\right) \nonumber\\
&  =\left(  \text{the number of entries of }b_{>i+1}\text{ that are smaller
than }a_{i}\right) \nonumber\\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since }b_{i+1}%
=a_{i}\right) \nonumber\\
&  =\left(  \text{the number of entries among }a_{i+2},a_{i+3},\ldots
,a_{n}\text{ that are smaller than }a_{i}\right)
\label{sol.monvars.SPmoves.a.3.pf.1}%
\end{align}
(since the entries of $b_{>i+1}$ are $a_{i+2},a_{i+3},\ldots,a_{n}$ (because
from (\ref{sol.monvars.SPmoves.a.b=}), we obtain $b_{>i+1}=\left(
a_{i+2},a_{i+3},\ldots,a_{n}\right)  $)). But the definition of $\ell
_{i}\left(  a\right)  $ yields%
\begin{align*}
\ell_{i}\left(  a\right)   &  =\left(  \text{the number of entries of }%
a_{>i}\text{ that are smaller than }a_{i}\right) \\
&  =\left(  \text{the number of entries among }a_{i+1},a_{i+2},a_{i+3}%
,\ldots,a_{n}\text{ that are smaller than }a_{i}\right) \\
&  =1+\left(  \text{the number of entries among }a_{i+2},a_{i+3},\ldots
,a_{n}\text{ that are smaller than }a_{i}\right)
\end{align*}
(here, we removed the entry $a_{i+1}$ from the list, but this changes the
number by $1$ since this entry is smaller than $a_{i}$ (since $a_{i}>a_{i+1}%
$)). In view of (\ref{sol.monvars.SPmoves.a.3.pf.1}), we can rewrite this as
$\ell_{i}\left(  a\right)  =1+\ell_{i+1}\left(  b\right)  $. Hence,
$\ell_{i+1}\left(  b\right)  =\ell_{i}\left(  a\right)  -1$. This proves
(\ref{sol.monvars.SPmoves.a.3}).]

\item For each $k\in\left\{  i+2,i+3,\ldots,n\right\}  $, we have%
\begin{equation}
\ell_{k}\left(  b\right)  =\ell_{k}\left(  a\right)  .
\label{sol.monvars.SPmoves.a.4}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.a.4}):} This is very similar to
(\ref{sol.monvars.SPmoves.a.1}).]
\end{itemize}

Now, (\ref{sol.monvars.SPmoves.la=}) (applied to $b$ instead of $a$) yields%
\begin{align*}
\ell\left(  b\right)   &  =\ell_{1}\left(  b\right)  +\ell_{2}\left(
b\right)  +\cdots+\ell_{n}\left(  b\right) \\
&  =\left(  \underbrace{\ell_{1}\left(  b\right)  }_{\substack{=\ell
_{1}\left(  a\right)  \\\text{(by (\ref{sol.monvars.SPmoves.a.1}))}%
}}+\underbrace{\ell_{2}\left(  b\right)  }_{\substack{=\ell_{2}\left(
a\right)  \\\text{(by (\ref{sol.monvars.SPmoves.a.1}))}}}+\cdots
+\underbrace{\ell_{i-1}\left(  b\right)  }_{\substack{=\ell_{i-1}\left(
a\right)  \\\text{(by (\ref{sol.monvars.SPmoves.a.1}))}}}\right)
+\underbrace{\ell_{i}\left(  b\right)  }_{\substack{=\ell_{i+1}\left(
a\right)  \\\text{(by (\ref{sol.monvars.SPmoves.a.2}))}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\underbrace{\ell_{i+1}\left(  b\right)  }%
_{\substack{=\ell_{i}\left(  a\right)  -1\\\text{(by
(\ref{sol.monvars.SPmoves.a.3}))}}}+\left(  \underbrace{\ell_{i+2}\left(
b\right)  }_{\substack{=\ell_{i+2}\left(  a\right)  \\\text{(by
(\ref{sol.monvars.SPmoves.a.4}))}}}+\underbrace{\ell_{i+3}\left(  b\right)
}_{\substack{=\ell_{i+3}\left(  a\right)  \\\text{(by
(\ref{sol.monvars.SPmoves.a.4}))}}}+\cdots+\underbrace{\ell_{n}\left(
b\right)  }_{\substack{=\ell_{n}\left(  a\right)  \\\text{(by
(\ref{sol.monvars.SPmoves.a.4}))}}}\right) \\
&  =\left(  \ell_{1}\left(  a\right)  +\ell_{2}\left(  a\right)  +\cdots
+\ell_{i-1}\left(  a\right)  \right)  +\ell_{i+1}\left(  a\right) \\
&  \ \ \ \ \ \ \ \ \ \ +\left(  \ell_{i}\left(  a\right)  -1\right)  +\left(
\ell_{i+2}\left(  a\right)  +\ell_{i+3}\left(  a\right)  +\cdots+\ell
_{n}\left(  a\right)  \right) \\
&  =\underbrace{\left(  \left(  \ell_{1}\left(  a\right)  +\ell_{2}\left(
a\right)  +\cdots+\ell_{i-1}\left(  a\right)  \right)  +\ell_{i+1}\left(
a\right)  +\ell_{i}\left(  a\right)  \right)  }_{\substack{=\ell_{1}\left(
a\right)  +\ell_{2}\left(  a\right)  +\cdots+\ell_{i+1}\left(  a\right)  }}\\
&  \ \ \ \ \ \ \ \ \ \ +\left(  \ell_{i+2}\left(  a\right)  +\ell_{i+3}\left(
a\right)  +\cdots+\ell_{n}\left(  a\right)  \right)  -\,1\\
&  =\underbrace{\left(  \left(  \ell_{1}\left(  a\right)  +\ell_{2}\left(
a\right)  +\cdots+\ell_{i+1}\left(  a\right)  \right)  +\left(  \ell
_{i+2}\left(  a\right)  +\ell_{i+3}\left(  a\right)  +\cdots+\ell_{n}\left(
a\right)  \right)  \right)  }_{\substack{=\ell_{1}\left(  a\right)  +\ell
_{2}\left(  a\right)  +\cdots+\ell_{n}\left(  a\right)  \\=\ell\left(
a\right)  \\\text{(by (\ref{sol.monvars.SPmoves.la=}))}}}-\,1\\
&  =\ell\left(  a\right)  -1.
\end{align*}
Hence, $\ell\left(  b\right)  =\ell\left(  a\right)  -1<\ell\left(  a\right)
$. This shows that $\ell\left(  a\right)  $ decreases with each S-move.

As we already said, this yields that the S-process must eventually stop,
because a nonnegative integer cannot decrease endlessly (without becoming
negative). Hence, Exercise \ref{exa.monvars.SPmoves} \textbf{(a)} is solved.
\medskip

\textbf{(b)} No. The process can go on forever.

\textit{Proof.} Start with the state $\left(  0,\dfrac{1}{3},\dfrac{-1}%
{3}\right)  $, and apply P-moves and S-moves as follows:%
\begin{align*}
\left(  0,\dfrac{1}{3},\dfrac{-1}{3}\right)   &  \overset{\text{S-move}%
}{\mapsto}\left(  0,\dfrac{-1}{3},\dfrac{1}{3}\right)  \overset{\text{P-move}%
}{\mapsto}\left(  \dfrac{2}{3},1,\dfrac{1}{3}\right) \\
&  \overset{\text{S-move}}{\mapsto}\left(  \dfrac{2}{3},\dfrac{1}{3},1\right)
\overset{\text{P-move}}{\mapsto}\left(  \dfrac{4}{3},\dfrac{5}{3},1\right) \\
&  \overset{\text{S-move}}{\mapsto}\left(  \dfrac{4}{3},1,\dfrac{5}{3}\right)
\overset{\text{P-move}}{\mapsto}\left(  2,\dfrac{7}{3},\dfrac{5}{3}\right)
\mapsto\cdots.
\end{align*}
(Each odd move is a S-move, and each even move is a P-move. This process
continues indefinitely because every two successive move cause all entries of
the state to increase by $\dfrac{2}{3}$, and thus the order relations that
make the moves possible are preserved.) \medskip

\textbf{(c)} Yes. The process will end.

\textit{Proof.} The following nice proof was found by Jan Nienhaus (
\url{https://mathoverflow.net/questions/456983/} ), although I have modified
it to fit better with the theme of this worksheet.

We consider the \textquotedblleft SP-process\textquotedblright\ -- i.e., the
process that successively applies S-moves or P-moves to an $n$-tuple of
integers. Its states are the $n$-tuples of integers\footnote{Yes, integers!
Indeed, by the requirements of Exercise \ref{exa.monvars.SPmoves}
\textbf{(c)}, we are starting with an $n$-tuple of integers, and of course we
will never get any non-integers during the process (since neither S-moves nor
P-moves can produce any non-integers).}, and its moves are the S-moves and the
P-moves. We would like to find a monovariant of this SP-process, so that we
can use the same argument as in part \textbf{(a)}.

It is tempting to reuse the monovariant $\ell\left(  a\right)  =\sum_{k=1}%
^{n}\ell_{k}\left(  a\right)  $ of the S-process that we constructed in our
above solution to Exercise \ref{exa.monvars.SPmoves} \textbf{(a)}.
Unfortunately, this does not work, since $\ell\left(  a\right)  $ is not a
monovariant of the SP-process: For instance, a P-move transforms $\left(
1,0,1\right)  $ into $\left(  1,2,1\right)  $, but $\ell\left(  1,2,1\right)
$ is not smaller than $\ell\left(  1,0,1\right)  $ (in fact, $\ell\left(
1,2,1\right)  =1$ and $\ell\left(  1,0,1\right)  =1$ are
equal).\footnote{Sometimes, $\ell\left(  a\right)  $ even increases with a
P-move.}

This does not mean that our above solution to Exercise
\ref{exa.monvars.SPmoves} \textbf{(a)} is completely useless here. In that
solution, we have also defined a number $\ell_{i}\left(  a\right)  $ for each
$n$-tuple $a$ of numbers and each $i\in\left\{  1,2,\ldots,n\right\}  $. We
shall again use these numbers and all the other notations we introduced in
that solution. Let us now define our new monovariant:

\begin{itemize}
\item If $a$ is an $n$-tuple of real numbers, then we define the nonnegative
integer%
\begin{equation}
m\left(  a\right)  :=\sum_{k=1}^{n}\left(  n-k\right)  !\cdot\ell_{k}\left(
a\right)  . \label{sol.monvars.SPmoves.ma=}%
\end{equation}
For example, if $a=\left(  4,2,4,1,3\right)  $, then $m\left(  a\right)
=4!\cdot3+3!\cdot1+2!\cdot2+1!\cdot0+0!\cdot0=82$.
\end{itemize}

Now, we shall show that this nonnegative integer $m\left(  a\right)  $ (where
$a=\left(  a_{1},a_{2},\ldots,a_{n}\right)  $ is our state) is a monovariant
of the SP-process. To do so, we must prove that if an S-move or a P-move
transforms an $n$-tuple $a$ into an $n$-tuple $b$, then $m\left(  b\right)
<m\left(  a\right)  $.

Let us prove this. Let an S-move or a P-move transform an $n$-tuple $a$ into
an $n$-tuple $b$. We must prove that $m\left(  b\right)  <m\left(  a\right)
$. (This time, we cannot prove $m\left(  b\right)  =m\left(  a\right)  -1$,
but we don't have to.)

Recall that $a=\left(  a_{1},a_{2},\ldots,a_{n}\right)  $. By assumption, we
are in one of the following two cases:

\textit{Case 1:} The $n$-tuple $b$ is obtained from $a$ by an S-move.

\textit{Case 2:} The $n$-tuple $b$ is obtained from $a$ by a P-move.

Let us first consider Case 2 (we will handle Case 1 afterwards). In this case,
$b$ is obtained from $a$ by a P-move. In other words,%
\begin{equation}
b=\left(  \underbrace{a_{1},a_{2},\ldots,a_{i-1}}_{\text{same entries as in
}a},\ a_{i+1}+1,\ a_{i}+1,\ \underbrace{a_{i+2},a_{i+3},\ldots,a_{n}%
}_{\text{same entries as in }a}\right)  \label{sol.monvars.SPmoves.b.b=}%
\end{equation}
for some $i\in\left\{  1,2,\ldots,n-1\right\}  $ satisfying $a_{i}>a_{i+1}$
(because a P-move replaces two consecutive entries $a_{i}$ and $a_{i+1}$ that
satisfy $a_{i}>a_{i+1}$ by $a_{i+1}+1$ and $a_{i}+1$). Consider this $i$.
Thus, $b_{i}=a_{i+1}+1$ and $b_{i+1}=a_{i}+1$.

We note that $a_{1},a_{2},\ldots,a_{n}$ are integers (since our states are
tuples of integers this time). Thus, in particular, $a_{i}$ and $a_{i+1}$ are
integers. Hence, from $a_{i}>a_{i+1}$, we obtain $a_{i}\geq a_{i+1}+1=b_{i}$
(since $b_{i}=a_{i+1}+1$). Hence, $b_{i}\leq a_{i}$.

Now, let us see how the numbers $\ell_{k}\left(  a\right)  $ differ from the
respective numbers $\ell_{k}\left(  b\right)  $. This is less predictable than
in part \textbf{(a)}, but we take what we can get:

\begin{itemize}
\item For each $k\in\left\{  1,2,\ldots,i-1\right\}  $, we have%
\begin{equation}
\ell_{k}\left(  b\right)  \leq\ell_{k}\left(  a\right)  .
\label{sol.monvars.SPmoves.b.1}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.b.1}):} Let $k\in\left\{
1,2,\ldots,i-1\right\}  $. Then, the $n$-tuples $a$ and $b$ have the same
$k$-th entries (since they differ only in their $i$-th and $\left(
i+1\right)  $-st positions). In other words, $a_{k}=b_{k}$.

The P-move that transforms $a$ into $b$ consists in swapping the $i$-th and
$\left(  i+1\right)  $-st entries (which are $a_{i}$ and $a_{i+1}$) and
incrementing them both by $1$. Since $k<i$, these two entries are contained in
$a_{>k}$ (before the move) and in $b_{>k}$ (after the move). Hence, the tuple
$b_{>k}$ is obtained from $a_{>k}$ by swapping two entries and incrementing
them by $1$. Inverting this operation, we see that $a_{>k}$ can be recovered
from $b_{>k}$ by decrementing two entries by $1$ and swapping them. Clearly,
this operation (decrementing and swapping two entries) cannot decrease the
number of entries that are smaller than $a_{k}$ (because if an entry of
$b_{>k}$ is smaller than $a_{k}$, then it remains smaller than $a_{k}$ when it
is decremented by $1$, and therefore becomes an entry of $a_{>k}$ smaller than
$a_{k}$). Hence,%
\begin{align*}
&  \left(  \text{the number of entries of }a_{>k}\text{ that are smaller than
}a_{k}\right) \\
&  \geq\left(  \text{the number of entries of }b_{>k}\text{ that are smaller
than }a_{k}\right)  .
\end{align*}


However, the definition of $\ell_{k}\left(  a\right)  $ yields%
\begin{align*}
\ell_{k}\left(  a\right)   &  =\left(  \text{the number of entries of }%
a_{>k}\text{ that are smaller than }a_{k}\right) \\
&  \geq\left(  \text{the number of entries of }b_{>k}\text{ that are smaller
than }a_{k}\right) \\
&  =\left(  \text{the number of entries of }b_{>k}\text{ that are smaller than
}b_{k}\right) \\
&  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \left(  \text{since }a_{k}%
=b_{k}\right) \\
&  =\ell_{k}\left(  b\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by the
definition of }\ell_{k}\left(  b\right)  \right)  .
\end{align*}
In other words, $\ell_{k}\left(  b\right)  \leq\ell_{k}\left(  a\right)  $.
This proves (\ref{sol.monvars.SPmoves.b.1}).]

\item We have
\begin{equation}
\ell_{i}\left(  b\right)  \leq\ell_{i}\left(  a\right)  -1.
\label{sol.monvars.SPmoves.b.2}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.b.2}):} Let us compare the two
tuples $a_{>i}$ and $b_{>i}$. According to (\ref{sol.monvars.SPmoves.b.b=}),
we have $b_{>i}=\left(  a_{i}+1,\ a_{i+2},a_{i+3},\ldots,a_{n}\right)  $,
while we obviously have $a_{>i}=\left(  a_{i+1},a_{i+2},a_{i+3},\ldots
,a_{n}\right)  $. Thus, the two tuples $b_{>i}$ and $a_{>i}$ differ only in
their first entry, which is $a_{i}+1$ in the former and $a_{i+1}$ in the
latter. What is important for us is that the first entry of $a_{>i}$ is
smaller than $a_{i}$ (since it is $a_{i+1}$, but we have $a_{i+1}<a_{i}$), but
the first entry of $b_{>i}$ is not (since it is $a_{i}+1$, which is greater
than $a_{i}$). Hence, the tuple $a_{>i}$ has one more entry that is smaller
than $a_{i}$ than $b_{>i}$ (since these two tuples differ only in their first entry).

But the definition of $\ell_{i}\left(  a\right)  $ yields%
\begin{align}
\ell_{i}\left(  a\right)   &  =\left(  \text{the number of entries of }%
a_{>i}\text{ that are smaller than }a_{i}\right) \nonumber\\
&  =\left(  \text{the number of entries of }b_{>i}\text{ that are smaller than
}a_{i}\right)  +1 \label{sol.monvars.SPmoves.b.2.pf.2}%
\end{align}
(since the tuple $a_{>i}$ has one more entry that is smaller than $a_{i}$ than
$b_{>i}$).

However, let us recall that $b_{i}\leq a_{i}$. Hence, each entry of $b_{>i}$
that is smaller than $b_{i}$ must also be smaller than $a_{i}$. Thus,%
\begin{align*}
&  \left(  \text{the number of entries of }b_{>i}\text{ that are smaller than
}b_{i}\right) \\
&  \leq\left(  \text{the number of entries of }b_{>i}\text{ that are smaller
than }a_{i}\right)  .
\end{align*}


Now, the definition of $\ell_{i}\left(  b\right)  $ yields%
\begin{align*}
\ell_{i}\left(  b\right)   &  =\left(  \text{the number of entries of }%
b_{>i}\text{ that are smaller than }b_{i}\right) \\
&  \leq\left(  \text{the number of entries of }b_{>i}\text{ that are smaller
than }a_{i}\right) \\
&  =\ell_{i}\left(  a\right)  -1\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{sol.monvars.SPmoves.b.2.pf.2})}\right)  .
\end{align*}
This proves (\ref{sol.monvars.SPmoves.b.2}).]

\item We cannot find an upper bound for $\ell_{i+1}\left(  b\right)  $ in
terms of $\ell_{i+1}\left(  a\right)  $, but we can at least state the
obvious: We have%
\begin{equation}
\ell_{i+1}\left(  b\right)  <n-i. \label{sol.monvars.SPmoves.b.3}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.b.3}):} The definition of
$\ell_{i+1}\left(  b\right)  $ yields%
\begin{align*}
\ell_{i+1}\left(  b\right)   &  =\left(  \text{the number of entries of
}b_{>i+1}\text{ that are smaller than }b_{i+1}\right) \\
&  \leq\left(  \text{the number of all entries of }b_{>i+1}\right) \\
&  =n-\underbrace{\left(  i+1\right)  }_{>i}\ \ \ \ \ \ \ \ \ \ \left(
\text{since }b_{>i+1}\text{ is an }\left(  n-\left(  i+1\right)  \right)
\text{-tuple}\right) \\
&  <n-i.
\end{align*}
This proves (\ref{sol.monvars.SPmoves.b.3}).]

\item For each $k\in\left\{  i+2,i+3,\ldots,n\right\}  $, we have%
\begin{equation}
\ell_{k}\left(  b\right)  =\ell_{k}\left(  a\right)  .
\label{sol.monvars.SPmoves.b.4}%
\end{equation}


[\textit{Proof of (\ref{sol.monvars.SPmoves.b.4}):} This is very similar to
(\ref{sol.monvars.SPmoves.a.1}).]
\end{itemize}

Now, the definition of $m\left(  b\right)  $ yields%
\begin{align*}
m\left(  b\right)   &  =\sum_{k=1}^{n}\left(  n-k\right)  !\cdot\ell
_{k}\left(  b\right) \\
&  =\sum_{k=1}^{i-1}\left(  n-k\right)  !\cdot\underbrace{\ell_{k}\left(
b\right)  }_{\substack{\leq\ell_{k}\left(  a\right)  \\\text{(by
(\ref{sol.monvars.SPmoves.b.1}))}}}+\left(  n-i\right)  !\cdot\underbrace{\ell
_{i}\left(  b\right)  }_{\substack{\leq\ell_{i}\left(  a\right)  -1\\\text{(by
(\ref{sol.monvars.SPmoves.b.2}))}}}+\left(  \underbrace{n-\left(  i+1\right)
}_{=n-i-1}\right)  !\cdot\underbrace{\ell_{i+1}\left(  b\right)
}_{\substack{<n-i\\\text{(by (\ref{sol.monvars.SPmoves.b.3}))}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\sum_{k=i+2}^{n}\left(  n-k\right)  !\cdot
\underbrace{\ell_{k}\left(  b\right)  }_{\substack{=\ell_{k}\left(  a\right)
\\\text{(by (\ref{sol.monvars.SPmoves.b.4}))}}}\\
&  <\sum_{k=1}^{i-1}\left(  n-k\right)  !\cdot\ell_{k}\left(  a\right)
+\left(  n-i\right)  !\cdot\left(  \ell_{i}\left(  a\right)  -1\right)
+\underbrace{\left(  n-i-1\right)  !\cdot\left(  n-i\right)  }%
_{\substack{=\left(  n-i\right)  !\\\text{(since }\left(  p-1\right)  !\cdot
p=p!\\\text{for any integer }p>0\text{)}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\sum_{k=i+2}^{n}\left(  n-k\right)  !\cdot\ell
_{k}\left(  a\right) \\
&  =\sum_{k=1}^{i-1}\left(  n-k\right)  !\cdot\ell_{k}\left(  a\right)
+\underbrace{\left(  n-i\right)  !\cdot\left(  \ell_{i}\left(  a\right)
-1\right)  +\left(  n-i\right)  !}_{\substack{=\left(  n-i\right)  !\cdot
\ell_{i}\left(  a\right)  \\\leq\left(  n-i\right)  !\cdot\ell_{i}\left(
a\right)  +\left(  n-\left(  i+1\right)  \right)  !\cdot\ell_{i+1}\left(
a\right)  \\\text{(since }\left(  n-\left(  i+1\right)  \right)  !\cdot
\ell_{i+1}\left(  a\right)  \text{ is nonnegative)}}}\\
&  \ \ \ \ \ \ \ \ \ \ +\sum_{k=i+2}^{n}\left(  n-k\right)  !\cdot\ell
_{k}\left(  a\right) \\
&  \leq\sum_{k=1}^{i-1}\left(  n-k\right)  !\cdot\ell_{k}\left(  a\right)
+\left(  n-i\right)  !\cdot\ell_{i}\left(  a\right)  +\left(  n-\left(
i+1\right)  \right)  !\cdot\ell_{i+1}\left(  a\right) \\
&  \ \ \ \ \ \ \ \ \ \ +\sum_{k=i+2}^{n}\left(  n-k\right)  !\cdot\ell
_{k}\left(  a\right) \\
&  =\sum_{k=1}^{n}\left(  n-k\right)  !\cdot\ell_{k}\left(  a\right)
=m\left(  a\right)
\end{align*}
(by the definition of $m\left(  a\right)  $). This concludes the proof of
$m\left(  b\right)  <m\left(  a\right)  $ in Case 2.

Let us now consider Case 1. In this case, $b$ is obtained from $a$ by an
S-move. Thus, as in our solution to part \textbf{(a)}, we see that%
\[
b=\left(  \underbrace{a_{1},a_{2},\ldots,a_{i-1}}_{\text{same entries as in
}a},a_{i+1},a_{i},\underbrace{a_{i+2},a_{i+3},\ldots,a_{n}}_{\text{same
entries as in }a}\right)
\]
for some $i\in\left\{  1,2,\ldots,n-1\right\}  $ satisfying $a_{i}>a_{i+1}$.
Consider this $i$.

We have already analyzed how the numbers $\ell_{k}\left(  b\right)  $ relate
to the numbers $\ell_{k}\left(  a\right)  $ in our above solution to part
\textbf{(a)}. We could try to reuse the results of that analysis (i.e., the
four equalities (\ref{sol.monvars.SPmoves.a.1}),
(\ref{sol.monvars.SPmoves.a.2}), (\ref{sol.monvars.SPmoves.a.3}) and
(\ref{sol.monvars.SPmoves.a.4})) again, but there is an easier way: We instead
argue that the inequalities (\ref{sol.monvars.SPmoves.b.1}),
(\ref{sol.monvars.SPmoves.b.2}), (\ref{sol.monvars.SPmoves.b.3}) and
(\ref{sol.monvars.SPmoves.b.4}) still hold (even though we are no longer in
Case 2!). Indeed, these inequalities can be proved similarly to how they were
proved in Case 2, with some minor changes (mostly simplifications, because an
S-move is like a P-move but without the incrementation part). Thus, the
inequality $m\left(  b\right)  <m\left(  a\right)  $ can be proved just as in
Case 2.

We have now proved $m\left(  b\right)  <m\left(  a\right)  $ in both Cases 1
and 2. Hence, $m\left(  b\right)  <m\left(  a\right)  $ always holds.
Therefore, $m\left(  a\right)  $ is a monovariant, which shows that the
SP-process will eventually terminate. Part \textbf{(c)} of the exercise is solved.
\end{proof}

The following exercise is one of the most famous problems of the International
Mathematical Olympiad, known to the contest community as \textquotedblleft the
pentagon game\textquotedblright\ (see \cite{WegRei07}, \cite{Erikss92} and
\cite[Chapter 3]{Erikss93} for further discussion and generalizations):

\begin{exercise}
\label{exe.monvars.pentagon}At each vertex of a regular pentagon, an integer
is written. Assume that the sum of all these five integers is positive.

We can make the following move: If $x,\ y,\ z$ are the integers at three
consecutive vertices of our pentagon (in this order), and if $y<0$, then we
can replace these integers $x,\ y,\ z$ by $x+y,\ -y,\ z+y$, respectively (see
Figure~\ref{fig.exe.monvars.pentagon.1} for an illustration).

We perform this move repeatedly. Prove that this process will eventually come
to an end (i.e., at some point, there will be no negative integers left on any vertex).

\flushright(International Mathematical Olympiad 1986/3)
\end{exercise}

\begin{figure}[ptb]%
\[
\begin{tikzpicture}[scale=2.5]
\node[fill=yellow] (0) at (0:1) {$a$};
\node[fill=yellow] (1) at (360/5:1) {$b$};
\node[fill=yellow] (2) at (2*360/5:1) {$c$};
\node[fill=yellow] (3) at (3*360/5:1) {$d$};
\node[fill=yellow] (4) at (4*360/5:1) {$e$};
\draw[thick] (0) -- (1) -- (2) -- (3) -- (4) -- (0);
\node (u) at (1.5,0) {$\mapsto$};
\begin{scope}[xshift=3cm]
\node[fill=yellow] (0b) at (0:1) {$a+b$};
\node[fill=yellow] (1b) at (360/5:1) {$-b$};
\node[fill=yellow] (2b) at (2*360/5:1) {$c+b$};
\node[fill=yellow] (3b) at (3*360/5:1) {$d$};
\node[fill=yellow] (4b) at (4*360/5:1) {$e$};
\draw[thick] (0b) -- (1b) -- (2b) -- (3b) -- (4b) -- (0b);
\end{scope}
\end{tikzpicture}
\]
\caption{A move in Exercise \ref{exe.monvars.pentagon}. The three integers
$x,\ y,\ z$ chosen for this move are $a,\ b,\ c$ here. This move can only be
made if $b < 0$.}%
\label{fig.exe.monvars.pentagon.1}%
\end{figure}

\begin{proof}
[Solution idea.]We encode the integers at the vertices of our pentagon as a
$5$-tuple, listing them in clockwise order (starting from some vertex we
choose at the onset).

Thus, we are dealing with a process whose states are the $5$-tuples $\left(
a,b,c,d,e\right)  \in\mathbb{Z}^{5}$, and whose moves are
\begin{align*}
\left(  a,b,c,d,e\right)   &  \mapsto\left(  a+b,-b,c+b,d,e\right)
\ \ \ \ \ \ \ \ \ \ \text{if }b<0;\\
\left(  a,b,c,d,e\right)   &  \mapsto\left(  a,b+c,-c,d+c,e\right)
\ \ \ \ \ \ \ \ \ \ \text{if }c<0;\\
\left(  a,b,c,d,e\right)   &  \mapsto\left(  a,b,c+d,-d,e+d\right)
\ \ \ \ \ \ \ \ \ \ \text{if }d<0;\\
\left(  a,b,c,d,e\right)   &  \mapsto\left(  a+e,b,c,d+e,-e\right)
\ \ \ \ \ \ \ \ \ \ \text{if }e<0;\\
\left(  a,b,c,d,e\right)   &  \mapsto\left(  -a,b+a,c,d,e+a\right)
\ \ \ \ \ \ \ \ \ \ \text{if }a<0.
\end{align*}
(Because of the cyclic symmetry, I could have just written down the first kind
of move and said \textquotedblleft the others are obtained from it by cyclic
rotation\textquotedblright, but I wanted to be precise.)

We want to show that the process must terminate (i.e., come to an end) after
finitely many moves. One way to prove such claims (as we already saw in
Subsubsection \ref{subsec.process.euclid}) is by finding a monovariant that is
a nonnegative integer and decreases with each move. Since a nonnegative
integer cannot decrease endlessly, this will yield that the process must come
to an end.

Of course, this is easier said than done! Invariants are easy to find: For
instance, the sum $a+b+c+d+e$ of all entries of a state $\left(
a,b,c,d,e\right)  $ is an invariant (since, e.g., a move of the form $\left(
a,b,c,d,e\right)  \mapsto\left(  a+b,-b,c+b,d,e\right)  $ changes it to
$\left(  a+b\right)  +\left(  -b\right)  +\left(  c+b\right)  +d+e$, which
simplifies back to $a+b+c+d+e$). But finding a proper monovariant is harder.
Here are two monovariants (one is enough, but I want to show different
approaches for pedagogical purposes):

\begin{enumerate}
\item The quantity
\[
f\left(  a,b,c,d,e\right)  :=\left(  a-c\right)  ^{2}+\left(  b-d\right)
^{2}+\left(  c-e\right)  ^{2}+\left(  d-a\right)  ^{2}+\left(  e-b\right)
^{2}%
\]
defined for each state $\left(  a,b,c,d,e\right)  $ is a monovariant that
decreases with each move. To prove this, we just have to check five
inequalities (one for each type of move). For instance, if we make a move of
the form%
\[
\left(  a,b,c,d,e\right)  \mapsto\left(  a+b,-b,c+b,d,e\right)
\ \ \ \ \ \ \ \ \ \ \text{with }b<0,
\]
then $f\left(  a,b,c,d,e\right)  $ is replaced by $f\left(
a+b,-b,c+b,d,e\right)  $. We must therefore show that $f\left(
a+b,-b,c+b,d,e\right)  <f\left(  a,b,c,d,e\right)  $. In order to show this,
we calculate the difference:%
\begin{align*}
&  f\left(  a+b,-b,c+b,d,e\right)  -f\left(  a,b,c,d,e\right) \\
&  =\left(  \left(  \left(  a+b\right)  -\left(  c+b\right)  \right)
^{2}+\left(  \left(  -b\right)  -d\right)  ^{2}+\left(  \left(  c+b\right)
-e\right)  ^{2}+\left(  d-\left(  a+b\right)  \right)  ^{2}+\left(  e-\left(
-b\right)  \right)  ^{2}\right) \\
&  \ \ \ \ \ \ \ \ \ \ -\left(  \left(  a-c\right)  ^{2}+\left(  b-d\right)
^{2}+\left(  c-e\right)  ^{2}+\left(  d-a\right)  ^{2}+\left(  e-b\right)
^{2}\right) \\
&  =2b\left(  a+b+c+d+e\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{after a long
but straightforward computation}\right)  .
\end{align*}
Now, recall that the sum $a+b+c+d+e$ is an invariant (as we already saw), and
thus equals its value at the beginning of the process; but the latter value is
$>0$ (since we assumed that the sum of all the five integers is positive at
the beginning of the process). Hence, $a+b+c+d+e>0$, so that%
\[
f\left(  a+b,-b,c+b,d,e\right)  -f\left(  a,b,c,d,e\right)  =2\underbrace{b}%
_{<0}\underbrace{\left(  a+b+c+d+e\right)  }_{>0}<0
\]
and therefore $f\left(  a+b,-b,c+b,d,e\right)  <f\left(  a,b,c,d,e\right)  $.
Thus, we have shown that the quantity $f\left(  a,b,c,d,e\right)  $ decreases
whenever we make a move of the form
\[
\left(  a,b,c,d,e\right)  \mapsto\left(  a+b,-b,c+b,d,e\right)
\ \ \ \ \ \ \ \ \ \ \text{with }b<0.
\]
Similarly, we can see that it decreases with any move of the other four forms
(indeed, because of the cyclic symmetry in the definition of $f\left(
a,b,c,d,e\right)  $, the proofs for the other four forms will be completely
analogous and need not be written out). Hence, $f\left(  a,b,c,d,e\right)  $
decreases with each move. But $f\left(  a,b,c,d,e\right)  $ is a nonnegative
integer (because it is defined as a sum of five squares of integers), and thus
cannot decrease endlessly. Hence, the process must come to an end, and the
problem is solved.

\item Another monovariant is the quantity%
\begin{align*}
&  g\left(  a,b,c,d,e\right) \\
&  :=\left\vert a\right\vert +\left\vert b\right\vert +\left\vert c\right\vert
+\left\vert d\right\vert +\left\vert e\right\vert \\
&  \ \ \ \ \ \ \ \ \ \ +\left\vert a+b\right\vert +\left\vert b+c\right\vert
+\left\vert c+d\right\vert +\left\vert d+e\right\vert +\left\vert
e+a\right\vert \\
&  \ \ \ \ \ \ \ \ \ \ +\left\vert a+b+c\right\vert +\left\vert
b+c+d\right\vert +\left\vert c+d+e\right\vert +\left\vert d+e+a\right\vert
+\left\vert e+a+b\right\vert \\
&  \ \ \ \ \ \ \ \ \ \ +\left\vert a+b+c+d\right\vert +\left\vert
b+c+d+e\right\vert +\left\vert c+d+e+a\right\vert \\
&  \ \ \ \ \ \ \ \ \ \ +\left\vert d+e+a+b\right\vert +\left\vert
e+a+b+c\right\vert .
\end{align*}
This complicated-looking sum actually does something quite simple: It adds the
absolute values of all \textquotedblleft contiguous partial
sums\textquotedblright\ of our five integers, where a \textquotedblleft
contiguous partial sum\textquotedblright\ means a sum of the integers at a few
consecutive vertices of the pentagon (for example, $d+e+a$ is a contiguous
partial sum, whereas $a+c+e$ is not).

Clearly, the quantity $g\left(  a,b,c,d,e\right)  $ is a nonnegative integer,
but why is it a monovariant? This is a bit trickier to prove than the
analogous property of $f\left(  a,b,c,d,e\right)  $, since absolute values
don't lend themselves to mechanical simplification like squares do. But it is
easy once you view it from the right perspective: If we make a move of the
form%
\[
\left(  a,b,c,d,e\right)  \mapsto\left(  a+b,-b,c+b,d,e\right)
\ \ \ \ \ \ \ \ \ \ \text{with }b<0,
\]
then most of the \textquotedblleft contiguous partial sums\textquotedblright%
\ remain unchanged except for the following six types:

\begin{enumerate}
\item[Type 1:] the ones that contain $a$ but not $b$ or $c$ (for example,
$e+a$);

\item[Type 2:] the ones that contain $a$ and $b$ but not $c$ (for example,
$e+a+b$);
\end{enumerate}

\begin{itemize}
\item[Type 3:] the ones that contain $c$ but not $b$ or $a$ (for example,
$c+d$);

\item[Type 4:] the ones that contain $c$ and $b$ but not $a$ (for example,
$b+c+d$);

\item[Type 5:] the one that contains $c$ and $a$ but not $b$ (there is only
one such sum, namely $c+d+e+a$);

\item[Type 6:] the one that contains only $b$ (that is, $b$ itself).
\end{itemize}

\noindent But even these types of sums change in a fairly predictable way:
Sums of Type 1 are turned into sums of Type 2 (for example, $e+a$ becomes
$e+a+b$ since we replace $a$ by $a+b$), whereas sums of Type 2 are turned into
sums of Type 1 (for example, $e+a+b$ becomes $e+\left(  a+b\right)  +\left(
-b\right)  =e+a$). Likewise, sums of Type 3 are turned into sums of Type 4,
and vice versa. Thus, as we add the absolute values of all these sums
together, the contributions of the sums of Types 1, 2, 3 and 4 remain the same
(even as the specific sums trade places), and the only real changes come from
the sums of Types 5 and 6. These sums are $c+d+e+a$ and $b$ before the move,
and they become $\left(  c+b\right)  +d+e+\left(  a+b\right)  $ and $-b$ after
move. Thus, in order to show that the total sum $g\left(  a,b,c,d,e\right)  $
decreases, we only need to check that%
\[
\left\vert \left(  c+b\right)  +d+e+\left(  a+b\right)  \right\vert
+\left\vert -b\right\vert <\left\vert c+d+e+a\right\vert +\left\vert
b\right\vert .
\]
But this is not hard: The addends $\left\vert -b\right\vert $ and $\left\vert
b\right\vert $ on the two sides are equal, so we can cancel them and it
remains to show the inequality%
\[
\left\vert \left(  c+b\right)  +d+e+\left(  a+b\right)  \right\vert
<\left\vert c+d+e+a\right\vert .
\]


Set $s:=a+b+c+d+e$. Then, we can rewrite this inequality as $\left\vert
s+b\right\vert <\left\vert s-b\right\vert $, since
\begin{align*}
\left(  c+b\right)  +d+e+\left(  a+b\right)   &  =\underbrace{a+b+c+d+e}%
_{=s}+\,b=s+b\ \ \ \ \ \ \ \ \ \ \text{and}\\
c+d+e+a  &  =\underbrace{a+b+c+d+e}_{=s}-\,b=s-b.
\end{align*}


But as we know, the quantity $s=a+b+c+d+e$ is an invariant and thus is
positive (since we assumed that the sum of all the five integers is positive
at the beginning of the process). Thus, we know that $s>0$ and $b<0$. From
this, we can easily conclude that $\left\vert s+b\right\vert <\left\vert
s-b\right\vert $\ \ \ \ \footnote{\textit{Proof.} There are many ways to check
this formally, but here is the geometric argument: The number $b$ is negative,
so that it lies left of $0$ on the number line. Therefore, $-b$ lies right of
$0$ on the number line. However, $s$ also lies right of $0$ on the number line
(since $s>0$). Hence, $s$ is closer to $-b$ than to $b$. In other words,
$\left\vert s-\left(  -b\right)  \right\vert <\left\vert s-b\right\vert $. In
other words, $\left\vert s+b\right\vert <\left\vert s-b\right\vert $.}. As
explained above, this shows that $g\left(  a,b,c,d,e\right)  $ decreases under
our move. Analogous arguments work for the other four types of moves, and thus
we have shown that $g\left(  a,b,c,d,e\right)  $ is a monovariant that
decreases with each move.

Since $g\left(  a,b,c,d,e\right)  $ is a nonnegative integer and thus cannot
decrease endlessly, we thus conclude that the process must terminate. This
solves the problem again.
\end{enumerate}

\textbf{Remarks:}

\begin{enumerate}
\item The exercise can be generalized to hexagons, heptagons and $n$-gons in
general. Our second monovariant $g\left(  a,b,c,d,e\right)  $ can easily be
adapted to this generalization (again, take the sum of the absolute values of
all \textquotedblleft contiguous partial sums\textquotedblright), but our
first monovariant $f\left(  a,b,c,d,e\right)  $ cannot (at least not easily).
Thus, our second solution, while longer, has the advantage of generalizability.

\item In the exercise, it is assumed that the sum of all five integers is
positive. This assumption is important. In fact, if the sum of all five
integers is negative, then the process cannot terminate! The reason for this
is simple: The sum of all five integers is an invariant, so it always stays
negative (if it starts out negative). Thus, after any number of moves, there
is at least one negative number on our pentagon (since otherwise, their sum
could not be negative); but this means that we can make yet another move.
Hence, the process goes on forever.

What happens if the sum of the five integers is zero? See Exercise
\ref{exe.monvars.pentagon0} for that.
\end{enumerate}
\end{proof}

Monovariants don't have to be numbers. They can also be logical statements
that become \textquotedblleft truer\textquotedblright\ with every move, in the
sense that if they are true before the move, then they remain true after the
move (but not necessarily vice versa). Here is a somewhat artificial but nice example:

\begin{exercise}
\label{exe.monvars.stones}You have three heaps of stones: one containing $51$
stones, one containing $49$ stones, and one containing $5$ stones. The
\emph{size} of a heap is defined to be the number of stones in this heap.

In a single move, you can combine two heaps into one; you can also break up
any even-sized heap into two equal-sized heaps (i.e., a heap with $2n$ stones
becomes two heaps with $n$ stones each).

Is it possible to achieve (by a sequence of such moves) $105$ heaps, each
containing one stone?

\flushright(Tournament of Towns 22.7.2)
\end{exercise}

\begin{proof}
[Solution idea.]The process described has an obvious invariant: the total
number of stones. But this is not too helpful.

Let us look at the first possible move. Since there are no even-sized heaps
initially, this first move must be a \textquotedblleft combine two
heaps\textquotedblright\ move. Thus, it results either in two heaps of sizes
$100$ and $5$, or in two heaps of sizes $51$ and $54$, or in two heaps of
sizes $56$ and $49$.

What do these three resulting states have in common? A bit of thought reveals
one pattern: In each of these states, the sizes of the heaps have an odd
divisor larger than $1$ in common. For instance, $100$ and $5$ have the odd
divisor $5$ in common; $51$ and $54$ have the odd divisor $3$ in common; $56$
and $49$ have the odd divisor $7$ in common.

We shall call a state \emph{good} if it has the property that the sizes of all
heaps have an odd divisor larger than $1$ in common. Thus, the initial state
(with three heaps of sizes $51$, $49$ and $5$) is not good, but we have just
shown that any move will transform it into a good state.

Moreover, applying a move to a good state will produce another good state,
because both possible types of moves (\textquotedblleft combine two
heaps\textquotedblright\ and \textquotedblleft break an even-sized heap into
two equal-sized heaps\textquotedblright) preserve odd
divisors.\footnote{\textit{Proof.} Let $d$ be an odd positive integer. If you
combine two heaps whose sizes $a$ and $b$ are both divisible by $d$, then the
size $a+b$ of the resulting heap will again be divisible by $d$. If you break
up an even-sized heap whose size $2n$ is divisible by $d$ into two heaps of
size $n$ each, then the size $n$ of these resulting heaps will again be
divisible by $d$ (since $d$ is odd, so that $d\mid2n$ entails $d\mid n$).}

Thus, the goodness of a state is a monovariant: Once you obtain a good state,
any further moves will preserve its goodness. In particular, this means that a
non-good state cannot be obtained from a good state.

Hence, the only non-good state that can be obtained from our initial state
(with three heaps of sizes $51$, $49$ and $5$) is the initial state itself
(since any other state would require making at least one move, but after that
move we already have a good state in front of us, and any further moves will
preserve its goodness). Hence, in particular, the desired \textquotedblleft
flat\textquotedblright\ state (i.e., the state with $105$ heaps, each
containing one stone) cannot be obtained, because it is not good and not the
initial state.
\end{proof}

\subsection{Working backwards}

Problem-solving is metaphorically (sometimes also literally) a form of
way-finding: You start from an origin, and you want to get to a destination.
It is natural to attempt this by looking around the origin and picking a
direction or trail that appears hopeful. This is called \emph{working
forwards}. In contrast, \emph{working backwards} means exploring the
destination and trying to understand how it could be reached, i.e., what the
last steps of a path to this destination might be.

Both of these approaches are useful. When searching for a proof, it is helpful
to analyze both the claims that can be derived from the assumptions (working
forwards) and the possible claims that could lead to the desired conclusion
(working backwards). When trying to construct an object with some desired
properties, it can be useful to ponder how such an object could arise and what
it could look like.

A much more down-to-earth manifestation of the \textquotedblleft working
backwards\textquotedblright\ principle appears when analyzing a process. Here,
you often ask yourself whether a given state $B$ can be obtained from a given
state $A$ (for instance, Exercise \ref{exe.invars.chameleon1} and Exercise
\ref{exe.monvars.stones} ask such questions). Working forwards means trying to
move from state $A$, whereas working backwards means trying to move into state
$B$. We saw in Exercise \ref{exe.monvars.stones} how the former can be
helpful. The following exercises illustrate the usefulness of the latter.

\begin{exercise}
\label{exe.wb.a+b-mod2}Five distinct points are chosen on a circle. At each of
these five points, an integer is written.

Every day, you perform the following ritual: For every two adjacent integers
on the circle, you write the sum of these two integers into the position
midway between these two integers on the circle. Having written these five
sums, you erase the original five integers (see
Figure~\ref{fig.exe.wb.a+b-mod2.1} for an illustration). In other words, every
day, you replace the five integers $a,b,c,d,e$ by
$a+b,\ b+c,\ c+d,\ d+e,\ e+a$.

On the first day, the five integers are $1,\ 2,\ 3,\ 4,\ 5$. Is it possible
that one day, all five integers on the circle will be even?
\end{exercise}

\begin{figure}[ptb]%
\[
\begin{tikzpicture}[scale=2.5]
\draw[thick] (0,0) circle [radius=1cm];
\node[fill=yellow] (0) at (0:1) {$a$};
\node[fill=yellow] (1) at (360/5:1) {$b$};
\node[fill=yellow] (2) at (2*360/5:1) {$c$};
\node[fill=yellow] (3) at (3*360/5:1) {$d$};
\node[fill=yellow] (4) at (4*360/5:1) {$e$};
\node (u) at (1.5,0) {$\mapsto$};
\begin{scope}[xshift=3cm]
\draw[thick] (0,0) circle [radius=1cm];
\node[fill=yellow] (0b) at (360/10:1) {$a+b$};
\node[fill=yellow] (1b) at (3*360/10:1) {$b+c$};
\node[fill=yellow] (2b) at (5*360/10:1) {$c+d$};
\node[fill=yellow] (3b) at (7*360/10:1) {$d+e$};
\node[fill=yellow] (4b) at (9*360/10:1) {$e+a$};
\end{scope}
\end{tikzpicture}
\]
\caption{The daily ritual in Exercise \ref{exe.wb.a+b-mod2}.}%
\label{fig.exe.wb.a+b-mod2.1}%
\end{figure}

\begin{proof}
[Solution idea.]The answer is \textquotedblleft no\textquotedblright.

\textit{Proof.} Assume the contrary. Thus, there exists an $i\in\mathbb{N}$
such that all five integers on day $i$ are even. Pick the \textbf{smallest}
such $i$. This $i$ cannot be $1$ (since the integers on day $1$ are
$1,\ 2,\ 3,\ 4,\ 5$, which are not all even). Hence, day $i-1$ exists.

Let $a,b,c,d,e$ be the five integers on day $i-1$. Thus, the five integers on
day $i$ are $a+b,\ b+c,\ c+d,\ d+e,\ e+a$. Since the latter five integers are
all even, we thus conclude that $a+b,\ b+c,\ c+d,\ d+e,\ e+a$ are all even.
Hence, the five integers $a,b,c,d,e$ all have the same parity -- i.e., they
are either all even or all odd.

Can they be all even? No, because that would mean that all five integers on
day $i-1$ are even, but this would contradict the fact that $i$ was the
\textbf{smallest} day on which all five integers are even. Hence, the five
integers $a,b,c,d,e$ must all be odd.

In other words, all five integers on day $i-1$ are odd. Therefore, $i-1$
cannot be $1$ (since the integers on day $1$ are $1,\ 2,\ 3,\ 4,\ 5$, which
are not all odd). Thus, day $i-2$ exists.

Let $a^{\prime},b^{\prime},c^{\prime},d^{\prime},e^{\prime}$ be the five
integers on day $i-2$. Thus, the five integers on day $i-1$ are $a^{\prime
}+b^{\prime},\ b^{\prime}+c^{\prime},\ c^{\prime}+d^{\prime},\ d^{\prime
}+e^{\prime},\ e^{\prime}+a^{\prime}$. But we know that the five integers on
day $i-1$ are $a,b,c,d,e$ (since this is how $a,b,c,d,e$ were defined).
Comparing these facts, we conclude that the integers $a,b,c,d,e$ are precisely
the integers $a^{\prime}+b^{\prime},\ b^{\prime}+c^{\prime},\ c^{\prime
}+d^{\prime},\ d^{\prime}+e^{\prime},\ e^{\prime}+a^{\prime}$ (although
possibly in a different order). Hence,%
\begin{align*}
a+b+c+d+e  &  =\left(  a^{\prime}+b^{\prime}\right)  +\left(  b^{\prime
}+c^{\prime}\right)  +\left(  c^{\prime}+d^{\prime}\right)  +\left(
d^{\prime}+e^{\prime}\right)  +\left(  e^{\prime}+a^{\prime}\right) \\
&  =2\left(  a^{\prime}+b^{\prime}+c^{\prime}+d^{\prime}+e^{\prime}\right)  .
\end{align*}
Therefore, $a+b+c+d+e$ is even. But $a+b+c+d+e$ is a sum of $5$ odd integers
(since $a,b,c,d,e$ are odd), and thus must be odd. This contradicts the
preceding sentence. This contradiction shows that our assumption was wrong,
and the exercise is solved.\footnote{Here is another way to obtain this
contradiction: The five sums $a^{\prime}+b^{\prime},\ b^{\prime}+c^{\prime
},\ c^{\prime}+d^{\prime},\ d^{\prime}+e^{\prime},\ e^{\prime}+a^{\prime}$ are
odd (since they are the five integers on day $i-1$, but we already know that
these five integers are odd). This entails that the parities of the six
integers $a^{\prime},\ b^{\prime},\ c^{\prime},\ d^{\prime},\ e^{\prime
},\ a^{\prime}$ alternate: i.e., if $a^{\prime}$ is odd, then $b^{\prime}$ is
even, thus $c^{\prime}$ is odd, thus $d^{\prime}$ is even, thus $e^{\prime}$
is odd, thus $a^{\prime}$ is even; and similarly, if $a^{\prime}$ is even,
then $b^{\prime}$ is odd, etc.. In either case, we obtain conflicting parities
for $a^{\prime}$, which gives us the contradiction we were looking for.}
\medskip

[\textit{Remark:} We could also rephrase part of the above argument as
follows: On any day starting with day $2$, the five integers on the circle
have an even sum, because they have the form $a+b,\ b+c,\ c+d,\ d+e,\ e+a$
where $a,b,c,d,e$ are the five integers from the day before. Thus, we cannot
have five odd integers on the circle, except on the very first day. Actually,
we can say something more concrete: The sum $a+b+c+d+e$ gets multiplied by $2$
every day, so that it is divisible by $2^{i-1}$ on day $i$.]
\end{proof}

\begin{exercise}
\label{exe.wb.equalizer-game.3}The three numbers $1$, $2$ and $4$ are written
on a blackboard. Every hour, you are allowed to pick two of the three numbers
-- say, $u$ and $v$ -- and replace each of them by $u+v$. (Thus, if the three
numbers are $a,\ b,\ c$, then you can turn them into $a+b,\ a+b,\ c$ or into
$a+c,\ b,\ a+c$ or into $a,\ b+c,\ b+c$.)

Is it possible that after some time, you have three equal numbers written on
the blackboard?
\end{exercise}

\begin{proof}
[Solution idea.]The answer is \textquotedblleft no\textquotedblright.

\textit{Proof.} Assume the contrary. Thus, three equal numbers are obtained
after some time.

We encode the three numbers on the blackboard as a triple $\left(
a,b,c\right)  \in\left\{  1,2,3,\ldots\right\}  ^{3}$ of positive integers.
Thus, we are dealing with a process whose states are triples $\left(
a,b,c\right)  \in\left\{  1,2,3,\ldots\right\}  ^{3}$, and whose moves are%
\begin{align*}
\left(  a,b,c\right)   &  \mapsto\left(  a+b,\ a+b,\ c\right)
\ \ \ \ \ \ \ \ \ \ \text{and}\\
\left(  a,b,c\right)   &  \mapsto\left(  a+c,\ b,\ a+c\right)
\ \ \ \ \ \ \ \ \ \ \text{and}\\
\left(  a,b,c\right)   &  \mapsto\left(  a,\ b+c,\ b+c\right)  .
\end{align*}
We start in the state $\left(  1,2,4\right)  $, and want to show that we can
never reach a state with three equal numbers, i.e., a state of the form
$\left(  x,x,x\right)  $.

We reason backwards: How could a state of the form $\left(  x,x,x\right)  $ be
reached? What could be a last move that leads to this state? The moves that
lead to this state are moves of the form%
\begin{align*}
\left(  u,v,x\right)   &  \mapsto\left(  x,x,x\right)  ,\\
\left(  u,x,v\right)   &  \mapsto\left(  x,x,x\right)
,\ \ \ \ \ \ \ \ \ \ \text{and}\\
\left(  x,u,v\right)   &  \mapsto\left(  x,x,x\right)  ,
\end{align*}
where $u$ and $v$ are two positive integers satisfying $u+v=x$. Thus, the
state preceding $\left(  x,x,x\right)  $ must have one of the forms $\left(
u,v,x\right)  $, $\left(  u,x,v\right)  $ and $\left(  x,u,v\right)  $ for two
such $u$ and $v$. This is good to know, but not as informative as we might
hope for, since there are lots of states of these forms.

However, we can simplify our life by also working forwards a little bit.
Namely, we observe the following: Each move results in a state that has two
equal entries! For example, the move $\left(  a,b,c\right)  \mapsto\left(
a+b,\ a+b,\ c\right)  $ results in a state whose first two entries are equal.

To restate this in a more convenient form, we say that a state is \emph{good}
if it has (at least) two equal entries. Each move thus results in a good
state. Thus, our process will only ever produce good states (except for the
initial state $\left(  1,2,4\right)  $, which is not good).

Hence, when reasoning backwards, we can restrict ourselves to \textbf{good}
states only (except for the initial state). So we ask ourselves not what
states can produce $\left(  x,x,x\right)  $, but only what \textbf{good}
states can produce $\left(  x,x,x\right)  $. This is much easier: The only
\textbf{good} states that can produce $\left(  x,x,x\right)  $ in a single
move are the states
\[
\left(  \dfrac{x}{2},\dfrac{x}{2},x\right)  ,\ \ \ \ \ \ \ \ \ \ \left(
\dfrac{x}{2},x,\dfrac{x}{2}\right)  ,\ \ \ \ \ \ \ \ \ \ \left(  x,\dfrac
{x}{2},\dfrac{x}{2}\right)
\]
(if $x$ is even; otherwise, there are no such states at all).

Thus, if we ever reach the state $\left(  x,x,x\right)  $, then we must reach
it from one of these three states (or else directly by a single move from the
initial state $\left(  1,2,4\right)  $, but this is easily seen to be
impossible\footnote{Indeed, the three possible moves from the initial state
$\left(  1,2,4\right)  $ produce the three states $\left(  3,3,4\right)  $,
$\left(  5,2,5\right)  $ and $\left(  1,6,6\right)  $, neither of which has
the form $\left(  x,x,x\right)  $.}). We WLOG assume that we reach it from
$\left(  \dfrac{x}{2},\dfrac{x}{2},x\right)  $ (since the other two options
are the same up to permutation of the entries, but the three numbers play
symmetric roles and thus can be permuted without changing the reasoning).
Thus, we reach $\left(  x,x,x\right)  $ from $\left(  \dfrac{x}{2},\dfrac
{x}{2},x\right)  $.

Now, let us think one step further backwards: How can we reach the state
$\left(  \dfrac{x}{2},\dfrac{x}{2},x\right)  $ ? The only way to reach this
state from a good state is by the move $\left(  \dfrac{x}{4},\dfrac{x}%
{4},x\right)  \mapsto\left(  \dfrac{x}{2},\dfrac{x}{2},x\right)  $ (because
the move must produce the two equal entries $\dfrac{x}{2}$ and $\dfrac{x}{2}$
by summing two smaller entries, and these two smaller entries must be equal in
order for the state to be good; thus, these two smaller entries must be
$\dfrac{x}{4}$ and $\dfrac{x}{4}$). Similarly, the only way to reach the state
$\left(  \dfrac{x}{4},\dfrac{x}{4},x\right)  $ from a good state is by the
move $\left(  \dfrac{x}{8},\dfrac{x}{8},x\right)  \mapsto\left(  \dfrac{x}%
{4},\dfrac{x}{4},x\right)  $. Continuing this reasoning further, we see that
the only good states from which we can reach $\left(  x,x,x\right)  $ are the
states of the form $\left(  \dfrac{x}{2^{i}},\dfrac{x}{2^{i}},x\right)  $ for
$i\in\mathbb{N}$ (as well as the cyclically rotated versions of these states).
We shall refer to the latter states as the \emph{hopeful states}. They have
the property that the ratio of any two entries is a (positive or negative)
power of $2$.

Thus, if $\left(  x,x,x\right)  $ can be obtained from $\left(  1,2,4\right)
$ by our process, then every good state obtained along the way must be a
hopeful state. In particular, the state obtained after the very first move
must be a hopeful state (since it is a good state). But this state is either
$\left(  3,3,4\right)  $ or $\left(  5,2,5\right)  $ or $\left(  1,6,6\right)
$ (since these are the three possible states that can be obtained from
$\left(  1,2,4\right)  $ by a single move), and neither of these three options
is a hopeful state (since the ratios $\dfrac{4}{3}$, $\dfrac{5}{2}$ and
$\dfrac{6}{1}$ are not powers of $2$). Hence, we obtain a contradiction.

This shows that $\left(  x,x,x\right)  $ cannot be obtained from $\left(
1,2,4\right)  $ by our process. This completes the proof.
\end{proof}

Note that Exercise \ref{exe.wb.equalizer-game.3} is the beginning of an
exciting story: We can play a similar game with four, five or $n$ numbers. The
answer depends on the parity of $n$:

\begin{itemize}
\item If $n>1$ is odd, then we cannot transform the $n$ integers
$1,\underbrace{2,2,\ldots,2}_{n-1\text{ times}}$ into $n$ equal integers by
repeatedly replacing two integers $x$ and $y$ by $x+y$ and $x+y$.

\item If $n$ is even, then we can transform any $n$ integers (or, more
generally, any $n$ complex numbers) into $n$ equal numbers by repeatedly
replacing two numbers $x$ and $y$ by $x+y$ and $x+y$.
\end{itemize}

\noindent See
\url{https://mathoverflow.net/questions/452221/make-all-numbers-equal-game}
for a discussion of this problem.

\subsection{Class problems}

The following problems are to be discussed during class.

\begin{exercise}
\label{exe.invars.chameleon2}Let $a,b,c\in\mathbb{N}$. We generalize Exercise
\ref{exe.invars.chameleon1} by starting with a state in which there are $a$
red, $b$ green and $c$ blue chameleons on the island.

We say that this state is \emph{winnable} if and only if it is possible (by an
appropriate arrangement of meetings between chameleons) to cause all
chameleons to adopt the same color.

Prove that the state is winnable if and only if (at least) two of the integers
$a,b,c$ are congruent modulo $3$.
\end{exercise}

\begin{exercise}
Start with the triple $\left(  2,3,4\right)  $ of numbers. In a single move,
you are allowed to choose two entries $x$ and $y$ of the triple, and replace
them with $\dfrac{3}{5}x-\dfrac{4}{5}y$ and $\dfrac{4}{5}x+\dfrac{3}{5}y$
(respectively). You are also allowed to permute the three entries.

\begin{enumerate}
\item[\textbf{(a)}] Can you reach the triple $\left(  1,3,5\right)  $ by such moves?

\item[\textbf{(b)}] What about the triple $\left(  0,2,5\right)  $ ?

\item[\textbf{(c)}] What about the triple $\left(  \dfrac{1}{3},\ \dfrac{2}%
{3},\ \dfrac{16}{3}\right)  $ ?
\end{enumerate}
\end{exercise}

\begin{exercise}
Alla, Bella and Caella are sitting around a circular table (in this order).
Alla opens a bag of nuts. She divides them evenly among Bella and Caella (as
evenly as possible: i.e., Bella and Caella each get $\left\lfloor
n/2\right\rfloor $ nuts, where $n$ is the number of nuts at Alla's disposal),
and eats the remaining nut (if there is any left). Then, it is Bella's turn,
and she does the same with the nuts she has: i.e., she divides them evenly
among Caella and Alla, and eats the remaining nut (if there is any left).
Then, Caella repeats the same procedure; after that, it is Alla's turn again,
and so on.

Assume that Alla's bag has more than $3$ nuts, and neither Bella nor Caella
had any nuts initially. Prove the following:

\begin{enumerate}
\item[\textbf{(a)}] At least one nut gets eaten at some point.

\item[\textbf{(b)}] Not all nuts get eaten (i.e., at least one nut gets passed
around endlessly).
\end{enumerate}

\flushright(Tournament of Towns 27.5.4)
\end{exercise}

\begin{exercise}
Consider an $n\times n$-chessboard. Some of its $n^{2}$ squares are infected.

Every hour, the infection spreads by the following rule: If a square has at
least two infected neighbors, then it gets infected as well. (The
\textquotedblleft neighbors\textquotedblright\ of a square are the squares
that share an edge with it; thus, a square can have up to $4$ neighbors.)
Prove the following:

\begin{enumerate}
\item[\textbf{(a)}] If all diagonal squares are initially infected, then all
squares will eventually get infected.

\item[\textbf{(b)}] If fewer than $n$ squares are initially infected, then at
least one square will never get infected.
\end{enumerate}
\end{exercise}

\begin{exercise}
Consider $n$ lightbulbs (arranged from left to right on a line), each of which
is either on or off. Assume that $n\geq1$.

If a lightbulb is off and has two neighbors (i.e., is neither at the left end
nor at the right end of the line), then you can remove it from the line, but
this causes the two neighboring lightbulbs to get flipped. (To \emph{flip} a
lightbulb means to turn it on if it was off, and to turn it off if it was on.)

Assume that all $n$ lightbulbs are initially off. Prove that it is possible to
remove $n-2$ lightbulbs by a sequence of such moves if and only if $n-1$ is
not divisible by $3$.
\end{exercise}

\subsection{Homework exercises}

Solve 4 of the 10 exercises below and upload your solutions on gradescope by
November 15.

\begin{exercise}
Recall the Euclidean algorithm discussed in Subsubsection
\ref{subsec.process.euclid}. Let $u$ and $v$ be two positive integers. Prove
that if we start the Euclidean algorithm in the state $\left(  u,v\right)  $,
then it will terminate after at most $\max\left\{  u,v\right\}  $ moves.
\medskip

[\textbf{Remark:} This is a sharp estimate, because if we start the Euclidean
algorithm in the state $\left(  n,1\right)  $, then it will take $n$ moves to
terminate:%
\[
\left(  n,1\right)  \mapsto\left(  n-1,1\right)  \mapsto\left(  n-2,1\right)
\mapsto\cdots\mapsto\left(  1,1\right)  \mapsto\left(  1,0\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{or }\mapsto\left(  0,1\right)  \right)  .
\]
On the other hand, the \textquotedblleft grown-up\textquotedblright\ version
of the Euclidean algorithm, which uses division with remainder instead of
subtraction, terminates much faster: see, e.g., \cite{Epasin83}.]
\end{exercise}

\begin{exercise}
Consider the process whose states are the $4$-tuples $\left(  a,b,s,t\right)
\in\left\{  1,2,3,\ldots\right\}  ^{4}$ of positive integers, and whose moves
are%
\begin{align*}
\left(  a,b,s,t\right)   &  \mapsto\left(  a,b-a,s,t+s\right)
\ \ \ \ \ \ \ \ \ \ \text{if }b>a;\\
\left(  a,b,s,t\right)   &  \mapsto\left(  a-b,b,s+t,t\right)
\ \ \ \ \ \ \ \ \ \ \text{if }a>b.
\end{align*}
Its end states are clearly the $4$-tuples $\left(  a,b,s,t\right)  $ with
$a=b$.

Now, let $u$ and $v$ be two positive integers. We run this process starting
with the state $\left(  u,v,u,v\right)  $. Prove the following:

\begin{enumerate}
\item[\textbf{(a)}] This process will eventually terminate.

\item[\textbf{(b)}] The end state at which it terminates is a $4$-tuple
$\left(  g,g,s,t\right)  $ with $g=\gcd\left(  u,v\right)  $ and $\dfrac
{s+t}{2}=\operatorname{lcm}\left(  u,v\right)  $.
\end{enumerate}

[\textbf{Example:} If $u=6$ and $v=9$, then the process runs as follows:%
\[
\left(  6,9,6,9\right)  \mapsto\left(  6,3,6,15\right)  \mapsto\left(
3,3,21,15\right)  ,
\]
and indeed we have $3=\gcd\left(  6,9\right)  $ and $\dfrac{21+15}%
{2}=18=\operatorname{lcm}\left(  6,9\right)  $.]
\end{exercise}

\begin{exercise}
Consider the following variant of Exercise \ref{exe.invars.chameleon1}:
Chameleons can come in four colors, and change colors only when three
chameleons of pairwise different colors meet (in which case they all take on
the fourth color). (No more than three chameleons meet at a time.)

Encode each state as a $4$-tuple $\left(  a,b,c,d\right)  $, where $a$ is the
number of chameleons of the first color, and so on. Say that a state $\left(
a,b,c,d\right)  $ is \emph{winnable} if an appropriate sequence of meetings
can transform it into a state where all chameleons have the same color.

\begin{enumerate}
\item[\textbf{(a)}] Prove that if a state $\left(  a,b,c,d\right)  $ is
winnable, then (at least) three of the integers $a,b,c,d$ are congruent modulo
$4$.

\item[\textbf{(b)}] Is the converse true?
\end{enumerate}
\end{exercise}

\begin{exercise}
Consider the following variant of Exercise \ref{exe.invars.chameleon1}: We
start with $a$ red, $b$ green and $c$ blue chameleons. The rules of color
change are the same as in Exercise \ref{exe.invars.chameleon1}, but the goal
we want to achieve is not that all chameleons have the same color, but rather
that the colors are equidistributed (i.e., there are equally many red, green
and blue chameleons on the island).

Prove a simple necessary and sufficient criterion (in terms of $a,b,c$) for
this goal to be achievable.
\end{exercise}

\begin{exercise}
You have a bank account with $2023$ dollars. You can split a bank account into
two, but this operation costs you $1$ dollar in fees. (Thus, you can split a
bank account with $n$ dollars into two bank accounts with $p$ and $q$ dollars
each, where $n=p+q+1$.) Can you use a sequence of such operations to end up
with all of your accounts containing exactly $2$ dollars each?
\end{exercise}

\begin{exercise}
\label{exe.monvars.pentagon0}Consider Exercise \ref{exe.monvars.pentagon}, but
now assume that the sum of all five integers is zero rather than positive.
Assume furthermore that not all five integers are zero at the onset. Will the
process go on forever, or will it terminate?
\end{exercise}

\begin{exercise}
Four real numbers $a,b,c,d$ are written on a whiteboard. Every hour, a ghost
flies by and replaces them by the numbers $a-b,\ b-c,\ c-d,\ d-a$. Prove that
eventually, at least one of the numbers will be too large (in absolute value)
to fit on the whiteboard, unless the original four numbers $a,b,c,d$ were all equal.
\end{exercise}

\begin{exercise}
Consider a sequence $\left(  a_{0},a_{1},a_{2},\ldots\right)  $ of non-zero
reals that satisfies%
\[
a_{n}^{2}=1+a_{n-1}a_{n+1}\ \ \ \ \ \ \ \ \ \ \text{for each }n\geq1.
\]
Prove that there exists a real number $\alpha$ such that $a_{n+1}=\alpha
a_{n}-a_{n-1}$ for all $n\geq1$.

\flushright(54th Putnam contest 1993, Problem A2)
\end{exercise}

\begin{exercise}
Let $m$ be a positive integer. Consider the ritual described in Exercise
\ref{exe.wb.a+b-mod2}, but with $2^{m}$ points on the circle instead of $5$
(and thus $2^{m}$ integers instead of $5$).

Prove that after $2^{m}$ days, all the integers on the circle will be even.
\end{exercise}

\begin{exercise}
Consider an $n$-tuple $\left(  a_{1},a_{2},\ldots,a_{n}\right)  $ of real
numbers. We are allowed to make the following three kinds of moves:

\begin{itemize}
\item \textbf{S-moves:} We pick two adjacent entries $a_{i}$ and $a_{i+1}$
that are \textquotedblleft out of order\textquotedblright\ (i.e., satisfy
$a_{i}>a_{i+1}$), and swap them (i.e., replace them by $a_{i+1}$ and $a_{i}$,
respectively). This is called an \emph{S-move}.

\item \textbf{L-moves:} We pick two adjacent entries $a_{i}$ and $a_{i+1}$
that are \textquotedblleft out of order\textquotedblright\ (i.e., satisfy
$a_{i}>a_{i+1}$), and replace them by $a_{i+1}$ and $a_{i+1}$ (that is, we
replace the larger entry by the smaller one). This is called an \emph{L-move}.

\item \textbf{U-moves:} We pick two adjacent entries $a_{i}$ and $a_{i+1}$
that are \textquotedblleft out of order\textquotedblright\ (i.e., satisfy
$a_{i}>a_{i+1}$), and replace them by $a_{i}$ and $a_{i}$ (that is, we replace
the smaller entry by the larger one). This is called a \emph{U-move}.
\end{itemize}

For instance, $\left(  4,3,1,2\right)  \mapsto\left(  3,4,1,2\right)  $ is an
S-move, $\left(  4,3,1,2\right)  \mapsto\left(  3,3,1,2\right)  $ is an
L-move, and $\left(  4,3,1,2\right)  \mapsto\left(  4,4,1,2\right)  $ is a U-move.

\begin{enumerate}
\item[\textbf{(a)}] Prove that if we keep applying S-moves and L-moves to our
$n$-tuple (sequentially), then we eventually end up with a weakly increasing
$n$-tuple (i.e., the process terminates).

\item[\textbf{(b)}] Is the same true if we allow all three kinds of moves?
\end{enumerate}
\end{exercise}

\bigskip

\begin{thebibliography}{99999999}                                                                                         %


\bibitem[Engel98]{Engel98}\href{https://doi.org/10.1007/b97682}{Arthur Engel,
\textit{Problem-Solving Strategies}, Springer 1998.}

\bibitem[Epasin83]{Epasin83}%
\href{https://www.fq.math.ca/Scanned/23-2/epasinghe.pdf}{P. W. Epasinghe,
\textit{Euclid's Algorithm and the Fibonacci Numbers}, Fibonacci Quarterly 23
(\textbf{1985}), issue 2, pp. 177--179.}

\bibitem[Erikss92]{Erikss92}%
\href{https://doi.org/10.1016/0024-3795(92)90274-E}{Kimmo Eriksson,
\textit{Convergence of Mozes's Game of Numbers}, Linear Algebra and its
Applications \textbf{166} (1992), pp. 151--165.}

\bibitem[Erikss93]{Erikss93}%
\href{https://archive.org/details/eriksson-strongly-convergent-games-thesis}{Kimmo
Eriksson, \textit{Strongly Convergent Games and Coxeter Groups}, PhD thesis at
KTH, 1993.}

\bibitem[GelAnd17]{GelAnd17}%
\href{https://doi.org/10.1007/978-3-319-58988-6}{R\u{a}zvan Gelca, Titu
Andreescu, \textit{Putnam and Beyond}, 2nd edition, Springer 2017.}

\bibitem[Grinbe20]{20f}Darij Grinberg, \textit{Math 235: Mathematical Problem
Solving}, 10 August 2021.\newline\url{https://www.cip.ifi.lmu.de/~grinberg/t/20f/mps.pdf}

\bibitem[StaRik08]{StaRik08}\href{https://bookstore.ams.org/mcl-1}{Zvezdelina
Stankova, Tom Rike, \textit{A Decade of the Berkeley Math Circle: The American
Experience, Volume I}, MSRI mathematical circles library \textbf{1}, AMS
2008.}

\bibitem[WegRei07]{WegRei07}Elias Wegert, Christian Reiher, \textit{Relaxation
Procedures on Graphs}, Discrete Applied Mathematics \textbf{157} (2009), pp.
2207--2216.\newline\url{https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=6ebf14e003ad7898838fb4b686c83dd6b3f1a36d}

\bibitem[Zeitz17]{Zeitz17}Paul Zeitz, \textit{The Art and Craft of Problem
Solving}, 3rd edition, Wiley 2017.
\end{thebibliography}


\end{document}