\documentclass[11pt]{article}

\usepackage{amsmath,amssymb,amsthm}

\usepackage{xcolor}

%\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}
\usepackage{tikz}
\usepackage{tikz-cd}
\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=*}
\setlist[enumerate]{itemsep=1pt}

\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 Wednesday, Week 8}
\bigskip

\centerline{Smith normal form}
\bigskip

\textbf{Motivation:} Let~$\mathfrak{a}$ be a nonzero ideal in a number $\mathfrak{O}_{K}$.
It turns out that the structure of the quotient ring
$\mathfrak{O}_{K}/\mathfrak{a}$ is interesting and useful. Our goal is to
reduced the problem of determining its structure to finding a canonical form for
an integer matrix using elementary row and column operations.

We have seen that~$\mathfrak{O}_{K}$ is a free~$\Z$-module of rank~$n$, that is,
there exist $\alpha_{1},\ldots,\alpha_{n}\in\mathfrak{O}_{K}$ such that we get
a $\Z$-module isomorphism $f\colon\mathfrak{O}_{K}\to \Z^{n}$ by sending $\alpha_{i}\to
e_{i}$ and extending linearly, i.e., $\sum_{i=1}^{n} a_i \alpha_{i}\mapsto
(a_{1},\ldots,a_{n})$.  Since~$\mathfrak{O}_{K}$ is Noetherian, $\mathfrak{a}$
is also finitely generated.  By the structure theorem for finitely generated
abelian groups (i.e., finitely generated $\Z$-modules), which we will prove next
time, it will follow that there is an isomorphism $g\colon\mathfrak{a}\simeq
\Z^{n}$.  We then get a commutative diagram\footnote{The diagram being
commutative means that if there are two ways to get from one space in the diagram
to another by composing functions that appear in the diagram, then those two
compositions of functions are equal.} with exact rows:
\begin{center}
  \begin{tikzcd}
    0\ar[r]&\mathfrak{a} \ar[r] \ar[d,"{g}"',"{\rotatebox{270}{$\approx$}}"]
    &\mathfrak{O}_{K} \ar[r] \ar[d,"f"',"{\rotatebox{90}{$\approx$}}"]
    &\mathfrak{O}_{K}/\mathfrak{a} \ar[r] \ar[d,dashed]&0\\
    0\ar[r]& \Z^n \ar[r,"M"] &\Z^n \ar[r] &\Z^n/\im(M)\ar[r] &0,
  \end{tikzcd}
\end{center}
where~$M$ is an $n\times n$ matrix with integer entries.  The vertical mapping
on the right-hand side is given by~$\overline{\alpha}\mapsto\overline{f(\alpha)}$.  Since the diagrams
commute and the rows are exact, it turns out the this mapping is a well-defined
isomorphism.  Using integer row an column operations, we will see that we can
replace~$M$ with a diagonal matrix from which the structure of~$\Z^{n}/\im(M)$
will be apparent.
\bigskip

\textbf{Diagonalization of integer matrices.} 
Let~$M$ be an~$m\times n$ matrix with integer coefficients.  The matrix~$M$
determines a $\Z$-linear mapping $\Z^{n}\to\Z^{m}$ via~$v\mapsto Mv$.  The \emph{cokernel}
of~$M$ (or its associated mapping) is the~$\Z$-module
\[
  \cok(M) := \Z^m/\im{M}.
\]
Recall that~$\im(M)$ is the same as the column space of~$M$.
So the cokernel of~$M$ is the set of integer vectors~$(a_1,\dots,a_m)$ for which
we add vectors as usual, but such that any vector that is a column of~$M$ is
thought of as the zero vector.  

\begin{eg}\ 
\begin{itemize}
  \item Let~$M=[5]$, a~$1\times 1$ matrix.  Then~$\cok(M)=\Z/5\Z$.
  \item Let~$M=\diag(2,3)$, a~$2\times 2$ diagonal matrix.  Then
    \begin{align*}
      \cok(M)=\Z^2/\Span\left\{ 
	\left(\begin{array}{c}
	    2\\0
	\end{array} \right),
	\left(\begin{array}{c}
	    0\\3
      \end{array} \right)\right\}&\xrightarrow{\sim}\Z/2\Z\oplus\Z/3\Z\\
      (a,b)&\mapsto(a\bmod 2,b\bmod 3).
    \end{align*}
    Setting~$(2,0)$ equal to~$(0,0)$ in~$\Z^2$, just means we can work
    modulo~$2$ in the first coordinate.  Similarly, we can work modulo~$3$ in the
    second coordinate.
  \item Let~$M=\diag(0,0,1,2,3)$.  Then
    \begin{align*}
      \cok(M)
      \simeq \Z/0\Z\oplus\Z0\Z\oplus\Z/1\Z\oplus\Z/2\Z\oplus\Z/3\Z
  &\xrightarrow{\sim}\Z\oplus\Z\oplus\Z/2\Z\oplus\Z/3\Z\\
      (a,b,c,d,e)&\mapsto(a,b,d,e).
    \end{align*}
    Here, we use the fact that~$\Z/0\Z=\Z$ and~$\Z/1\Z=\{0\}$.  For instance,
    in~$\cok(M)$, the third coordinate is always equivalent to~$0$ modulo~$1$,
    hence, we can drop that coordinate in our isomorphism.
\end{itemize}
\end{eg}

\begin{defn}
 The {\em integer row (resp., column) operations} on an integer matrix
 consist of the following:
 \begin{enumerate}[itemsep=-2pt]
   \item swapping two rows (resp., columns);
   \item negating a row (resp., column);
   \item adding one row (resp., column) to a different row (resp., column).
 \end{enumerate}
\end{defn}

\textbf{Claim.} By performing integer row and column operations, the
matrix~$M$ can be transformed into a diagonal matrix~$D$, i.e.,~$D_{ij}=0$
for~$i\neq j$.  To make the final form unique, one may insist that the diagonal
elements satisfy~$D_{i,i}|D_{i+1,i+1}$ for all~$i$.  Start with the
the identity matrix~$I_m$ and perform all of the same row operations
on~$I_m$ as used in the reduction of~$M$ to~$D$ to create a matrix~$P$.
Similarly, start with~$I_n$ and perform the same column operations on it as
used in the reduction of~$M$ to~$D$ to create a matrix~$Q$.  Then
both~$P$ and~$Q$ have inverses that are integer matrices
(equivalently,~$\det(P)=\pm1$ and~$\det(Q)=\pm1$), and
\[
  PMQ = D.
\]
Roughly, the algorithm for reducing $M$ to a diagonal matrix goes like this: First,
permute rows, if necessary, to ensure that some nonzero entry is in
the first row.  Next, use
column operations to put the gcd of the elements in the first row into
the~$1,1$-position of the matrix.  Then use the first column to make the other
entries in the first row equal to~$0$.  Next, use row operations to put
the gcd of the first column into the~$1,1$-position,  Then use row operations to
make the other entries in the first column equal to~$0$.  By this time, you may
have put nonzero entries in the first row again.  Repeat.  Eventually, every
entry in the first row and column besides the~$1,1$-entry will be~$0$.  The
first row and column are now completely processed.  Proceed
inductively, using rows and columns operations not involving rows and columns
not previously processed.

In terms of mappings, the above process yields the commutative diagram
\begin{center}
  \begin{tikzcd}
    0\ar[r]&\Z^n \ar[r,"M"] \ar[d,"{Q^{-1}}"',"{\rotatebox{270}{$\approx$}}"]
    &\Z^m \ar[r] \ar[d,"P"',"{\rotatebox{90}{$\approx$}}"]
    &\cok(M) \ar[r] \ar[d,dashed]&0\\
    0\ar[r]& \Z^n \ar[r,"D"] &\Z^m \ar[r] &\cok(D)\ar[r] &0,
  \end{tikzcd}
\end{center}
We have an isomorphism~$\cok(M)\mapsto\cok(D)$ induced by $P$ as follows:
$\overline{v}\mapsto\overline{Pv}$.
Since~$D$ is diagonal, we may easily write $\cok(D)$ as a product of cyclic
groups of the form~$\Z/n_i\Z$ for various integers~$n_{i}$.  (Going back to our
motivating goal, note how the above procedure will allow us to identify
$\mathfrak{O}_{K}/\mathfrak{a}$ as a product of cyclic groups.)

\begin{eg} We illustrate the procedure using the following matrix.
  \[
  M=
  \left(\begin{array}{rrrr}
      2&-1&-1&0\\
      -1&4&-1&-2\\
      -1&-1&3&-1\\
      0&-2&-1&3
  \end{array} \right).
  \]
  Perform integer row and column operations to diagonalize~$M$:
  \begin{align*}
  \left(\begin{array}{rrrr}
      2&-1&-1&0\\
      -1&4&-1&-2\\
      -1&-1&3&-1\\
      0&-2&-1&3
  \end{array} \right)
  &\xrightarrow{c_1\to c_1+c_2}
  \left(\begin{array}{rrrr}
      1&-1&-1&0\\
      3&4&-1&-2\\
      -2&-1&3&-1\\
      -2&-2&-1&3
  \end{array} \right)\\[10pt]
  &\xrightarrow[c_3\to c_3+c_1]{c_2\to c_2+c_1}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      3&7&2&-2\\
      -2&-3&1&-1\\
      -2&-4&-3&3
  \end{array} \right)\\[10pt]
  &\xrightarrow[r_3\to r_3+2r_1,r_4\to r_4+2r_1]{r_2\to r_2-3r_1}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&7&2&-2\\
      0&-3&1&-1\\
      0&-4&-3&3
  \end{array} \right)\\[10pt]
  &\xrightarrow{c_2\to c_2-3c_3}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&2&-2\\
      0&-6&1&-1\\
      0&5&-3&3
  \end{array} \right)\\[10pt]
  &\xrightarrow[c_4\to c_4+2c_2]{c_3\to c_3-2c_2}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&-6&13&-13\\
      0&5&-13&13
  \end{array} \right)\\[10pt]
  &\xrightarrow[r_4\to r_4-5r_2]{r_3\to r_3+6r_2}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&0&13&-13\\
      0&0&-13&13
  \end{array} \right)\\[10pt]
  &\xrightarrow{c_4\to c_4+c_3}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&0&13&0\\
      0&0&-13&0\end{array} \right)\\[10pt]
  &\xrightarrow{r_4\to r_4+r_3}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&0&13&0\\
      0&0&0&0
  \end{array} \right).
  \end{align*}
  Apply the row operations above to~$I_4$ to get~$P$ and apply the column
  operations to~$I_4$ to get~$Q$:
  \begin{align*}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&0&1&0\\
      0&0&0&1
  \end{array} \right)
  &\xrightarrow[r_3\to r_3+2r_1,r_4\to r_4+2r_1]{r_2\to r_2-3r_1}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      -3&1&0&0\\
      2&0&1&0\\
      2&0&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow[r_4\to r_4-5r_2]{r_3\to r_3+6r_2}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      -3&1&0&0\\
      -16&6&1&0\\
      17&-5&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow{r_4\to r_4+r_3}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      -3&1&0&0\\
      -16&6&1&0\\
      1&1&1&1
  \end{array} \right)=P.
  \end{align*}
  \begin{align*}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      0&1&0&0\\
      0&0&1&0\\
      0&0&0&1
  \end{array} \right)
  &\xrightarrow{c_1\to c_1+c_2}
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      1&1&0&0\\
      0&0&1&0\\
      0&0&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow[c_3\to c_3+c_1]{c_2\to c_2+c_1}
  \left(\begin{array}{rrrr}
      1&1&1&0\\
      1&2&1&0\\
      0&0&1&0\\
      0&0&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow{c_2\to c_2-3c_3}
  \left(\begin{array}{rrrr}
      1&-2&1&0\\
      1&-1&1&0\\
      0&-3&1&0\\
      0&0&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow[c_4\to c_4+2c_2]{c_3\to c_3-2c_2}
  \left(\begin{array}{rrrr}
      1&-2&5&-4\\
      1&-1&3&-2\\
      0&-3&7&-6\\
      0&0&0&1
  \end{array} \right)\\[10pt]
  &\xrightarrow{c_4\to c_4+c_3}
  \left(\begin{array}{rrrr}
      1&-2&5&1\\
      1&-1&3&1\\
      0&-3&7&1\\
      0&0&0&1
  \end{array} \right)=Q.
  \end{align*}
  Therefore,
  \[
    P=
    \left(\begin{array}{rrrr}
      1&0&0&0\\
      -3&1&0&0\\
      -16&6&1&0\\
      1&1&1&1
  \end{array} \right)
  \quad\text{and}\quad
  Q=
  \left(\begin{array}{rrrr}
      1&-2&5&1\\
      1&-1&3&1\\
      0&-3&7&1\\
      0&0&0&1
  \end{array} \right).
  \]
  We then have
  \begin{align*}
  PMQ&= 
  \left(\begin{array}{rrrr}
      1&0&0&0\\
      -3&1&0&0\\
      -16&6&1&0\\
      1&1&1&1
  \end{array} \right)
  \left(\begin{array}{rrrr}
      2&-1&-1&0\\
      -1&4&-1&-2\\
      -1&-1&3&-1\\
      0&-2&-1&3
  \end{array} \right)
  \left(\begin{array}{rrrr}
      1&-2&5&1\\
      1&-1&3&1\\
      0&-3&7&1\\
      0&0&0&1
  \end{array} \right)\\[10pt]
  &= 
  \left(\begin{array}{cccc}
      1&0&0&0\\
      0&1&0&0\\
      0&0&13&0\\
      0&0&0&0
  \end{array} \right)=:D.
  \end{align*}
  Therefore,
  \[
    \cok(M)\simeq\cok(D)\simeq\Z/1\Z\oplus\Z/1\Z\oplus\Z/13\Z\oplus\Z
    \simeq\Z\oplus\Z/13\Z.
  \]
  The explicit isomorphism $\cok(M)\to\cok(D)$ given by the matrix~$P$
  \begin{align*}
    \cok(M)=\Z^4/\im(M)&\to\Z/1\Z\oplus\Z/1\Z\oplus\Z/13\Z\oplus\Z\qquad\to\qquad\Z/13\Z\oplus\Z\\
    (a,b,c,d)
    &\mapsto P
    \left(\begin{array}{c}
        a\\b\\c\\d
    \end{array} \right)
    =
    \left(\begin{array}{c}
        a\\-3a+b\\-16a+6b+c\\a+b+c+d
    \end{array} \right)
    \mapsto
    (-16a+6b+c,a+b+c+d).
  \end{align*}
  Check that each column of~$M$ is sent to~$(0,0)$ under this mapping, and
  thus the mapping is well-defined.
\end{eg}
\medskip

\textbf{Smith normal form.}

\begin{defn}
 An $m\times n$ integer matrix $M$ is in {\em Smith normal form} if
 \[
   M=\diag(s_1,\dots,s_k,0,\dots,0),
 \]
 a diagonal matrix, where $s_1,\dots,s_k$ are positive integers such that
 $s_i|s_{i+1}$ for all $i$.  The $s_i$ are called the {\em invariant factors}
 of $M$.
\end{defn}
\medskip

\begin{eg}
  The matrix 
  \[
  M:=
  \left(
  \begin{array}{cccc}
    1&0&0&0\\
    0&2&0&0\\
    0&0&12&0\\
    0&0&0&0\\
    0&0&0&0
  \end{array}
  \right)
  \]
  is in Smith normal form with invariant factors $s_1=1$, $s_2=2$, and $s_3=12$.  
  
  We have 
  \[
   \cok(M):= \Z^5/\im(M)\simeq \Z/1\Z\times\Z/2\Z\times\Z/{12}\Z\times\Z^2\simeq
   \Z/2\Z\times\Z/12\Z\times\Z^2.
  \]
  So $\cok(M)$ has rank $r=2$ and its invariant factors are $2$ and $12$.  
  
  Note that $1$ is an invariant factor of $M$ but not of $\cok(M)$.  By
  definition, the invariant factors of a finitely generated abelian group are
  greater than $1$; the invariant factors of $M$ equal to $1$ do not affect the
  isomorphism class of $\cok(M)$ since $\Z_1$ is the trivial group.
\end{eg}

An algorithm for computing the Smith normal form is presented
below.  For our purposes, however, the diagonalization procedure given
above is sufficient.  
\bigskip

\textbf{Computing the Smith normal form.} The Smith normal form of an integer
matrix exists and it unique.  (Uniqueness can be shown by relating the invariant
factors to the greatest common divisors of the $i\times i$ minors of the matrix
for each~$i$.)  We show existence here in the form of an
algorithm.   Let~$M$ be an $m\times n$ integer
matrix.
\medskip

  \textbf{Step 1.} By permuting rows and columns we may assume that
  $m_{11}$ is the smallest nonzero entry in absolute value.  By adding integer
  multiples of the first row to other rows or the first column to other columns,
  attempt to make all entries in the first row and first column except the
  $(1,1)$-entry equal to $0$.  If during the process any nonzero entry in the
  matrix appears with absolute value less than $m_{11}$, permute rows and
  columns to bring that entry into the $(1,1)$-position.  In this way,~$m_{11}$
  remains the smallest nonzero entry.  Since the succession of values for
  $m_{11}$ are nonzero and decreasing in magnitude, the process eventually
  terminates with a matrix of the form
      \begin{center}
	\begin{tikzpicture}[]
	  \draw (0,0) node () {$\displaystyle
	    \left(
	    \begin{array}{c|cccc}
	      m_{11}&0&0&\cdots&0\\\hline
	      0&&&&\\
	      0&&&&\\
              \vdots&&&&\\
	      0&&&&\\
	    \end{array}
	    \right)
	  $};
	  \draw (0.6,-0.4) node () {$\displaystyle M'$};
	\end{tikzpicture}
      \end{center}
  where $M'$ is an $(m-1)\times(n-1)$ integer matrix.  Negating the first row,
  if necessary, we take $m_{11}>0$.

 \textbf{Step 2.}
 If there is an entry of $M'$ that is not divisible by $m_{11}$,
 say~$m_{ij}$, then add column $j$ to column $1$ and go back to
 Step~1.  Again, since the $(1,1)$-entry is nonzero and
 decreases in magnitude, this new process terminates.  Therefore, we may assume
 that $m_{11}$ divides every entry of $M'$.

 \textbf{Step 3.} Apply Steps 1 and 2 to $M'$, and thus, by recursion, we
 produce an equivalent matrix in Smith normal form.
\end{document}
