Matrices over PID Let $R$ be a PID and $A,B\in\operatorname{M}_n(R)$ are $n\times n$ matrices such that $\det(A)\sim\det(B)\neq0$,i.e., the ideals generated by $\det(A)$ and $\det(B)$ are the same, does there exist $X,Y\in\operatorname{GL}_n(R)$ such that $XA=B$ and $BY=A$?
 A: No. 
For example with $R=\Bbb{Z}$ we can use
$$
A=\left(\begin{array}{cc}2&0\\0&2\end{array}\right)\qquad\text{and}\qquad
B=\left(\begin{array}{cc}4&0\\0&1\end{array}\right).
$$
Here for all $X\in GL_2(\Bbb{Z})$ all the entries of $XA$ are even, so we never get $XA=B$. Yet $\det A=\det B=4$.

In general the answer revolves around the concept of
invariant factors. Invariant factors of $A$ and $B$ need to be the same (up to unit factors). The diagonal entries of these two example matrices are their invariant factors, and these are not equal. OTOH if two matrices share their invariang factors then we can find matrices $P,Q\in GL_n(R)$ such that $A=PBQ$. Not quite what you asked about, but related. I guess sharing invariant factors is not a sufficient criterion. Thinking...
The free $R$-submodules of $R^n$ spanned by the rows of $A$ and $XA$ are the same. This is because the rows of $XA$ are $R$-linear combinations of rows of $A$. As $X$ is
invertible, we can also go in the other direction. The general condition is thus that $XA=B$ happens, iff the rowsubmodules $Row(A)$ (resp. $Row(B)$) of $A$ (resp. $B$) are equal. Similarly $BY=A$ has a solution $Y\in GL_n(R)$ iff the columnsubmodule of $B$ and $A$ are equal. Invariant factors only capture information about the isomorphism type of $R^n/Row(A)$ (resp. $R^n/Row(B)$).
