Diagonalization of a quadratic form in integers Hello,
Recently I've been studying the problem of quadratic form diagonalization. Suppose that we have a form $F(x,y,z)$ with corresponding symmetric matrix $M$. This form is equivalent to another form $F'(x',y',z')$ which is in Smith normal form. The matrix that corresponds to $F'$ is $M'$ and it is diagonal. Note that both $F$ and $F'$ have integral coefficients. It is known that there exist two matrices $A$ and $B$ (which coefficients are integers as well) such that $M' = AMB$.
Now, do I understand correctly that $F$ and $F'$ represent exactly the same set of integers? If so, am I right that there must exist a change of variables of the form
$$
x = a_{11}x' + a_{12}y' + a_{13} z'
$$
$$
y = a_{21}x' + a_{22}y' + a_{23} z'
$$
$$
z = a_{31}x' + a_{32}y' + a_{33} z'
$$
that transforms $F$ into $F'$? Finally, is it possible to deduce the matrix $(a_{ij})$ given $M'$, $M$, $A$ and $B$?
P.S. Here's an example. I have the following matrix $M$ of determinant 1:
$$
5, 13, 1
$$
$$
13, 34, 0
$$
$$
1, 0, 35
$$
It corresponds to $M' = I$ where $I$ is an identity matrix. The Sage command M.smith_form() produced the following $A$:
$$
0, 0, 1
$$
$$
0, 1, 0
$$
$$
1, 0, 0
$$
and $B$:
$$
-34, -455, 1190
$$
$$
13, 174, -455
$$
$$
1, 13, -34
$$
Now I need to find $(a_{ij})$.
 A: The actual correct manipulation is
$$  
 \left(  \begin{array}{rrr}
  3 &  -1 & 0  \\\
   -5 & 2 & 0 \\\
   -34 & 13 & 1     
\end{array} 
  \right)  \cdot 
 \left(  \begin{array}{rrr}
  5 &  13 & 1  \\\
   13 & 34 & 0 \\\
   1 & 0 & 35     
\end{array} 
  \right)  \cdot 
 \left(  \begin{array}{rrr}
  3 &  -5 & -34  \\\
   -1 & 2 & 13 \\\
   0 & 0 & 1     
\end{array} 
  \right) 
 =
 \left(  \begin{array}{rrr}
  1 &  0 & 0  \\\
   0 & 1 & 0 \\\
   0 & 0 & 1     
\end{array} 
  \right)
  $$
Taking the sign for transpose as an apostrophe, we evaluate a quadratic form with symmetric matrix $A$ at a column vector $x$ as $$ x' A x.   $$ We change from one symmetric matrix to another by taking a matrix $P$ of determinant $1$ and finding $P' A P,$ as I do above. This is called an equivalence. Typically, for dimension $3$ or higher, most authors allow $\det P = \pm 1.$
There is no guarantee that a for diagonalizes over the integers. There is also no guarantee of diagonalization over $\mathbb Q,$ as there may be the necessity for a few terms of type $xy$ or $x^2 + xy+y^2$ in $\mathbb Z_2,$ the $2$-adic integers. 
I'm not entirely sure what to recommend, but Rational Quadratic Forms by Cassels is an inexpensive Dover reprint.
