I am given a matrix of the following form:
$$M = \begin{pmatrix}
 a\_0 & -1 & \cdots & \cdots & -1 \newline
 -1 & a\_1 & \ddots & & \vdots \newline
 \vdots & \ddots & \ddots & \ddots & \vdots \newline
 \vdots & & \ddots & \ddots & -1 \newline
 -1 & \cdots & \cdots & -1 & a\_n 
\end{pmatrix}$$
 with $a\_i \in \mathbb{Z}$, $a\_i > 0$.


Is there an easy way to write down the Smith normal form of this matrix?


greatz Johannes



Smith normal form of a Matrix with -1 outside the diagonal
According to <http://www-math.mit.edu/~rstan/transparencies/snf.pdf>, 
the Smith Normal form for a nonsingular matrix $M$ is 
$$
\textrm{Diag}(e\_1,\ldots, e\_n),
$$
where $e\_1\cdots e\_i = \gcd \big( i\times i\textrm{ minors of }M \big)$. 


There are infinitely many $a\_1,\ldots, a\_n$ such that $M$ is nonsingular, so we assume that $M$ is nonsingular for convenience. The singular case may be treated separately.


**Case 1 : $M$ is nonsingular**


Since the matrix has $-1$ in most of the entries, the $i\times i$ minors are relatively easy to find. 


From this, the $1\times 1$ entry $e\_1$ is easily seen to be $1$. 


The $2\times 2$ entry $e\_2$ can be obtained from 
$$
e\_2=e\_1e\_2=\gcd\big( \{a\_i+1 | i=1,\ldots,n\}, \{a\_ia\_j-1 | 1\leq i<j\leq n\}\big).
$$
Since $a\_ia\_j-1=(a\_i+1)(a\_j+1)-(a\_i+1)-(a\_j+1)$, we have
$$
e\_2=\gcd\big( \{a\_i+1 | i=1,\ldots,n\}\big).
$$
The $3\times 3$ entry $e\_3$ is obtained from
$$
\begin{align}
e\_1e\_2e\_3&=\gcd\big( \{(a\_i+1)(a\_j+1) | 1\leq i<j\leq n\}, \{(a\_i+1)(a\_j+1)(a\_k+1) -(a\_i+1)(a\_j+1) - (a\_j+1)(a\_i+1) - (a\_k+1)(a\_i+1)|1\leq i<j<k\leq n\}\big)\\
&=\gcd\big( \{(a\_i+1)(a\_j+1) | 1\leq i<j\leq n\} \big)
\end{align}
$$


In general, for $2\leq i\leq n-1$, 
$$
e\_1\cdots e\_i = \gcd\big( \{\prod\_{k=1}^{i-1} (a\_{j\_k}+1) | 1\leq j\_1< \cdots <j\_{i-1}\leq n\}\big).
$$
Then $e\_n$ is obtained from 
$$
e\_n=\frac{\det M}{e\_1\cdots e\_{n-1}}.$$


**Case 2: $M$ is singular**


This case, we have 
$$
1 = \sum\_{i=1}^n \frac1{a\_i+1}.
$$
Since $1\neq \sum\_{i=1}^{n-1}\frac1{a\_i+1}$, the rank of $M$ is $n-1$ and we can proceed the same method as in Case 1, after putting all zeros on the last column and the last row by row/column operations. 


