\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[breaklinks=True]{hyperref}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{needspace}
\usepackage{tabls}
\usepackage{tikz}
\usepackage{bbding}
%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{Version=5.50.0.2960}
%TCIDATA{LastRevised=Saturday, December 16, 2023 00:19: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}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\newcounter{exer}
\newcounter{exera}
\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}{\begin{small}}{\end{small}}
\iffalse
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{convention}[1][Convention]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newenvironment{question}[1][Question]{\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}
\newcommand\arxiv[1]{\href{http://www.arxiv.org/abs/#1}{\texttt{arXiv:#1}}}
\setlength\tablinesep{3pt}
\setlength\arraylinesep{3pt}
\setlength\extrarulesep{3pt}
\setlength\textheight{22.5cm}
\setlength\textwidth{14.8cm}
\newenvironment{verlong}{}{}
\newenvironment{vershort}{}{}
\newenvironment{noncompile}{}{}
\excludecomment{verlong}
\includecomment{vershort}
\excludecomment{noncompile}
\newcommand{\defn}[1]{{\color{darkred}\emph{#1}}}
\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{\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{\are}{\ar@{-}}
\newcommand{\arebi}[1][]{\ar@{<-}@/_/[#1] \ar@/^/[#1]}
\newcommand{\of}{\text{ of }}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 1, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 1: Introduction}

\textbf{website:}
\texttt{\href{https://www.cip.ifi.lmu.de/~grinberg/t/23wd}{\texttt{https://www.cip.ifi.lmu.de/\symbol{126}%
grinberg/t/23wd}}}

\subsection{What is this about?}

My name is Darij Grinberg.

This is a course on \textbf{discrete mathematics}. To us, discrete mathematics
means the mathematics of finite, discrete objects: integers, finite sets,
occasionally some more complex creatures such as graphs and polynomials.
Integer sequences, while theoretically infinite, are also included since one
usually makes statements about finite pieces of the sequence. Much of linear
algebra logically belongs to discrete mathematics, but there are separate
courses entirely devoted to it, so we won't touch on it here.

Discrete mathematics is in contrast to \textbf{continuous mathematics}, which
studies real numbers, continuous functions and infinite sets. This mostly
begins with analysis (or calculus, which is its less rigorous variant).

So this course will introduce you to the major topics of discrete mathematics:

\begin{itemize}
\item \textbf{mathematical induction} and \textbf{recursion};

\item \textbf{elementary number theory} (the properties of divisibility, prime
numbers, coprimality, possibly applications like the RSA cryptosystem);

\item basic \textbf{enumerative combinatorics} (counting and binomial coefficients);

\item basic \textbf{graph theory}.
\end{itemize}

We will neither go very deep nor be fully rigorous about everything. There are
deeper, more specific classes on most of these subjects:

\begin{itemize}
\item Math 220 is a deeper introduction to mathematical proof.

\item Math 222 is a quarter-length introduction to enumerative combinatorics.
(I have \href{https://www.cip.ifi.lmu.de/~grinberg/t/22fco/}{notes for this}
on my website.)

\item Math 530 is an introduction to graph theory. (I have
\href{https://www.cip.ifi.lmu.de/~grinberg/t/22s/}{notes for this} on my website.)

\item CS 303 is a course on cryptography.

\item I plan to teach elementary number theory as a class next Fall (Math T480).
\end{itemize}

\section{Induction and recursion}

\subsection{The Tower of Hanoi}

Let me start with a puzzle called
\href{https://en.wikipedia.org/wiki/Tower_of_Hanoi}{the \textbf{Tower of
Hanoi}}.

You have $3$ pegs (or rods). The first peg has $n$ disks stacked on it. The
$n$ disks have $n$ different sizes, and they are stacked in the order of their
size, with the smallest one on top. Here is how this looks like for $n=8$
(with the $3$ pegs numbered $1,2,3$ from left to right):%
\[
\includegraphics[scale=0.3]{WP-toh.jpg}
\]
(image by \href{https://en.wikipedia.org/wiki/User:Evanherk}{User:Evanherk} on
\href{https://en.wikipedia.org/wiki/File:Tower_of_Hanoi.jpeg}{Wikipedia},
licensed under
\href{https://creativecommons.org/licenses/by-sa/3.0/deed.en}{the CC
Attribution-Share Alike 3.0 Unported License}).

You can make a certain kind of moves (\textquotedblleft\textbf{Hanoi
moves}\textquotedblright): You can take the topmost disk from one peg and move
it on top of another peg. However, you are only allowed to do this if this
disk is smaller than the other disks currently on the latter peg; in other
words, you must never stack a larger disk atop a smaller disk.

Your \textbf{goal} is to move all $n$ disks onto the third peg.

\bigskip

This game can actually be played online, e.g., at
\url{https://codepen.io/eliortabeka/pen/yOrrxG}. (Be warned that this site has
$n=7$ hardcoded into it. But you can easily fix this by modifying
\textquotedblleft disksNum = 3\textquotedblright\ and changing
\textquotedblleft minMoves = 127\textquotedblright\ to \textquotedblleft
minMoves = 0\textquotedblright. Also note that the game allows you to win by
moving all disks to peg $2$ as well, but this is clearly not a significant difference.)

\bigskip

Let us analyze the case $n=3$. In this case, one strategy to win the game
(i.e., achieve the goal) is as follows:

\begin{enumerate}
\item Move the smallest disk from peg $1$ to peg $3$.

\item Move the middle disk from peg $1$ to peg $2$.

\item Move the smallest disk from peg $3$ to peg $2$.

\item Move the largest disk from peg $1$ to peg $3$.

\item Move the smallest disk from peg $2$ to peg $1$.

\item Move the middle disk from peg $2$ to peg $3$.

\item Move the smallest disk from peg $1$ to peg $3$.
\end{enumerate}

So we can win in $7$ moves for $n=3$.

\bigskip

What about other values of $n$ ? The questions we can ask are the following:

\begin{question}
\textbf{1.} Can we always win the game?

\textbf{2.} If so, then what is the smallest \# of moves\footnotemark\ we need
to make?
\end{question}

\footnotetext{The symbol \textquotedblleft\#\textquotedblright\ means
\textquotedblleft number\textquotedblright.}Let us record the answers for
small values of $n$:

\begin{itemize}
\item For $n=0$, we win in $0$ moves (since all disks -- of which there are
none -- are on peg $3$ already). This sounds very pedantic and pointless, but
it's not a bad start.

\item For $n=1$, we win in $1$ move (just move the single disk directly).

\item For $n=2$, we win in $3$ moves. Fewer moves are not enough, for fairly
simple logical reasons: We need $1$ move to free the largest disk, then $1$
move to move it to peg $3$, then $1$ more move to get the other disk on top of it.

\item For $n=3$, we win in $7$ moves. But do we need $7$ moves, or can we do
with less?

\item For $n=4$, what happens?
\end{itemize}

Solving the problem by brute force gets harder and harder as $n$ grows. But we
can try to analyze our strategy for $n=3$ and see if there is a pattern behind it.

We observe that the largest disk moves only once, and its move is right in the
middle of the strategy. So our strategy for $n=3$ can be summarized as follows:

\begin{enumerate}
\item[1.--3.] Move the two smaller disks from peg $1$ onto peg $2$.

\item[4.] Move the largest disk from peg $1$ onto peg $3$.

\item[5.--7.] Move the two smaller disks from peg $2$ onto peg $3$.
\end{enumerate}

Moreover, the moves 1--3 in this strategy are essentially a Tower of Hanoi
game played only with the two smaller disks, except that the goal is not to move
them to peg $3$ but to move them to peg $2$ (but this doesn't matter, because
the two games are clearly \textquotedblleft isomorphic\textquotedblright\ --
i.e., the roles of pegs $2$ and $3$ are swapped but otherwise everything is
the same). The largest disk stays at the bottom of peg $1$ all the time and
thus does not prevent any of the moves (since all the other disks are smaller
than it and thus can fit on top of it).

Move 4 moves the newly liberated largest disk from peg $1$ onto peg $3$.

Moves 5--7 are again a little Tower of Hanoi game for the two smaller disks,
except that now they have to be moved from peg $2$ to peg $3$. Again, the
largest disk (which is now on the bottom of peg $3$) does not interfere with
any of the moves.

Now the logic behind the above strategy has become clear (and also easier to memorize).

\bigskip

Does this help us solve the $n=4$ case?

Yes! We can win in $15$ moves by a strategy that has the same structure:

\begin{enumerate}
\item[1.--7.] Move the three smaller disks from peg $1$ onto peg $2$. (This is
a little Tower of Hanoi game for these three smaller disks. The largest disk
rests at the bottom of peg $1$ and does not interfere.)

\item[8.] Move the largest disk from peg $1$ onto peg $3$.

\item[9.--15.] Move the three smaller disks from peg $2$ onto peg $3$. (This
is again a little Tower of Hanoi game for these three smaller disks. The
largest disk rests at the bottom of peg $3$ and does not interfere.)
\end{enumerate}

Thus, we don't just have a strategy for $n=3$ and one for $n=4$, but actually
a \textquotedblleft meta-strategy\textquotedblright\ that lets us win the game
for $n$ disks if we know how to win it for $n-1$ disks. We will still call
this \textquotedblleft meta-strategy\textquotedblright\ a strategy.

\bigskip

Let us summarize what we gain from this strategy.

\begin{definition}
For any integer $n\geq0$, we let $m_{n}$ denote the \# of moves needed to win
the Tower of Hanoi game with $n$ disks. If the game cannot be won with $n$ disks, then we set
$m_{n}=\infty$ (where $\infty$ is not a number but just a symbol).
\end{definition}

Thus, both of our Questions 1 and 2 boil down to computing $m_{n}$.

Here is a table of small values of $m_{n}$ obtained using our strategy:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|c|c|c|c|}\hline
$n$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$\\\hline
$m_{n}$ & $0$ & $1$ & $3$ & $7$ & $15$ & $31$ & $63$ & $127$ & $255$\\\hline
\end{tabular}
\
\]
Note that these values are easily computed using our strategy, because in
order to win the game for a given $n$, we have to win it for $n-1$, then make
one extra move, then win it for $n-1$ again. So we get $m_{n}=m_{n-1}%
+1+m_{n-1}=2m_{n-1}+1$ (for $n \geq 1$).

Right?

\bigskip

Not so fast! We have proved that, e.g., the game can be won in $127$ moves for
$n=7$. We have not proved that it cannot be won in fewer moves. So the formula
$m_{n}=2m_{n-1}+1$ has been proved not for the \# of moves needed to win, but
rather for the \# of moves needed to win \textbf{using our strategy}. Maybe
there is a better strategy that wins for $n=7$ in (say) $109$ moves?

\bigskip

So what we really have proved is the following:

\begin{proposition}
\label{prop.hanoi.1}Let $n$ be a positive integer. If $m_{n-1}$ is an integer
(i.e., if $m_{n-1}\neq\infty$), then $m_{n}\leq2m_{n-1}+1$.
\end{proposition}

To gain some writing experience, let us write out the proof in detail:

\begin{proof}
Assume that $m_{n-1}$ is an integer. Thus, we can win the game for $n-1$ disks
in $m_{n-1}$ moves. Let $S$ be the strategy (i.e., the sequence of moves)
needed to do this. So the strategy $S$ moves $n-1$ disks from peg $1$ onto peg
$3$ in $m_{n-1}$ moves.

Let $S_{23}$ be the same strategy as $S$, but with the roles of pegs $2$ and
$3$ swapped. Thus, $S_{23}$ moves $n-1$ disks from peg $1$ onto peg $2$ in
$m_{n-1}$ moves.

Let $S_{12}$ be the same strategy as $S$, but with the roles of pegs $1$ and
$2$ swapped. Thus, $S_{12}$ moves $n-1$ disks from peg $2$ onto peg $3$ in
$m_{n-1}$ moves.

Now, we proceed as follows to win the game with $n$ disks:

\begin{enumerate}
\item[A.] We use strategy $S_{23}$ to move the $n-1$ smaller disks from peg
$1$ onto peg $2$. (This is allowed because the largest disk rests at the
bottom of peg $1$ and does not interfere with the movement of smaller disks.)

\item[B.] We move the largest disk from peg $1$ onto peg $3$. (This is allowed
because this disk is free (i.e., there are no disks on top of it) and because
peg $3$ is empty, since all the other disks are on peg $2$.)

\item[C.] We use strategy $S_{12}$ to move the $n-1$ smaller disks from peg
$2$ onto peg $3$. (Again, this is allowed since the largest disk rests at the
bottom of peg $3$ and does not interfere.)
\end{enumerate}

This strategy wins the game (for $n$ disks) in $m_{n-1}+1+m_{n-1}=2m_{n-1}+1$
many moves. So the game for $n$ disks can be won in $2m_{n-1}+1$ many moves.
In other words, $m_{n}\leq2m_{n-1}+1$. This proves Proposition
\ref{prop.hanoi.1}.
\end{proof}

\bigskip

Now, let us see if the inequality $m_{n}\leq2m_{n-1}+1$ that we have proved is
an equality or just an inequality -- i.e., whether the above strategy is
optimal or there is a faster one. I claim it is the former:

\begin{proposition}
\label{prop.hanoi.2}Let $n$ be a positive integer. If $m_{n-1}$ is an integer
(i.e., if $m_{n-1}\neq\infty$), then $m_{n}=2m_{n-1}+1$.
\end{proposition}

\begin{proof}
Again, assume that $m_{n-1}$ is an integer.

We need to show that $m_{n}=2m_{n-1}+1$. It suffices to show that $m_{n}%
\geq2m_{n-1}+1$ (since Proposition \ref{prop.hanoi.1} yields $m_{n}%
\leq2m_{n-1}+1$, and we can combine these two inequalities to get
$m_{n}=2m_{n-1}+1$). In other words, it suffices to show that any winning
strategy for $n$ disks has at least $2m_{n-1}+1$ many moves.

So let us consider a winning strategy $T$ for $n$ disks. Somewhere during the
strategy $T$, the largest disk has to move (since it starts out on peg $1$ but
has to end up on peg $3$). Let us refer to these moves (the ones that move the
largest disk) as the \textbf{special moves}. There may be several special
moves or just one, but as we just said, there has to be \textbf{at least} one.

\textbf{Before the first special move} can happen, the smallest $n-1$ disks
have to be moved away from peg $1$ (since they would otherwise block the
largest disk from moving). Moreover, these smallest $n-1$ disks must all be
moved onto the same peg (since otherwise, both pegs $2$ and $3$ would be
occupied, and then the largest disk would have nowhere to move). Thus, before
the first special move can happen, we must have won the Tower of Hanoi game
for $n-1$ disks. Hence, before the first special move can happen, we already
need to have made $m_{n-1}$ moves (since $m_{n-1}$ is the smallest \# of moves
that can win the game for $n-1$ disks).

Now, consider what happens \textbf{after the last special move}. This last
special move necessarily moves the largest disk to peg $3$ (since that's where
this disk has to come to rest). After that, we still need to move all the
other disks onto peg $3$. At the time we are making the last special moves,
these other disks must all be on the same peg (since they can be neither on
the peg from which the largest disk is moving, nor on the peg to which it is
moving\footnote{because in either case, they would block the move of the
largest disk}). Therefore, after the last special move, we still need to move
all the remaining $n-1$ disks from one peg to another. And this is again
tantamount to winning the game for $n-1$ disks. So this again needs at least
$m_{n-1}$ moves.

So in total, we know that our strategy $T$ needs to have

\begin{enumerate}
\item at least $m_{n-1}$ moves before the first special move,

\item at least one special move, and

\item at least $m_{n-1}$ moves after the last special move.
\end{enumerate}

Thus, it needs to have at least $m_{n-1}+1+m_{n-1}=2m_{n-1}+1$ many moves in
total. This proves $m_{n}\geq2m_{n-1}+1$.
\end{proof}

\bigskip

Proposition \ref{prop.hanoi.2} confirms the table we have carelessly made
before:%
\[%
\begin{tabular}
[c]{|c||c|c|c|c|c|c|c|c|c|}\hline
$n$ & $0$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$\\\hline
$m_{n}$ & $0$ & $1$ & $3$ & $7$ & $15$ & $31$ & $63$ & $127$ & $255$\\\hline
\end{tabular}
\
\]
Obviously, you can keep using Proposition \ref{prop.hanoi.2} to compute
$m_{9},m_{10},m_{11},\ldots$. Indeed, the equation%
\begin{equation}
m_{n}=2m_{n-1}+1 \label{eq.hanoi.rec}%
\end{equation}
is what is called a \textbf{recursive formula} for the numbers $m_{n}$. This
means a formula that allows you to compute $m_{n}$ using the previous values
$m_{0},m_{1},\ldots,m_{n-1}$. In our case, we only need the direct predecessor
$m_{n-1}$, so this is a particularly convenient recursive formula.

\bigskip

Still, can we perhaps do better? Can we find an \textbf{explicit formula} --
i.e., one that gives us $m_{n}$ directly?

Some of you have already guessed such a formula:
\[
m_{n}=2^{n}-1.
\]


Is there a way to see this without guessing? Let's try applying the recursive
formula (\ref{eq.hanoi.rec}) again and again, simplifying each time:%
\begin{align*}
m_{n}  &  =2m_{n-1}+1\ \ \ \ \ \ \ \ \ \ \left(  \text{by (\ref{eq.hanoi.rec}%
)}\right) \\
&  =2\left(  2m_{n-2}+1\right)  +1\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.hanoi.rec}), applied to }n-1\right) \\
&  =4m_{n-2}+2+1\\
&  =4\left(  2m_{n-3}+1\right)  +2+1\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.hanoi.rec}), applied to }n-2\right) \\
&  =8m_{n-3}+4+2+1\\
&  =8\left(  2m_{n-4}+1\right)  +4+2+1\ \ \ \ \ \ \ \ \ \ \left(  \text{by
(\ref{eq.hanoi.rec}), applied to }n-3\right) \\
&  =16m_{n-4}+8+4+2+1\\
&  =\cdots\ \ \ \ \ \ \ \ \ \ \left(  \text{keep going until you reach }%
m_{0}\right) \\
&  =2^{n}\underbrace{m_{0}}_{=0}+2^{n-1}+2^{n-2}+\cdots+2^{0}\\
&  =2^{n-1}+2^{n-2}+\cdots+2^{0}\\
&  =2^{0}+2^{1}+2^{2}+\cdots+2^{n-1}.
\end{align*}
I claim that the right hand side is $2^{n}-1$. Next time, we will see why.


\end{document}