%! TEX root = NT.tex
% vim: tw=50
% 06/10/2023 10AM

\setcounter{section}{-1}
\section{Introduction}

Number Theory: the study of $\ZZ = \{0, \pm 1, \pm
2, \ldots\}$.

We're interested in questions about:
\begin{itemize}
  \item Distribution of the \glspl{prime} $p \in \ZZ$.
    For example,
    \[ \pi(x) = \#\{\text{\glspl{prime} $p \le x$}\} \]
    How big is $\pi(x)$ as a function of $x$?

    It turns out that the Riemann hypothesis is
    equivalent to
    \[ \forall x \ge 3, |\pi(x) - \li(x)| \le
    \sqrt{x} \cdot \log x \]
    where $\li(x)$ is defined as
    \[ \li(x) = \int_{t = 2}^x \frac{1}{\log(t)}
    \dd t \]
  \item Diophantine equations. For example,
    Fermat's Last Theorem, which says that if $N
    \in \NN$< $N \ge 3$ then the equation
    \[ X^N + Y^N = Z^N \]
    has no solutions with $X, Y, Z \in \ZZ$ such
    that $XYZ = 0$.
  \item Computation. How can we quickly test
    whether a given $N \in \NN$ is \gls{prime}? If it's
    not \gls{prime}, how can you quickly find its
    \gls{prime_factorisation}?
\end{itemize}
We will address all of these themes using
techniques coming from IA Numbers and Sets.

\newpage
\section{Primes Numbers and Congruences}

\begin{flashcard}[division-algorithm]
\begin{proposition}[Division algorithm]
  \label{division_algorithm}
  Let $a, b \in \ZZ$, $b > 0$. Then there exists a
  unique pair of $q, r \in \ZZ$ with $0 \le r < b$
  such that $a = qb + R$.
\end{proposition}

\begin{proof}
  \cloze{
  Let $S = \{a - qb \mid q \in \ZZ\}$. We know $S$
  contains non-negative elements, so contains a
  least one, call it $r$. Then $a = qb + r$. If $r
  \ge b$, then $r - b \ge 0$, contradicting the
  minimality of $r \in S$. This shows existence of
  $q, r$. If $q', r'$ have the same property, then
  $qb + r = q'b + r' \implies r - r' = (q' - q)b$.
  Note that $-b < r - r' < b$. The only multiple
  of $b$ satisfying this is $0$, so $r = r'$ and
  $q = q'$.
  }
\end{proof}
\end{flashcard}

\begin{notation*}
  \glssymboldefn{divides_mid}{divides}{divides}
  \glssymboldefn[divides_mid]{doesnt_divide_mid}{doesn't
  divide}{doesn't divide}
  If $r = 0$, then $a = qb$. In this case we say
  that $b$ divides and write $b \mid a$.
  Otherwise, $b \nmid a$.
\end{notation*}
\vspace{-1em}

Let $a_1, \ldots, a_n \in \ZZ$ not all $0$. Let
\[ I = \{\lambda_1 a_1 + \cdots + \lambda_n a_n
\mid \lambda_i \in \ZZ\} \subset \ZZ \]
If $x, y \in I$, $k, l \in \ZZ$, then $kx + ly \in
I$ (this means that $I$ is an ideal of $\ZZ$).

\begin{flashcard}[Z-is-PID]
\begin{lemma}
  \label{Z_is_PID}
  There exists a unique $d \in \NN$ such that $I =
  d\ZZ = \{md \mid m \in \ZZ\}$.
\end{lemma}

\begin{proof}
  \cloze{
  Let $d$ be the least positive element of $I$.
  Then if $a \in I$, we can write $a = qd + r$, $0
  \le r < d$. Then $r = a - qd \in I$. By
  minimality of $d$, we must have $r = 0$, hence
  $a \in d\ZZ$, and $I \subset d\ZZ$. Clearly $I
  \supset d\ZZ$, hence $I = d\ZZ$.
  }
\end{proof}
\end{flashcard}

Note that $a_1, \ldots, a_n \in I = d\ZZ$.
Therefore, $d \divides a_i$ for all $i = 1, \ldots,
n$. If $e \in \NN$, and $e \divides a_i \forall i$,
then $e \divides d$.

\glsnoundefn{gcd}{greatest common
divisor}{greatest common divisors}
\glssymboldefn{gcd}{gcd}{gcd}
We call $d$ the greatest common divisor of $a_1,
\ldots, a_n$ and write $d = (a_1, \ldots, a_n) =
\gcd(a_1, \ldots, a_n)$.

\begin{hiddenflashcard}[gcd-defn]
\begin{definition*}[gcd]
  \cloze{
  Given $a_1, \ldots, a_n \in \ZZ$, we define
  $\gcd(a_1, \ldots, a_n)$ to be the non-negative
  number $d$ such that
  \[ \{\lambda_1 a_1 + \cdots + \lambda_n a_n \mid
  \lambda_i \in \ZZ\} = d\ZZ .\]
  One can prove that:
  \begin{itemize}
    \item Such a $d$ \fcemph{always exists}.
    \item $d \mid a_i \forall i$.
    \item If $e \mid a_i \forall i$, then $e \mid
      d$.
  \end{itemize}
  }
\end{definition*}
\end{hiddenflashcard}

\glsnoundefn{euclid_alg}{Euclid's algorithm}{N/A}
We can use repeated application of the
\hyperref[division_algorithm]{division algorithm}
to find $\gcdbrack(a, b)$. This is
\emph{Euclid's algorithm}.

Suppose $a, b \in \NN$, $a > b$. Then
\begin{align*}
  a
  &= q_1 b + r_1
  &&(0 \le r_1 < b) \\
  b
  &= q_2 r_1 + r_2
  &&(0 \le r_2 < r_1) \\
  r_1
  &= q_3 r_2 + r_3
  &&(0 \le r_3 < r_2) \\
  &~~\vdots \\
  r_k
  &= q_{k + 2} r_{k + 1} + r_{k + 2}
  &&(0 \le r_{k + 2} < r_{k + 1}) \\
\end{align*}
\textbf{Claim:} we must eventually have $r_{k + 2}
= 0$. Why? Because $b > r_1 > r_2 > \cdots > r_{k
+ 2} \ge 0$.

Then $\gcdbrack(a, b) = r_{k + 1}$. Why? Because
$\gcdbrack(a, b) =
\gcdbrack(b_1, r_1) = \gcdbrack(r_1, r_2) = \cdots
= \gcdbrack(r_{k + 1},
r_{k + 2}) = r_{k + 1}$.

\begin{corollary}
  Let $a, b \in \ZZ$, not both $0$, $c \in \ZZ$.
  Then the following are equivalent:
  \begin{enumerate}[(1)]
    \item There exist $x, y \in \ZZ$ such that $xa
      + yb = c$.
    \item $\gcdbrack(a, b) \divides c$.
  \end{enumerate}
\end{corollary}
\vspace{-1em}

This is a special case of \cref{Z_is_PID} with $n
= 2$, $a_1 = a$, $a_2 = b$. In particular, we can
always find $x, y \in \ZZ$ such that $xa + yb =
\gcdbrack(a, b)$.

We can use Euclid's algorithm to find such $x, y$.

\begin{example*}
  $a = 34$, $b = 25$.
  \begin{align*}
    34
    &= 1 \times 25 + 9 \\
    25
    &= 2 \times 9 + 7 \\
    9
    &= 1 \times 7 + 2 \\
    7
    &= 3 \times 2 + 1 \\
    2
    &= 2 \times 1
  \end{align*}
  Therefore $\gcdbrack(34, 25) = 1$.
  \begin{center}
    \begin{tabular}{c|cc}
      $r$ & $x$ & $y$ \\
      \hline
      34 & 1 & 0 \\
      25 & 0 & 1 \\
      9 & 1 & -1 \\
      7 & -2 & 3 \\
      2 & 3 & -4 \\
      1 & -11 & 15
    \end{tabular}
    So $1 = -11 \times 34 + 15 \times 25$.
  \end{center}
\end{example*}

\begin{definition}
  \glsnoundefn{prime}{prime}{primes}
  We say $p \in \NN$ is prime if $p > 1$ and
  $\forall b \in \NN$, if $b \divides p$ then $b = 1$
  or $b = p$.
\end{definition}

\begin{flashcard}[Euclids-lemma]
\begin{lemma}
  \label{Euclids_lemma}
  Let $p$ be a \gls{prime} number, $a, b \in \ZZ$. Then
  if $p \divides (ab)$, then $p \divides a$ or $p
  \divides b$.
\end{lemma}

\begin{proof}
  \cloze{
  Suppose $p \divides ab$, $p \ndivides a$. We must
  \emph{show} $p \divides b$.

  Consider $\gcdbrack(a, p)$. Then $\gcdbrack(a,
  p) \divides p$ so $\gcdbrack(a,
  p) = 1$ or $\gcdbrack(a, p) = p$. But
  $\gcdbrack(a, p) \divides a$ so
  $\gcdbrack(a, p) \neq p$, so $\gcdbrack(a, p) = 1$. Therefore
  there exist $x, y \in \ZZ$ such that $xa + yp =
  1$.

  Multiply by $b$: $xab + ypb = b$, so $p \divides b$.
  }
\end{proof}
\end{flashcard}

\begin{flashcard}[fundamental-theorem-of-arithmetic]
\begin{theorem}[Fundamental Theorem of Arithmetic]
  \glsnoundefn{prime_factorisation}{prime
  factorisation}{prime factorisations}
  \label{FTA}
  Let $N \in \NN$. Then there is an expression $N
  = \prod_{i = 1}^k p_i^{a_i}$ where $p_i$'s are
  distinct \gls{prime} numbers, and $a_i \ge 1$ $\forall
  i = 1, \ldots, k$. Moreover, this expression is
  unique up to reordering the $p_i$'s.
\end{theorem}

\begin{proof}
  \cloze{
  Existence: Induction on $N \ge 1$, noting that
  $N = 1$ has a unique expression as a product of
  \glspl{prime}. If $N > 1$, either $N$ is
  \gls{prime} (in
  which case we clearly have a representation as a
  product of \glspl{prime}), or $N = ab$, where $1 < a, b
  < N$ (and we can use this product to find a
  representation for $N$ as a product of
  \glspl{prime}).

  Uniqueness: Induction on $N \ge 1$, base case $N
  = 1$ already treated. If $N > 1$, and we have
  expressions $N = \prod_{i = 1}^k p_i^{a_i} =
  \prod_{j = 1}^l q_j^{b_j}$. Then $p_1 \divides N =
  \prod_{j = 1}^l q_j^{b_j}$. By
  \cref{Euclids_lemma}, $p_q \divides q_j$ for some
  $j$. Since $p_1 > 1$ and $q_j$ is \gls{prime}, $p_1 =
  q_j$. After relabelling, can assume $j = 1$.
  Then
  \[ \frac{N}{p_1} = p_1^{a_1 - 1} \prod_{i = 1}^k
  p_i^{a_i} = q_1^{b_1 - 1} \prod_{j = 2}^l
  q_j^{b_j} \]
  Now $N / p_1 < N$, so by induction, $k = l$ and
  $a_i = b_i$ for all $i$.
  }
\end{proof}
\end{flashcard}
