Determinants
行列式
Track signed volume, invertibility, and elimination without confusing determinant size with numerical conditioning.
determinantsHow much area survives a linear map?
Transform the unit square using . Its edge vectors become and , forming a parallelogram with base two and height three. Its area is six. The determinant records this volume scaling together with orientation: swapping those columns changes the sign, while the area remains six.
If two columns lie on the same line, the square collapses to a line and loses its two-dimensional area. This gives a geometric reason that a zero determinant and failure of invertibility are connected. It does not say that every individual output vector becomes zero. MML, Section 4.1
Unit square
det = 1 · area = 1
After transformation
det = 6 · area = 6
Swap the columns
det = -6 · area = 6
Definition and useful identities
For a real 2×2 matrix,
A general definition uses all permutations of column indices:
Each product chooses one entry from each row and each column. Its sign is positive for an even number of pair swaps and negative for an odd number. For two rows this produces . There are products, so the definition is useful for reasoning but a poor direct algorithm for large matrices.
Another characterization is that the determinant is linear in each column separately, changes sign when two columns are exchanged, and equals one on the identity. “Separately” matters: scaling one column by multiplies the result by ; scaling the whole n×n matrix multiplies it by .
| Operation or condition | Consequence |
|---|---|
| Swap two rows | Reverse the determinant’s sign |
| Add a multiple of one row to another | Leave the determinant unchanged |
| Triangular matrix | Multiply its diagonal entries |
| Compose two square maps | |
| Full rank square matrix | Determinant is nonzero |
The first two row operations explain a practical calculation. Use elimination to make the matrix upper triangular without scaling rows, track row swaps, then multiply the diagonal. If no nonzero pivot remains in a column, the matrix is singular. For the opening example, the matrix is already triangular and gives . Scaling all entries by two gives , not twelve.
The product of eigenvalues, counted with algebraic multiplicity over the complex numbers, also equals the determinant. This includes matrices that cannot be diagonalized. For real matrices the product is real even when some eigenvalues occur as complex-conjugate pairs. Volume interpretation and eigenvalue products appear in Deep Learning, Section 2.11; eigenvalue conditions are developed in the next article.
Elimination with exact rational arithmetic
This runnable example accepts integers and Fraction values. Exact rational arithmetic makes a zero pivot unambiguous for these inputs. It chooses the first nonzero pivot, records swaps, and preserves the caller’s matrix.
from fractions import Fraction
def determinant(matrix):
n = len(matrix)
if not n or any(len(row) != n for row in matrix):
raise ValueError("a nonempty square matrix is required")
if any(not isinstance(x, (int, Fraction)) for row in matrix for x in row):
raise ValueError("use integers or Fraction entries for exact arithmetic")
a = [[Fraction(x) for x in row] for row in matrix]
sign = 1
product = Fraction(1)
for j in range(n):
pivot = next((i for i in range(j,n) if a[i][j] != 0), None)
if pivot is None:
return Fraction(0)
if pivot != j:
a[j], a[pivot] = a[pivot], a[j]
sign = -sign
diagonal = a[j][j]
product *= diagonal
for i in range(j+1,n):
factor = a[i][j]/diagonal
a[i][j] = Fraction(0)
for k in range(j+1,n):
a[i][k] -= factor*a[j][k]
return sign*product
a = [[2,1],[0,3]]
assert determinant(a) == 6
assert determinant([[4,2],[0,6]]) == 24
assert determinant([[0,3],[2,1]]) == -6
assert determinant([[1,2],[2,4]]) == 0
assert determinant([[0,2,1],[1,0,3],[4,1,0]]) == 25
assert determinant([[Fraction(1,10),0],[0,Fraction(1,10)]]) == Fraction(1,100)
assert determinant([[-3]]) == -3
assert a == [[2,1],[0,3]] # input was not modified
for bad in ([], [[1,2]], [[1.0]]):
try:
determinant(bad)
except ValueError:
pass
else:
raise AssertionError("invalid input accepted")
There are rational arithmetic operations and additional storage. This is an arithmetic-operation count, not a bound assuming rational operations have fixed cost: numerators and denominators may grow. For floating-point data, production routines generally use pivoted factorizations and assess numerical error. The exact teaching routine is not a replacement for them.
A small determinant is not a conditioning test
Compare and . The first has determinant but scales all directions equally. The second has determinant one while scaling its two directions by factors separated by twelve orders of magnitude. Determinant size mixes scale and dimension; it does not measure relative sensitivity of solving a system. Use singular values and an appropriate condition number for that question.
In floating point, “exactly zero” and “too small to resolve reliably” also differ. Multiplying many pivots can overflow or underflow; storing sign and the sum of log absolute pivots can avoid the final product’s range problem. Such a representation does not repair a poorly conditioned factorization.
Nor does determinant one imply an orthogonal transformation. The shear preserves area but changes some lengths and angles. Rectangular matrices have no ordinary determinant; use rank, singular values, or a clearly specified geometric quantity instead.
Keep scale and orientation separate
- What happens to a 3×3 determinant if every entry doubles? Answer: it is multiplied by .
- Swap two rows twice. What is the net effect? Answer: no change; two sign reversals cancel.
- Does determinant zero mean for every ? Answer: no. For , only the second coordinate direction is collapsed.
- The shear above maps to what? Answer: , whose length is rather than one. Area preservation is weaker than orthogonality.
Why determinants recur in AI mathematics
A change of variables in a probability density uses the absolute determinant of a local Jacobian to account for volume change. Gaussian normalization and some likelihood calculations use log determinants. These applications require their own assumptions: invertibility, dimension, and positive definiteness cannot be inferred merely from a convenient formula. When solving , use a suitable solver rather than explicitly computing determinants for every coordinate.
Make a prediction, then check
If every entry of a 2×2 matrix is multiplied by 3, what multiplies its determinant?
Learning objectives
- Explain determinant, row-swap sign, and singularity using signed area.
- Compute small determinants exactly by elimination and distinguish scale from conditioning.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Checked elimination and row-swap signs against the permutation definition for 100 rational matrices of sizes 1×1 through 5×5.
- Checked the illustrated areas 1,6,6 and determinants 1,6,−6; separated scale, singularity, and conditioning.
- Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §4.1, printed pp.99–103 / PDF pp.105–109; determinant/eigenvalue relation Theorem 4.16
- Deep Learning — Chapter 2: Linear Algebra · §2.11, determinant as eigenvalue product and volume scale
Related topics