How to prove $\operatorname{Tr}(AB) = \operatorname{Tr}(BA)$?

Observe that if $A$ and $B$ are $n\times n$ matrices, $A=(a_{ij})$, and $B=(b_{ij})$, then $$(AB)_{ii} = \sum_{k=1}^n a_{ik}b_{ki},$$ so $$ \operatorname{Tr}(AB) = \sum_{j=1}^n\sum_{k=1}^n a_{jk}b_{kj}. $$ Conclude calculating the term $(BA)_{ii}$ and comparing both traces.


The efficient @hjhjhj57: answer

$$\text{Tr}(AB) = \text{Tr}(BA)= \sum a_{ij} b_{ji}$$

Now we can start to understand why if we do a circular permutation of the factors the expression

$$\text{Tr}( A_1 A_2 \ldots A_m)$$

does not change, and what is the expression.

Assume now $A$,$B$ square. Then certainly $\det(AB) = \det(BA)$, using the multiplicative property of the $\det$.

In fact, the matrices $AB$ and $BA$ have the same characteristic polynomial, so in particular the same trace, and the same determinant.


For any couple $(A,B)$ of $n\times n$ matrices with complex entries, the following identity holds: $$ \operatorname{Tr}(AB) = \operatorname{Tr}(BA).$$

Proof. Assuming $A$ is an invertible matrix, $AB$ and $BA$ share the same characteristic polynomial, since they are conjugated matrices due to $BA = A^{-1}(AB)A$. In particular they have the same trace. Equivalently, they share the same eigenvalues (counted according to their algebraic multiplicity) hence they share the sum of such eigenvalues. On the other hand, if $A$ is a singular matrix then $A_\varepsilon\stackrel{\text{def}}{=} A+\varepsilon I$ is an invertible matrix for any $\varepsilon\neq 0$ small enough. It follows that $\operatorname{Tr}(A_\varepsilon B) = \operatorname{Tr}(B A_\varepsilon)$, and since $\operatorname{Tr}$ is a continuous operator, by considering the limits of both sides as $\varepsilon\to 0$ we get $\operatorname{Tr}(AB)=\operatorname{Tr}(BA)$ just as well.