The Trace
The sum of the diagonal entries equals the sum of the eigenvalues and is invariant under cyclic reordering.
Definition
The trace of a square matrix A, written tr(A), is the sum of its diagonal entries: tr(A) = sum of A[i,i]. Despite its simple definition, the trace carries deep meaning: it equals the sum of the eigenvalues of A, counted with multiplicity, even when those eigenvalues are complex or the matrix is not diagonalizable.
Properties
- tr(A + B) = tr(A) + tr(B)
- tr(cA) = c tr(A)
- tr(A^T) = tr(A)
- tr(AB) = tr(BA), the cyclic property
- tr(A) = sum of eigenvalues
The cyclic property tr(AB) = tr(BA) holds even when AB and BA differ, and it extends to tr(ABC) = tr(BCA) = tr(CAB). This makes the trace invariant under a change of basis: tr(P^{-1} A P) = tr(A), so the trace is a genuine property of the underlying linear map, not of its matrix representation.
The Frobenius inner product
The trace defines an inner product on matrices: = tr(A^T B), which sums the products of corresponding entries. Its induced norm is the Frobenius norm, the square root of the sum of squared entries. This connects the trace to least-squares measures of matrix size and error.
Uses
In statistics the trace of a covariance matrix is the total variance. In quantum mechanics the trace of a density operator is 1, and expectation values are traces of operator products. In machine learning the trace appears in regularizers and in the nuclear norm, the sum of singular values.
import numpy as np
A = np.random.rand(5, 5)
print(np.isclose(np.trace(A), np.linalg.eigvals(A).sum().real)) # True
Because it collapses a whole operator to one basis-independent number, the trace is a convenient diagnostic when comparing discretized physics operators across different grids.