If $A,B$ are square matrices and $A^2=A,B^2=B,AB=BA$, then calculate $\det (A-B)$.
My solution: consider $(A-B)^3=A^3-3A^2B+3AB^2-B^3=A^3-B^3=A-B$, then $\det(A-B)=0\vee 1\vee -1$
The result of the book is the same as mine, but their solution is different. They begin: "Since $A^2=A$ and $B^2=B$, $A$ and $B$ are diagonalizable; moreover, since $AB=BA$, then there exists a invertible matrix $P$ such that $P^{-1}AP$ and $P^{-1}BP$ are diagonal matrices."
The statement has two parts, and I don't understand both. So I really need a specific explanation for those two parts.
Thanks in advance.