a) If A is invertible or A=On then clearly AB−BA=On. Assume A=On, with det(A)=0. Let P∈C[X] be the minimal polynomial of the matrix A. Since P(0)=0 and P=X, the polynomial P has the form P=Xk+ak−1Xk−1+⋯+a1X, where 2≤k≤n. From the relation P(A)B=On and the hypothesis, we obtain
Ak−1+ak−1Ak−2+⋯+a2A+a1AB=On.(1)
Since P is minimal, we have a1=0 and AB=−a11(Ak−1+ak−1Ak−2+⋯+a2A). So AB commutes with A. Therefore A=A2B=A(AB)=ABA. Then, by multiplying with BA the relation (1) to the right, we obtain
Ak−1+ak−1Ak−2+⋯+a2A+a1AB2A=On.(2)
From (1) and (2) it results a1(AB2A−AB)=On. Since a1=0, we get AB2A=AB. Thus, (AB−BA)2=(ABA)B−AB2A−B(A2B)+B(ABA)=AB−AB−BA+BA=On.
Alternative solution.
a) From rank(A)=rank(A2)≤rank(A2)≤rank(A), we obtain rank(A)=rank(A2). Denote r=rank(A). There are the matrices X∈Mn,r(C) and Y∈Mr,n(C), with rank(X)=rank(Y)=r, such that A=XY. We have YX∈Mr(C) and
r=rank(A)=rank(A2)=rank((XY)2)=rank(X(YX)Y)≤rank(YX).
Hence YX is an invertible matrix and from the relation A2B=A we find YBX=Ir. Therefore ABA=(XY)B(XY)=X(YBX)Y=XY=A. From the relations A2B=A and ABA=A, we get
(AB−BA)2=(AB)2+(BA)2−AB2A−BA2B=(ABA)B+B(ABA)−AB2A−B(A2B)=AB+BA−AB2A−BA=AB(In−BA)
and
(AB−BA)3=AB(In−BA)(AB−BA)=AB(AB−BA−BA2B+(BA)2)=AB(AB−BA−B(A2B)+B(ABA))=AB(AB−BA−BA+BA)=AB(AB−BA)=(ABA)B−AB2A=AB−(AB)(BA)=AB(In−BA).
Thus, (AB−BA)3=(AB−BA)2. It follows that, if λ∈C is an eigenvalue of the matrix AB−BA, then λ3=λ2, hence λ∈{0,1}. But Tr(AB−BA)=0. Then all the eigenvalues of the matrix AB−BA are 0. Therefore (AB−BA)n=On. From the proved relation (AB−BA)3=(AB−BA)2 we deduce (AB−BA)2=On.
b) Let us define the matrices A=(On−kOk,n−kOn−k,kIk), B=(On−kOk,n−kCIk), where C∈Mn−k,k(C) is an arbitrary matrix with rank(C)=k≤n−k (for k=0, we define A=B=On). We have A2B=AB=A, BA=B and AB−BA=A−B=(On−kOk,n−k−COk), so rank(AB−BA)=k.