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?
 A: First, here is how you can figure out the answer by process of elimination. We can see that if $A$ and $B$ are both identity, then the condition is satisfied, and $A^2 + B^2 = 2I$ in that case. This rules out option (d). Next, note that $A^2 + B^2$ is symmetric in $A$ and $B$, so if (a) were correct, then by symmetry (b) must be correct also. So that leaves (c).
Now, this doesn't establish that (c) is actually correct. To solve the problem properly, note that
$$A = BA = (AB)A = A(BA) = A^2$$,
and similarly $B = B^2$. Thus, $A^2 + B^2 = A + B$.
A: 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'$.
