How do I get this matrix in Smith Normal Form? And, is Smith Normal Form unique? As part of a larger problem, I want to compute the Smith Normal Form of $xI-B$ over $\mathbb{Q}[x]$ where 
$$
B=\begin{pmatrix} 5 & 2 & -8 & -8 \\ -6 & -3 & 8 & 8 \\ -3 & -1 & 3 & 4 \\ 3 & 1 & -4 & -5\end{pmatrix}.
$$
So I do some elementary row and column operations and get to 
$$\begin{pmatrix} 1+x & -2 & 0 & 0 \\ -3(x+1) & x+3 & 0 & 0 \\ 0 & 1 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix}.
$$
Then I work with the upper left 3x3 matrix, and ultimately get:
$$\begin{pmatrix} x-3 & 0 & 0 & 0 \\ 0 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix}.
$$
So now I have a diagonal matrix (and I'm pretty sure I didn't mess anything up in performing row and column operations), except according to http://mathworld.wolfram.com/SmithNormalForm.html, the diagonal entries are supposed to divide each other, but obviously x-3 does not divide x+1. This means that: either I did something wrong, or diagonal matrix is not unique. Any ideas for how to transform my final matrix into a matrix whose diagonal entries divide each other?
 A: To expand my comment...Add column 2 to column 1. Subtract row 2 from row 1. Now you have a scalar in the (1,1) position -- rescale to 1. 
$$\begin{pmatrix} x-3 & 0 & 0 & 0 \\ 0 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
\begin{pmatrix} x-3 & 0 & 0 & 0 \\ x+1 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
$$
$$\begin{pmatrix} -4 & -x-1 & 0 & 0 \\ x+1 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
\begin{pmatrix} 1 & (1/4)(x+1) & 0 & 0 \\ x+1 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
$$
Now add $(-1/4)(x+1)$ times column 1 to column 2 (to clear everything beside 1).
$$\begin{pmatrix} 1 & 0 & 0 & 0 \\ x+1 & x+1-(1/4)(x+1)^2 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
$$
Add $-(x+1)$ times row 1 to row 2 (to clear everything below 1) & simplify the (2,2)-entry. Then rescale row 2 (so the polynomial is monic). 
$$\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & -(1/4)(x+1)(x-3) & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & (x+1)(x-3) & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & x+1\end{pmatrix} \sim
$$
Finally swap columns 2 and 4 and then rows 2 and 4 to switch the positions of $(x+1)(x-3)$ and $x+1$. We are left with the Smith normal form.
$$\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & x+1 & 0 & 0 \\ 0 & 0 & x+1 & 0 \\ 0 & 0 & 0 & (x+1)(x-3)\end{pmatrix} 
$$
