Trace of Matrix Product

Theorem
Let $\mathbf A$ and $\mathbf B$ be square matrices of order $n$.

Let $\mathbf A \mathbf B$ be the (conventional) matrix product of $\mathbf A$ and $\mathbf B$.

Then:
 * $\displaystyle \operatorname{tr} \left({\mathbf A \mathbf B}\right) = \sum_{i \mathop = 1}^n \sum_{j \mathop = 1}^n a_{i j} b_{j i}$

where $\operatorname{tr} \left({\mathbf A \mathbf B}\right)$ denotes the trace of $\mathbf A \mathbf B$.

Using the summation convention, this can be expressed as:
 * $\operatorname{tr} \left({\mathbf A \mathbf B}\right) = a_{i j} b_{j i}$

Proof
Let $\mathbf C := \mathbf A \mathbf B$.

By definition of matrix product:


 * $\displaystyle c_{i k} = \sum_{j \mathop = 1}^n a_{i j} b_{j k}$

Thus for the diagonal elements:


 * $\displaystyle c_{i i} = \sum_{j \mathop = 1}^n a_{i j} b_{j i}$

By definition of trace:


 * $\displaystyle \operatorname{tr} \left({\mathbf C}\right) = \sum_{i \mathop = 1}^n c_{i i}$

Hence the result.