TITLE: If $A^2=A$ then prove that $\textrm{tr}(A)=\textrm{rank}(A)$.
QUESTION [8 upvotes]: Let $A\not=I_n$ be an $n\times n$ matrix such that $A^2=A$ , where $I_n$ is the identity matrix of order $n$.  Then prove that ,
(A) $\textrm{tr}(A)=\textrm{rank}(A)$.
(B) $\textrm{rank}(A)+\textrm{rank}(I_n-A)=n$
I found by example that these hold, but I am unable to prove them.

REPLY [4 votes]: Every vector $x$ can be written as
$$
                    x = (I-A)x + Ax
$$
The vector $x_0 = (I-A)x$ satisfies $Ax_0=0$, while $x_1 = Ax$ satisfies $Ax_1=x_1$. So you can choose a basis of elements
$$
               \{ x_{0,1},x_{0,2},\cdots,x_{0,k}\}\cup\{ x_{1,1},x_{1,2},\cdots,x_{1,n-k} \}
$$
where $A=0$ on the subspace spanned by $\{ x_{0,1},x_{0,2},\cdots,x_{0,k} \}$ and where $A=I$ on the subspace spanned by $\{ x_{1,1},x_{1,2},\cdots,x_{1,n-k}\}$. In this basis, the matrix representation of $A$ has $0$'s in the first $k$ diagonal entries and has $1$'s in the next $n-k$ diagonal positions; all other matrix entries are $0$'s. Once you understand this representation, $(A)$ and $(B)$ become more-or-less obvious.