# Smith normal form

In mathematics, the Smith normal form is a normal form that can be defined for any matrix (not necessarily square) with entries in a principal ideal domain (PID). The Smith normal form of a matrix is diagonal, and can be obtained from the original matrix by multiplying on the left and right by invertible square matrices. In particular, the integers are a PID, so one can always calculate the Smith normal form of an integer matrix. The Smith normal form is very useful for working with finitely generated modules over a PID, and in particular for deducing the structure of a quotient of a free module.

## Definition

Let A be a nonzero m×n matrix over a principal ideal domain R. There exist invertible ${\displaystyle m\times m}$ and ${\displaystyle n\times n}$-matrices S, T so that the product S A T is

${\displaystyle {\begin{pmatrix}\alpha _{1}&0&0&&\cdots &&0\\0&\alpha _{2}&0&&\cdots &&0\\0&0&\ddots &&&&0\\\vdots &&&\alpha _{r}&&&\vdots \\&&&&0&&\\&&&&&\ddots &\\0&&&\cdots &&&0\end{pmatrix}}.}$

and the diagonal elements ${\displaystyle \alpha _{i}}$ satisfy ${\displaystyle \alpha _{i}\mid \alpha _{i+1}\;\forall \;1\leq i. This is the Smith normal form of the matrix A. The elements ${\displaystyle \alpha _{i}}$ are unique up to multiplication by a unit and are called the elementary divisors, invariants, or invariant factors. They can be computed (up to multiplication by a unit) as

${\displaystyle \alpha _{i}={\frac {d_{i}(A)}{d_{i-1}(A)}},}$

where ${\displaystyle d_{i}(A)}$ (called i-th determinant divisor) equals the greatest common divisor of all ${\displaystyle i\times i}$ minors of the matrix A and ${\displaystyle d_{0}(A):=1}$.

## Algorithm

The first goal is to find invertible square matrices S and T such that the product S A T is diagonal. This is the hardest part of the algorithm. Once diagonality is achieved, it becomes relatively easy to put the matrix into Smith normal form. Phrased more abstractly, the goal is to show that, thinking of A as a map from ${\displaystyle R^{n}}$ (the free R-module of rank n) to ${\displaystyle R^{m}}$ (the free R-module of rank m), there are isomorphisms ${\displaystyle S:R^{m}\to R^{m}}$ and ${\displaystyle T:R^{n}\to R^{n}}$ such that ${\displaystyle S\cdot A\cdot T}$ has the simple form of a diagonal matrix. The matrices S and T can be found by starting out with identity matrices of the appropriate size, and modifying S each time a row operation is performed on A in the algorithm by the same row operation, and similarly modifying T for each column operation performed. Since row operations are left-multiplications and column operations are right-multiplications, this preserves the invariant ${\displaystyle A'=S'\cdot A\cdot T'}$ where ${\displaystyle A',S',T'}$ denote current values and A denotes the original matrix; eventually the matrices in this invariant become diagonal. Only invertible row and column operations are performed, which ensures that S and T remain invertible matrices.

For a in R \ {0}, write δ(a) for the number of prime factors of a (these exist and are unique since any PID is also a unique factorization domain). In particular, R is also a Bézout domain, so it is a gcd domain and the gcd of any two elements satisfies a Bézout's identity.

To put a matrix into Smith normal form, one can repeatedly apply the following, where t loops from 1 to m.

### Step I: Choosing a pivot

Choose jt to be the smallest column index of A with a non-zero entry, starting the search at column index jt-1+1 if t > 1.

We wish to have ${\displaystyle a_{t,j_{t}}\neq 0}$; if this is the case this step is complete, otherwise there is by assumption some k with ${\displaystyle a_{k,j_{t}}\neq 0}$, and we can exchange rows ${\displaystyle t}$ and k, thereby obtaining ${\displaystyle a_{t,j_{t}}\neq 0}$.

Our chosen pivot is now at position (t, jt).

### Step II: Improving the pivot

If there is an entry at position (k,jt) such that ${\displaystyle a_{t,j_{t}}\nmid a_{k,j_{t}}}$, then, letting ${\displaystyle \beta =\gcd \left(a_{t,j_{t}},a_{k,j_{t}}\right)}$, we know by the Bézout property that there exist σ, τ in R such that

${\displaystyle a_{t,j_{t}}\cdot \sigma +a_{k,j_{t}}\cdot \tau =\beta .}$

By left-multiplication with an appropriate invertible matrix L, it can be achieved that row t of the matrix product is the sum of σ times the original row t and τ times the original row k, that row k of the product is another linear combination of those original rows, and that all other rows are unchanged. Explicitly, if σ and τ satisfy the above equation, then for ${\displaystyle \alpha =a_{t,j_{t}}/\beta }$ and ${\displaystyle \gamma =a_{k,j_{t}}/\beta }$ (which divisions are possible by the definition of β) one has

${\displaystyle \sigma \cdot \alpha +\tau \cdot \gamma =1,}$

so that the matrix

${\displaystyle L_{0}={\begin{pmatrix}\sigma &\tau \\-\gamma &\alpha \\\end{pmatrix}}}$

is invertible, with inverse

${\displaystyle {\begin{pmatrix}\alpha &-\tau \\\gamma &\sigma \\\end{pmatrix}}.}$

Now L can be obtained by fitting ${\displaystyle L_{0}}$ into rows and columns t and k of the identity matrix. By construction the matrix obtained after left-multiplying by L has entry β at position (t,jt) (and due to our choice of α and γ it also has an entry 0 at position (k,jt), which is useful though not essential for the algorithm). This new entry β divides the entry ${\displaystyle a_{t,j_{t}}}$ that was there before, and so in particular ${\displaystyle \delta (\beta )<\delta (a_{t,j_{t}})}$; therefore repeating these steps must eventually terminate. One ends up with a matrix having an entry at position (t,jt) that divides all entries in column jt.

### Step III: Eliminating entries

Finally, adding appropriate multiples of row t, it can be achieved that all entries in column jt except for that at position (t,jt) are zero. This can be achieved by left-multiplication with an appropriate matrix. However, to make the matrix fully diagonal we need to eliminate nonzero entries on the row of position (t,jt) as well. This can be achieved by repeating the steps in Step II for columns instead of rows, and using multiplication on the right by the transpose of the obtained matrix L. In general this will result in the zero entries from the prior application of Step III becoming nonzero again.

However, notice that the ideals generated by the elements at position (t,jt) form an ascending chain, because entries from a later step always divide entries from a previous step. Therefore, since R is a Noetherian ring (it is a PID), the ideals eventually become stationary and do not change. This means that at some stage after Step II has been applied, the entry at (t,jt) will divide all nonzero row or column entries before applying any more steps in Step II. Then we can eliminate entries in the row or column with nonzero entries while preserving the zeros in the already-zero row or column. At this point, only the block of A to the lower right of (t,jt) needs to be diagonalized, and conceptually the algorithm can be applied recursively, treating this block as a separate matrix. In other words, we can increment t by one and go back to Step I.

### Final step

Applying the steps described above to the remaining non-zero columns of the resulting matrix (if any), we get an ${\displaystyle m\times n}$-matrix with column indices ${\displaystyle j_{1}<\ldots where ${\displaystyle r\leq \min(m,n)}$. The matrix entries ${\displaystyle (l,j_{l})}$ are non-zero, and every other entry is zero.

Now we can move the null columns of this matrix to the right, so that the nonzero entries are on positions ${\displaystyle (i,i)}$ for ${\displaystyle 1\leq i\leq r}$. For short, set ${\displaystyle \alpha _{i}}$ for the element at position ${\displaystyle (i,i)}$.

The condition of divisibility of diagonal entries might not be satisfied. For any index ${\displaystyle i for which ${\displaystyle \alpha _{i}\nmid \alpha _{i+1}}$, one can repair this shortcoming by operations on rows and columns ${\displaystyle i}$ and ${\displaystyle i+1}$ only: first add column ${\displaystyle i+1}$ to column ${\displaystyle i}$ to get an entry ${\displaystyle \alpha _{i+1}}$ in column i without disturbing the entry ${\displaystyle \alpha _{i}}$ at position ${\displaystyle (i,i)}$, and then apply a row operation to make the entry at position ${\displaystyle (i,i)}$ equal to ${\displaystyle \beta =\gcd(\alpha _{i},\alpha _{i+1})}$ as in Step II; finally proceed as in Step III to make the matrix diagonal again. Since the new entry at position ${\displaystyle (i+1,i+1)}$ is a linear combination of the original ${\displaystyle \alpha _{i},\alpha _{i+1}}$, it is divisible by β.

The value ${\displaystyle \delta (\alpha _{1})+\cdots +\delta (\alpha _{r})}$ does not change by the above operation (it is δ of the determinant of the upper ${\displaystyle r\times r}$ submatrix), whence that operation does diminish (by moving prime factors to the right) the value of

${\displaystyle \sum _{j=1}^{r}(r-j)\delta (\alpha _{j}).}$

So after finitely many applications of this operation no further application is possible, which means that we have obtained ${\displaystyle \alpha _{1}\mid \alpha _{2}\mid \cdots \mid \alpha _{r}}$ as desired.

Since all row and column manipulations involved in the process are invertible, this shows that there exist invertible ${\displaystyle m\times m}$ and ${\displaystyle n\times n}$-matrices S, T so that the product S A T satisfies the definition of a Smith normal form. In particular, this shows that the Smith normal form exists, which was assumed without proof in the definition.

## Applications

The Smith normal form is useful for computing the homology of a chain complex when the chain modules of the chain complex are finitely generated. For instance, in topology, it can be used to compute the homology of a simplicial complex or CW complex over the integers, because the boundary maps in such a complex are just integer matrices. It can also be used to determine the invariant factors that occur in the structure theorem for finitely generated modules over a principal ideal domain, which includes the fundamental theorem of finitely generated abelian groups.

## Example

As an example, we will find the Smith normal form of the following matrix over the integers.

${\displaystyle {\begin{pmatrix}2&4&4\\-6&6&12\\10&-4&-16\end{pmatrix}}}$

The following matrices are the intermediate steps as the algorithm is applied to the above matrix.

${\displaystyle \to {\begin{pmatrix}2&0&0\\-6&18&24\\10&-24&-36\end{pmatrix}}\to {\begin{pmatrix}2&0&0\\0&18&24\\0&-24&-36\end{pmatrix}}}$
${\displaystyle \to {\begin{pmatrix}2&0&0\\0&18&24\\0&-6&-12\end{pmatrix}}\to {\begin{pmatrix}2&0&0\\0&6&12\\0&18&24\end{pmatrix}}}$
${\displaystyle \to {\begin{pmatrix}2&0&0\\0&6&12\\0&0&-12\end{pmatrix}}\to {\begin{pmatrix}2&0&0\\0&6&0\\0&0&12\end{pmatrix}}}$

So the Smith normal form is

${\displaystyle {\begin{pmatrix}2&0&0\\0&6&0\\0&0&12\end{pmatrix}}}$

and the invariant factors are 2, 6 and 12.

## Similarity

The Smith normal form can be used to determine whether or not matrices with entries over a common field are similar. Specifically two matrices A and B are similar if and only if the characteristic matrices ${\displaystyle xI-A}$ and ${\displaystyle xI-B}$ have the same Smith normal form.

For example, with

{\displaystyle {\begin{aligned}A&{}={\begin{bmatrix}1&2\\0&1\end{bmatrix}},&&{\mbox{SNF}}(xI-A)={\begin{bmatrix}1&0\\0&(x-1)^{2}\end{bmatrix}}\\B&{}={\begin{bmatrix}3&-4\\1&-1\end{bmatrix}},&&{\mbox{SNF}}(xI-B)={\begin{bmatrix}1&0\\0&(x-1)^{2}\end{bmatrix}}\\C&{}={\begin{bmatrix}1&0\\1&2\end{bmatrix}},&&{\mbox{SNF}}(xI-C)={\begin{bmatrix}1&0\\0&(x-1)(x-2)\end{bmatrix}}.\end{aligned}}}

A and B are similar because the Smith normal form of their characteristic matrices match, but are not similar to C because the Smith normal form of the characteristic matrices do not match.