Cramer's Rule

lean4-prooflinear-algebravisualization
xi=det(Ai)det(A)x_i = \frac{\det(A_i)}{\det(A)}

Statement

Let AA be an invertible n×nn \times n matrix over a commutative ring RR (so det(A)\det(A) is a unit), and let bRnb \in R^n. The unique solution xx to Ax=bAx = b satisfies:

xi=det(Ai(b))det(A)x_i = \frac{\det(A_i(b))}{\det(A)}

where Ai(b)A_i(b) is the matrix AA with its ii-th column replaced by bb.

In the non-invertible / commutative ring setting, the adjugate form of the rule states:

A(cramer(A,b))=det(A)bA \cdot (\operatorname{cramer}(A, b)) = \det(A) \cdot b

where cramer(A,b)i=det(Ai(b))\operatorname{cramer}(A, b)_i = \det(A_i(b)), without requiring det(A)\det(A) to be a unit.

Visualization

Solve the 2×22 \times 2 system:

{2x+y=5x+3y=7\begin{cases} 2x + y = 5 \\ x + 3y = 7 \end{cases}

which corresponds to Ax=bAx = b with:

A=(2113),b=(57)A = \begin{pmatrix} 2 & 1 \\ 1 & 3 \end{pmatrix}, \quad b = \begin{pmatrix} 5 \\ 7 \end{pmatrix}

Compute det(A)\det(A):

det(A)=(2)(3)(1)(1)=5\det(A) = (2)(3) - (1)(1) = 5

Since det(A)=50\det(A) = 5 \neq 0, the system has a unique solution.

Compute det(A1(b))\det(A_1(b)) — replace column 1 with bb:

A1=(5173),det(A1)=(5)(3)(1)(7)=8A_1 = \begin{pmatrix} 5 & 1 \\ 7 & 3 \end{pmatrix}, \quad \det(A_1) = (5)(3) - (1)(7) = 8

Compute det(A2(b))\det(A_2(b)) — replace column 2 with bb:

A2=(2517),det(A2)=(2)(7)(5)(1)=9A_2 = \begin{pmatrix} 2 & 5 \\ 1 & 7 \end{pmatrix}, \quad \det(A_2) = (2)(7) - (5)(1) = 9

Apply Cramer's rule:

x=det(A1)det(A)=85,y=det(A2)det(A)=95x = \frac{\det(A_1)}{\det(A)} = \frac{8}{5}, \qquad y = \frac{\det(A_2)}{\det(A)} = \frac{9}{5}

Verify:

285+95=255=5,85+395=355=72\cdot\frac{8}{5} + \frac{9}{5} = \frac{25}{5} = 5 \checkmark, \qquad \frac{8}{5} + 3\cdot\frac{9}{5} = \frac{35}{5} = 7 \checkmark

Proof Sketch

The adjugate satisfies Aadj(A)=det(A)IA \cdot \operatorname{adj}(A) = \det(A) \cdot I by definition (cofactor expansion). Setting cramer(A,b)=adj(A)b\operatorname{cramer}(A, b) = \operatorname{adj}(A) \cdot b, one computes:

Acramer(A,b)=Aadj(A)b=det(A)bA \cdot \operatorname{cramer}(A, b) = A \cdot \operatorname{adj}(A) \cdot b = \det(A) \cdot b

The ii-th component of adj(A)b\operatorname{adj}(A) \cdot b is j(1)i+jdet(Aji)bj\sum_j (-1)^{i+j} \det(A_{ji})\, b_j, which is precisely the cofactor expansion of det(Ai(b))\det(A_i(b)) along column ii. When det(A)\det(A) is a unit, dividing through gives the classical formula xi=det(Ai(b))/det(A)x_i = \det(A_i(b))/\det(A).

Connections

  • Rank–Nullity TheoremRank–Nullity Theoremrank(f)+nullity(f)=dimV\operatorname{rank}(f) + \operatorname{nullity}(f) = \dim VThe dimensions of image and kernel of a linear map sum to the domain dimensionRead more → — Cramer's rule applies when nullity(A)=0\operatorname{nullity}(A) = 0; otherwise the system has no unique solution.
  • Determinant MultiplicativityDeterminant Multiplicativitydet(AB)=det(A)det(B)\det(AB) = \det(A)\,\det(B)The determinant of a product equals the product of determinantsRead more → — the adjugate identity Aadj(A)=det(A)IA \cdot \operatorname{adj}(A) = \det(A) I is a consequence of cofactor expansion and the multiplicativity of det\det.
  • Cayley–Hamilton TheoremCayley–Hamilton TheorempA(A)=0  where  pA(λ)=det(λIA)p_A(A) = 0 \;\text{where}\; p_A(\lambda) = \det(\lambda I - A)Every square matrix satisfies its own characteristic polynomialRead more → — the adjugate adj(A)\operatorname{adj}(A) appears in the Cayley–Hamilton proof; pA(A)=0p_A(A) = 0 is assembled from the identity (λIA)adj(λIA)=pA(λ)I(\lambda I - A)\operatorname{adj}(\lambda I - A) = p_A(\lambda)I.
  • Spectral TheoremSpectral TheoremA=QΛQT  (real symmetric case)A = Q \Lambda Q^T \;\text{(real symmetric case)}Every real symmetric matrix is orthogonally diagonalizableRead more → — in an orthogonal basis of eigenvectors, the linear system decouples and each component's solution is bi/λib_i/\lambda_i, a spectral analogue of Cramer's formula.
  • Quadratic FormulaQuadratic Formulax=b±b24ac2ax = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}Solve any quadratic equation using the discriminantRead more → — for n=1n=1, Cramer's rule recovers x=b/ax = b/a; the quadratic formula solves the n=2n=2 eigenvalue equation.

Lean4 Proof

/-- Cramer's rule in adjugate form: A *ᵥ (cramer A b) = det(A) • b.
    This holds over any commutative ring without requiring det(A) to be
    a unit. Mathlib locates this in LinearAlgebra.Matrix.Adjugate. -/
theorem cramers_rule {n R : Type*}
    [Fintype n] [DecidableEq n] [CommRing R]
    (A : Matrix n n R) (b : n  R) :
    A *ᵥ (Matrix.cramer A b) = A.det • b :=
  Matrix.mulVec_cramer A b