Solution (source code)

= Solution

Use the <Einstein summation convention>, with repeated component indices summed. The following three expressions are listed separately below. For cyclic invariance of the <trace>,
$$
\operatorname{tr}(ABC)=a_{ij}b_{jk}c_{ki}=c_{ki}a_{ij}b_{jk}=\operatorname{tr}(CAB),
$$
where the middle equality commutes scalar entries, not the <matrices> themselves. If $A$ is invertible, this gives
$$
\boxed{\operatorname{tr}(ABA^{-1})=\operatorname{tr}(BA^{-1}A)=\operatorname{tr}B.}
$$
This is <similarity invariance of trace>.