<s>[INST] If $A$ and $B$ are two matrices such that $AB=B$ and $BA=A$ then how to show that $A^2+B^2$ equals $A+B$? 
If $A$ and $B$ are two matrices such that $AB=B$ and $BA=A$ then  $A^2+B^2$ equals ?
(a) $2AB$
(b) $2BA$
(c) $A+B$
(d) $AB$

I tried 
$(A+B)^2=A^2+B^2+AB+BA$
or,$A^2+B^2=(A+B)^2-AB-BA$
$=(A+B)^2-A-B$
$
=(A+B)^2-(A+B)=(A+B)(A+B-1)$
How to reach the answer from here?
 [/INST] More precisely, there is a positive integer $p$ s.t. $A,B$ are simultaneously similar to $A'=\begin{pmatrix}I_p&0\\0&0_{n-p}\end{pmatrix},B'=\begin{pmatrix}I_p&Q\\0&0_{n-p}\end{pmatrix}$ where $Q$ is an arbitrary $(p\times n-p)$ matrix.
Proof. Since $A^2=A$, there is $p$ s.t. $A$ is similar to $A'=\begin{pmatrix}I_p&0\\0&0_{n-p}\end{pmatrix}$; let $B'=\begin{pmatrix}P_p&Q\\R&S_{n-p}\end{pmatrix}$. Then just proceed with identification in the relations $A'B'=B',B'A'=A'$.
</s>