Special type of normal form of matrix in principal ideal domain $\DeclareMathOperator\GL{GL}\DeclareMathOperator\PSL{PSL}$I want to ask the following, Given $X \in n \times n$ matrix that all the elements are integers and $X=X^{T}$ is symmetric.
Can one always find a matrix $W$ an $n \times n$  matrix that all the elements are integers and $K \in \PSL(n, \mathbb{Z})$ i.e. $\det(K)=\pm 1$ such that
$
X=W^{T}KW
$ ?
For example, if $X=\begin{pmatrix}
0 & m\\
m & 0  
\end{pmatrix}, m \geq 2.$ One can write
$X=\begin{pmatrix}
0 & m\\
1 & 0  
\end{pmatrix}\begin{pmatrix}
0 & 1\\
1 & 0  
\end{pmatrix}\begin{pmatrix}
0 & 1\\
m & 0  
\end{pmatrix}$ which satisfy the requirements.
I believe this is true (when $\det(X)=\pm 1$ or $n=1$ it is trivial). But I can not prove it.
This is very close to the Smith normal form. But I can not find such decomposition in the literature.
Is there any literature or comments? Very appreciated.
 A: As LSpice mentioned, you want $K\in GL_n(\mathbb{Z})$, not $PSL_n(\mathbb{Z})$. As abx noticed, a necessary condition is that $\det(X)=\pm m^2$ for some integer $m$.
However, this condition is not sufficient.
Here is a infinite family of counterexamples.
Let  $X=d I_2$ where $d$ is a positive integer which is not a sum of two squares (for example , take $d$ to be a prime number congruent to $3$ modulo $4$).
I claim that the desired decomposition does not exist.
Assume the contrary, and let $U=com(W)^t$, so that $W^{-1}=\det(W)^{-1} U$. Note that $U$ has integer entries.
Since $\det(K)\det(W)^2=\det(X)=d^2$, we have $\det(K)=1$, $\det(W)^2=d^2$,  and thus $U^t X U=d^2 K$, that is $U^t U=d K$. Notice that it implies that $K$ is positive definite since $d\geq 1$.
Since $K$ is a positive definite symmetric matrice with integer coefficients having determinant $1$, it is the Gram matrix of a positive definite unimodular lattice.  Now, since there is only one positive definite unimodular lattice of rank $2$ up to isomorphism, that is $\mathbb{Z}^2$ (see for example Quadratic and Hermitian forms, W. Scharlau, p.398-399), we have $K=V^t V$ for some $V\in GL_2(\mathbb{Z})$. Hence we get $R^t R=d I_2$, where $R=UV^{-1}$. Note that $R$ has integral coefficients, since $U$ and $V^{-1}$ do. Now, looking at the coefficient in position $(1,1)$, we get that $d$ is a sum of two squares, a contradiction.
