# 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:

$\ds \map \tr {\mathbf A \mathbf B} = \sum_{i \mathop = 1}^n \sum_{j \mathop = 1}^n a_{i j} b_{j i}$

where $\map \tr {\mathbf A \mathbf B}$ denotes the trace of $\mathbf A \mathbf B$.

Using the Einstein summation convention, this can be expressed as:

$\map \tr {\mathbf A \mathbf B} = a_{i j} b_{j i}$

## Proof

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

By definition of matrix product:

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

Thus for the diagonal elements:

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

By definition of trace:

$\ds \map \tr {\mathbf C} = \sum_{i \mathop = 1}^n c_{i i}$

Hence the result.

$\blacksquare$