\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=Monday, February 03, 2025 10:20:50}
%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{\arinj}{\ar@{_{(}->}}
\newcommand{\arinjrev}{\ar@{^{(}->}}
\newcommand{\arsurj}{\ar@{->>}}
\newcommand{\arelem}{\ar@{|->}}
\newcommand{\arback}{\ar@{<-}}
\newcommand{\are}{\ar@{-}}
\newcommand{\arebi}[1][]{\ar@{<-}@/_/[#1] \ar@/^/[#1]}
\newcommand{\of}{\text{ of }}
\definecolor{darkgreen}{rgb}{0,.5,0}
\newtheoremstyle{plainsl}
{8pt plus 2pt minus 4pt}
{8pt plus 2pt minus 4pt}
{\slshape}
{0pt}
{\bfseries}
{.}
{5pt plus 1pt minus 1pt}
{}
\theoremstyle{plainsl}
\ihead{Lecture 17, version \today}
\ohead{page \thepage}
\cfoot{}
\begin{document}
\section*{Math 332 Winter 2023, Lecture 17: Rings}

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

\section{Rings and ideals (cont'd)}

\setcounter{subsection}{13}

\subsection{An introduction to divisibility theory (cont'd)}

\setcounter{subsubsection}{6}

\setcounter{theo}{12}

\subsubsection{Irreducible and prime elements (cont'd)}

Recall one of the definitions from Lecture 16:

\begin{definition}
Let $R$ be a commutative ring. Let $r\in R$ be nonzero and not a unit.

\textbf{(a)} We say that $r$ is \textbf{irreducible} (in $R$) if it has the
following property: Whenever $a,b\in R$ satisfy $ab=r$, at least one of $a$
and $b$ is a unit.

\textbf{(b)} We say that $r$ is \textbf{prime} (in $R$) if it has the
following property: Whenever $a,b\in R$ satisfy $r\mid ab$, we have $r\mid a$
or $r\mid b$.
\end{definition}

Both of these notions \textquotedblleft irreducible\textquotedblright\ and
\textquotedblleft prime\textquotedblright\ generalize prime numbers (up to sign).

\setcounter{theo}{14}

The following connection between \textquotedblleft
irreducible\textquotedblright\ and \textquotedblleft prime\textquotedblright%
\ has already been noticed in Lecture 16:

\begin{proposition}
\label{prop.rings.prime-is-irred}Let $R$ be an integral domain. Then, any
prime element of $R$ is irreducible.
\end{proposition}

In a PID (= integral domain where each ideal is principal), this goes both ways:

\begin{proposition}
\label{prop.pid.irred-is-prime}Let $R$ be a PID (for example, a Euclidean
domain). Let $r\in R$. Then, $r$ is prime if and only if $r$ is irreducible.
\end{proposition}

One proof of this proposition is given in the text (Proposition 2.15.4); we
shall give another. This latter proof will rely on the following two general lemmas:

\begin{lemma}
\label{lem.ring.ab-div-ac}Let $R$ be an integral domain. Let $a,b,c\in R$ be
such that $a\neq0$. If $ab\mid ac$, then $b\mid c$.
\end{lemma}

\begin{proof}
Assume that $ab\mid ac$. In other words, $ac=abr$ for some $r\in R$. Consider
this $r$. We have $a\left(  c-br\right)  =ac-abr=0$ (since $ac=abr$). Since
$R$ is an integral domain, we thus conclude that $c-br=0$ (since $a\neq0$). In
other words, $c=br$. This entails that $b\mid c$. Thus, Lemma
\ref{lem.ring.ab-div-ac}.
\end{proof}

\begin{lemma}
\label{lem.ring.gcd-ab-ac}Let $R$ be an integral domain. Let $a,b,c\in R$ be
such that $a\neq0$. Assume that the elements $ab$ and $ac$ have a gcd $g$.
Then, the elements $b$ and $c$ have a gcd $h$ such that $g=ah$.
\end{lemma}

\begin{proof}
The element $a$ is a common divisor of $ab$ and $ac$ (obviously), and thus
must divide $g$ (by the definition of a gcd, since $g$ is a gcd of $ab$ and
$ac$). In other words, there exists some $r\in R$ such that $g=ar$. Consider
this $r$.

Since $g$ is a gcd of $ab$ and $ac$, we have $g\mid ab$ and $g\mid ac$. From
$ar=g\mid ab$, we obtain $r\mid b$ (by Lemma \ref{lem.ring.ab-div-ac}, applied
to $r$ and $b$ instead of $b$ and $c$). Similarly, $r\mid c$. Thus, $r$ is a
common divisor of $b$ and $c$.

Now, let $s$ be any common divisor of $b$ and $c$. Then, $s\mid b$, so that
$b=sb^{\prime}$ for some $b^{\prime}\in R$. This $b^{\prime}$ then satisfies
$a\underbrace{b}_{=sb^{\prime}}=asb^{\prime}$, so that $as\mid ab$. Similarly,
$as\mid ac$. Hence, $as$ is a common divisor of $ab$ and $ac$. Therefore, $as$
divides $g$ (since $g$ is a gcd of $ab$ and $ac$). In other words, $as\mid
g=ar$. Hence, Lemma \ref{lem.ring.ab-div-ac} (applied to $s$ and $r$ instead
of $b$ and $c$) yields $s\mid r$.

Forget that we fixed $s$. We thus have shown that any common divisor $s$ of
$b$ and $c$ satisfies $s\mid r$. In other words, any common divisor of $b$ and
$c$ divides $r$. Since we also know that $r$ is a common divisor of $b$ and
$c$, we thus conclude that $r$ is a gcd of $b$ and $c$ (by the definition of a
gcd). Hence, the elements $b$ and $c$ have a gcd $h$ such that $g=ah$ (namely,
$h=r$), since we know that $g=ar$. This proves Lemma \ref{lem.ring.gcd-ab-ac}.
\end{proof}

\begin{proof}
[Proof of Proposition \ref{prop.pid.irred-is-prime}.]$\Longrightarrow:$ This
follows from Proposition \ref{prop.rings.prime-is-irred}.

$\Longleftarrow:$ Assume that $r$ is irreducible. We must prove that $r$ is prime.

So let $a,b\in R$ be such that $r\mid ab$. We must show that $r\mid a$ or
$r\mid b$.

If $a=0$, then this is obvious (since $r\mid0$). Thus, we WLOG assume that
$a\neq0$.

Theorem 1.14.11 in Lecture 16 shows that $ab$ and $ar$ have a gcd in $R$. Let
$g$ be this gcd. Then, $g\mid ab$ and $g\mid ar$.

We have $r\mid ab$ (by assumption) and $r\mid ar$ (obviously). Hence, $r$ is a
common divisor of $ab$ and $ar$. Thus, $r$ divides $g$ (by the definition of a
gcd, since $g$ is a gcd of $ab$ and $ar$). That is, $r\mid g$.

Lemma \ref{lem.ring.gcd-ab-ac} (applied to $c=r$) yields that the elements $b$
and $r$ have a gcd $h$ such that $g=ah$. Consider this $h$. Since $h$ is a gcd
of $b$ and $r$, we have $h\mid b$ and $h\mid r$.

In particular, $h\mid r$. In other words, there exists some $k\in R$ such that
$r=kh$. Consider this $k$.

So we have $kh=r$. Since $r$ is irreducible, this entails that at least one of
the elements $k$ and $h$ is a unit (by the definition of \textquotedblleft
irreducible\textquotedblright). Thus, we are in one of the following cases:

\textit{Case 1:} The element $k$ is a unit.

\textit{Case 2:} The element $h$ is a unit.\footnote{Cases 1 and 2 cannot
overlap, because if $k$ and $h$ were both units, then their product $kh=r$
would be a unit as well, but $r$ is irreducible and thus not a unit. But we
don't care about this, since cases in a proof can overlap.}

Let us first consider Case 1. In this case, the element $k$ is a unit. Hence,
$k$ has an inverse $k^{-1}$. From $r=kh$, we thus obtain $h=rk^{-1}$, so that
$r\mid h\mid b$. Thus, $r\mid a$ or $r\mid b$. So we are done in Case 1.

Let us next consider Case 2. In this case, the element $h$ is a unit. Hence,
$h$ has an inverse $h^{-1}$. From $g=ah$, we thus obtain $a=gh^{-1}$. Thus,
$g\mid a$. Hence, $r\mid g\mid a$. Thus, $r\mid a$ or $r\mid b$. So we are
done in Case 2.

Hence, in both cases, we have shown that $r\mid a$ or $r\mid b$. As we
explained, this completes the proof of the \textquotedblleft$\Longleftarrow
$\textquotedblright\ direction of Proposition \ref{prop.pid.irred-is-prime}.
\end{proof}

\subsubsection{Irreducible factorizations and UFDs}

The following theorem generalizes the classical \textquotedblleft Fundamental
Theorem of Arithmetic\textquotedblright\ (i.e., the fact that each positive
integer has a prime factorization, which is unique up to reordering the factors):

\begin{theorem}
\label{thm.pid.ufd}Let $R$ be a PID. Then, any nonzero element $r\in R$ can be
decomposed (up to associates) into a product of irreducible (i.e., prime)
elements of $R$. Moreover, this product is unique up to order and associateness.

In detail: Let $r\in R$ be a nonzero element. Then, there is a tuple $\left(
p_{1},p_{2},\ldots,p_{n}\right)  $ of irreducible (i.e., prime) elements of
$R$ such that%
\[
r\sim p_{1}p_{2}\cdots p_{n}.
\]
If $\left(  p_{1},p_{2},\ldots,p_{n}\right)  $ and $\left(  q_{1},q_{2}%
,\ldots,q_{m}\right)  $ are two such tuples, then $\left(  p_{1},p_{2}%
,\ldots,p_{n}\right)  $ can be obtained from $\left(  q_{1},q_{2},\ldots
,q_{m}\right)  $ by reordering the entries and replacing them by associate entries.
\end{theorem}

\begin{proof}
See a textbook, e.g., \cite[\S 8.3, Theorem 14]{DumFoo04} or \cite[Theorem
8.15]{Knapp1}. Just a few words about the proof:

Uniqueness is proved just as for integers.

Existence is tricky: Just as for integers, you start with $r$ and keep
factoring it further and further (avoiding unit factors) until no more
divisors remain. But you have to argue that this factoring process won't go on
forever, and this is no longer as easy as for integers. (It is easy when $R$
has a \textquotedblleft multiplicative norm\textquotedblright, i.e., a map
$N:R\rightarrow\mathbb{N}$ such that $N\left(  a\right)  <N\left(  ab\right)
$ whenever $a,b\in R$ are nonzero and $b$ is not a unit. For example, if
$R=\mathbb{Z}\left[  i\right]  $, then the Euclidean norm $N:\mathbb{Z}\left[
i\right]  \rightarrow\mathbb{N}$ defined by $N\left(  a+bi\right)
=a^{2}+b^{2}$ has this property.)
\end{proof}

Integral domains $R$ in which the claim of Theorem \ref{thm.pid.ufd} holds are
called \textbf{UFDs} (short for \textbf{unique factorization domains}). This
class is wider than the PIDs. For instance, the polynomial rings
$\mathbb{Z}\left[  x\right]  $ (the ring of all univariate polynomials in $x$
with integer coefficients) and $\mathbb{Q}\left[  x,y\right]  $ (the ring of
all polynomials in two variables $x$ and $y$ with rational coefficients) are
UFDs but not PIDs.

We will not focus on UFDs in this course, but we briefly note that they have
some (but not all) of the nice properties of PIDs. In particular, in a UFD,
any two elements have a gcd and an lcm. (But we shall not prove this.)

\subsubsection{A synopsis}

The following corollary combines several results we have seen above in a
convenient hierarchy:

\begin{corollary}
\label{cor.UFD.hierarchy}We have%
\begin{align*}
\left\{  \text{fields}\right\}   &  \subseteq\left\{  \text{Euclidean
domains}\right\}  \subseteq\left\{  \text{PIDs}\right\}  \subseteq\left\{
\text{UFDs}\right\} \\
&  \subseteq\left\{  \text{integral domains}\right\}  \subseteq\left\{
\text{commutative rings}\right\}  \subseteq\left\{  \text{rings}\right\}  .
\end{align*}

\end{corollary}

Let us illustrate this hierarchy in a symbolic picture:%
\[%
%TCIMACRO{\TeXButton{tikz hierarchy}{\begin{tikzpicture}[scale=0.6]
%\draw(-4, -2) rectangle (16.8, 8);
%\draw(-3.5, -1.75) rectangle (14.7, 7);
%\draw(-3, -1.5) rectangle (12.6, 6);
%\draw(-2.5, -1.25) rectangle (10.5, 5);
%\draw(-2, -1) rectangle (8.4, 4);
%\draw(-1.5, -0.75) rectangle (6.3, 3);
%\draw(-1, -0.5) rectangle (4.2, 2);
%\node(A) at (14, 7.5) {rings};
%\node(A) at (10, 6.5) {commutative rings};
%\node(A) at (8, 5.5) {integral domains};
%\node(A) at (8, 4.5) {UFDs};
%\node(A) at (6, 3.5) {PIDs};
%\node(A) at (2, 2.5) {Euclidean domains};
%\node(A) at (2, 1.5) {fields};
%\end{tikzpicture}}}%
%BeginExpansion
\begin{tikzpicture}[scale=0.6]
\draw(-4, -2) rectangle (16.8, 8);
\draw(-3.5, -1.75) rectangle (14.7, 7);
\draw(-3, -1.5) rectangle (12.6, 6);
\draw(-2.5, -1.25) rectangle (10.5, 5);
\draw(-2, -1) rectangle (8.4, 4);
\draw(-1.5, -0.75) rectangle (6.3, 3);
\draw(-1, -0.5) rectangle (4.2, 2);
\node(A) at (14, 7.5) {rings};
\node(A) at (10, 6.5) {commutative rings};
\node(A) at (8, 5.5) {integral domains};
\node(A) at (8, 4.5) {UFDs};
\node(A) at (6, 3.5) {PIDs};
\node(A) at (2, 2.5) {Euclidean domains};
\node(A) at (2, 1.5) {fields};
\end{tikzpicture}%
%EndExpansion
\]


All the \textquotedblleft$\subseteq$\textquotedblright\ signs in Corollary
\ref{cor.UFD.hierarchy} are strict inclusions; let us briefly recall some
examples showing this:

\begin{itemize}
\item The rings $\mathbb{Z}$ and $\mathbb{Z}\left[  i\right]  $ and
$\mathbb{Z}\left[  \sqrt{-2}\right]  $ and $\mathbb{Z}\left[  \sqrt{2}\right]
$ and the polynomial ring $\mathbb{Q}\left[  x\right]  $ are Euclidean
domains, but not fields.

\item The ring $\mathbb{Z}\left[  \alpha\right]  $ for $\alpha=\dfrac
{1+\sqrt{-19}}{2}$ is a PID, but not a Euclidean domain.

\item The polynomial rings $\mathbb{Q}\left[  x,y\right]  $ and $\mathbb{Z}%
\left[  x\right]  $ are UFDs, but not PIDs.

\item The rings $\mathbb{Z}\left[  2i\right]  $ and $\mathbb{Z}\left[
\sqrt{-3}\right]  $ are integral domains, but not UFDs.

\item The ring $\mathbb{Z}/6\cong\mathbb{Z}/2\times\mathbb{Z}/3$ is a
commutative ring, but not an integral domain.

\item The matrix ring $\mathbb{Q}^{2\times2}$ and the ring of quaternions
$\mathbb{H}$ are not commutative.
\end{itemize}

\subsection{Application: Fermat's $p=x^{2}+y^{2}$ theorem}

As an application of some of the above, we will show a result of Fermat:

\begin{theorem}
[Fermat's two-squares theorem]\label{thm.fermat.p=xx+yy}Let $p$ be a prime
number\footnotemark\ such that $p\equiv1\operatorname{mod}4$. Then, $p$ can be
written as a sum of two perfect squares.
\end{theorem}

\footnotetext{in the sense of classical number theory, i.e., an integer $p>1$
with no positive divisors other than $1$ and $p$}For example,%
\begin{align*}
5  &  =1^{2}+2^{2};\\
13  &  =2^{2}+3^{2};\\
17  &  =1^{2}+4^{2};\\
29  &  =2^{2}+5^{2}.
\end{align*}


\bigskip

I will prove Theorem \ref{thm.fermat.p=xx+yy} using rings (specifically, the
ring $\mathbb{Z}/p$ of residue classes and the ring $\mathbb{Z}\left[
i\right]  $ of Gaussian integers). The first ingredient of the proof is a
curious fact about primes, known as \textbf{Wilson's theorem}:

\begin{theorem}
[Wilson's theorem]\label{thm.wilson}Let $p$ be a prime. Then, $\left(
p-1\right)  !\equiv-1\operatorname{mod}p$.
\end{theorem}

\begin{proof}
We must show that $\overline{\left(  p-1\right)  !}=\overline{-1}$ in
$\mathbb{Z}/p$.

In $\mathbb{Z}/p$, we have%
\begin{equation}
\overline{\left(  p-1\right)  !}=\overline{1\cdot2\cdot\cdots\cdot\left(
p-1\right)  }=\overline{1}\cdot\overline{2}\cdot\cdots\cdot\overline{p-1}.
\label{pf.thm.wilson.1}%
\end{equation}


Recall that every ring $R$ has a group of units, which is denoted by
$R^{\times}$. (Its elements are the units of $R$, and its operation is
multiplication.) Since the ring $\mathbb{Z}/p$ is a field (because $p$ is
prime), its group of units $\left(  \mathbb{Z}/p\right)  ^{\times}$ consists
of all nonzero elements of $\mathbb{Z}/p$. Thus,%
\[
\left(  \mathbb{Z}/p\right)  ^{\times}=\left\{  \overline{1},\overline
{2},\ldots,\overline{p-1}\right\}  ,
\]
with all the $p-1$ elements $\overline{1},\overline{2},\ldots,\overline{p-1}$
being distinct. Hence, the product of all units of $\mathbb{Z}/p$ is%
\[
\prod_{a\in\left(  \mathbb{Z}/p\right)  ^{\times}}a=\overline{1}\cdot
\overline{2}\cdot\cdots\cdot\overline{p-1}.
\]
Comparing this with (\ref{pf.thm.wilson.1}), we find%
\begin{equation}
\overline{\left(  p-1\right)  !}=\prod_{a\in\left(  \mathbb{Z}/p\right)
^{\times}}a. \label{pf.thm.wilson.3}%
\end{equation}


Now, recall that any unit $a$ of $\mathbb{Z}/p$ (or of any other ring) has an
inverse $a^{-1}$, which is also a unit and satisfies $\left(  a^{-1}\right)
^{-1}=a$. Thus, the units of $\mathbb{Z}/p$ can be paired up in pairs
$\left\{  a,a^{-1}\right\}  $ consisting of a unit $a$ and its inverse
$a^{-1}$. The only units left unpaired will be the units that are their own
inverses. These units are the elements $a\in\mathbb{Z}/p$ that satisfy
$a^{2}=\overline{1}$, and a moment of thought reveals that they are
$\overline{1}$ and $\overline{-1}$ (because $a^{2}=\overline{1}$ entails
$0=a^{2}-\overline{1}=\left(  a-\overline{1}\right)  \left(  a+\overline
{1}\right)  $, and since $\mathbb{Z}/p$ is an integral domain, this equality
can only hold if either $a-\overline{1}$ or $a+\overline{1}$ is $0$). Thus,
all units other than $\overline{1}$ and $\overline{-1}$ are paired. Hence, in
the product of all units of $\mathbb{Z}/p$, we can pair up each factor other
than $\overline{1}$ and $\overline{-1}$ with its inverse:
\[
\prod_{a\in\left(  \mathbb{Z}/p\right)  ^{\times}}a=\underbrace{\left(
a_{1}\cdot a_{1}^{-1}\right)  }_{=1}\cdot\underbrace{\left(  a_{2}\cdot
a_{2}^{-1}\right)  }_{=1}\cdot\cdots\cdot\underbrace{\left(  a_{k}\cdot
a_{k}^{-1}\right)  }_{=1}\cdot\,\overline{1}\cdot\overline{-1}=\overline{-1}.
\]
Hence, (\ref{pf.thm.wilson.3}) can be rewritten as $\overline{\left(
p-1\right)  !}=\overline{-1}$, which means precisely that $\left(  p-1\right)
!\equiv-1\operatorname{mod}p$. This proves Theorem \ref{thm.wilson}.

(Caution: The above argument breaks down a bit for $p=2$, but this case is
trivial anyway.)
\end{proof}

\begin{corollary}
\label{cor.wilson.u!2gen}Let $p$ be an odd prime (i.e., a prime distinct from
$2$). Let $u=\dfrac{p-1}{2}\in\mathbb{N}$. Then, $u!^{2}\equiv-\left(
-1\right)  ^{u}\operatorname{mod}p$.
\end{corollary}

\begin{proof}
Theorem \ref{thm.wilson} yields%
\[
\left(  p-1\right)  !\equiv-1\operatorname{mod}p.
\]


However,
\begin{align*}
\left(  p-1\right)  !  &  =1\cdot2\cdot\cdots\cdot\left(  p-1\right) \\
&  =\left(  1\cdot2\cdot\cdots\cdot\dfrac{p-1}{2}\right)  \cdot\left(
\underbrace{\left(  \dfrac{p-1}{2}+1\right)  }_{\equiv-\dfrac{p-1}%
{2}\operatorname{mod}p}\cdot\cdots\cdot\underbrace{\left(  p-2\right)
}_{\equiv-2\operatorname{mod}p}\cdot\underbrace{\left(  p-1\right)  }%
_{\equiv-1\operatorname{mod}p}\right) \\
&  \equiv\left(  1\cdot2\cdot\cdots\cdot\dfrac{p-1}{2}\right)  \cdot\left(
\left(  -\dfrac{p-1}{2}\right)  \cdot\cdots\cdot\left(  -2\right)
\cdot\left(  -1\right)  \right) \\
&  =\left(  1\cdot2\cdot\cdots\cdot u\right)  \cdot\underbrace{\left(  \left(
-u\right)  \cdot\cdots\cdot\left(  -2\right)  \cdot\left(  -1\right)  \right)
}_{\substack{=\left(  -1\right)  ^{u}\cdot\left(  u\cdot\cdots\cdot
2\cdot1\right)  \\=\left(  -1\right)  ^{u}\cdot\left(  1\cdot2\cdot\cdots\cdot
u\right)  }}\ \ \ \ \ \ \ \ \ \ \left(  \text{since }\dfrac{p-1}{2}=u\right)
\\
&  =\left(  1\cdot2\cdot\cdots\cdot u\right)  \cdot\left(  -1\right)
^{u}\cdot\left(  1\cdot2\cdot\cdots\cdot u\right) \\
&  =\left(  -1\right)  ^{u}\cdot\left(  \underbrace{1\cdot2\cdot\cdots\cdot
u}_{=u!}\right)  ^{2}=\left(  -1\right)  ^{u}\cdot u!^{2}\operatorname{mod}p,
\end{align*}
so that%
\[
\left(  -1\right)  ^{u}\cdot u!^{2}\equiv\left(  p-1\right)  !\equiv
-1\operatorname{mod}p.
\]
Multiplying both sides of this congruence by $\left(  -1\right)  ^{u}$, we
obtain%
\[
u!^{2}\equiv-\left(  -1\right)  ^{u}\operatorname{mod}p.
\]
This proves Corollary \ref{cor.wilson.u!2gen}.
\end{proof}

\begin{corollary}
\label{cor.wilson.u!2}Let $p$ be a prime such that $p\equiv1\operatorname{mod}%
4$. Let $u=\dfrac{p-1}{2}\in\mathbb{N}$. Then, $u!^{2}\equiv
-1\operatorname{mod}p$.
\end{corollary}

\begin{proof}
Apply Corollary \ref{cor.wilson.u!2gen}, and observe that $\left(  -1\right)
^{u}=1$ (since $p\equiv1\operatorname{mod}4$, so that $u$ is even). Corollary
\ref{cor.wilson.u!2} follows.
\end{proof}

\bigskip

Corollary \ref{cor.wilson.u!2} brings us somewhat closer to our goal: Its
claim $u!^{2}\equiv-1\operatorname{mod}p$ can be rewritten as $p\mid
u!^{2}+1=u!^{2}+1^{2}$. Now, if we could somehow turn this divisibility into
an equality...

Of course, we cannot do this directly. But let us recall the Gaussian integers
and their ring $\mathbb{Z}\left[  i\right]  $. In this ring, the equality
$p=u!^{2}+1^{2}$ can be rewritten as $p=\left(  u!+i\right)  \left(
u!-i\right)  $, which is promising.

To get any mileage out of this, we recall our favorite Euclidean norm $N$ on
$\mathbb{Z}\left[  i\right]  $. This is the map%
\begin{align*}
N:\mathbb{Z}\left[  i\right]   &  \rightarrow\mathbb{N},\\
a+bi  &  \mapsto a^{2}+b^{2}=\left\vert a+bi\right\vert ^{2}%
\ \ \ \ \ \ \ \ \ \ \left(  \text{for }a,b\in\mathbb{Z}\right)  .
\end{align*}


It has a further nice property (which is not part of its Euclideanness):

\begin{proposition}
\label{prop.Zi.norm-mult}We have%
\[
N\left(  \alpha\beta\right)  =N\left(  \alpha\right)  N\left(  \beta\right)
\ \ \ \ \ \ \ \ \ \ \text{for any }\alpha,\beta\in\mathbb{Z}\left[  i\right]
.
\]

\end{proposition}

\begin{proof}
Straightforward computation (write $\alpha$ as $\alpha=a+bi$ and write $\beta$
as $\beta=c+di$, and multiply).
\end{proof}

\begin{corollary}
\label{cor.Zi.norm-div}Let $\alpha$ and $\beta$ be two Gaussian integers such
that $\alpha\mid\beta$ in $\mathbb{Z}\left[  i\right]  $. Then, $N\left(
\alpha\right)  \mid N\left(  \beta\right)  $ in $\mathbb{Z}$.
\end{corollary}

\begin{proof}
We have $\beta=\alpha\gamma$ for some $\gamma\in\mathbb{Z}\left[  i\right]  $
(since $\alpha\mid\beta$). This $\gamma$ then satisfies $N\left(
\beta\right)  =N\left(  \alpha\gamma\right)  =N\left(  \alpha\right)  N\left(
\gamma\right)  $ (by Proposition \ref{prop.Zi.norm-mult}). Profit.
\end{proof}

\begin{corollary}
\label{cor.Zi.units}The units of $\mathbb{Z}\left[  i\right]  $ are exactly
the elements $\alpha\in\mathbb{Z}\left[  i\right]  $ satisfying $N\left(
\alpha\right)  =1$, and these elements are precisely $1,\ i,\ -1,\ -i$.
\end{corollary}

\begin{proof}
Easy exercise (specifically, \cite[homework set \#2, Exercise 6 \textbf{(d)}%
]{21w}). The fact that the Gaussian integers $1,\ i,\ -1,\ -i$ are the only
elements $\alpha\in\mathbb{Z}\left[  i\right]  $ satisfying $N\left(
\alpha\right)  =1$ is easily checked (what are the integer solutions of the
equations $x^{2}+y^{2}=1$) ? Clearly, these elements are units. Conversely,
any unit $\alpha$ of $\mathbb{Z}\left[  i\right]  $ satisfies $\alpha\mid1$ in
$\mathbb{Z}\left[  i\right]  $ and therefore $N\left(  \alpha\right)  \mid
N\left(  1\right)  $ in $\mathbb{Z}$ (by Corollary \ref{cor.Zi.norm-div}),
which means $N\left(  \alpha\right)  \mid N\left(  1\right)  =1$ and therefore
$N\left(  \alpha\right)  =1$.
\end{proof}

\begin{lemma}
\label{lem.Zi.div-frac}Let $\alpha$ and $\beta$ be Gaussian integers such that
$\alpha\neq0$. Then, $\alpha\mid\beta$ in $\mathbb{Z}\left[  i\right]  $ if
and only if $\dfrac{\beta}{\alpha}\in\mathbb{Z}\left[  i\right]  $.
\end{lemma}

\begin{proof}
Trivial.
\end{proof}

\bigskip

We are now ready to prove Fermat's two-squares theorem:

\begin{proof}
[Proof of Theorem \ref{thm.fermat.p=xx+yy}.]Let $u=\dfrac{p-1}{2}$. This
$u\in\mathbb{N}$ since $p$ is odd. Furthermore, Corollary \ref{cor.wilson.u!2}
yields $u!^{2}\equiv-1\operatorname{mod}p$. Thus, $p\mid u!^{2}+1$ in
$\mathbb{Z}$, so that $p\mid u!^{2}+1=\left(  u!+i\right)  \left(
u!-i\right)  $ in $\mathbb{Z}\left[  i\right]  $.

However, $p\nmid u!+i$ (by Lemma \ref{lem.Zi.div-frac}), since $\dfrac
{u!+i}{p}=\dfrac{u!}{p}+\dfrac{1}{p}i\notin\mathbb{Z}\left[  i\right]  $.
Similarly, $p\nmid u!-i$.

Thus, $p$ divides a product of two elements of $\mathbb{Z}\left[  i\right]  $
(namely, the product of $u!+i$ and $u!-i$), but does not divide any of the two
factors. This shows that $p$ is not prime in $\mathbb{Z}\left[  i\right]  $.
But $\mathbb{Z}\left[  i\right]  $ is a PID, and thus the prime elements of
$\mathbb{Z}\left[  i\right]  $ are precisely the irreducible elements of
$\mathbb{Z}\left[  i\right]  $ (by Proposition \ref{prop.pid.irred-is-prime}).
Therefore, $p$ is not irreducible in $\mathbb{Z}\left[  i\right]  $. In other
words, $p$ can be written as $p=ab$ for two non-units $a$ and $b$ of
$\mathbb{Z}\left[  i\right]  $. Consider these non-units $a$ and $b$.

From $p=ab$, we obtain%
\[
N\left(  p\right)  =N\left(  ab\right)  =N\left(  a\right)  N\left(  b\right)
\ \ \ \ \ \ \ \ \ \ \left(  \text{by Proposition \ref{prop.Zi.norm-mult}%
}\right)  ,
\]
so that%
\[
N\left(  a\right)  N\left(  b\right)  =N\left(  p\right)  =p^{2}+0^{2}=p^{2}.
\]
Since $N\left(  a\right)  $ and $N\left(  b\right)  $ are nonnegative
integers, this entails that we have%
\begin{align*}
&  \text{either }\left(  N\left(  a\right)  =1\text{ and }N\left(  b\right)
=p^{2}\right) \\
&  \text{or }\left(  N\left(  a\right)  =p\text{ and }N\left(  b\right)
=p\right) \\
&  \text{or }\left(  N\left(  a\right)  =p^{2}\text{ and }N\left(  b\right)
=1\right)
\end{align*}
(because the Fundamental Theorem of Arithmetic shows that the only ways to
decompose $p^{2}$ as a product of two nonnegative integers are $1\cdot p^{2}$
and $p\cdot p$ and $p^{2}\cdot1$). However, the first of these three options
is impossible (because $N\left(  a\right)  =1$ would force $a$ to be a
unit\footnote{by Corollary \ref{cor.Zi.units}}, contradicting the fact that
$a$ is a non-unit). Similarly, the third option is impossible. Hence, the
second option must hold. In other words, we have $N\left(  a\right)  =p$ and
$N\left(  b\right)  =p$.

Now, write the Gaussian integer $a$ as $a=x+yi$ for $x,y\in\mathbb{Z}$. Then,
the definition of $N$ yields $N\left(  a\right)  =x^{2}+y^{2}$, so that
$x^{2}+y^{2}=N\left(  a\right)  =p$. Thus, Theorem \ref{thm.fermat.p=xx+yy} is proved!
\end{proof}

\bigskip

Theorem \ref{thm.fermat.p=xx+yy} is the tip of a deep iceberg, which took
several centuries to explore (and still appears to be less than fully mapped).
The most obvious next step is extending it to non-primes:

\begin{theorem}
\label{thm.fermat.n=xx+yy}Let $n$ be a positive integer with prime
factorization $n=2^{a}p_{1}^{b_{1}}p_{2}^{b_{2}}\cdots p_{k}^{b_{k}}$, where
$p_{1},p_{2},\ldots,p_{k}$ are distinct primes larger than $2$, and where
$a,b_{1},b_{2},\ldots,b_{k}$ are nonnegative integers. (In particular, if $n$
is odd, then $a=0$.)

Then:

\textbf{(a)} The number $n$ can be written as a sum of two perfect squares if
and only if the following condition holds: For each $i\in\left\{
1,2,\ldots,k\right\}  $ satisfying $p_{i}\equiv3\operatorname{mod}4$, the
exponent $b_{i}$ is even.

\textbf{(b)} If this condition holds, then the number of ways to write $n$ as
a sum of two perfect squares (to be more precise: the number of pairs $\left(
x,y\right)  \in\mathbb{Z}\times\mathbb{Z}$ satisfying $n=x^{2}+y^{2}$) is
$4\cdot\prod_{\substack{i\in\left\{  1,2,\ldots,k\right\}  ;\\p_{i}%
\equiv1\operatorname{mod}4}}\left(  b_{i}+1\right)  $.
\end{theorem}

For a proof of this theorem, see \cite[Theorem 4.2.62]{19s} or \cite[\S 8.1,
Corollary 19]{DumFoo04}. (The proof again uses Gaussian integers in a rather
neat way. Actually, proving the \textquotedblleft if\textquotedblright\ part
of Theorem \ref{thm.fermat.n=xx+yy} \textbf{(a)} is a neat
exercise\footnote{Keep in mind that $0$ is a perfect square.}.)

More about decompositions of integers into sums of perfect squares can be found

\begin{itemize}
\item in \cite[\S 8.3]{DumFoo04};

\item in Keith Conrad's
\url{https://kconrad.math.uconn.edu/math5230f12/handouts/Zinotes.pdf} ;

\item in \cite[\S 4.2]{19s}.
\end{itemize}

\bigskip

Instead of writing integers $n$ in the form $n=x^{2}+y^{2}$, we can try to
write them in the form $x^{2}+2y^{2}$ or $x^{2}+3y^{2}$ or $x^{2}+4y^{2}$ or
$x^{2}+5y^{2}$ or $x^{2}+xy+y^{2}$ or $\left\vert x^{2}-2y^{2}\right\vert $ or
many other such forms. Each time, we can ask when this is possible, and how
many ways there are. These questions vary widely in difficulty, and even their
most basic variants (which prime numbers can be written in a given form?) can
be extremely hard. A whole book \cite{Cox22} has been written entirely about
the question of writing prime(!) numbers in the form $x^{2}+ny^{2}$ for
positive integers $n$; just answering these questions for different $n$
requires rather advanced mathematics. Here is a summary of answers for certain
values of $n$ (see \cite{Cox22} for proofs of these and many more results):

\begin{theorem}
\label{thm.rings.p=xx+nyy}Let $p$ be a prime number.

\textbf{(a)} We can write $p$ in the form $p=x^{2}+y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p=2$ or $p\equiv1\operatorname{mod}4$.

\textbf{(b)} We can write $p$ in the form $p=x^{2}+2y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p\equiv1,3\operatorname{mod}8$. (The notation
\textquotedblleft$p\equiv1,3\operatorname{mod}8$\textquotedblright\ is
shorthand for \textquotedblleft$p$ is congruent to $1$ or to $3$ modulo
$8$\textquotedblright. Similar shorthands will be used in the following parts.)

\textbf{(c)} We can write $p$ in the form $p=x^{2}+3y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p=3$ or $p\equiv1\operatorname{mod}3$.

\textbf{(d)} We can write $p$ in the form $p=x^{2}+4y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p\equiv1\operatorname{mod}4$.

\textbf{(e)} We can write $p$ in the form $p=x^{2}+5y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p\equiv1,9\operatorname{mod}20$.

\textbf{(f)} We can write $p$ in the form $p=x^{2}+6y^{2}$ with $x,y\in
\mathbb{Z}$ if and only if $p\equiv1,7\operatorname{mod}24$.

\textbf{(g)} We can write $p$ in the form $p=x^{2}+14y^{2}$ with
$x,y\in\mathbb{Z}$ if and only if we have $p\equiv
1,9,15,23,25,39\operatorname{mod}56$ and there exists some integer $z$
satisfying $\left(  z^{2}+1\right)  ^{2}\equiv8\operatorname{mod}p$.

\textbf{(h)} We can write $p$ in the form $p=x^{2}+27y^{2}$ with
$x,y\in\mathbb{Z}$ if and only if we have $p\equiv1\operatorname{mod}3$ and
there exists some integer $z$ satisfying $z^{3}\equiv2\operatorname{mod}p$.
\end{theorem}

Part \textbf{(a)} of Theorem \ref{thm.rings.p=xx+nyy} follows from Theorem
\ref{thm.fermat.p=xx+yy} and its fairly easy converse. Parts \textbf{(b)} and
\textbf{(d)} are exercises in the text, so can be done with fairly elementary
methods. (Actually, you can prove part \textbf{(d)} right now, using nothing
but part \textbf{(a)} and a bit of thought.) Part \textbf{(c)} looks
superficially similar, but is significantly harder to prove since
$\mathbb{Z}\left[  \sqrt{-3}\right]  $ is not a PID (or even a UFD);
nevertheless, fairly elementary proofs exist\footnote{See, e.g.,
\url{https://math.stackexchange.com/a/76917/} for one such proof.}. Part
\textbf{(e)} is proved using genus theory of quadratic forms in \cite[(2.22)]%
{Cox22}. Part \textbf{(f)} requires class field theory (\cite[Theorem
5.33]{Cox22}). Parts \textbf{(g)} and \textbf{(h)} can be proved using
elliptic functions from complex analysis (\cite[Chapters 2 and 3]{Cox22}).
Note the additional \textquotedblleft there exists some integer $z$%
\textquotedblright\ conditions in parts \textbf{(g)} and \textbf{(h)}; such
conditions can be avoided for $x^{2}+ny^{2}$ when $n$ is small, but eventually
become necessary. See \url{https://mathoverflow.net/questions/79342/} for more
about the need for such conditions, and see \cite[Chapters 2 and 3]{Cox22} for
their exact nature.

\bigskip

We can also ask about sums of more than two squares. Lagrange proved that
every nonnegative integer can be written as a sum of \textbf{four} squares
(that is, each $n\in\mathbb{N}$ can be written as $n=x^{2}+y^{2}+z^{2}+w^{2}$
for some $x,y,z,w\in\mathbb{Z}$). These days, one of the shortest proofs of
this fact uses the so-called \textit{Hurwitz quaternions} -- a quaternion
analogue of Gaussian integers. See
\url{https://en.wikipedia.org/wiki/Lagrange's_four-square_theorem} or
\cite{Haensc16} or \cite{Schwar14} for the proof.

\begin{thebibliography}{99999999}                                                                                         %


\bibitem[21w]{21w}Darij Grinberg, \textit{Math 533: Abstract Algebra I, Winter
2021}.\newline\url{https://www.cip.ifi.lmu.de/~grinberg/t/21w/}

\bibitem[Cox22]{Cox22}David A. Cox, \textit{Primes of the form }$x^{2}+ny^{2}%
$, AMS Chelsea Publishing \textbf{387}, 3rd edition, AMS 2022.

\bibitem[DumFoo04]{DumFoo04}David S. Dummit, Richard M. Foote,
\textit{Abstract Algebra}, 3rd edition, Wiley 2004.\newline See
\url{https://site.uvm.edu/rfoote/files/2022/06/errata_3rd_edition.pdf} for errata.

\bibitem[Grinbe19]{19s}Darij Grinberg, \textit{Introduction to Modern Algebra
(UMN Spring 2019 Math 4281 notes)}, 29 June 2019.\newline\url{http://www.cip.ifi.lmu.de/~grinberg/t/19s/notes.pdf}

\bibitem[Haensc16]{Haensc16}Anna Haensch, \textit{Quaternions and the
four-square theorem}, 2016.\newline\url{https://www.mathcs.duq.edu/~haensch/411Materials/Quaternions.pdf}

\bibitem[Knapp16]{Knapp1}Anthony W. Knapp, \textit{Basic Algebra}, Digital 2nd
edition 2016.\newline\url{http://www.math.stonybrook.edu/~aknapp/download.html}

\bibitem[Schwar14]{Schwar14}Rich Schwartz, \textit{Math 153: The Four Square
Theorem}, April 12, 2014.\newline\url{https://www.math.brown.edu/reschwar/M153/lagrange.pdf}
\end{thebibliography}


\end{document}