\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=Thursday, December 28, 2023 12:03:35}
%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 9, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 221 Winter 2023, Lecture 9: Elementary number theory}

\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}}}

\setcounter{section}{2}

\section{Elementary number theory}

\setcounter{subsection}{2}

\subsection{Division with remainder (cont'd)}

\setcounter{subsubsection}{4}

\setcounter{theo}{14}

\subsubsection{Congruence in terms of remainders}

Here is one more application of division with remainder: a new criterion for
congruence. Specifically, two integers $a$ and $b$ are congruent modulo a
given positive integer $d$ if and only if they leave the same remainder when
divided by $d$ (that is, satisfy $a\%d=b\%d$). In other words:

\begin{proposition}
\label{prop.ent.quo-rem.modd}Let $d$ be a positive integer. Let $a$ and $b$ be
two integers. Then, $a\equiv b\operatorname{mod}d$ if and only if $a\%d=b\%d$.
\end{proposition}

\begin{proof}
Proposition 3.3.11 \textbf{(a)} from Lecture 8 (applied to $n=a$) yields that
$a\%d\in\left\{  0,1,\ldots,d-1\right\}  $ and $a\%d\equiv a\operatorname{mod}%
d$. Similarly, $b\%d\in\left\{  0,1,\ldots,d-1\right\}  $ and $b\%d\equiv
b\operatorname{mod}d$.

We must prove the logical equivalence $\left(  a\equiv b\operatorname{mod}%
d\right)  \ \Longleftrightarrow\ \left(  a\%d=b\%d\right)  $. In other words,
we must prove the two implications%
\[
\left(  a\equiv b\operatorname{mod}d\right)  \ \Longrightarrow\ \left(
a\%d=b\%d\right)
\]
and%
\[
\left(  a\%d=b\%d\right)  \ \Longrightarrow\ \left(  a\equiv
b\operatorname{mod}d\right)  .
\]
Let us prove these implications separately:

\textit{Proof of }$\left(  a\equiv b\operatorname{mod}d\right)
\ \Longrightarrow\ \left(  a\%d=b\%d\right)  $\textit{:} Assume that $a\equiv
b\operatorname{mod}d$. Thus, $b\equiv a\operatorname{mod}d$ (by symmetry of
congruence -- i.e., by Proposition 3.2.4 \textbf{(b)} from Lecture 7).
Combining $b\%d\equiv b\operatorname{mod}d$ with $b\equiv a\operatorname{mod}%
d$, we obtain $b\%d\equiv a\operatorname{mod}d$ (by transitivity of congruence
-- i.e., by Proposition 3.2.4 \textbf{(c)} from Lecture 7).

Thus, we know that $b\%d\in\left\{  0,1,\ldots,d-1\right\}  $ and $b\%d\equiv
a\operatorname{mod}d$. Hence, Proposition 3.3.11 \textbf{(c)} from Lecture 8
(applied to $n=a$ and $c=b\%d$) yields $b\%d=a\%d$. In other words,
$a\%d=b\%d$. Thus, we have proved the implication $\left(  a\equiv
b\operatorname{mod}d\right)  \ \Longrightarrow\ \left(  a\%d=b\%d\right)  $.

\textit{Proof of }$\left(  a\%d=b\%d\right)  \ \Longrightarrow\ \left(
a\equiv b\operatorname{mod}d\right)  $\textit{:} Assume that $a\%d=b\%d$.
However, we know that $a\%d\equiv a\operatorname{mod}d$, so that $a\equiv
a\%d\operatorname{mod}d$ (by symmetry of congruence). In view of $a\%d=b\%d$,
we can rewrite this as $a\equiv b\%d\operatorname{mod}d$. Combining this with
$b\%d\equiv b\operatorname{mod}d$, we obtain $a\equiv b\operatorname{mod}d$
(by transitivity of congruence -- i.e., by Proposition 3.2.4 \textbf{(c)} from
Lecture 7). Thus, we have proved the implication $\left(  a\%d=b\%d\right)
\ \Longrightarrow\ \left(  a\equiv b\operatorname{mod}d\right)  $.

Now, both implications are proved, so that Proposition
\ref{prop.ent.quo-rem.modd} is proved.
\end{proof}

\subsubsection{The birthday lemma}

If you have lived for exactly $n$ days, then you are $n//365$ years and
$n\%365$ days old (assuming, for simplicity, that every year has exactly $365$
days; leapyears would complicate this a lot). On any \textquotedblleft
normal\textquotedblright\ day, the latter number (that is, $n\%365$) increases
by $1$ while the former number (that is, $n//365$) stays unchanged. But on a
birthday, the latter number gets reset to $0$ while the former number
increases by $1$. This simple and intuitive observation is not specific to
$365$, and is worth stating as a proposition:

\begin{proposition}
[birthday lemma]\label{prop.ent.quo-rem.bday}Let $n\in\mathbb{Z}$, and let $d$
be a positive integer. Then:

\textbf{(a)} If $d\mid n$, then
\begin{align*}
n//d  &  =\left(  \left(  n-1\right)  //d\right)
+1\ \ \ \ \ \ \ \ \ \ \text{and}\\
n\%d  &  =0\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ \left(
n-1\right)  \%d=d-1.
\end{align*}


\textbf{(b)} If $d\nmid n$, then
\[
n//d=\left(  n-1\right)  //d\ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ n\%d=\left(  \left(  n-1\right)  \%d\right)  +1.
\]

\end{proposition}

It should be easy to prove both parts of this lemma, but we give a proof for
the sake of completeness.

\begin{fineprint}
\begin{proof}
[Proof of Proposition \ref{prop.ent.quo-rem.bday}.]\textbf{(a)} Assume that
$d\mid n$. Thus, $n=dq$ for some $q\in\mathbb{Z}$. Consider this $q$.

Recall Definition 3.3.2 from Lecture 8. We have $q\in\mathbb{Z}$ and
$0\in\left\{  0,1,\ldots,d-1\right\}  $ and $n=qd+0$ (since $qd+0=qd=dq=n$).
In other words, $\left(  q,0\right)  $ is a quo-rem pair of $n$ and $d$ (by
the definition of a quo-rem pair). Hence, Definition 3.3.2 from Lecture 8
shows that $n//d=q$ and $n\%d=0$.

On the other hand, from $n=dq$, we obtain%
\begin{align*}
n-1  &  =dq-1\\
&  =\left(  q-1\right)  d+\left(  d-1\right)  \ \ \ \ \ \ \ \ \ \ \left(
\text{since }\left(  q-1\right)  d+\left(  d-1\right)  =qd-d+d-1=qd-1\right)
.
\end{align*}
Thus, we have $q-1\in\mathbb{Z}$ and $d-1\in\left\{  0,1,\ldots,d-1\right\}  $
and $n-1=\left(  q-1\right)  d+\left(  d-1\right)  $. In other words, the pair
$\left(  q-1,d-1\right)  $ is a quo-rem pair of $n-1$ and $d$ (by the
definition of a quo-rem pair). Hence, Definition 3.3.2 from Lecture 8 shows
that $\left(  n-1\right)  //d=q-1$ and $\left(  n-1\right)  \%d=d-1$.

Now, from $\left(  n-1\right)  //d=q-1$, we obtain $\left(  \left(
n-1\right)  //d\right)  +1=q=n//d$. In other words, $n//d=\left(  \left(
n-1\right)  //d\right)  +1$. Combining this with $n\%d=0$ and $\left(
n-1\right)  \%d=d-1$, we see that Proposition \ref{prop.ent.quo-rem.bday}
\textbf{(a)} has been proved.

\textbf{(b)} Assume that $d\nmid n$. Let $q=n//d$ and $r=n\%d$. Then, by the
definition of quotient and remainder, we have%
\[
q\in\mathbb{Z}\ \ \ \ \ \ \ \ \ \ \text{and}\ \ \ \ \ \ \ \ \ \ r\in\left\{
0,1,\ldots,d-1\right\}  \ \ \ \ \ \ \ \ \ \ \text{and}%
\ \ \ \ \ \ \ \ \ \ n=qd+r.
\]
If we had $r=0$, then we would have $n=qd+\underbrace{r}_{=0}=qd=dq$, which
would entail $d\mid n$; but this would contradict $d\nmid n$. Hence, we cannot
have $r=0$. In other words, $r$ is not $0$.

So $r$ is an element of the set $\left\{  0,1,\ldots,d-1\right\}  $ but is not
$0$. Therefore, $r$ is one of the remaining elements $1,2,\ldots,d-1$.
Therefore, $r-1$ is one of the elements $0,1,\ldots,d-2$. Thus, $r-1\in
\left\{  0,1,\ldots,d-1\right\}  $.

Also, from $n=qd+r$, we obtain $n-1=\left(  qd+r\right)  -1=qd+\left(
r-1\right)  $. So we know that $q\in\mathbb{Z}$ and $r-1\in\left\{
0,1,\ldots,d-1\right\}  $ and $n-1=qd+\left(  r-1\right)  $. In other words,
the pair $\left(  q,r-1\right)  $ is a quo-rem pair of $n-1$ and $d$ (by the
definition of a quo-rem pair). Hence, Definition 3.3.2 from Lecture 8 shows
that $\left(  n-1\right)  //d=q$ and $\left(  n-1\right)  \%d=r-1$.

Thus, $\left(  n-1\right)  //d=q=n//d$, so that $n//d=\left(  n-1\right)
//d$. Also, from $\left(  n-1\right)  \%d=r-1$, we obtain $\left(  \left(
n-1\right)  \%d\right)  +1=r=n\%d$, so that $n\%d=\left(  \left(  n-1\right)
\%d\right)  +1$. Thus, we have proved Proposition \ref{prop.ent.quo-rem.bday}
\textbf{(b)}.
\end{proof}
\end{fineprint}

Part of Proposition \ref{prop.ent.quo-rem.bday} can be restated using the
floor notation:

\begin{corollary}
\label{cor.ent.quo-rem.floor-bday}Let $n\in\mathbb{Z}$, and let $d$ be a
positive integer. Then:

\textbf{(a)} If $d\mid n$, then
\[
\left\lfloor \dfrac{n}{d}\right\rfloor =\left\lfloor \dfrac{n-1}%
{d}\right\rfloor +1.
\]


\textbf{(b)} If $d\nmid n$, then
\[
\left\lfloor \dfrac{n}{d}\right\rfloor =\left\lfloor \dfrac{n-1}%
{d}\right\rfloor .
\]

\end{corollary}

\begin{fineprint}
\begin{proof}
Proposition 3.3.13 yields $n//d=\left\lfloor \dfrac{n}{d}\right\rfloor $. The
same argument (applied to $n-1$ instead of $n$) yields $\left(  n-1\right)
//d=\left\lfloor \dfrac{n-1}{d}\right\rfloor $.

\textbf{(a)} Assume that $d\mid n$. Then, Proposition
\ref{prop.ent.quo-rem.bday} \textbf{(a)} yields $n//d=\left(  \left(
n-1\right)  //d\right)  +1$. In view of $n//d=\left\lfloor \dfrac{n}%
{d}\right\rfloor $ and $\left(  n-1\right)  //d=\left\lfloor \dfrac{n-1}%
{d}\right\rfloor $, we can rewrite this as $\left\lfloor \dfrac{n}%
{d}\right\rfloor =\left\lfloor \dfrac{n-1}{d}\right\rfloor +1$. This proves
Corollary \ref{cor.ent.quo-rem.floor-bday} \textbf{(a)}.

\textbf{(b)} Assume that $d\nmid n$. Then, Proposition
\ref{prop.ent.quo-rem.bday} \textbf{(b)} yields $n//d=\left(  n-1\right)
//d$. In view of $n//d=\left\lfloor \dfrac{n}{d}\right\rfloor $ and $\left(
n-1\right)  //d=\left\lfloor \dfrac{n-1}{d}\right\rfloor $, we can rewrite
this as $\left\lfloor \dfrac{n}{d}\right\rfloor =\left\lfloor \dfrac{n-1}%
{d}\right\rfloor $. This proves Corollary \ref{cor.ent.quo-rem.floor-bday}
\textbf{(b)}.
\end{proof}
\end{fineprint}

\subsection{Greatest common divisors}

\subsubsection{Definition}

The following definition plays a crucial role in number theory, particularly
in the study of prime numbers that will be the topic of next lecture.

\begin{definition}
\label{def.ent.gcd}Let $a$ and $b$ be two integers.

\textbf{(a)} The \textbf{common divisors} of $a$ and $b$ are the integers that
divide $a$ and simultaneously divide $b$.

\textbf{(b)} The \textbf{greatest common divisor} of $a$ and $b$ is the
largest among the common divisors of $a$ and $b$, unless $a=b=0$. In the case
$a=b=0$, it is defined to be $0$ instead.

We denote the greatest common divisor of $a$ and $b$ as $\gcd\left(
a,b\right)  $, and we refer to it as the \textbf{gcd} of $a$ and $b$.
\end{definition}

We will soon see that this greatest common divisor is well-defined (see Remark
\ref{rmk.ent.gcd.wd} below). But first, some examples:

\begin{itemize}
\item What is $\gcd\left(  4,6\right)  $ ?

The divisors of $4$ are $-4,-2,-1,1,2,4$.

The divisors of $6$ are $-6,-3,-2,-1,1,2,3,6$.

Thus, the common divisors of $4$ and $6$ are $-2,-1,1,2$.

So the greatest common divisor of $4$ and $6$ is $2$. That is, $\gcd\left(
4,6\right)  =2$.

\item What is $\gcd\left(  0,5\right)  $ ?

The divisors of $0$ are all integers (you cannot list them all).

The divisors of $5$ are $-5,-1,1,5$.

Thus, the common divisors of $0$ and $5$ are just the divisors of $5$, which
are $-5,-1,1,5$.

So the gcd is $5$. That is, $\gcd\left(  0,5\right)  =5$.

\item What is $\gcd\left(  0,0\right)  $ ?

The common divisors of $0$ and $0$ are all integers, so there is no greatest
one among them, but we have defined $\gcd\left(  0,0\right)  $ to be $0$.
(This is the reason why we had to make an exception for the $a=b=0$ case in
Definition \ref{def.ent.gcd} \textbf{(b)}.)
\end{itemize}

Let us now convince ourselves that $\gcd\left(  a,b\right)  $ is well-defined:

\begin{remark}
\label{rmk.ent.gcd.wd}Let $a,b\in\mathbb{Z}$. We want to show that
$\gcd\left(  a,b\right)  $ is well-defined in Definition \ref{def.ent.gcd}
\textbf{(b)}.

If $a=b=0$, then this is clear, since we defined this gcd to be $0$.

Consider the remaining case -- i.e., the case when $a\neq0$ or $b\neq0$ (or both).

For instance, let us assume that $a\neq0$. Then, the divisors $d$ of $a$ all
satisfy $\left\vert d\right\vert \leq\left\vert a\right\vert $ (since
Proposition 3.1.4 \textbf{(b)} from Lecture 7 shows that they satisfy
$\operatorname*{abs}d\leq\operatorname*{abs}a$, which in our present notations
means $\left\vert d\right\vert \leq\left\vert a\right\vert $). In other words,
all these divisors are integers in the interval $\left[  -\left\vert
a\right\vert ,\ \left\vert a\right\vert \right]  $. Hence, there are finitely
many of them. Therefore, there are finitely many common divisors of $a$ and
$b$ (since any common divisor of $a$ and $b$ is a divisor of $a$). On the
other hand, there is at least one common divisor of $a$ and $b$ (namely, $1$).
Therefore, the set of all common divisors of $a$ and $b$ is nonempty and
finite, and thus has a maximum element. In other words, there is a (literally)
largest among the common divisors of $a$ and $b$. This shows that $\gcd\left(
a,b\right)  $ is well-defined when $a\neq0$.

An analogous argument leads to the same conclusion when $b\neq0$. Thus, we
have shown that $\gcd\left(  a,b\right)  $ is always well-defined.
\end{remark}

This argument also gives us a slow and stupid algorithm to compute
$\gcd\left(  a,b\right)  $ when $a\neq0$: We just go through all integers in
the interval $\left[  -\left\vert a\right\vert ,\ \left\vert a\right\vert
\right]  $, and check which of them are common divisors of $a$ and $b$. But
there is a much faster algorithm.

\subsubsection{Basic properties}

To find this algorithm, we first collect some basic properties of gcds:

\begin{proposition}
\label{prop.ent.gcd.basics}\textbf{(a)} We have $\gcd\left(  a,b\right)
\in\mathbb{N}$ for any $a,b\in\mathbb{Z}$.

\textbf{(b)} We have $\gcd\left(  a,0\right)  =\gcd\left(  0,a\right)
=\left\vert a\right\vert $ for any $a\in\mathbb{Z}$.

\textbf{(c)} We have $\gcd\left(  a,b\right)  =\gcd\left(  b,a\right)  $ for
any $a,b\in\mathbb{Z}$.

\textbf{(d)} If $a,b,c\in\mathbb{Z}$ satisfy $b\equiv c\operatorname{mod}a$,
then $\gcd\left(  a,b\right)  =\gcd\left(  a,c\right)  $.

\textbf{(e)} We have $\gcd\left(  a,b\right)  =\gcd\left(  a,\ ua+b\right)  $
for any $a,b,u\in\mathbb{Z}$.

\textbf{(f)} We have $\gcd\left(  a,b\right)  =\gcd\left(  a,\ b\%a\right)  $
for any positive integer $a$ and any $b\in\mathbb{Z}$.

\textbf{(g)} We have $\gcd\left(  a,b\right)  \mid a$ and $\gcd\left(
a,b\right)  \mid b$ for any $a,b\in\mathbb{Z}$.

\textbf{(h)} We have $\gcd\left(  -a,b\right)  =\gcd\left(  a,b\right)  $ and
$\gcd\left(  a,-b\right)  =\gcd\left(  a,b\right)  $ for any $a,b\in
\mathbb{Z}$.

\textbf{(i)} If $a,b\in\mathbb{Z}$ satisfy $a\mid b$, then $\gcd\left(
a,b\right)  =\left\vert a\right\vert $.
\end{proposition}

\begin{proof}
\textbf{(a)} Let $a,b\in\mathbb{Z}$. We must prove that $\gcd\left(
a,b\right)  \in\mathbb{N}$.

If $a=b=0$, then this follows from $\gcd\left(  0,0\right)  =0\in\mathbb{N}$.

Thus, let us assume that not both of $a$ and $b$ are $0$. Then, $\gcd\left(
a,b\right)  $ is literally the greatest common divisor of $a$ and $b$. If
$\gcd\left(  a,b\right)  $ was negative, then $-\gcd\left(  a,b\right)  $
would be an even greater common divisor of $a$ and $b$ (since $-\gcd\left(
a,b\right)  $ divides whatever $\gcd\left(  a,b\right)  $ divides, but the
negativity of $\gcd\left(  a,b\right)  $ implies $-\gcd\left(  a,b\right)
>\gcd\left(  a,b\right)  $), which would contradict the previous sentence.
Hence, $\gcd\left(  a,b\right)  $ cannot be negative. Thus, $\gcd\left(
a,b\right)  \in\mathbb{N}$. This proves Proposition \ref{prop.ent.gcd.basics}
\textbf{(a)}. \medskip

\textbf{(b)} Let $a\in\mathbb{Z}$. Every integer is a divisor of $0$. Thus,
the common divisors of $a$ and $0$ are just the divisors of $a$. However, the
largest divisor of $a$ is $\left\vert a\right\vert $ (unless $a=0$, which case
can be easily handled separately)\footnote{This fact is a consequence of
Proposition 3.1.4 \textbf{(b)} in Lecture 7 (recalling that $\left\vert
a\right\vert $ was called $\operatorname*{abs}a$ back in that proposition).}.
Hence, the greatest common divisor of $a$ and $0$ is $\left\vert a\right\vert
$. In other words, we have $\gcd\left(  a,0\right)  =\left\vert a\right\vert
$. Similarly, we can see that $\gcd\left(  0,a\right)  =\left\vert
a\right\vert $. Thus, Proposition \ref{prop.ent.gcd.basics} \textbf{(b)} is
proved. \medskip

\textbf{(c)} Proposition \ref{prop.ent.gcd.basics} \textbf{(c)} follows from
observing that $a$ and $b$ play equal roles in Definition \ref{def.ent.gcd}.
\medskip

\textbf{(d)} Let $a,b,c\in\mathbb{Z}$ satisfy $b\equiv c\operatorname{mod}a$.
We must prove that $\gcd\left(  a,b\right)  =\gcd\left(  a,c\right)  $.

If $a=0$, then this is clearly true (because in this case, $b\equiv
c\operatorname{mod}a$ becomes $b\equiv c\operatorname{mod}0$, which entails
$b=c$).

It thus remains to consider the case $a\neq0$ only. In this case, $\gcd\left(
a,b\right)  $ is literally the greatest common divisor of $a$ and $b$, whereas
$\gcd\left(  a,c\right)  $ is literally the greatest common divisor of $a$ and
$c$. Hence, in order to prove that these two gcds are equal, it will suffice
to show that the common divisors of $a$ and $b$ are precisely the common
divisors of $a$ and $c$. To do this, in turn, it suffices to prove the
following two claims:

\begin{statement}
\textit{Claim 1:} Each common divisor of $a$ and $b$ is a common divisor of
$a$ and $c$.
\end{statement}

\begin{statement}
\textit{Claim 2:} Each common divisor of $a$ and $c$ is a common divisor of
$a$ and $b$.
\end{statement}

Before we prove these two claims, let us recall that $b\equiv
c\operatorname{mod}a$; in other words, $c\equiv b\operatorname{mod}a$ (by the
symmetry of congruence). Hence, the numbers $b$ and $c$ play equal roles in
our setting. Thus, Claims 1 and 2 are analogous, so that any proof of one of
the two will also prove the other (once the roles of $b$ and $c$ are switched).

\begin{proof}
[Proof of Claim 1.]Let $d$ be a common divisor of $a$ and $b$. Thus, $d\mid a$
and $d\mid b$ (by the definition of a common divisor). In other words, we have
$a=dx$ and $b=dy$ for some integers $x$ and $y$. Consider these $x$ and $y$.

But $b\equiv c\operatorname{mod}a$. In other words, $a\mid b-c$. Hence, $d\mid
a\mid b-c$ (by the transitivity of divisibility). In other words, $b-c=dz$ for
some integer $z$. Consider this $z$.

Now, $b-\left(  b-c\right)  =c$, so that
\[
c=\underbrace{b}_{=dy}-\underbrace{\left(  b-c\right)  }_{=dz}%
=dy-dz=d\underbrace{\left(  y-z\right)  }_{\text{an integer}}.
\]
Therefore, $d\mid c$. From $d\mid a$ and $d\mid c$, we conclude that $d$ is a
common divisor of $a$ and $c$.

So we have shown that if $d$ is a common divisor of $a$ and $b$, then $d$ is a
common divisor of $a$ and $c$. In other words, each common divisor of $a$ and
$b$ is a common divisor of $a$ and $c$. This proves Claim 1.
\end{proof}

\begin{proof}
[Proof of Claim 2.]As we said, we can obtain a proof of Claim 2 by switching
the roles of $b$ and $c$ in the above proof of Claim 1 (because we have
$c\equiv b\operatorname{mod}a$).
\end{proof}

Combining Claim 1 with Claim 2, we see that the common divisors of $a$ and $b$
are precisely the common divisors of $a$ and $c$. Therefore, the greatest
common divisor of $a$ and $b$ equals the greatest common divisor of $a$ and
$c$. In other words, $\gcd\left(  a,b\right)  =\gcd\left(  a,c\right)  $. This
proves Proposition \ref{prop.ent.gcd.basics} \textbf{(d)}. \medskip

\textbf{(e)} Proposition \ref{prop.ent.gcd.basics} \textbf{(e)} follows from
Proposition \ref{prop.ent.gcd.basics} \textbf{(d)} (applied to $c=ua+b$),
since $b\equiv ua+b\operatorname{mod}a$ (because $b-\left(  ua+b\right)  =-ua$
is divisible by $a$). \medskip

\textbf{(f)} Proposition \ref{prop.ent.gcd.basics} \textbf{(f)} follows from
Proposition \ref{prop.ent.gcd.basics} \textbf{(d)} (applied to $c=b\%a$),
since $b\equiv b\%a\operatorname{mod}a$ (because Proposition 3.3.11
\textbf{(a)} from Lecture 8 yields $b\%a\equiv b\operatorname{mod}a$).
\medskip

\textbf{(g)} is obvious when $a=b=0$ (since $0\mid0$), and otherwise follows
from the definition of $\gcd\left(  a,b\right)  $. \medskip

\textbf{(h)} The divisors of $a$ are precisely the divisors of $-a$. The
divisors of $b$ are precisely the divisors of $-b$. Thus, the common divisors
of $a$ and $b$ remain unchanged if we replace $a$ by $-a$ or replace $b$ by
$-b$. Therefore, Proposition \ref{prop.ent.gcd.basics} \textbf{(h)} follows
from the definition of the gcd. \medskip

\textbf{(i)} Let $a,b\in\mathbb{Z}$ satisfy $a\mid b$. Then, $b\equiv
0\operatorname{mod}a$. Hence, Proposition \ref{prop.ent.gcd.basics}
\textbf{(d)} (applied to $c=0$) yields $\gcd\left(  a,b\right)  =\gcd\left(
a,0\right)  =\left\vert a\right\vert $ (by Proposition
\ref{prop.ent.gcd.basics} \textbf{(b)}). This proves Proposition
\ref{prop.ent.gcd.basics} \textbf{(i)}.
\end{proof}

\begin{corollary}
[Euclidean recursion for the gcd]\label{cor.ent.gcd.euclid}Let $a\in
\mathbb{Z}$, and let $b$ be a positive integer. Then,%
\[
\gcd\left(  a,b\right)  =\gcd\left(  b,\ a\%b\right)  .
\]

\end{corollary}

\begin{proof}
Proposition \ref{prop.ent.gcd.basics} \textbf{(c)} yields%
\[
\gcd\left(  a,b\right)  =\gcd\left(  b,a\right)  =\gcd\left(  b,\ a\%b\right)
\]
(by Proposition \ref{prop.ent.gcd.basics} \textbf{(f)}, applied to $b$ and $a$
instead of $a$ and $b$). This proves Corollary \ref{cor.ent.gcd.euclid}.
\end{proof}

\subsubsection{The Euclidean algorithm}

By applying Corollary \ref{cor.ent.gcd.euclid} repeatedly, we can compute gcds
rather quickly: For example,%
\begin{align*}
\gcd\left(  93,\ 18\right)   &  =\gcd\left(  18,\ \underbrace{93\%18}%
_{=3}\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by Corollary
\ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  18,\ 3\right) \\
&  =\gcd\left(  3,\ \underbrace{18\%3}_{=0}\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Corollary \ref{cor.ent.gcd.euclid}%
}\right) \\
&  =\gcd\left(  3,\ 0\right)  =\left\vert 3\right\vert
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Proposition \ref{prop.ent.gcd.basics}
\textbf{(b)}}\right) \\
&  =3
\end{align*}
and%
\begin{align*}
\gcd\left(  1145,\ 739\right)   &  =\gcd\left(  739,\ \underbrace{1145\%739}%
_{=406}\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by Corollary
\ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  739,\ 406\right) \\
&  =\gcd\left(  406,\ \underbrace{739\%406}_{=333}\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Corollary \ref{cor.ent.gcd.euclid}%
}\right) \\
&  =\gcd\left(  406,\ 333\right) \\
&  =\gcd\left(  333,\ \underbrace{406\%333}_{=73}\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Corollary \ref{cor.ent.gcd.euclid}%
}\right) \\
&  =\gcd\left(  333,\ 73\right) \\
&  =\gcd\left(  73,\ 333\%73\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  73,\ 41\right) \\
&  =\gcd\left(  41,\ 73\%41\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  41,\ 32\right) \\
&  =\gcd\left(  32,\ 41\%32\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  32,\ 9\right) \\
&  =\gcd\left(  9,\ 32\%9\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  9,\ 5\right) \\
&  =\gcd\left(  5,\ 9\%5\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  5,\ 4\right) \\
&  =\gcd\left(  4,\ 5\%4\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  4,\ 1\right) \\
&  =\gcd\left(  1,\ 4\%1\right)  \ \ \ \ \ \ \ \ \ \ \left(  \text{by
Corollary \ref{cor.ent.gcd.euclid}}\right) \\
&  =\gcd\left(  1,\ 0\right)  =\left\vert 1\right\vert
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Proposition \ref{prop.ent.gcd.basics}
\textbf{(b)}}\right) \\
&  =1.
\end{align*}


These two computations are instances of a general algorithm for computing
$\gcd\left(  a,b\right)  $ for any two numbers $a\in\mathbb{Z}$ and
$b\in\mathbb{N}$. This algorithm proceeds as follows:

\begin{itemize}
\item If $b=0$, then the gcd is $\left\vert a\right\vert $.

\item If $b>0$, then we replace $a$ and $b$ by $b$ and $a\%b$ and recurse
(i.e., we apply the method again to $b$ and $a\%b$ instead of $a$ and $b$).
\end{itemize}

In Python code, this algorithm looks as follows:\medskip\Needspace{6pc}

\texttt{\qquad def gcd(a, b): \# for b nonnegative }

\texttt{\qquad\qquad if b == 0:}

\texttt{\qquad\qquad\qquad return abs(a) \# This is the absolute value of a.}

\texttt{\qquad\qquad return gcd(b, a\%b)} \medskip

This algorithm is called the \textbf{Euclidean algorithm}. Let us convince
ourselves that it really terminates (rather than getting stuck in an endless loop):

\begin{proposition}
\label{prop.ent.gcd.euclid-terminates}Let $a\in\mathbb{Z}$ and $b\in
\mathbb{N}$. Then, the Euclidean algorithm terminates after at most $b$ steps.
(Here, we count each time that the algorithm replaces $a$ and $b$ by $b$ and
$a\%b$ as a \textquotedblleft step\textquotedblright.)
\end{proposition}

\begin{proof}
In each step of the Euclidean algorithm, the second argument $b$ gets replaced
by $a\%b$. This has the consequence that $b$ decreases by at least $1$ (since
the definition of a remainder yields $a\%b\in\left\{  0,1,\ldots,b-1\right\}
$ and thus $a\%b\leq b-1$). But $b$ remains nonnegative throughout the
algorithm. Thus, $b$ cannot decrease (by at least $1$) more than $b_{0}$ times
in succession, where $b_{0}$ is the original value of $b$ (as it was fed into
the algorithm). Hence, the algorithm cannot have more than $b_{0}$ steps. In
other words, the algorithm must terminate after at most $b_{0}$ steps. This
proves Proposition \ref{prop.ent.gcd.euclid-terminates} (since $b_{0}$ is
precisely the original value of $b$).
\end{proof}

Proposition \ref{prop.ent.gcd.euclid-terminates} greatly overestimates the
actual time that the Euclidean algorithm needs to terminate: In truth, it
terminates after at most $\log_{2}\left(  ab\right)  +2$ steps (if $a$ and $b$
are positive)\footnote{\textit{Hints to the proof.} Recall that each step of
the algorithm replaces the numbers $a$ and $b$ by $b$ and $a\%b$. Since
$b>a\%b$ (because $a\%b\in\left\{  0,1,\ldots,b-1\right\}  $ entails
$a\%b<b$), this yields that after each step of the algorithm, the
\textquotedblleft current\textquotedblright\ numbers $a$ and $b$ satisfy
$a>b$.
\par
Now, consider the product $ab$ of the two numbers $a$ and $b$. We claim that
each step of the algorithm, except perhaps the first one, decreases this
number by a factor of at least $2$. In order to see this, you need to show
that $b\left(  a\%b\right)  \leq\dfrac{ab}{2}$ whenever $a>b$. But this
follows from $a\%b\leq\dfrac{a}{2}$, which in turn follows easily from $a>b$
(why?).
\par
Now you know that the product $ab$ decreases by a factor of at least $2$ at
each step of the algorithm except for the first one. In other words, its
binary logarithm $\log_{2}\left(  ab\right)  $ decreases by at least $1$ at
each step of the algorithm except for the first one. At the first step, it
also decreases or stays unchanged. From this, it follows easily that the
algorithm cannot have more than $\log_{2}\left(  ab\right)  +1$ steps until it
reaches a situation in which $\log_{2}\left(  ab\right)  \leq0$. But in such a
situation, we must have $a=b=1$, and it will only take one more step to reach
the end of the algorithm.}, which is usually much fewer than $b$. Some
variants of the Euclidean algorithm get to the goal even faster. This
speediness is part of the reason why the Euclidean algorithm (and greatest
common divisors) is so useful in practical applications of number theory.
\medskip

The Euclidean algorithm can be easily adapted to arbitrary $b\in\mathbb{Z}$
instead of just $b\in\mathbb{N}$ (by adding a first step in which we replace
$b$ by $-b$ if $b$ is negative):\medskip\Needspace{6pc}

\texttt{\qquad def gcd(a, b): \# for b arbitrary }

\texttt{\qquad\qquad if b
%TCIMACRO{\TEXTsymbol{<} }%
%BeginExpansion
$<$
%EndExpansion
0:}

\texttt{\qquad\qquad\qquad return gcd(a, -b) \# replace b by -b.}

\texttt{\qquad\qquad if b == 0:}

\texttt{\qquad\qquad\qquad return abs(a) \# This is the absolute value of a.}

\texttt{\qquad\qquad return gcd(b, a\%b)}

\subsubsection{Bezout's theorem and the extended Euclidean algorithm}

The Euclidean algorithm can be adapted so that it doesn't only compute
$\gcd\left(  a,b\right)  $, but also expresses $\gcd\left(  a,b\right)  $ as
an \textquotedblleft integer linear combination\textquotedblright\ of $a$ and
$b$ (that is, as a multiple of $a$ plus a multiple of $b$). This allows us to
prove the following theorem:

\begin{theorem}
[Bezout's theorem for integers]\label{thm.ent.gcd.bezout}Let $a$ and $b$ be
two integers. Then, there exist two integers $x$ and $y$ such that
\[
\gcd\left(  a,b\right)  =xa+yb.
\]

\end{theorem}

We will soon prove this theorem. First, we introduce a notation and give a few examples:

\begin{definition}
\label{def.ent.gcd.bezout-pair}Let $a$ and $b$ be two integers. Then, a
\textbf{Bezout pair} for $\left(  a,b\right)  $ means a pair $\left(
x,y\right)  $ of two integers satisfying $\gcd\left(  a,b\right)  =xa+yb$.
\end{definition}

For instance, a Bezout pair for $\left(  4,7\right)  $ is a pair $\left(
x,y\right)  $ of integers satisfying $\gcd\left(  4,7\right)  =x\cdot
4+y\cdot7$. In view of $\gcd\left(  4,7\right)  =1$, this latter equation
simplifies to $1=4x+7y$. So a Bezout pair for $\left(  4,7\right)  $ is a
solution to this equation $1=4x+7y$ in \textbf{integers} $x$ and $y$. This is
similar to the coin problem from \S 1.9.1 (in Lecture 5), in the sense that
you can think of such a Bezout pair $\left(  x,y\right)  $ as a way to pay $1$
cent with $x$ many $4$-cent coins and $y$ many $7$-cent coins, assuming that
you are allowed to get change (because $x$ and $y$ are allowed to be
negative). Without change, of course, you could not pay $1$ cent using
$4$-cent coins and $7$-cent coins. But with change, it works: You pay two
$4$-cent coins and get one $7$-cent coin in return, and thus end up paying
$2\cdot4+\left(  -1\right)  \cdot7=1$ cent, which is what you wanted. In other
words, the pair $\left(  x,y\right)  =\left(  2,-1\right)  $ satisfies
$1=4x+7y$. In other words, $\left(  2,-1\right)  $ is a Bezout pair for
$\left(  4,7\right)  $. There are also other Bezout pairs for $\left(
4,7\right)  $, for example $\left(  -5,3\right)  $ (since $4\left(  -5\right)
+7\cdot3=1$). So a Bezout pair is usually not unique.

So Bezout's theorem can be restated as follows: For any two integers $a$ and
$b$, you can pay $\gcd\left(  a,b\right)  $ cents with $a$-cent coins and
$b$-cent coins, if you can get change\footnote{more precisely: if you can get
change in $a$-cent coins and $b$-cent coins (and there are infinitely many
coins of either denomination available)}. What denominations can be paid
\textbf{without} change is a more complicated story, and we will return to
this in \S 3.8 (Lecture 11).

Here is another example: A Bezout pair for $\left(  6,16\right)  $ is $\left(
3,-1\right)  $, since $\gcd\left(  6,16\right)  =2=6x+16y$ for $\left(
x,y\right)  =\left(  3,-1\right)  $.

\bigskip

So Bezout's theorem (Theorem \ref{thm.ent.gcd.bezout}) is saying that for any
two integers $a,b\in\mathbb{Z}$, there exists a Bezout pair for $\left(
a,b\right)  $.

How can we prove this theorem? Induction (particularly strong induction)
appears to be a reasonable method. Unfortunately, induction can only be used
to prove a statement about elements of a set of the form $\left\{
k,k+1,k+2,\ldots\right\}  $ for a given integer $k$ (that is, a statement
about integers from a given lower bound onwards). To put it differently,
induction can only prove a statement that \textquotedblleft starts
somewhere\textquotedblright\ (even if it is presented as a strong induction
with no base case). Meanwhile, in Bezout's theorem, both $a$ and $b$ are just
arbitrary integers, so they can be arbitrarily low.

This hurdle can be surmounted: While we cannot prove Bezout's theorem by
induction directly, we can first restrict it to the case when $b\in\mathbb{N}%
$, and prove this restriction by induction. In other words, we shall use
induction to prove the following particular case of Bezout's theorem:

\begin{lemma}
[restricted Bezout's theorem]\label{lem.ent.gcd.bezout-ZN}Let $a\in\mathbb{Z}$
and $b\in\mathbb{N}$. Then, there exists a Bezout pair for $\left(
a,b\right)  $.
\end{lemma}

Once this lemma is proved, we will quickly deduce Bezout's theorem in full
generality from it. So let us prove this lemma.

\begin{proof}
[Proof of Lemma \ref{lem.ent.gcd.bezout-ZN}.]We shall use strong induction on
$b$. Here, we do not consider $a$ to be fixed. Thus, the statement that we
will be proving for all $b\in\mathbb{N}$ is%
\[
P\left(  b\right)  :=\left(  \text{for each }a\in\mathbb{Z}\text{, there
exists a Bezout pair for }\left(  a,b\right)  \right)  .
\]
Our goal is to prove this statement $P\left(  b\right)  $ for all
$b\in\mathbb{N}$. We shall do this by strong induction on $b$:

\textit{Base case:} Let us prove the statement $P\left(  0\right)  $. Indeed,
for each $a\in\mathbb{Z}$, let us set
\[
\operatorname*{sign}a:=%
\begin{cases}
1, & \text{if }a>0;\\
0, & \text{if }a=0;\\
-1, & \text{if }a<0.
\end{cases}
\]
Then, for each $a\in\mathbb{Z}$, the pair $\left(  \operatorname*{sign}%
a,0\right)  $ is a Bezout pair for $\left(  a,0\right)  $, since%
\begin{align*}
\gcd\left(  a,0\right)   &  =\left\vert a\right\vert
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Proposition \ref{prop.ent.gcd.basics}
\textbf{(b)}}\right) \\
&  =\left(  \operatorname*{sign}a\right)  \cdot a\ \ \ \ \ \ \ \ \ \ \left(
\begin{array}
[c]{c}%
\text{this is a general fact that holds for any real}\\
\text{number }a\text{, and can be easily verified by}\\
\text{checking the cases }a>0\text{, }a=0\text{ and }a<0
\end{array}
\right) \\
&  =\left(  \operatorname*{sign}a\right)  \cdot a+0\cdot0.
\end{align*}
Hence, for each $a\in\mathbb{Z}$, there exists a Bezout pair for $\left(
a,0\right)  $. In other words, the statement $P\left(  0\right)  $ holds.

\textit{Induction step:} Fix a positive integer $b$. We must prove the
implication%
\[
\left(  P\left(  0\right)  \ \text{AND }P\left(  1\right)  \text{ AND
}P\left(  2\right)  \text{ AND }\cdots\text{ AND }P\left(  b-1\right)
\right)  \Longrightarrow P\left(  b\right)  .
\]
Thus, we assume (as the induction hypothesis) that $P\left(  0\right)  \ $AND
$P\left(  1\right)  $ AND $P\left(  2\right)  $ AND $\cdots$ AND $P\left(
b-1\right)  $ holds. In other words, we assume that the $b$ statements
$P\left(  0\right)  ,\ P\left(  1\right)  ,\ P\left(  2\right)  ,\ \ldots
,\ P\left(  b-1\right)  $ all hold. In other words, we assume that%
\begin{align*}
&  \left(  \text{for each }a\in\mathbb{Z}\text{, there exists a Bezout pair
for }\left(  a,0\right)  \right)  \text{ and}\\
&  \left(  \text{for each }a\in\mathbb{Z}\text{, there exists a Bezout pair
for }\left(  a,1\right)  \right)  \text{ and}\\
&  \left(  \text{for each }a\in\mathbb{Z}\text{, there exists a Bezout pair
for }\left(  a,2\right)  \right)  \text{ and}\\
&  \cdots\ \ \ \ \ \ \ \ \ \ \text{and}\\
&  \left(  \text{for each }a\in\mathbb{Z}\text{, there exists a Bezout pair
for }\left(  a,b-1\right)  \right)  .
\end{align*}
In other words, we assume that for each $a\in\mathbb{Z}$ and each
$d\in\left\{  0,1,\ldots,b-1\right\}  $, there exists a Bezout pair for
$\left(  a,d\right)  $. Renaming $a$ as $c$ here, we can restate this as
follows: We assume that for each $c\in\mathbb{Z}$ and each $d\in\left\{
0,1,\ldots,b-1\right\}  $, there exists a Bezout pair for $\left(  c,d\right)
$. So this is our induction hypothesis (brought to its most convenient form).

Our goal is now to prove $P\left(  b\right)  $. In other words, we must prove
that for each $a\in\mathbb{Z}$, there exists a Bezout pair for $\left(
a,b\right)  $.

So we fix an $a\in\mathbb{Z}$, and we set out to find a Bezout pair for
$\left(  a,b\right)  $.

The Euclidean recursion (Corollary \ref{cor.ent.gcd.euclid}) yields%
\begin{equation}
\gcd\left(  a,b\right)  =\gcd\left(  b,\ a\%b\right)  .
\label{pf.lem.ent.gcd.bezout-ZN.4}%
\end{equation}
However, $a\%b\in\left\{  0,1,\ldots,b-1\right\}  $ (by Proposition 3.3.11
\textbf{(a)} from Lecture 8, applied to $n=a$ and $d=b$).

Recall our induction hypothesis, which says that for each $c\in\mathbb{Z}$ and
each $d\in\left\{  0,1,\ldots,b-1\right\}  $, there exists a Bezout pair for
$\left(  c,d\right)  $. We can apply this to $c=b$ and $d=a\%b$ (because
$b\in\mathbb{Z}$ and $a\%b\in\left\{  0,1,\ldots,b-1\right\}  $), and thus
conclude that there exists a Bezout pair for $\left(  b,\ a\%b\right)  $. Let
us denote this Bezout pair by $\left(  u,v\right)  $. Thus, by the definition
of a Bezout pair, $u$ and $v$ are integers and satisfy
\begin{equation}
\gcd\left(  b,\ a\%b\right)  =ub+v\left(  a\%b\right)  .
\label{pf.lem.ent.gcd.bezout-ZN.5}%
\end{equation}


However, Proposition 3.3.11 \textbf{(d)} from Lecture 8 (applied to $n=a$ and
$d=b$) yields%
\[
a=\left(  a//b\right)  b+\left(  a\%b\right)  .
\]
Solving this for $a\%b$, we obtain%
\begin{equation}
\left(  a\%b\right)  =a-\left(  a//b\right)  b.
\label{pf.lem.ent.gcd.bezout-ZN.7}%
\end{equation}


Now, (\ref{pf.lem.ent.gcd.bezout-ZN.4}) becomes%
\begin{align*}
\gcd\left(  a,b\right)   &  =\gcd\left(  b,\ a\%b\right)
=ub+v\underbrace{\left(  a\%b\right)  }_{\substack{=a-\left(  a//b\right)
b\\\text{(by (\ref{pf.lem.ent.gcd.bezout-ZN.7}))}}}\ \ \ \ \ \ \ \ \ \ \left(
\text{by (\ref{pf.lem.ent.gcd.bezout-ZN.5})}\right) \\
&  =ub+v\left(  a-\left(  a//b\right)  b\right) \\
&  =ub+va-v\left(  a//b\right)  b\\
&  =\underbrace{v}_{\text{an integer}}a+\underbrace{\left(  u-v\left(
a//b\right)  \right)  }_{\text{an integer}}b.
\end{align*}
Thus, we have written $\gcd\left(  a,b\right)  $ as a multiple of $a$ plus a
multiple of $b$. More specifically, the pair%
\[
\left(  v,\ u-v\left(  a//b\right)  \right)
\]
is a Bezout pair for $\left(  a,b\right)  $. And so we conclude that there
exists a Bezout pair for $\left(  a,b\right)  $ (because we just found one).
This proves the statement $P\left(  b\right)  $ for our $b$, and thus
completes the induction step.

Hence, by induction, we have shown that $P\left(  b\right)  $ holds for all
$b\in\mathbb{N}$. But this is saying precisely that there exists a Bezout pair
for $\left(  a,b\right)  $ whenever $a\in\mathbb{Z}$ and $b\in\mathbb{N}$.
Thus, Lemma \ref{lem.ent.gcd.bezout-ZN} is proved.
\end{proof}

This inductive proof contains a recursive algorithm for finding a Bezout pair
for $\left(  a,b\right)  $ whenever $a\in\mathbb{Z}$ and $b\in\mathbb{N}$.
Written in Python, this algorithm looks as follows:\footnote{Here,
\texttt{sign(a)} is what was called $\operatorname*{sign}a$ in the above
proof. In Python, this can be defined as follows:\medskip
\par
\texttt{\qquad def sign(a):}
\par
\texttt{\qquad\qquad if a
%TCIMACRO{\TEXTsymbol{<} }%
%BeginExpansion
$<$
%EndExpansion
0:}
\par
\texttt{\qquad\qquad\qquad return -1}
\par
\texttt{\qquad\qquad if a == 0:}
\par
\texttt{\qquad\qquad\qquad return 0}
\par
\texttt{\qquad\qquad if a
%TCIMACRO{\TEXTsymbol{>} }%
%BeginExpansion
$>$
%EndExpansion
0:}
\par
\texttt{\qquad\qquad\qquad return 1}}\medskip\Needspace{6pc}

\texttt{\qquad def bezout\_pair(a, b): \# for b nonnegative }

\texttt{\qquad\qquad if b == 0:}

\texttt{\qquad\qquad\qquad return (sign(a), 0)}

\texttt{\qquad\qquad(u, v) = bezout\_pair(b, a\%b)}

\texttt{\qquad\qquad return (v, u - v * (a//b))} \medskip

This algorithm is known as the \textbf{extended Euclidean algorithm}.

\bigskip

Now that Lemma \ref{lem.ent.gcd.bezout-ZN} has been proven, Bezout's theorem
in the general case (Theorem \ref{thm.ent.gcd.bezout}) easily follows:

\begin{proof}
[Proof of Theorem \ref{thm.ent.gcd.bezout}.]We are in one of the following two cases:

\textit{Case 1:} We have $b\geq0$.

\textit{Case 2:} We have $b<0$.

Let us first consider Case 1. In this case, $b\geq0$. Hence, $b\in\mathbb{N}$.
Thus, Lemma \ref{lem.ent.gcd.bezout-ZN} yields that there exists a Bezout pair
for $\left(  a,b\right)  $. In other words, there exists a pair $\left(
x,y\right)  $ of two integers satisfying $\gcd\left(  a,b\right)  =xa+yb$ (by
the definition of a Bezout pair). But this is precisely what Theorem
\ref{thm.ent.gcd.bezout} is claiming. Thus, Theorem \ref{thm.ent.gcd.bezout}
is proved in Case 1.

Let us now consider Case 2. In this case, $b<0$. Hence, $-b>0$, so that
$-b\in\mathbb{N}$. Hence, Lemma \ref{lem.ent.gcd.bezout-ZN} (applied to $-b$
instead of $b$) yields that there exists a Bezout pair for $\left(
a,-b\right)  $. Let $\left(  u,v\right)  $ be this Bezout pair. Then, by the
definition of a Bezout pair, $u$ and $v$ are integers and satisfy $\gcd\left(
a,-b\right)  =ua+v\left(  -b\right)  $.

However, Proposition \ref{prop.ent.gcd.basics} \textbf{(h)} yields
$\gcd\left(  a,-b\right)  =\gcd\left(  a,b\right)  $. Thus,%
\[
\gcd\left(  a,b\right)  =\gcd\left(  a,-b\right)  =ua+\underbrace{v\left(
-b\right)  }_{=\left(  -v\right)  b}=ua+\left(  -v\right)  b.
\]
Thus, there exist two integers $x$ and $y$ such that $\gcd\left(  a,b\right)
=xa+yb$ (namely, $x=u$ and $y=-v$). This proves Theorem
\ref{thm.ent.gcd.bezout} in Case 2.

We have now proved Theorem \ref{thm.ent.gcd.bezout} in both Cases 1 and 2, so
that the theorem always holds.
\end{proof}

\subsubsection{The universal property of the gcd}

Bezout's theorem is helpful for proving properties of gcds. Here is the most
important one, which is called the \textbf{universal property of the gcd}:

\begin{theorem}
[universal property of the gcd]\label{thm.ent.gcd.uniprop}Let $a,b,m\in
\mathbb{Z}$. Then, we have the equivalence%
\[
\left(  m\mid a\text{ and }m\mid b\right)  \ \Longleftrightarrow\ \left(
m\mid\gcd\left(  a,b\right)  \right)  .
\]

\end{theorem}

In other words, the common divisors of $a$ and $b$ are precisely the divisors
of $\gcd\left(  a,b\right)  $. In other words, $\gcd\left(  a,b\right)  $ is
not just the greatest among the common divisors of $a$ and $b$ (if $a$ and $b$
are not both $0$), but it also is divisible by all of them.

\begin{proof}
[Proof of Theorem \ref{thm.ent.gcd.uniprop}.]We must prove the two
implications%
\[
\left(  m\mid a\text{ and }m\mid b\right)  \ \Longrightarrow\ \left(
m\mid\gcd\left(  a,b\right)  \right)
\]
and%
\[
\left(  m\mid\gcd\left(  a,b\right)  \right)  \ \Longrightarrow\ \left(  m\mid
a\text{ and }m\mid b\right)  .
\]


The second of these two implications is easy to prove: If $m\mid\gcd\left(
a,b\right)  $, then $m\mid a$ (since $m\mid\gcd\left(  a,b\right)  \mid a$)
and $m\mid b$ (similarly).

It thus remains to prove the first implication: i.e., to prove that%
\[
\left(  m\mid a\text{ and }m\mid b\right)  \ \Longrightarrow\ \left(
m\mid\gcd\left(  a,b\right)  \right)  .
\]


To prove this, we assume that $m\mid a$ and $m\mid b$. We must show that
$m\mid\gcd\left(  a,b\right)  $.

Bezout's theorem (Theorem \ref{thm.ent.gcd.bezout}) tells us that there exist
two integers $x$ and $y$ such that $\gcd\left(  a,b\right)  =xa+yb$. Consider
these $x$ and $y$. Then, $m\mid a\mid xa$, so that $xa$ is a multiple of $m$.
Similarly, $yb$ is a multiple of $m$. Thus, $xa+yb$ is a multiple of $m$ as
well (since a sum of two multiples of $m$ is again a multiple of $m$). But
this is saying that $\gcd\left(  a,b\right)  $ is a multiple of $m$ (since
$\gcd\left(  a,b\right)  =xa+yb$). In other words, $m\mid\gcd\left(
a,b\right)  $. But this is precisely what we wanted to show. Thus, the first
implication is proved, and the proof of Theorem \ref{thm.ent.gcd.uniprop} is complete.
\end{proof}


\end{document}