Solution (source code)

= Solution

For every nonnegative integer $k$,
$$
(BA)^{k+1}=B(AB)^kA.
$$
Consequently, if $m_{AB}(AB)=0$, then
$$
(BA)m_{AB}(BA)=B\,m_{AB}(AB)A=0.
$$
By the divisibility characterization of the <minimal polynomial>,
$$
m_{BA}(t)\mid t,m_{AB}(t).
$$
Interchanging $A$ and $B$ also gives $m_{AB}(t)\mid t,m_{BA}(t)$. Therefore the <Minimal polynomials of AB and BA> can differ only in the exponent of the factor $t$, and that exponent differs by at most one.

If $AB$ is <diagonalizable matrix>[diagonalizable], its minimal polynomial has no repeated roots. The preceding divisibility says that every nonzero <Jordan block> of $BA$ has size one and every zero-eigenvalue block has size at most two. Squaring $BA$ preserves the one-dimensional nonzero blocks and sends every size-at-most-two nilpotent block to zero. Thus the <Jordan normal form> of $(BA)^2$ is diagonal, so
$$
\boxed{AB\text{ diagonalizable}\ \Longrightarrow\ (BA)^2\text{ diagonalizable}}.
$$