Solution (source code)

= Solution

The <matrix trace> is the sum of diagonal entries, $\operatorname{tr}A=\sum_{i=1}^nA_{ii}$. For any two square <matrices>,
$$
\operatorname{tr}(BC)=\sum_{i,j}B_{ij}C_{ji}
=\sum_{j,i}C_{ji}B_{ij}=\operatorname{tr}(CB).
$$
Apply this <cyclic property of the trace> with $B=T$ and $C=AT^{-1}$:
$$
\boxed{\operatorname{tr}(TAT^{-1})=\operatorname{tr}(AT^{-1}T)=\operatorname{tr}A.}
$$
Thus <matrix similarity> preserves the <matrix trace>; no assumption that either <matrix> is diagonalizable is needed.