Is the relation $a $~$ b$ iff $ ab$ is square on $\mathbb{Z}$ transitive? I'm trying to determine whether the relation given above is a equivalence relation. I've already proved it is reflexive and symmetric, but I'm stuck trying to prove (or disprove) its transitivity. I got this far:
if $a$ ~ $b$ and $b$ ~ $c$ then that must mean that $ab$ and $bc$ are square. So, considering a square number multiplied by a square number is itself a square number, $abbc = ac\cdot b^2$ is square. But I'm not really getting anywhere from here. Help would be greatly appreciated!
 A: The given relation is not transitive: this is due to the fact that $a0=0$ is a square for every $a$, so the equivalence class of $0$ would be the whole $\mathbb{Z}$. So, for instance,
$$
2\sim 0,\quad 0\sim 3
$$
but $2\not\sim 3$.
If you consider the relation over $\mathbb{Z}\setminus\{0\}$, then it is indeed an equivalence relation. Symmetry and reflexivity are obvious, so let's tackle transitivity. Assume $a\sim b$ and $b\sim c$. Then
$$
ab=h^2,\quad bc=k^2
$$
that implies $ab^2c=(hk)^2$. Now $b$ divides $h^2$ and also $k^2$, so $b^2$ divides $h^2k^2$; thus
$$
\frac{h^2k^2}{b^2}=\left(\frac{hk}{b}\right)^{\!2}
$$
Now we can use the fact that if an integer has a rational square root, then this square root is actually an integer. Indeed, suppose
$$
\left(\frac{p}{q}\right)^{\!2}=n
$$
is an integer, with $\gcd(p,q)=1$. Then $p^2=nq^2$ and, if a prime divides $q$ it must also divide $p^2$, hence $p$. So no prime can divide $q$ and therefore $q=\pm1$.
A: Apparently the relation is transitive on $\mathbb{Z}\setminus\{0\}$.
Assume $a\sim b$ and $b\sim c$ with $x^2 = ab$ and $y^2 = bc$. Let $z = \frac{xy}{b}$. Then $z^2 = \frac{abbc}{b^2} = ac$. We need to show, that $b \mid xy$. We have $b \mid x^2,y^2$, so $b^2 \mid x^2y^2$, hence $b \mid xy$. This is because there is a $k\in \mathbb{Z}$ with $b^2k = x^2y^2$ and so $b\sqrt{k} = xy$. If $\sqrt{k}\notin \mathbb{Z}$, then $\sqrt{k}$ is irrational and then so is $b\sqrt{k}$ (Contradiction). So $a\sim c$.
If we include to $0$, we have the following counterexample:
We have $1\sim 0$ and $0\sim 2$ because $0^2 = 1\cdot 0$ and $0^2 = 0\cdot 2$, but clearly $1\not\sim 2$.
