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?

-
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. Wipe out everything in its row and column. Now your diagonal is 1,x+1,x+1,x+1. –  Bill Cook Oct 30 '11 at 1:14
Also, Smith Normal Form is unique (if you rescale all polynomials to monic polynomials at the end). –  Bill Cook Oct 30 '11 at 1:16
Thank you so much, bill! –  Alison Oct 30 '11 at 3:01
Wait, do you meant $(x+1)(x+5)$? –  Alison Oct 30 '11 at 3:37
@BillCook Please consider converting your comment into an answer, so that this question gets removed from the unanswered tab. If you do so, it is helpful to post it to this chat room to make people aware of it (and attract some upvotes). For further reading upon the issue of too many unanswered questions, see here, here or here. –  Julian Kuelshammer Jun 11 '13 at 20:26

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}$$

-