TExcelTAD
Home › Linear Algebra & Matrix Theory › The Cayley-Hamilton Theorem

The Cayley-Hamilton Theorem

Every square matrix satisfies its own characteristic polynomial: plug the matrix into p(λ)=det⁡(A−λI)p(\lambda) = \det(A - \lambda I) and you get the zero matrix. This surprising fact means that any power of an n×nn \times n matrix, and its inverse, can be written using only I,A,…,An−1I, A, \ldots, A^{n-1}.

The statement

Let p(λ)=det⁡(A−λI)=cnλn+⋯+c1λ+c0p(\lambda) = \det(A - \lambda I) = c_n\lambda^n + \cdots + c_1\lambda + c_0 be the characteristic polynomial of the n×nn \times n matrix AA (Finding Eigenvalues). Replace λ\lambda by AA and the constant c0c_0 by c0Ic_0 I:

Cayley–Hamilton:p(A)=cnAn+⋯+c1A+c0I=0(the zero matrix)\text{Cayley–Hamilton:} \qquad p(A) = c_n A^n + \cdots + c_1 A + c_0 I = 0 \qquad \text{(the zero matrix)}

For a 2×22 \times 2 matrix, p(λ)=λ2−tr⁡(A)λ+det⁡(A)p(\lambda) = \lambda^2 - \operatorname{tr}(A)\lambda + \det(A), so

A2−tr⁡(A)⋅A+det⁡(A)⋅I=0A^2 - \operatorname{tr}(A) \cdot A + \det(A) \cdot I = 0

Take A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}, with trace 5 and determinant −2-2. The theorem says A2=5A+2IA^2 = 5A + 2I:

A2=[1⋅1+2⋅31⋅2+2⋅43⋅1+4⋅33⋅2+4⋅4]=[7101522]5A+2I=[5+2101520+2]=[7101522]✓\begin{aligned} A^2 &= \begin{bmatrix} 1 \cdot 1 + 2 \cdot 3 & 1 \cdot 2 + 2 \cdot 4 \\ 3 \cdot 1 + 4 \cdot 3 & 3 \cdot 2 + 4 \cdot 4 \end{bmatrix} = \begin{bmatrix} 7 & 10 \\ 15 & 22 \end{bmatrix} \\ 5A + 2I &= \begin{bmatrix} 5 + 2 & 10 \\ 15 & 20 + 2 \end{bmatrix} = \begin{bmatrix} 7 & 10 \\ 15 & 22 \end{bmatrix} \quad \checkmark \end{aligned}
python · try it yourself
from sympy import Matrix, symbols, eye, zeros

lam = symbols("lambda")
A = Matrix([[2, 0, 1], [1, 3, -1], [0, 1, 1]])
p = A.charpoly(lam)                # SymPy uses det(lambda*I - A), monic
print("p(lambda) =", p.as_expr())
coeffs = p.all_coeffs()            # highest power first
n = A.shape[0]
pA = zeros(n, n)
for power, c in zip(range(n, -1, -1), coeffs):
    pA += c * A**power
print("p(A) =", pA.tolist())
p(lambda) = lambda**3 - 6*lambda**2 + 12*lambda - 9
p(A) = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

SymPy's charpoly uses det⁡(λI−A)\det(\lambda I - A), which is (−1)ndet⁡(A−λI)(-1)^n \det(A - \lambda I): same roots, and p(A)=0p(A) = 0 either way.

Why it is true (a sketch)

For diagonalizable matrices it is quick. If A=PDP−1A = PDP^{-1} then p(A)=P p(D) P−1p(A) = P\,p(D)\,P^{-1}, and p(D)=diag⁡(p(λ1),…,p(λn))=0p(D) = \operatorname{diag}(p(\lambda_1), \ldots, p(\lambda_n)) = 0 because every λi\lambda_i is a root of pp.

In general, the diagonalizable matrices are "dense": any matrix is a limit of matrices with distinct eigenvalues (perturb the diagonal slightly), and both sides of p(A)=0p(A) = 0 depend continuously on the entries. A purely algebraic proof uses the adjugate identity (A−λI)⋅adj⁡(A−λI)=p(λ)⋅I(A - \lambda I) \cdot \operatorname{adj}(A - \lambda I) = p(\lambda) \cdot I and compares coefficients of λ\lambda.

Note: The tempting one-line proof "p(A)=det⁡(A−A⋅I)=det⁡(0)=0p(A) = \det(A - A \cdot I) = \det(0) = 0" is wrong. In det⁡(A−λI)\det(A - \lambda I), λ\lambda is a scalar; substituting a matrix inside the determinant gives the number 0, while p(A)p(A) is a matrix. The theorem needs a real argument.

Use 1: the inverse as a polynomial in AA

Rearrange p(A)=0p(A) = 0 to isolate II. For 2×22 \times 2 matrices with det⁡(A)≠0\det(A) \ne 0:

A2−tr⁡(A)⋅A=−det⁡(A)⋅I→A⋅(A−tr⁡(A)⋅I)=−det⁡(A)⋅IA−1=tr⁡(A)⋅I−Adet⁡(A)\begin{aligned} A^2 - \operatorname{tr}(A) \cdot A &= -\det(A) \cdot I \quad \to \quad A \cdot (A - \operatorname{tr}(A) \cdot I) = -\det(A) \cdot I \\ A^{-1} &= \frac{\operatorname{tr}(A) \cdot I - A}{\det(A)} \end{aligned}

For A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix}: A−1=5I−A−2=1−2[4−2−31]=[−211.5−0.5]A^{-1} = \frac{5I - A}{-2} = \frac{1}{-2}\begin{bmatrix} 4 & -2 \\ -3 & 1 \end{bmatrix} = \begin{bmatrix} -2 & 1 \\ 1.5 & -0.5 \end{bmatrix}, the familiar "swap the diagonal, negate the rest, divide by the determinant" rule (Application: A Formula for the Inverse). In nn dimensions the same rearrangement writes A−1A^{-1} as a polynomial of degree n−1n - 1 in AA, with coefficients from the characteristic polynomial.

Use 2: high powers collapse

Since AnA^n is a combination of lower powers, so is every higher power. Concretely, divide λk\lambda^k by p(λ)p(\lambda): λk=q(λ)p(λ)+r(λ)\lambda^k = q(\lambda)p(\lambda) + r(\lambda) with deg⁡r<n\deg r < n. Substituting AA kills the first term:

Ak=r(A)where r=remainder of λk divided by p(λ)A^k = r(A) \qquad \text{where } r = \text{remainder of } \lambda^k \text{ divided by } p(\lambda)
python · try it yourself
from sympy import Matrix, symbols, rem, eye, Poly

lam = symbols("lambda")
A = Matrix([[1, 2], [3, 4]])
p = A.charpoly(lam).as_expr()       # lambda**2 - 5*lambda - 2
r = Poly(rem(lam**10, p, lam), lam)
print("remainder of lambda^10 mod p:", r.as_expr())
b, a = r.all_coeffs()               # r = b*lambda + a
print("b*A + a*I == A**10:", b * A + a * eye(2) == A**10)
print("A**10 =", (A**10).tolist())
remainder of lambda^10 mod p: 3486025*lambda + 1297782
b*A + a*I == A**10: True
A**10 = [[4783807, 6972050], [10458075, 15241882]]

So A10A^{10} is determined by two numbers, the remainder's coefficients. The same idea speeds up linear-recurrence computations: the nn-th term of a recurrence of order dd needs only polynomial arithmetic modulo the characteristic polynomial, O(d2log⁡n)O(d^2 \log n) operations instead of O(d3log⁡n)O(d^3 \log n) for matrix powers.

The minimal polynomial

p(A)=0p(A) = 0 is one polynomial that kills AA, but sometimes a smaller one does. The minimal polynomial is the monic polynomial of least degree with m(A)=0m(A) = 0. It divides pp, and AA is diagonalizable exactly when mm has no repeated roots. For the identity II (n×nn \times n), p(λ)=(1−λ)np(\lambda) = (1 - \lambda)^n but m(λ)=λ−1m(\lambda) = \lambda - 1.

In software

  • Fast linear recurrences: competitive-programming "Kitamasa" and polynomial-based methods for huge-nn terms rest on Cayley–Hamilton.
  • Matrix functions: etAe^{tA}, sin⁡(A)\sin(A) or A\sqrt{A} for a small matrix can be written as r(A)r(A) with deg⁡r<n\deg r < n, which libraries use for 2×22 \times 2 and 3×33 \times 3 closed forms (rotations, spring steps).
  • Krylov methods: iterative solvers like conjugate gradient and GMRES look for solutions in span⁡{b,Ab,A2b,…}\operatorname{span}\{\mathbf{b}, A\mathbf{b}, A^2\mathbf{b}, \ldots\}. Cayley–Hamilton guarantees that span stops growing after at most nn steps and contains A−1bA^{-1}\mathbf{b}.

Exercises

Exercise 1: Verify for a 2×22 \times 2 matrix

For A=[2113]A = \begin{bmatrix} 2 & 1 \\ 1 & 3 \end{bmatrix}, write the Cayley–Hamilton equation and check it.

Answer

A2−5A+5I=0A^2 - 5A + 5I = 0, since A2=[55510]=5A−5IA^2 = \begin{bmatrix} 5 & 5 \\ 5 & 10 \end{bmatrix} = 5A - 5I.

Solution
tr⁡=5,det⁡=6−1=5→p(λ)=λ2−5λ+5A2=[4+12+32+31+9]=[55510]5A−5I=[10−55515−5]=[55510]✓\begin{aligned} &\operatorname{tr} = 5, \quad \det = 6 - 1 = 5 \quad \to \quad p(\lambda) = \lambda^2 - 5\lambda + 5 \\ A^2 &= \begin{bmatrix} 4 + 1 & 2 + 3 \\ 2 + 3 & 1 + 9 \end{bmatrix} = \begin{bmatrix} 5 & 5 \\ 5 & 10 \end{bmatrix} \\ 5A - 5I &= \begin{bmatrix} 10 - 5 & 5 \\ 5 & 15 - 5 \end{bmatrix} = \begin{bmatrix} 5 & 5 \\ 5 & 10 \end{bmatrix} \quad \checkmark \end{aligned}

Exercise 2: Inverse and cube

For the same AA, use the theorem to write A−1A^{-1} and A3A^3 as combinations of AA and II.

Answer

A−1=5I−A5=15[3−1−12]A^{-1} = \frac{5I - A}{5} = \frac{1}{5}\begin{bmatrix} 3 & -1 \\ -1 & 2 \end{bmatrix}; A3=20A−25I=[15202035]A^3 = 20A - 25I = \begin{bmatrix} 15 & 20 \\ 20 & 35 \end{bmatrix}.

Solution
A2−5A=−5I→A(A−5I)=−5I→A−1=5I−A5A3=A⋅A2=A(5A−5I)=5A2−5A=5(5A−5I)−5A=20A−25I20A−25I=[40−25202060−25]=[15202035]\begin{aligned} A^2 - 5A &= -5I \quad \to \quad A(A - 5I) = -5I \quad \to \quad A^{-1} = \frac{5I - A}{5} \\ A^3 &= A \cdot A^2 = A(5A - 5I) = 5A^2 - 5A = 5(5A - 5I) - 5A = 20A - 25I \\ 20A - 25I &= \begin{bmatrix} 40 - 25 & 20 \\ 20 & 60 - 25 \end{bmatrix} = \begin{bmatrix} 15 & 20 \\ 20 & 35 \end{bmatrix} \end{aligned}

Exercise 3: A matrix of order 4

A 2×22 \times 2 matrix AA has trace 0 and determinant 1. Show that A2=−IA^2 = -I and A4=IA^4 = I. Give an example.

Answer

Cayley–Hamilton gives A2−0⋅A+1⋅I=0A^2 - 0 \cdot A + 1 \cdot I = 0, so A2=−IA^2 = -I and A4=(−I)2=IA^4 = (-I)^2 = I. Example: the 90∘90^\circ rotation [0−110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}.

Solution
p(λ)=λ2−0⋅λ+1=λ2+1→A2+I=0A4=(A2)2=(−I)2=I[0−110]: trace 0, det⁡=0⋅0−(−1)⋅1=1\begin{aligned} p(\lambda) &= \lambda^2 - 0 \cdot \lambda + 1 = \lambda^2 + 1 \quad \to \quad A^2 + I = 0 \\ A^4 &= (A^2)^2 = (-I)^2 = I \\ &\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}: \ \text{trace } 0, \ \det = 0 \cdot 0 - (-1) \cdot 1 = 1 \end{aligned}

Another example is [1−21−1]\begin{bmatrix} 1 & -2 \\ 1 & -1 \end{bmatrix} (trace 0, det⁡=−1+2=1\det = -1 + 2 = 1): not a rotation, yet applying it four times still gives the identity.

Exercise 4: A 3×33 \times 3 power by remainder

For A=[0100012−12]A = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 2 & -1 & 2 \end{bmatrix}, compute A8A^8 as r(A)r(A) with rr of degree at most 2, and confirm it in SymPy.

Answer

p(λ)=λ3−2λ2+λ−2=(λ−2)(λ2+1)p(\lambda) = \lambda^3 - 2\lambda^2 + \lambda - 2 = (\lambda - 2)(\lambda^2 + 1), the remainder is r(λ)=51λ2+52r(\lambda) = 51\lambda^2 + 52, so A8=51A2+52I=[5205110211022040205]A^8 = 51A^2 + 52I = \begin{bmatrix} 52 & 0 & 51 \\ 102 & 1 & 102 \\ 204 & 0 & 205 \end{bmatrix}.

Solution

AA is a companion matrix: its last row says A3=2A2−A+2IA^3 = 2A^2 - A + 2I, so p(λ)=λ3−2λ2+λ−2=λ2(λ−2)+(λ−2)=(λ−2)(λ2+1)p(\lambda) = \lambda^3 - 2\lambda^2 + \lambda - 2 = \lambda^2(\lambda - 2) + (\lambda - 2) = (\lambda - 2)(\lambda^2 + 1). The remainder r(λ)=aλ2+bλ+cr(\lambda) = a\lambda^2 + b\lambda + c agrees with λ8\lambda^8 at the three roots 2,i,−i2, i, -i (there λ8=q⋅p+r\lambda^8 = q \cdot p + r with p=0p = 0):

r(i)=−a+bi+c=i8=1r(−i)=−a−bi+c=1→b=0, c=a+1r(2)=4a+c=28=256→5a+1=256→a=51, c=52\begin{aligned} r(i) &= -a + bi + c = i^8 = 1 \\ r(-i) &= -a - bi + c = 1 && \to \quad b = 0, \ c = a + 1 \\ r(2) &= 4a + c = 2^8 = 256 && \to \quad 5a + 1 = 256 \quad \to \quad a = 51, \ c = 52 \end{aligned}
python · try it yourself
from sympy import Matrix, symbols, rem, eye

lam = symbols("lambda")
A = Matrix([[0, 1, 0], [0, 0, 1], [2, -1, 2]])
p = A.charpoly(lam).as_expr()
print("p =", p, "  remainder:", rem(lam**8, p, lam))
print("51A^2 + 52I == A^8:", 51 * A**2 + 52 * eye(3) == A**8)
print("A^8 =", (A**8).tolist())
p = lambda**3 - 2*lambda**2 + lambda - 2   remainder: 51*lambda**2 + 52
51A^2 + 52I == A^8: True
A^8 = [[52, 0, 51], [102, 1, 102], [204, 0, 205]]

Test yourself

What does the Cayley–Hamilton theorem say?

  1. Every matrix is diagonalizable
  2. A matrix satisfies its own characteristic polynomial: p(A)=0p(A) = 0
  3. det⁡(A)\det(A) is the sum of the eigenvalues
  4. AT=A−1A^T = A^{-1}

A 2×22 \times 2 matrix has trace 4 and determinant 3. Which identity holds?

  1. A2=4A−3IA^2 = 4A - 3I
  2. A2=3A−4IA^2 = 3A - 4I
  3. A2=4A+3IA^2 = 4A + 3I
  4. A2=−4A+3IA^2 = -4A + 3I

Why is 'p(A)=det⁡(A−A⋅I)=0p(A) = \det(A - A \cdot I) = 0' not a valid proof?

  1. Because det⁡(0)\det(0) is not 0
  2. Because the λ\lambda in det⁡(A−λI)\det(A - \lambda I) is a scalar; that substitution gives the number 0, not the matrix p(A)p(A)
  3. Because A⋅I≠AA \cdot I \ne A
  4. It is a valid proof