Given $A,B$ are $n \times n$ matrices, $(A+B)^2=A+B,r(A+B)=r(A)+r(B)$. Prove: $A^2=A,B^2=B$ Given $A,B$ are $n \times n$ matrices, $(A+B)^2=A+B,r(A+B)=r(A)+r(B)$.
Prove: $A^2=A,B^2=B$
I don't know how to use $r(A+B)=r(A)+r(B)$
 A: Following what user1551 said in the comments, we have: $\operatorname{Im}(A)\cap\operatorname{Im}(B) = \{0\}$.
(You did not specify the base field, so I'll just take any field $\mathbb{K}$.)
Denote the transpose of a matrix $M$ as $M^T$.
Since $r(M) = r(M^T)$ for all matrices $M \in \mathcal{M}_n(\mathbb{K})$ (one way to envision it is that the rank of a matrix $M$ is the maximum $k$ such that there exists an invertible minor $N$ of $M$ of size $k \times k$, and then see that for all minors $N$, $N^T$ is a minor of $M^T$, as well as recall that $\det(N) = \det(N^T)$), we also have:
$$r\left(A^T + B^T\right) = r\left((A+B)^T\right) = r\left(A^T\right) + r\left(B^T\right)$$
Therefore, from the same arguments as before: $\operatorname{Im}\left(A^T\right)\cap\operatorname{Im}\left(B^T\right) = \{0\}$.
Now, let $x \in \mathbb{K}^n$. We get:
$$Ax + Bx = \left(A+B\right)^2x = \left(A^2 + AB + BA + B^2\right)x = A\big((A + B)x\big) + B\big((A+B)x\big)$$
Thus, from $\operatorname{Im}(A)\cap\operatorname{Im}(B) = \{0\}$, we obtain:
$$\begin{cases}Ax = A\big((A + B)x\big)\\ Bx = B\big((A+B)x\big)\end{cases} \quad\Rightarrow\quad \begin{cases}A^2x = (A - AB)x\\ B^2x = (B - BA)x\end{cases}$$
Since this holds for any $x \in \mathbb{K}^n$, we can conclude that:
$$\begin{cases}A^2 = (A - AB)\\ B^2 = (B - BA)\end{cases}$$
By transposing everything, this grants:
$$\begin{cases}(A^2)^T = (A - AB)^T\\ (B^2)^T = (B - BA)^T\end{cases} \quad\Rightarrow\quad \begin{cases}(A^T)^2 = A^T - B^TA^T\\ (B^T)^2 = B^T - A^TB^T\end{cases}$$
Again, let $y \in \mathbb{K}^n$. We have:
$$\begin{cases}A^T(A^Ty) = A^Ty + B^T(-A^Ty)\\ B^T(B^Ty) = B^Ty + A^T(-B^Ty)\end{cases}$$
Hence, this time with $\operatorname{Im}\left(A^T\right)\cap\operatorname{Im}\left(B^T\right) = \{0\}$:
$$\begin{cases}A^T(A^Ty) &= A^Ty \\ 0 &= B^T(-A^Ty)\\ B^T(B^Ty) &= B^Ty \\ 0 &= A^T(-B^Ty)\end{cases}$$
Due to this holding for all $y \in \mathbb{K}^n$, the first and third lines give us $(A^T)^2 = A^T$ and $(B^T)^2 = B^T$, therefore: $A^2 = A$ and $B^2 = B$, and we have finished. (The second and fourth lines give more precision to the result: the image of $A$ is a subspace of the kernel of $B$ and vice-versa).
A: It seems like you are working on your linear algebra worksheet(very similar to mine).@Burno B 's answer is beautiful,but there's also a tricky method just using the properties of the rank of matrix.
We know that the elementary row (or column) transformation doesn't change the rank of a matrix,so we have
$$
\begin{pmatrix}
A&0&0\\
0&B&0\\
0&0&I-A-B
\end{pmatrix}
\sim
\begin{pmatrix}
A&0&0\\
0&B&0\\
A&B&I-A-B
\end{pmatrix}
\sim
\begin{pmatrix}
A&0&A\\
0&B&B\\
A&B&I
\end{pmatrix}
$$
$$
\sim
\begin{pmatrix}
A-A^2&-AB&0\\
-BA&B-B^2&0\\
A&B&I
\end{pmatrix}
\sim
\begin{pmatrix}
A-A^2&-AB&0\\
-BA&B-B^2&0\\
0&0&I
\end{pmatrix}
$$
and
$$
r(A)+r(B)+r(I-A-B)=r\begin{pmatrix}
A-A^2&-AB\\
-BA&B-B^2
\end{pmatrix}+r(I)=r\begin{pmatrix}
A-A^2&-AB\\
-BA&B-B^2
\end{pmatrix}+n
$$
Also,
$$
(A+B)^2=(A+B)\implies r(A+B)+r(I-A-B)=n
$$
$$
r(A+B)=r(A)+r(B)\implies r(A)+r(B)+r(I-A-B)=n
$$
which implies
$$
r\begin{pmatrix}
A-A^2&-AB\\
-BA&B-B^2
\end{pmatrix}=0
$$
so
$$
A^2=A,B^2=B,AB=BA=0
$$
