Prove that two matrices commute iff the square of the matrices commute In my textbook there is a task in which I have to prove the relation
\begin{equation}
AB=BA\Leftrightarrow A^2B^2=B^2A^2.
\end{equation}
For ($\Rightarrow$) it is easy
\begin{equation}
AB=BA\Rightarrow (AB)^2=(BA)^2\Rightarrow ABAB=BABA\Rightarrow BBAA=AABB.
\end{equation}
But how do I prove ($\Leftarrow$)?

The equivalence is incorrect. Take for example
$$A = \begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix} \qquad B = \begin{pmatrix} 2 & 1 \\ 1 & 2\end{pmatrix}.$$
