\documentclass[11pt]{article}

\usepackage{amsmath,amssymb,amsthm}

\usepackage{xcolor}
\usepackage{tikz}
\usepackage{tikz-cd}

%\usepackage{systeme}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}


\theoremstyle{definition}
\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{eg}[thm]{Example}
\newtheorem{ex}[thm]{Exercise}
\newtheorem{defn}[thm]{Definition}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{remark}[thm]{Remark}
\newtheorem{question}[thm]{Question}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\tikzstyle{ball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=1.3pt]
\tikzstyle{miniball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=0.5pt]
\tikzstyle{mminiball} = [circle,shading=ball, ball color=black,
    minimum size=0.6mm,inner sep=0.1pt]
\usetikzlibrary{arrows.meta}
\tikzset{>={Latex[length=2mm,width=1.5mm]}}
\tikzset{->-/.style={decoration={markings, mark=at position #1 with
  {\arrow{>}}},postaction={decorate}}}
\usetikzlibrary{decorations.pathmorphing}    
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{arrows.meta,calc}
\usetikzlibrary{bending}
\usetikzlibrary{decorations.markings,shapes.geometric}
\tikzset{->-/.style={decoration={markings, mark=at position #1 with
  {\arrow{>}}},postaction={decorate}}}
\tikzset{-|-/.style={decoration={markings, mark=at position #1 with
  {\arrow{stealth}}},postaction={decorate}}}
\tikzset{movearrow/.style 2 args ={
        decoration={markings,
	  mark= at position {#1} with {\arrow{#2}} ,
        },
        postaction={decorate}
    }
}

%\usepackage{graphicx}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage{enumitem}
%\setlist[enumerate]{leftmargin=*}

%\allowdisplaybreaks

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

%\usepackage{algorithm}
%\usepackage[noend]{algpseudocode}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\W}{\mathbb{W}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\newcommand{\incid}{\mathcal{I}(P)}
\newcommand{\tL}{\widetilde{L}}
\newcommand{\tV}{\widetilde{V}}
\newcommand{\F}{\mathcal{F}}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\wt}{\mathrm{wt}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}
\DeclareMathOperator{\Div}{\mathrm{Div}}
\DeclareMathOperator{\Pic}{\mathrm{Pic}}
\DeclareMathOperator{\Jac}{\mathrm{Jac}}
\DeclareMathOperator{\cok}{\mathrm{cok}}
\DeclareMathOperator{\sgn}{\mathrm{sgn}}
\DeclareMathOperator{\outdeg}{\mathrm{outdeg}}
\DeclareMathOperator{\supp}{\mathrm{supp}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Math 361 lecture for Monday, Week 1}
\bigskip

\centerline{Pythagorean triples}
\bigskip

A \emph{Pythagorean triple} is a tuple $(x,y,z)$ of positive integers such that 
\[
  x^2+y^2=z^2.
\]
It is \emph{primitive} if $\gcd(x,y,z)=1$.
\medskip

\begin{eg}
  We have $3^{2}+4^{2}=5^{2}$:
  \begin{center}
    \begin{tikzpicture}[scale=0.5]
      \draw (0,0)--(4,0)--(0,3)--(0,0);
      \draw (0,0)--(0.3,0)--(0.3,0.3)--(0,0.3);
      \node at (-0.5,1.5) {$3$};
      \node at (1.8,-0.5) {$4$};
      \node at (2.3,2) {$5$};
      \node at (4.3,0) {.};
    \end{tikzpicture}
  \end{center}
\end{eg}

\textbf{Problem.} Find all primitive Pythagorean triples.
\medskip

\textbf{First observations.}
\begin{enumerate}
  \item If $(x,y,z)$ is a primitive Pythagorean triple, and $m$ is a positive
    integer, then $(mx,my,mz)$ is a Pythagorean triple.  If $(x,y,z)$ is any
    Pythagorean triple, then canceling common factors yields a primitive
    Pythagorean triple.
  \item If two of $x,y,z$ in a Pythagorean triple $(x,y,z)$ share a prime factor $p$, then so does the
    third.  For instance, if $x=px'$ and $z=pz'$, then $y^{2}=z^2-x^2$ is divisible
    by~$p$.  Since~$p$ divides~$y^{2}$ and~$p$ is prime, considering the prime
    factorization of~$y$, we see that~$p$ divides $y$.  Thus, for a Pythagorean triple~$(x,y,z)$, we
    have $\gcd(x,y,z)=1$ if and only if $x,y,z$ are pairwise relatively prime.
  \item If $(x,y,z)$ is a primitive Pythagorean theorem, then $z$ must be odd,
    and exactly one of $x$ and $y$ is even and one is odd.
    Here are the squares modulo $4$:
    \[
      0^{2}=0,\ 1^{2}=1,\ 2^{2}=0,\ 3^{2}=1\bmod 4.
    \]
    If a number is odd, then it is $1$ or $3$ modulo~$4$, and hence, its square
    is $1$ modulo $4$. Similarly, if a number is even, it is $0$ or $2$
    modulo~$4$, and its square is $0$
    modulo $4$.  Since~$(x,y,z)$ is primitive, then since we just saw that
    $x,y,z$ are pairwise relatively prime,
    at most one of $x$ and~$y$ is even.  This means that $x^{2}+y^2$ is
    either~$1$ or $2$ modulo~$4$.  However, $z^2=x^2+y^2\neq 2\bmod 4$, since
    no square is $2$ modulo~$4$.  So $z^2=x^2+y^2=1$.  The result follows.
\end{enumerate}

The key idea we will use to find all Pythagorean triples is the factorization
\[
  x^2+y^2=(x+iy)(x-iy).
\]
Define
\[
  \Q(i)=\{a+bi: a,b\in \Q\}\subset \C.
\]
Then $\Q(i)$ is a field.  For instance, $\Q(i)$ is closed under multiplication:
if $a,b,c,d\in\Q$, then
\[
  (a+bi)(c+di)=(ac-db)+(ad+bc)i\in\Q(i).
\]
Further, if $a+bi\neq0$, its inverse is
\[
 \frac{1}{a+bi}=\frac{1}{a+bi}\cdot \frac{a-bi}{a-bi}=\frac{1}{a^2+b^2}(a-bi)
 =\frac{a}{a^2+b^2}-\frac{b}{a^2+b^2}i\in
 \Q(i).
\]
The field $\Q(i)$ is the smallest subfield of $\C$ containing $i$.  Define the
\emph{Gaussian integers} to be the ring
\[
  \Z[i]:=\{a+bi: a,b\in \Z\}.
\]
We will define the word ``ring'' next time.  For now, just think of it as a
field except that multiplicative inverses of nonzero elements are not
guaranteed.  For instance, $\Z$, itself, is also a ring.
\medskip

\textbf{Factorization in $\Z[i]$.} Here, we will see that the relationship between $\Q(i)$ and $\Z[i]$ is much like the relationship
between $\Q(i)$ and $\Z[i]$.  

\begin{defn}\ 
  \begin{enumerate}
    \item Let $a,b\in\Z[i]$.  Then $a$ \emph{divides} $b$, written $a|b$ if
      there exists $c\in\Z[i]$ such that $b=ac$.
    \item An element $u\in\Z[i]$ is a \emph{unit} if $u|1$, i.e., if there
      exists $v\in\Z[i]$ such that $1=uv$.
    \item An element $p\in\Z[i]$ is \emph{prime} if it is not $0$ or a unit and
      whenever $p$ divides $ab$ for some $a,b\in\Z[i]$, then $p|a$ or $p|b$.
  \end{enumerate}
\end{defn}

\textbf{Fact.} The ring $\Z[i]$ is a unique factorization domain (UFD).  That is,
every element nonzero $a\in\Z[i]$ can be written uniquely, up to order, in the form
\[
  a = u \prod_{i=1}^{k} p_{i}^{e_{i}} 
\]
where $u$ is a unit, the $p_{i}$ are primes, and the $e_{i}$ are positive
integers.  (We will go into this topic more deeply later.)
\begin{eg}
It will follow from homework that the units of $\Z[i]$ are $\pm 1$ and $\pm i$,
and that $1\pm i$ is prime.  Although $2$ is prime in $\Z$, it is not prime in
$\Z[i]$.  Its prime factorization in $\Z[i]$ is
\[
  2 = (1+i)(1-i).
\]
\end{eg}

\begin{prop}\label{prop:pyth}
  Let~$(x,y,z)$ be a primitive Pythagorean triple.
  Then
  \[
    x+iy=uw^2
  \]
  for some $u,w\in\Z[i]$ with $u$ a unit.
\end{prop}
\begin{proof}
 Let $p\in \Z[i]$ be an arbitrary prime dividing
  $x+iy$. It suffices to show that~$p$ divides $x+iy$ an even number of times,
  i.e., $p$ occurs with even multiplicity in the prime factorization of~$x+iy$.

 Say the prime factorization of $z$ is
 \[
   z = v \prod_{i=1}^{k} p_{i}^{e_{i}},
 \]
 with $v$ a unit and the $p_{i}$ primes in $\Z[i]$.
Since
\[
  (x+iy)(x-iy)=z^{2}=v^{2}\prod_{i=1}^{k} p_{i}^{2e_{i}} 
\]
and $p|(x+iy)$, it follows that~$p=p_{i}$ for some~$i$ and $p$ divides $z^{2}$
an even number of times.  Since all of the primes in the prime factorization of
$z^{2}$ come from primes in the factorizations of $x+iy$ and $x-iy$, is suffices
to show that~$p$ does not divide $(x-iy)$.  

For the sake of contradiction, suppose $p$ divides both $x+iy$ and $x-iy$.  So
$p$ divides $z^2=(x+iy)(x-iy)$, and since~$p$ is prime, it divides~$z$.
Further, $p$ divides~$(x+iy)-(x-iy)=2x$.  Note that when we talk about dividing
here, we mean dividing as elements in the ring~$\Z[i]$, not as elements $\Z$.
Thus, for instance~$p|z$ means there exists~$s\in \Z[i]$ such that~$z=ps$.

Since~$(x,y,z)$ is primitive, it follows that $x$ and $z$ are relatively prime.
(Be careful here: this means that~$x$ and $z$ share no integer prime factors, and
we are concerned about divisibility by $p$ in $\Z[i]$.)
As we saw earlier, $z$ is odd.  Hence, $2x$ and~$z$ are relatively prime
integers. Recall that
if $a,b\in\Z$, then $\gcd(a,b)$ is an integer linear combination of $a$ and $b$.
Therefore, there exist $m,n\in\Z$ such that
\[
  2xm+zn=\gcd(2x,z)=1.
\]
Thinking again about division in~$\Z[i]$, since $p$ divides both~$2x$ and $z$,
it follows that $p|1$, and hence, $p$ is a unit, which contradicts the fact
that~$p$ is prime.  This contradiction completes the proof.
\end{proof}

\begin{cor}
  The primitive Pythagorean triples are exactly
  \[
    (m^2-n^2,2mn,m^2+n^2)\quad \text{or}\quad (2mn, m^2-n^2,m^2+n^2) 
  \]
  where~$m,n\in \Z_{>0}$ are relatively prime, not both of the same parity, and $m>n$.
\end{cor}
\begin{proof}
  We leave the check that the displayed triples are primitive if and only if $m$
  and $n$ are relatively prime and of differing parity as an exercise.  (Hint: Rule out the case of a
  shared factor of $2$ first. As part of that case, what goes wrong if $m$ and
  $n$ have the same parity?)

  Next, note that
  \begin{align*}
    (m^2-n^2)^{2}+(2mn)^{2}
    &= (m^4-2m^2n^2+n^4)+4m^2n^2\\
    &=m^4+2m^2n^2+n^4\\
    &=(m^2+n^2)^{2}.
  \end{align*}
  for all~$m,n\in\Z$. So the displayed triples are Pythagorean triples (we take
  $m>n$ so that each component is positive).

  For the converse, suppose~$(x,y,z)$ is a primitive Pythagorean triple.  By
  Proposition~\ref{prop:pyth}, 
  \[
   (x+iy)(x-iy) =  x^2+y^2 = z^2\quad\Rightarrow\quad x+iy=uw^2
  \]
  for some $u,w\in\Z[i]$ with~$u$ a unit.  Write~$w=m+ni$ with~$m,n\in\Z$. It
  follows that
  \[
    x+iy=u(m+in)^{2}=u((m^2-n^2)+2mni).
  \]
  The units in $\Z[i]$ are $\pm 1$ and $\pm i$.  Equating real and imaginary
  parts, we have
  \[
    (|x|,|y|)=(|m^2-n^2|,|2mn|)\quad \text{or}\quad (|x|,|y|)=(|2mn|,|m^2-n^2|).
  \]
  Since~$x,y>0$, the result follows.
\end{proof}

\begin{ex}  Show that the Pythagorean triple $(9,12,15)$ does not have either of the forms
  in the corollary.  Why isn't that a contradiction?  How can you modify the
  corollary so that it covers all Pythagorean triples?
\end{ex}
\end{document}
