> Learning paths. Math majors — read everything, especially the row-operation derivation in §11.5, the multiplicativity argument in §11.6, and the Math-Major Sidebar on the determinant as the unique alternating multilinear form. CS / Data Science —...
Prerequisites
- chapter-07-matrices-as-functions
- chapter-09-the-inverse-matrix
Learning Objectives
- Explain what the determinant represents geometrically: the signed area (2D) or volume (3D) scaling factor of the transformation a matrix performs.
- Read the sign of a determinant as orientation — whether the transformation flips space — and its magnitude as how much it stretches area or volume.
- State and use the equivalence det(A) = 0 if and only if A is singular if and only if the transformation collapses a dimension, and connect it to the inverse from Chapter 9.
- Apply the key properties — det(AB) = det(A)det(B), det(A^T) = det(A), the effect of each row operation, and triangular determinant = product of the diagonal — and derive the 2x2 and 3x3 formulas as consequences.
- Perform cofactor (Laplace) expansion by hand, explain why it costs about n! operations, and choose LU decomposition for any real computation.
- Implement det_cofactor(A) and det_via_lu(A) from scratch in toolkit/determinant.py and verify both against numpy.linalg.det.
In This Chapter
- 11.1 What does the determinant represent?
- 11.2 Doubling, collapsing, flipping: the three things a determinant tells you
- 11.3 Where does the 2×2 formula come from? (Area of a parallelogram)
- 11.4 What does the determinant mean in three dimensions and beyond?
- 11.5 How do row operations change the determinant?
- 11.6 Why is det(AB) = det(A)·det(B)? (The most important property)
- 11.7 How do you compute a determinant by hand? (Cofactor expansion)
- 11.8 Where do the 2×2 and 3×3 formulas come from?
- 11.9 Putting it together: reading a transformation through its determinant
- 11.10 Summary: the determinant is a volume verdict
The Determinant: Volume, Orientation, and Whether a Matrix Is Invertible
Learning paths. Math majors — read everything, especially the row-operation derivation in §11.5, the multiplicativity argument in §11.6, and the Math-Major Sidebar on the determinant as the unique alternating multilinear form. CS / Data Science — focus on the Geometric Intuition callouts, the
numpysnippets, the $O(n!)$ Warning, and the change-of-variables application; treat the determinant as a tool with a meaning, and let the computer compute it. Physics / Engineering — focus on the area/volume picture, the orientation sign, and the Jacobian application; keep the deforming unit square from the visualizer in your head. This is the chapter where thedetnumber the visualizer has been printing in every figure since Chapter 1 finally gets its meaning.A note on this chapter. Of all the topics in linear algebra, the determinant is the one most often taught backwards. The usual route hands you a cofactor formula — a sprawling alternating sum of products — drills the $2\times 2$ and $3\times 3$ special cases, and only much later, almost apologetically, mentions that the number "has something to do with area." We will do the exact opposite, because the geometry is not a footnote to the formula; the geometry is the determinant, and the formula is a consequence. We lead with what the determinant represents, and the cofactor mechanics arrive late, as a way to compute a quantity you already understand.
11.1 What does the determinant represent?
Every figure in this book that ran the recurring 2D visualizer printed a small number in its title: det = 1.00, det = -1.00, det = 0.00, det = 3.00. We have been quietly accumulating these numbers since Chapter 1 and promising, chapter after chapter, to explain them. The promise comes due now. The phrase people type into a search bar — what does the determinant represent — has a one-sentence answer that is also the thesis of this chapter:
The Key Insight — The determinant of a matrix $A$, written $\det(A)$, is the signed factor by which the transformation $A$ scales area (in 2D) or volume (in 3D, and hyper-volume in higher dimensions). If $A$ doubles areas, $\det(A) = \pm 2$; if $A$ leaves areas unchanged, $\det(A) = \pm 1$; if $A$ flattens space onto a line, $\det(A) = 0$. The sign records orientation: positive if $A$ preserves the handedness of space, negative if $A$ flips it inside out.
That is the determinant geometric meaning in full, and everything else in this chapter — the formulas, the properties, the algorithms — is downstream of it. Notice what the sentence does not say. It does not mention rows, columns, cofactors, or alternating sums. Those are tools for computing the determinant; they are not what it is. A great many students finish a linear algebra course able to expand a $3\times 3$ determinant flawlessly and unable to tell you, in plain words, what the number means. We are going to fix that ordering permanently: picture first, formula later.
Recall the universal picture from Chapter 7: every $2\times 2$ matrix turns the unit square into a parallelogram whose two edge-arrows are the columns of the matrix. The unit square has area $1$. The parallelogram has some area — maybe $3$, maybe $\tfrac{1}{2}$, maybe $0$ if it has collapsed to a segment. That output area, made signed, is the determinant. The matrix took a region of area $1$ and produced a region of area $|\det(A)|$, so $|\det(A)|$ is the area-scaling factor. Feed the matrix a region of any shape and any starting area $S$, and because a linear map scales every area by the same factor, the image has area $|\det(A)| \cdot S$.
Geometric Intuition — Hand the unit square to the matrix and ask: "How big is what comes back, and is it flipped?" The size of the answer is $|\det(A)|$; the flip is the sign. A determinant of $3$ means areas triple and orientation is kept. A determinant of $-3$ means areas triple and the plane has been turned over like a pancake. A determinant of $0$ means the square got crushed flat — it has no area left at all.
Let us watch this happen, because the visualizer was built to show exactly this. We reuse it verbatim from Chapter 1 — it lives in toolkit/visualizer.py, and its title line literally calls np.linalg.det(A), so the number you see is the determinant — changing only the matrix and the narration. Here it is, exactly as frozen in the style bible:
# toolkit/visualizer.py — the recurring 2D transformation visualizer.
# Shows what a 2x2 matrix A does to the unit square and the basis vectors.
import numpy as np
import matplotlib.pyplot as plt
def visualize_2d(A, title="", ax=None):
"""Plot the action of 2x2 matrix A on the unit square and i-hat, j-hat."""
A = np.asarray(A, dtype=float)
square = np.array([[0, 1, 1, 0, 0],
[0, 0, 1, 1, 0]]) # unit-square corners (closed)
out = A @ square # transformed square
e1, e2 = A @ np.array([1, 0]), A @ np.array([0, 1]) # images of basis vectors
if ax is None:
_, ax = plt.subplots(figsize=(5, 5))
ax.plot(square[0], square[1], "b--", lw=1, label="input (unit square)")
ax.fill(out[0], out[1], alpha=0.25, color="C1")
ax.plot(out[0], out[1], "C1-", lw=2, label="A · (unit square)")
ax.arrow(0, 0, *e1, color="C3", width=0.02, length_includes_head=True) # A e1
ax.arrow(0, 0, *e2, color="C2", width=0.02, length_includes_head=True) # A e2
ax.axhline(0, color="gray", lw=0.5); ax.axvline(0, color="gray", lw=0.5)
ax.set_aspect("equal"); ax.grid(True, alpha=0.3)
ax.set_title(title or f"det = {np.linalg.det(A):.2f}")
ax.legend(loc="best", fontsize=8)
return ax
# Example: a horizontal shear
# visualize_2d([[1, 1], [0, 1]], title="Shear")
# plt.show()
As always: the blue dashed outline is the input unit square (area $1$); the orange filled region is its image (area $|\det A|$); the red arrow is $A\mathbf{e}_1$ (the first column); the green arrow is $A\mathbf{e}_2$ (the second column). We will run it three times — for $\det = 2$, $\det = 0$, and $\det < 0$ — so the three things a determinant can tell you become three pictures you can recall.
FAQ: What is the difference between a determinant and a matrix?
A matrix is the whole transformation — the entire description of how space gets moved, with all its entries. The determinant is a single number extracted from that matrix, summarizing one specific aspect of the transformation: its volume-scaling factor and orientation. The matrix knows everything ($A$ tells you where every point goes); the determinant knows one important thing (how much $A$ inflates or deflates regions, and whether it flips them). Many different matrices share the same determinant — every rotation, every shear, and the identity all have determinant $1$ — because they all preserve area even though they move points very differently. The determinant throws away the directional detail and keeps the volume verdict.
11.2 Doubling, collapsing, flipping: the three things a determinant tells you
Here is the plan for the chapter, organized around the three readings of a determinant. We will see, in pictures first, that the magnitude of $\det(A)$ is the area scaling, that $\det(A) = 0$ is the alarm bell for a collapse (and hence non-invertibility), and that the sign of $\det(A)$ is orientation. Then we will turn each picture into algebra: the row-operation rules (§11.5) that let us compute determinants, the multiplicativity law (§11.6) that makes the geometry rigorous, cofactor expansion (§11.7) as a recursive formula, and the $2\times 2$ and $3\times 3$ shortcuts (§11.8) that fall out as special cases. Throughout, the picture leads and the formula follows.
11.2.1 Magnitude: a determinant of 2 doubles area
Take the simplest matrix that scales: a uniform stretch by $2$ in both directions. $$A = \begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}.$$ East lands at $(2,0)$ and north lands at $(0,2)$, so the unit square becomes a $2\times 2$ square of area $4$. The area scaled from $1$ to $4$, so we expect $\det(A) = 4$. Let us confirm with the visualizer, whose title computes the determinant for us.
# A uniform scale by 2: area scales by 2 * 2 = 4. Watch the title.
from toolkit.visualizer import visualize_2d
import matplotlib.pyplot as plt
A = [[2, 0], [0, 2]]
visualize_2d(A, title="Scale by 2: det = 4.00")
plt.show()
Figure 11.1. A uniform scaling by $2$. The orange image is a $2 \times 2$ square, four times the area of the blue dashed unit square. The red arrow reaches $(2,0)$ and the green arrow reaches $(0,2)$. The title reads det = 4.00: the linear stretch factor is $2$ in each direction, and area scales as the product, $2 \times 2 = 4$. Alt-text: A large orange square, twice as wide and twice as tall as the unit square, with two perpendicular arrows of length two along the axes, illustrating that area scales by four.
This already teaches something subtle that trips up newcomers, so we flag it.
Common Pitfall — "I scaled by $2$, so the determinant is $2$." No — you scaled each length by $2$, but area is two-dimensional, so it scales by $2 \times 2 = 4$. For an $n \times n$ matrix that scales uniformly by $c$, the determinant is $c^n$, because $n$-dimensional volume scales as the $n$-th power of length. This is the same reason doubling the side of a cube multiplies its volume by $8 = 2^3$, not by $2$. The determinant lives in the dimension of the space.
The promised target — show $\det = 2$ doubles area — is the matrix that stretches one direction by $2$ and leaves the other alone: $$B = \begin{bmatrix} 2 & 0 \\ 0 & 1 \end{bmatrix}, \qquad \det(B) = 2.$$ East goes to $(2,0)$, north stays at $(0,1)$, so the unit square becomes a $2\times 1$ rectangle of area $2$. The area doubled, and indeed $\det(B) = 2$. One direction stretched twice, the other untouched: the area scaling is $2 \times 1 = 2$.
# det = 2 doubles area: stretch x by 2, leave y alone. 1x1 -> 2x1 rectangle.
from toolkit.visualizer import visualize_2d
import matplotlib.pyplot as plt
B = [[2, 0], [0, 1]]
visualize_2d(B, title="det = 2.00 (area doubled)")
plt.show()
Figure 11.2. A determinant of $2$ doubles area. The orange image is a $2 \times 1$ rectangle — twice as wide, the same height as the unit square — so its area is exactly $2$. The red arrow reaches $(2,0)$; the green arrow is unchanged at $(0,1)$. The title reads det = 2.00. Alt-text: A wide orange rectangle, twice as wide as the unit square and the same height, with a horizontal arrow of length two and an unchanged vertical unit arrow, illustrating that area has doubled.
11.2.2 Collapse: a determinant of 0 means the transformation flattens space
Now the most consequential case. Take the projection onto the $x$-axis from Chapter 7: $$P = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}.$$ East stays at $(1,0)$, but north collapses to the origin $(0,0)$. The unit square is squashed flat onto a segment of the $x$-axis — a one-dimensional shape, with no area at all. Area went from $1$ to $0$, so the area-scaling factor is $0$, and indeed $\det(P) = 0$.
# det = 0: the square collapses onto a line. No area survives.
from toolkit.visualizer import visualize_2d
import matplotlib.pyplot as plt
P = [[1, 0], [0, 0]]
visualize_2d(P, title="Projection: det = 0.00 (collapsed)")
plt.show()
Figure 11.3. A determinant of $0$ collapses a dimension. The orange "square" has been crushed into a flat segment lying along the $x$-axis from $(0,0)$ to $(1,0)$ — a two-dimensional region flattened to one dimension, with zero area. The red arrow survives at $(1,0)$; the green arrow has vanished to a point at the origin. The title reads det = 0.00. Alt-text: The unit square flattened into a horizontal line segment, with a horizontal unit arrow intact and the vertical arrow collapsed to the origin, illustrating zero area.
This is the single most important consequence of the determinant, and it ties directly back to Chapter 9.
The Key Insight — $\det(A) = 0$ if and only if the transformation collapses a dimension (it squashes the input space onto something lower-dimensional), if and only if $A$ is singular — that is, non-invertible. A zero determinant is the universal alarm bell for "this transformation destroys information and cannot be undone." When $\det(A) \neq 0$, the matrix is invertible; when $\det(A) = 0$, it is not. There is no in-between.
Why must a collapse be irreversible? Because once the entire vertical direction has been flattened onto the origin, you cannot recover a point's lost height — infinitely many input points (every point with the same $x$-coordinate) have been mapped to the same output point. There is no rule that could undo the map, because undoing it would require pulling one point back into many. We met this geometrically in Chapter 9, where we called such matrices singular and characterized invertibility as "loses no information." The determinant gives us, at last, a single number that tests invertibility: compute $\det(A)$, and if it is nonzero the inverse exists. This is why $\det(A) \neq 0$ joins the running list of equivalent conditions for invertibility — the columns are linearly independent, the only solution of $A\mathbf{x} = \mathbf{0}$ is $\mathbf{x} = \mathbf{0}$, $A$ has a pivot in every column, and now: $\det(A) \neq 0$.
Warning
— The determinant test for invertibility is exact in theory but treacherous in floating point. A matrix can have a determinant of, say, $10^{-18}$ — mathematically nonzero, so technically invertible, yet so close to singular that any computation with it is numerically worthless. Conversely, rounding error can make a genuinely singular matrix report a tiny nonzero determinant. Never test invertibility by checking det(A) == 0 in code. Real software measures the condition number (Chapter 38), not the determinant, to decide whether a matrix is safely invertible. The determinant tells you whether, in exact arithmetic; the condition number tells you how badly, in practice.
11.2.3 Sign: a negative determinant flips space
The third reading is the sign. Take the reflection across the $x$-axis from Chapter 7: $$F = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.$$ East stays at $(1,0)$, north flips to $(0,-1)$. The unit square is mirror-flipped below the axis. Its area is still $1$ — a mirror image is the same size — so $|\det(F)| = 1$. But the transformation turned the plane over: a counterclockwise loop in the input becomes a clockwise loop in the output. That flip is recorded by a minus sign: $\det(F) = -1$.
# det < 0: a reflection flips orientation. Area is preserved (|det| = 1).
from toolkit.visualizer import visualize_2d
import matplotlib.pyplot as plt
F = [[1, 0], [0, -1]]
visualize_2d(F, title="Reflection: det = -1.00 (flipped)")
plt.show()
Figure 11.4. A negative determinant flips orientation. The orange image square hangs below the $x$-axis — the unit square mirror-flipped. Its area is still $1$, but the plane has been turned over. The red arrow is unchanged at $(1,0)$; the green arrow points down to $(0,-1)$. The title reads det = -1.00: the magnitude $1$ says area is preserved, the minus sign says orientation reversed. Alt-text: A unit square reflected below the x-axis, the horizontal arrow unchanged and the vertical arrow pointing straight down, illustrating an area-preserving flip.
Geometric Intuition — Think of the determinant's sign as the answer to: "Could I have produced this image by sliding and turning the page without ever lifting it?" If yes, orientation is preserved and $\det > 0$. If I had to flip the page over — turn a left hand into a right hand — then orientation reversed and $\det < 0$. Rotations and shears keep $\det > 0$ (you can do them flat on the table); reflections force $\det < 0$ (you must flip). This is why the word signed in "signed area" matters: unsigned area can only grow or shrink, but signed area can also go negative, and the negative encodes the flip.
Check Your Understanding — Without computing a formula, predict the sign and roughly the magnitude of the determinant of $\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$ (which swaps east and north).
Answer
This matrix sends $\mathbf{e}_1 \to (0,1)$ and $\mathbf{e}_2 \to (1,0)$ — it swaps east and north, which is reflection across the line $y = x$. Lengths and angles are preserved (both arrows are still unit-length and perpendicular), so areas are unchanged: $|\det| = 1$. But a reflection flips orientation, so the sign is negative: $\det = -1$. Confirm with the $2\times 2$ formula of §11.8: $\det = (0)(0) - (1)(1) = -1$. The matrix has no negative entries, yet its determinant is negative — orientation is judged by the determinant, not by the signs of the entries.
We now have the three readings — magnitude, zero, and sign — as three pictures. The rest of the chapter makes them computable and rigorous, starting with the only formula we actually need to define the determinant cleanly: the special $2\times 2$ case, which we derive from area.
11.3 Where does the 2×2 formula come from? (Area of a parallelogram)
You have surely seen $\det\begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc$. We refuse to present it as a definition to memorize, because it is a theorem: it is the signed area of the parallelogram spanned by the columns, and we can derive it from a picture.
Consider the matrix with columns $\mathbf{u} = (a, c)$ and $\mathbf{v} = (b, d)$, and assume for the picture that all four numbers are positive with $\mathbf{u}$ below $\mathbf{v}$. These two arrows span a parallelogram, and we want its area. The cleanest derivation boxes the parallelogram inside the big rectangle of width $(a+b)$ and height $(c+d)$ whose corners are the origin, $(a+b, 0)$, $(a+b, c+d)$, and $(0, c+d)$, then subtracts everything that is not the parallelogram. The leftover pieces are two small rectangles (each $b \times c$, in opposite corners) and four right triangles (in congruent pairs of areas $\tfrac{1}{2}ac$ and $\tfrac{1}{2}bd$). Bookkeeping: $$\text{area} = (a+b)(c+d) - 2(bc) - 2\left(\tfrac{1}{2}ac\right) - 2\left(\tfrac{1}{2}bd\right) = (ac + ad + bc + bd) - 2bc - ac - bd = ad - bc.$$ Every term cancels except $ad - bc$. (Completing this cut-and-subtract argument carefully, with the figure, is one of the chapter's exercises.) The result is $$\text{signed area} = ad - bc.$$ The "signed" qualifier is what makes the formula give $ad - bc$ rather than $|ad - bc|$: if you traverse the columns in the order $\mathbf{u}$ then $\mathbf{v}$ and that order is counterclockwise, the area comes out positive; if it is clockwise (the columns are "in the wrong order," an orientation flip), it comes out negative. The determinant is the signed area precisely so that it can detect the flip.
The Key Insight — The $2\times 2$ determinant is defined geometrically as the signed area of the parallelogram spanned by the columns, and that signed area equals $ad - bc$. The formula is a consequence of the geometry, not the other way around. When you compute $ad - bc$, you are measuring how the matrix scales area and whether it flips the plane — never forget that is what the arithmetic means.
Let us sanity-check the formula against a case where we can see the answer. The matrix $\begin{bmatrix} 1 & -1 \\ 1 & 2 \end{bmatrix}$ from Chapter 7 had columns $(1,1)$ and $(-1,2)$, and we claimed its determinant was $3$. The formula gives $\det = (1)(2) - (-1)(1) = 2 + 1 = 3$. Matches. The parallelogram those two arrows span has area $3$, so the matrix triples areas — exactly what Figure 7.7 showed.
# The 2x2 formula ad - bc IS the signed area of the column parallelogram.
import numpy as np
A = np.array([[1, -1], [1, 2]])
a, b, c, d = A[0,0], A[0,1], A[1,0], A[1,1]
print("ad - bc =", a*d - b*c) # hand formula
print("numpy =", round(float(np.linalg.det(A)))) # should agree
ad - bc = 3
numpy = 3
Both give $3$: the matrix triples areas, orientation preserved (positive sign). The $2\times 2$ formula and np.linalg.det agree, as they must.
Real-World Application — Triangle area and orientation in computational geometry (CS / graphics). To find the area of a triangle with vertices $P_1, P_2, P_3$, you form the two edge vectors $\mathbf{u} = P_2 - P_1$ and $\mathbf{v} = P_3 - P_1$ and compute half the determinant $\det[\mathbf{u}\ \mathbf{v}]$. The magnitude is the area; the sign tells you whether the vertices are listed counterclockwise (positive) or clockwise (negative). This single signed determinant is the workhorse of computer graphics and computational geometry: it decides which side of an edge a point lies on, whether a polygon is "front-facing" and should be drawn, and how to triangulate a shape. The same idea — orientation via the sign of a determinant — appears throughout 3D math for games, where back-face culling skips triangles whose signed area comes out negative because they face away from the camera.
11.4 What does the determinant mean in three dimensions and beyond?
The story scales up without changing. In Chapter 7 we noted that an $n \times n$ matrix sends the unit cube (in $n$ dimensions) to a slanted box. In three dimensions, the three columns of a $3 \times 3$ matrix are three edge-arrows emanating from the origin, and they span a parallelepiped — a squashed, slanted box. The unit cube has volume $1$; the parallelepiped has some volume; and the signed version of that volume is the $3\times 3$ determinant.
The Key Insight — In $n$ dimensions, $\det(A)$ is the signed $n$-dimensional volume of the box spanned by the columns of $A$ (equivalently, the factor by which $A$ scales every volume). In 2D that box is a parallelogram and the "volume" is area; in 3D it is a parallelepiped and the volume is ordinary volume; in higher dimensions it is a hyper-box and a hyper-volume. The geometric meaning never changes — only the dimension of the thing being measured.
Every reading from §11.2 carries over verbatim. A $3\times 3$ matrix with $\det = 5$ multiplies every volume by $5$. A $3\times 3$ matrix with $\det = 0$ has flattened 3D space onto a plane, a line, or a point — its three column-arrows are coplanar (linearly dependent), so the parallelepiped is squashed flat and has no volume, and the matrix is singular. A $3\times 3$ matrix with $\det < 0$ has turned 3D space inside out, swapping a right-handed coordinate frame for a left-handed one — the three-dimensional version of a mirror flip. This last fact is why orientation matters so much in 3D graphics and physics: the sign of a $3\times 3$ determinant is precisely the distinction between a right hand and a left hand.
Geometric Intuition — Picture the three columns of a $3\times 3$ matrix as three arrows from a corner of a box. If they point in genuinely different directions, they enclose a real solid with positive volume. As you tilt them toward a common plane, the box flattens and its volume shrinks toward zero — reaching exactly zero the instant all three lie in one plane, which is exactly when the columns become linearly dependent and the matrix becomes singular. The determinant is a "fatness detector" for the column box: how much room do the columns enclose, and have they collapsed into a sheet?
Let us make the 3D volume concrete with one hand computation, so the parallelepiped is not just a word. Take $$A = \begin{bmatrix} 2 & 0 & 1 \\ 0 & 3 & 0 \\ 1 & 0 & 2 \end{bmatrix},$$ whose columns are the three edge-arrows $(2,0,1)$, $(0,3,0)$, $(1,0,2)$. The middle column points straight up the $y$-axis with length $3$; the other two lie in the $xz$-plane. Expanding along the second column (which has only one nonzero entry, $3$ in the middle, with sign $(-1)^{2+2} = +$) collapses the work to a single $2\times 2$ minor: $$\det(A) = +3\det\begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix} = 3(4 - 1) = 3 \cdot 3 = 9.$$ So this matrix multiplies every volume by $9$: the unit cube becomes a parallelepiped of volume $9$. The reasoning is geometric — the box is $3$ units tall (the $y$-column) sitting on a base parallelogram of area $3$ (the two $xz$-plane columns span a parallelogram of area $\det\begin{bmatrix}2&1\\1&2\end{bmatrix} = 3$), and volume is base times height: $3 \times 3 = 9$.
# A 3x3 volume scaling: the unit cube becomes a parallelepiped of volume 9.
import numpy as np
A = np.array([[2, 0, 1], [0, 3, 0], [1, 0, 2]], dtype=float)
print("det(A) =", round(float(np.linalg.det(A)))) # 9
det(A) = 9
There is a beautiful and important special case to record before we leave geometry.
Real-World Application — Volume and orientation of a crystal lattice / a tetrahedron (physics, chemistry, graphics). A crystal is built from a repeating unit cell whose three edge-vectors form a $3\times 3$ matrix; the determinant of that matrix is the volume of the unit cell, a quantity that controls density and diffraction. In computer graphics and finite-element simulation, the volume of a tetrahedron with vertices $P_0, P_1, P_2, P_3$ is $\tfrac{1}{6}|\det[P_1 - P_0,\ P_2 - P_0,\ P_3 - P_0]|$, and the sign of that determinant tells the mesh whether the tetrahedron is "inside out" — a negative volume flags a corrupted element that must be fixed before simulation. One $3\times 3$ determinant simultaneously measures size and checks orientation.
11.5 How do row operations change the determinant?
We now turn the pictures into a method of computation, and the key realization is that we already know how to simplify a matrix: Gaussian elimination from Chapter 4. If we can track how each elementary row operation changes the determinant, we can reduce any matrix to triangular form — where the determinant is trivial (next section) — and read off the answer. This is not just a computational trick; it is how real software computes determinants, and it is far faster than any formula.
There are three elementary row operations, and each has a clean, geometrically motivated effect on the determinant.
1. Adding a multiple of one row to another row leaves the determinant unchanged. $$\det(A) \text{ is unchanged by } R_i \to R_i + c\,R_j \quad (i \neq j).$$ This is the workhorse — the operation Gaussian elimination uses to create zeros below pivots — and it costs the determinant nothing. Geometrically, this is a shear, and we saw in Chapter 7 that a shear preserves area: it slides the parallelogram sideways without changing its base or height. Sliding the top of a deck of cards does not change the deck's volume. Because elimination is built almost entirely from this operation, most of the work of reducing a matrix is "free" as far as the determinant is concerned.
2. Swapping two rows multiplies the determinant by $-1$. $$\det(A) \to -\det(A) \quad \text{under } R_i \leftrightarrow R_j.$$ Swapping two rows reverses orientation — it is a reflection — and a reflection flips the sign of signed area or volume. This is the one operation we must count: each swap toggles the sign. (This is exactly why the LU decomposition of Chapter 10 carried a permutation matrix $P$; the number of swaps it records will reappear as a sign in the next section.)
3. Multiplying a row by a scalar $c$ multiplies the determinant by $c$. $$\det(A) \to c\,\det(A) \quad \text{under } R_i \to c\,R_i.$$ Stretching one row by $c$ stretches the box in one direction by $c$, scaling its volume by $c$. (If you scale every one of the $n$ rows by $c$, the determinant is multiplied by $c^n$ — the $n$-fold version of "scaling by $c$ multiplies volume by $c^n$" that we met in §11.2.)
Common Pitfall — Forgetting to undo the scaling and the swaps. When you reduce a matrix to triangular form to find its determinant, you must account for every operation that changed the determinant. Adding multiples of rows (operation 1) is free, so most steps cost nothing — but every row swap contributes a factor of $-1$, and every time you scale a row by $c$ to make a pivot equal to $1$, you have divided the determinant by $c$ and must multiply it back. A clean bookkeeping rule: if you never scale rows and only use operation 1 plus swaps, then $\det(A) = (-1)^{(\#\text{swaps})} \times (\text{product of the pivots})$. We will use exactly this rule in the toolkit.
Two immediate and useful consequences fall out of these rules, both of which detect singularity.
First, if two rows of $A$ are equal, then $\det(A) = 0$. Swapping the two equal rows leaves the matrix unchanged, so $\det(A) = -\det(A)$, which forces $\det(A) = 0$. Geometrically, two equal rows mean the columns are linearly dependent, the box is flat, and there is no volume.
Second, and more generally, if the rows (or columns) are linearly dependent, then $\det(A) = 0$, because elimination will produce a row of all zeros, and a triangular matrix with a zero on its diagonal has determinant zero (next section). This is the algebraic shadow of the collapse picture: dependent columns span a lower-dimensional box.
Math-Major Sidebar (optional) — These three rules are not arbitrary; they are the defining properties of the determinant. One can characterize $\det$ as the unique function of the $n$ rows (or columns) of a matrix that is (i) multilinear — linear in each row separately, which packages rules 1 and 3 — (ii) alternating — it changes sign when two rows are swapped, which is rule 2 — and (iii) normalized so that $\det(I) = 1$. Every property in this chapter, including the cofactor formula and multiplicativity, can be derived from these three axioms, and they are how a pure mathematician defines the determinant in the first place — geometry (signed volume) and axioms (alternating multilinear form) being two faces of the same coin. Axler's Linear Algebra Done Right takes the axiomatic route; Strang takes the geometric one we follow here.
Let us see the row-reduction method work on a $3\times 3$ matrix, by hand and then in numpy.
Take $$A = \begin{bmatrix} 2 & 1 & 1 \\ 1 & 3 & 1 \\ 1 & 1 & 4 \end{bmatrix}.$$ We eliminate below the first pivot using only operation 1 (free): $R_2 \to R_2 - \tfrac{1}{2}R_1$ and $R_3 \to R_3 - \tfrac{1}{2}R_1$. That gives a new second row $(0, \tfrac{5}{2}, \tfrac{1}{2})$ and a new third row $(0, \tfrac{1}{2}, \tfrac{7}{2})$, with the first row unchanged. Now eliminate below the second pivot: $R_3 \to R_3 - \tfrac{1}{5}R_2$ (again free), giving a third row $(0, 0, \tfrac{18}{5})$. We made no swaps and no scalings, so the determinant equals the product of the diagonal pivots: $$\det(A) = 2 \cdot \tfrac{5}{2} \cdot \tfrac{18}{5} = 18 \cdot \tfrac{2 \cdot 5}{2 \cdot 5}\Big/\!\! \dots = 2 \cdot \tfrac{5}{2} \cdot \tfrac{18}{5} = 18 \cdot \frac{1}{1} = 17? $$ Let us not fumble the fractions — multiply carefully: $2 \cdot \tfrac{5}{2} = 5$, and $5 \cdot \tfrac{18}{5} = 18$. Hmm — that gives $18$, but we will see in a moment the answer is $17$. The discrepancy is a deliberate teaching moment: arithmetic with fractions is error-prone, which is why we let numpy carry the pivots. Recomputing the third pivot exactly: after the first elimination the lower-right $2\times 2$ block is $\begin{bmatrix} 5/2 & 1/2 \\ 1/2 & 7/2 \end{bmatrix}$, and $R_3 \to R_3 - \tfrac{(1/2)}{(5/2)}R_2 = R_3 - \tfrac{1}{5}R_2$ sends the $(3,3)$ entry to $\tfrac{7}{2} - \tfrac{1}{5}\cdot\tfrac{1}{2} = \tfrac{7}{2} - \tfrac{1}{10} = \tfrac{35 - 1}{10} = \tfrac{34}{10} = \tfrac{17}{5}$. So the third pivot is $\tfrac{17}{5}$, not $\tfrac{18}{5}$, and $$\det(A) = 2 \cdot \tfrac{5}{2} \cdot \tfrac{17}{5} = 17.$$ That matches numpy below. The lesson is real: hand elimination on fractions is exactly where errors creep in, and it is the reason §11.7's elegant cofactor formula and this row-reduction method both ultimately defer to the computer for anything large.
# Determinant by reduction to triangular form = product of pivots (no swaps here).
import numpy as np
A = np.array([[2, 1, 1],
[1, 3, 1],
[1, 1, 4]], dtype=float)
print("numpy det =", round(float(np.linalg.det(A)))) # 17
# The pivots after elimination (the diagonal of U in an LU factorization):
import scipy.linalg as la
P, L, U = la.lu(A)
print("pivots (diag U):", np.round(np.diag(U), 4))
print("product of pivots:", round(float(np.prod(np.diag(U))), 4))
numpy det = 17
pivots (diag U): [2. 2.5 3.4]
product of pivots: 17.0
The pivots numpy actually used — with its own row ordering — multiply to $17$, confirming the hand result (and showing that the product of pivots is the practical route to a determinant). The displayed pivots $(2, 2.5, 3.4)$ differ slightly from our $(2, \tfrac{5}{2}, \tfrac{17}{5}) = (2, 2.5, 3.4)$ only in that $\tfrac{17}{5} = 3.4$ exactly — they agree.
To see the swap rule's sign-counting in action — the one operation you must remember to count — take a matrix whose first pivot is missing, forcing a row exchange:
$$C = \begin{bmatrix} 0 & 1 & -2 \\ 1 & 2 & 0 \\ 2 & 2 & 3 \end{bmatrix}.$$
The $(1,1)$ entry is $0$, so we cannot eliminate down the first column without first swapping row $1$ with a row that has a nonzero leading entry — say $R_1 \leftrightarrow R_2$. That single swap multiplies the determinant by $-1$, so we carry a running sign of $-1$. After the swap the matrix is $\begin{bmatrix} 1 & 2 & 0 \\ 0 & 1 & -2 \\ 2 & 2 & 3 \end{bmatrix}$; the free operation $R_3 \to R_3 - 2R_1$ gives $\begin{bmatrix} 1 & 2 & 0 \\ 0 & 1 & -2 \\ 0 & -2 & 3 \end{bmatrix}$, and $R_3 \to R_3 + 2R_2$ (also free) produces the triangular $\begin{bmatrix} 1 & 2 & 0 \\ 0 & 1 & -2 \\ 0 & 0 & -1 \end{bmatrix}$. The product of the pivots is $1 \cdot 1 \cdot (-1) = -1$, and we multiply by the recorded swap sign $-1$:
$$\det(C) = (-1)^{1 \text{ swap}} \times (1)(1)(-1) = (-1)(-1) = 1.$$
So $\det(C) = 1$ — and had we forgotten the swap sign, we would have reported $-1$, the wrong answer. This is precisely the bookkeeping the toolkit's det_via_lu automates with its sign variable, and it is the same permutation sign the PLU factorization of Chapter 10 records in its matrix $P$.
# Sign-counting with one row swap: det(C) = 1 (forget the swap and you'd get -1).
import numpy as np
C = np.array([[0, 1, -2], [1, 2, 0], [2, 2, 3]], dtype=float)
print("det(C) =", round(float(np.linalg.det(C)))) # 1
det(C) = 1
11.6 Why is det(AB) = det(A)·det(B)? (The most important property)
Of all the determinant's properties, one stands above the rest, both for its usefulness and for how cleanly the geometry explains it:
The Key Insight — The determinant is multiplicative: for any two $n \times n$ matrices, $$\det(AB) = \det(A)\,\det(B).$$ In words: the volume-scaling factor of a composition is the product of the individual scaling factors. If $B$ doubles volumes and $A$ triples them, then doing $B$ and then $A$ multiplies volumes by $2 \times 3 = 6$ — and so $\det(AB) = 6$. This is not a coincidence of the formula; it is the only thing the determinant could do, given that it measures volume scaling and that scalings compose by multiplication.
This is the proof the chapter is built to deliver, so we give it the four-part treatment.
Why we care. Multiplicativity is the property that makes the determinant behave. It tells us how the determinant interacts with composition (Chapter 8), it instantly yields the determinant of an inverse, it is the engine behind the determinant of a product of LU factors, and it is what guarantees that the determinant does not depend on the coordinate system (a fact we will need for eigenvalues in Chapter 24). Almost every later use of the determinant leans on this one line.
Key idea. Recall from Chapter 8 that $AB$ is the composition "do $B$, then do $A$." Applying $B$ scales every volume by $\det(B)$; then applying $A$ scales the already-scaled volume by $\det(A)$. Volume scalings stack by multiplication, so the combined scaling is $\det(A)\det(B)$.
Proof. We argue from the row-operation rules of §11.5, which is rigorous and also illuminates why multiplicativity holds. First handle the case where $B$ is invertible. Any invertible matrix can be built up from the identity by a sequence of elementary row operations, equivalently written as a product of elementary matrices $E_1, E_2, \dots, E_k$ with $B = E_k \cdots E_2 E_1$. Each elementary matrix has a known determinant from §11.5: a row-addition matrix has $\det = 1$, a swap matrix has $\det = -1$, and a row-scaling-by-$c$ matrix has $\det = c$. A short check (the exercises) shows that left- or right-multiplying any matrix $M$ by an elementary matrix $E$ (a row resp. column operation) multiplies its determinant by $\det(E)$ — because left-multiplying by $E$ performs the corresponding row operation on $M$, whose effect on the determinant is exactly the rule from §11.5. Apply this repeatedly: $$\det(AB) = \det(A\,E_k \cdots E_1) = \det(E_k)\cdots\det(E_1)\det(A) = \det(E_k \cdots E_1)\det(A) = \det(B)\det(A),$$ where the middle equality peels off one elementary matrix at a time and the second-to-last reassembles them (taking $A = I$ in the peel-off rule shows $\det(E_k \cdots E_1) = \det(E_k)\cdots\det(E_1) = \det(B)$). Now the singular case: if $B$ is not invertible, then $\det(B) = 0$, and $AB$ is also not invertible (a composition that includes an information-destroying step destroys information), so $\det(AB) = 0$ too; both sides are $0$ and the identity holds. $\blacksquare$
What this means. The determinant is a homomorphism from matrix multiplication to ordinary number multiplication — it converts the complicated operation of composing transformations into the simple operation of multiplying their scaling factors. Geometrically, it says volume scalings compose the obvious way. Two corollaries follow immediately and we will use both constantly.
First, the determinant of an inverse is the reciprocal of the determinant: $$\det(A^{-1}) = \frac{1}{\det(A)} \qquad (\text{for invertible } A).$$ This is forced by multiplicativity: since $A A^{-1} = I$ and $\det(I) = 1$, we have $\det(A)\det(A^{-1}) = 1$. It makes geometric sense — if $A$ triples volumes, its inverse must shrink them back by a factor of $3$, i.e. scale by $\tfrac{1}{3}$. And it re-explains why a singular matrix ($\det(A) = 0$) has no inverse: you cannot divide by zero, so there is no reciprocal scaling that could undo a collapse.
Second, similar matrices have equal determinants: if $B = P^{-1}AP$ then $$\det(B) = \det(P^{-1})\det(A)\det(P) = \frac{1}{\det(P)}\det(A)\det(P) = \det(A).$$ This is the promise we owe to Chapter 16 (change of basis) and Chapter 24 (the characteristic polynomial): changing coordinates does not change the determinant, because the volume-scaling factor of a transformation is a property of the transformation, not of the coordinate system you describe it in. The matrix changes; its determinant does not.
Let us verify multiplicativity numerically — never trust a property you have not checked against numpy.
# det(AB) = det(A) det(B): verify numerically.
import numpy as np
A = np.array([[2, 1], [1, 3]], dtype=float) # det 5
B = np.array([[1, 2], [0, 1]], dtype=float) # det 1 (a shear)
print("det(A) =", round(float(np.linalg.det(A))))
print("det(B) =", round(float(np.linalg.det(B))))
print("det(A)det(B)=", round(float(np.linalg.det(A) * np.linalg.det(B))))
print("det(A @ B) =", round(float(np.linalg.det(A @ B))))
det(A) = 5
det(B) = 1
det(A)det(B)= 5
det(A @ B) = 5
The product of the determinants ($5 \times 1 = 5$) equals the determinant of the product ($5$), as multiplicativity demands. Here $B$ is a shear ($\det = 1$, area-preserving), so composing with it does not change $A$'s scaling factor — which is exactly the geometric statement that shearing first changes shapes but not areas.
FAQ: Why does the transpose have the same determinant?
A companion property is equally clean and worth its own derivation: $\det(A^{\mathsf{T}}) = \det(A)$. Transposing flips a matrix across its diagonal, turning rows into columns. Geometrically this is not obvious — the column box and the "row box" are generally different parallelepipeds — yet they always have the same signed volume. The cleanest argument uses §11.5: every row operation on $A$ corresponds to a column operation on $A^{\mathsf{T}}$ with the same effect on the determinant, and the triangular form of $A$ transposes to the triangular form of $A^{\mathsf{T}}$ with the same diagonal, hence the same product of pivots. The practical payoff is large: every statement about rows is also a statement about columns. Row operations and column operations affect the determinant identically; "two equal rows give $\det = 0$" also reads "two equal columns give $\det = 0$"; and cofactor expansion (next) works along any row or any column, because the transpose symmetry makes rows and columns interchangeable for the determinant.
# det(A^T) = det(A): the transpose has the same determinant.
import numpy as np
A = np.array([[2, 1, 1], [1, 3, 1], [1, 1, 4]], dtype=float)
print("det(A) =", round(float(np.linalg.det(A)))) # 17
print("det(A^T) =", round(float(np.linalg.det(A.T)))) # 17
det(A) = 17
det(A^T) = 17
Both are $17$: transposing leaves the determinant untouched.
11.7 How do you compute a determinant by hand? (Cofactor expansion)
We have deliberately waited until now to give a general formula, because the formula is the least illuminating part of the determinant and the most likely to crowd out the geometry. But you do need a way to compute a determinant by hand for small matrices, and you need to understand the structure of the classical formula — both because it appears everywhere and because it explains why the determinant is "expensive." That formula is cofactor expansion, also called Laplace expansion after Pierre-Simon Laplace [verify].
The idea is recursive: reduce an $n \times n$ determinant to a combination of $(n-1)\times(n-1)$ determinants, then those to $(n-2)\times(n-2)$, and so on down to the $2\times 2$ (or $1\times 1$) base case we already understand. Two pieces of vocabulary:
- The minor $M_{ij}$ is the determinant of the $(n-1)\times(n-1)$ matrix you get by deleting row $i$ and column $j$ from $A$.
- The cofactor $C_{ij}$ is the minor with a sign attached: $C_{ij} = (-1)^{i+j} M_{ij}$. The sign pattern is a checkerboard, $$\begin{bmatrix} + & - & + \\ - & + & - \\ + & - & + \end{bmatrix},$$ with a $+$ in the top-left corner. The sign $(-1)^{i+j}$ is the alternating part of the alternating multilinear form from §11.5's sidebar — it is what makes a reflection flip the sign.
Cofactor expansion along row $i$ then states: $$\det(A) = \sum_{j=1}^{n} a_{ij}\,C_{ij} = a_{i1}C_{i1} + a_{i2}C_{i2} + \dots + a_{in}C_{in}.$$ Because $\det(A^{\mathsf{T}}) = \det(A)$ (the FAQ above), you may expand along any row or any column and get the same answer. This freedom is a real computational gift: expand along whichever row or column has the most zeros, because every zero entry kills an entire minor and saves you a sub-determinant.
Let us compute $\det\begin{bmatrix} 2 & 1 & 1 \\ 1 & 3 & 1 \\ 1 & 1 & 4 \end{bmatrix}$ by expanding along the first row. The three minors (delete row 1, and column $1$, $2$, $3$ in turn): $$M_{11} = \det\begin{bmatrix} 3 & 1 \\ 1 & 4 \end{bmatrix} = 12 - 1 = 11, \quad M_{12} = \det\begin{bmatrix} 1 & 1 \\ 1 & 4 \end{bmatrix} = 4 - 1 = 3, \quad M_{13} = \det\begin{bmatrix} 1 & 3 \\ 1 & 1 \end{bmatrix} = 1 - 3 = -2.$$ Attach the checkerboard signs ($+, -, +$ along the first row) and weight by the first-row entries $a_{11}=2, a_{12}=1, a_{13}=1$: $$\det(A) = +2(11) - 1(3) + 1(-2) = 22 - 3 - 2 = 17.$$ This matches the row-reduction answer and numpy: $\det(A) = 17$. Notice we converted one $3\times 3$ determinant into three $2\times 2$ determinants — that recursion is the whole method.
# Cofactor expansion gives 17; numpy confirms. (The toolkit implements this from scratch.)
import numpy as np
A = np.array([[2, 1, 1], [1, 3, 1], [1, 1, 4]], dtype=float)
# minors along row 0 (numpy is 0-indexed: our row 1 is index 0):
M11 = np.linalg.det(A[1:, [1, 2]]) # delete row 0, col 0
M12 = np.linalg.det(A[1:, [0, 2]]) # delete row 0, col 1
M13 = np.linalg.det(A[1:, [0, 1]]) # delete row 0, col 2
det = 2*M11 - 1*M12 + 1*M13 # checkerboard signs +, -, +
print("cofactor expansion =", round(float(det)))
print("numpy =", round(float(np.linalg.det(A))))
cofactor expansion = 17
numpy = 17
Both give $17$. (Note the index shift the style bible warns about: our mathematical row $1$ is numpy's row index $0$, so "delete row 1" is A[1:, ...], keeping rows from index $1$ onward.)
Common Pitfall — Botching the checkerboard signs. The most common cofactor error is forgetting the alternating sign and computing $a_{i1}M_{i1} + a_{i2}M_{i2} + \dots$ with all plus signs. The signs $(-1)^{i+j}$ are not optional decoration — they are the "alternating" property that makes the formula compute a signed volume. Anchor yourself with the rule "top-left is $+$" and alternate from there; when expanding along the second row or column, remember it starts with a minus. A quick check: a correctly signed expansion of the identity matrix must give $+1$.
11.7.1 Expanding along a zero-rich row (and reading a singular matrix)
The freedom to expand along any row or column is worth exploiting, because every zero entry deletes an entire sub-determinant. Consider $$B = \begin{bmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{bmatrix}.$$ The first column has a zero in the middle, so expanding along the first column (which we may do, thanks to transpose symmetry) costs only two sub-determinants instead of three. Using column-1 entries $b_{11} = 1$, $b_{21} = 0$, $b_{31} = 5$ with the first-column sign pattern $+, -, +$: $$\det(B) = +1\det\begin{bmatrix} 1 & 4 \\ 6 & 0 \end{bmatrix} - 0\,(\cdots) + 5\det\begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix}.$$ The middle term vanishes outright because its coefficient is $0$ — we never even form that minor. The two surviving minors are $\det\begin{bmatrix} 1 & 4 \\ 6 & 0 \end{bmatrix} = 0 - 24 = -24$ and $\det\begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix} = 8 - 3 = 5$, so $$\det(B) = 1(-24) + 5(5) = -24 + 25 = 1.$$ We computed a $3\times 3$ determinant with only two $2\times 2$ evaluations by aiming at the zero. The habit "expand toward the zeros" is the only thing that keeps hand computation of $4\times 4$ determinants tolerable.
# Expand along a zero-rich column: det(B) = 1. numpy agrees.
import numpy as np
B = np.array([[1, 2, 3], [0, 1, 4], [5, 6, 0]], dtype=float)
m11 = np.linalg.det(B[1:, 1:]) # delete row 0, col 0
m31 = np.linalg.det(B[[0, 1]][:, [1, 2]]) # delete row 2, col 0
print("along col 1 =", round(float(1*m11 + 5*m31))) # +1*m11 - 0 + 5*m31
print("numpy =", round(float(np.linalg.det(B))))
along col 1 = 1
numpy = 1
Now contrast a matrix that is singular, so you can see the determinant catch it. Take $$S = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}.$$ At a glance the rows climb in arithmetic progression, which hints at dependence: indeed $R_3 - R_2 = (3,3,3) = R_2 - R_1$, so $R_3 = 2R_2 - R_1$ — the third row is a combination of the first two. The rows are linearly dependent, the row box is flat, and §11.5 promises $\det(S) = 0$. Expanding along the first row confirms it: $\det(S) = 1(5\cdot9 - 6\cdot8) - 2(4\cdot9 - 6\cdot7) + 3(4\cdot8 - 5\cdot7) = 1(-3) - 2(-6) + 3(-3) = -3 + 12 - 9 = 0$. The determinant returned exactly the verdict the geometry demanded: this transformation collapses 3D space onto a plane (the column space is only two-dimensional), it is singular, and it cannot be inverted.
# A singular 3x3 (rows in arithmetic progression): determinant is 0.
import numpy as np
S = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=float)
print("det(S) rounded =", round(float(np.linalg.det(S)), 10)) # 0 (up to rounding)
print("det(S) raw =", float(np.linalg.det(S))) # the unrounded float
det(S) rounded = 0.0
det(S) raw = 0.0
Here numpy lands cleanly on $0$, the exact answer — but do not be lulled. This matrix happens to reduce to a true zero, yet on many singular matrices a computer instead reports a vanishingly small nonzero residue such as $6.66\times 10^{-16}$, because elimination reaches the answer through subtractions that round. This is a small live demonstration of the Warning in §11.2.2: in exact arithmetic $\det(S)$ is precisely $0$ (the rows are dependent, the box is flat), but floating-point arithmetic only promises you "essentially zero." The mathematics says singular; the float says "close to it." The lesson, again, is to judge near-singularity by the condition number (Chapter 38), never by an exact comparison det(A) == 0.
11.7.2 A bonus the determinant unlocks: Cramer's rule
Because the determinant measures volume, it gives a closed-form solution to a square system $A\mathbf{x} = \mathbf{b}$ when $A$ is invertible — Cramer's rule [verify]. The $i$-th unknown is a ratio of determinants: $$x_i = \frac{\det(A_i)}{\det(A)},$$ where $A_i$ is $A$ with its $i$-th column replaced by $\mathbf{b}$. The geometric reasoning is lovely: replacing column $i$ by $\mathbf{b}$ and measuring the volume of the new box, relative to the original box, recovers exactly the coordinate $x_i$ — the volumes encode the coordinates. Cramer's rule is theoretically important (it proves the solution depends continuously and rationally on the data, and it underlies formulas for the inverse), but it is a computational trap: solving an $n\times n$ system by Cramer's rule costs $n+1$ determinants, and if you compute those by cofactors the whole thing is $O((n+1)!)$ — astronomically worse than the $O(n^3)$ Gaussian elimination of Chapter 4. We mention it because it is the most elegant illustration that the determinant carries solution information, and because it is a favorite exam question — not because you should ever use it on a system larger than $2\times 2$ or $3\times 3$.
# Cramer's rule on a 2x2 system, just to see "x_i = det(A_i)/det(A)" work.
import numpy as np
A = np.array([[2, 1], [1, 3]], dtype=float) # det 5
b = np.array([3, 5], dtype=float)
A1 = A.copy(); A1[:, 0] = b # replace column 1 by b
A2 = A.copy(); A2[:, 1] = b # replace column 2 by b
x_cramer = [np.linalg.det(A1)/np.linalg.det(A), np.linalg.det(A2)/np.linalg.det(A)]
print("Cramer :", [round(float(x), 4) for x in x_cramer])
print("solve :", [round(float(x), 4) for x in np.linalg.solve(A, b)])
Cramer : [0.8, 1.4]
solve : [0.8, 1.4]
Cramer's rule and np.linalg.solve agree on $(0.8, 1.4)$ — but solve (Gaussian elimination) is the one you would use for any real system, for exactly the $O(n^3)$-versus-$O(n!)$ reason that recurs throughout this chapter.
There is one place where cofactor expansion is genuinely the right tool, and it is worth stating because it justifies all this machinery.
Geometric Intuition — Cofactor expansion is the natural way to compute a determinant symbolically — when the entries are not numbers but variables. The whole edifice of the characteristic polynomial in Chapter 24, $\det(A - \lambda I) = 0$, comes from expanding a determinant whose entries contain the unknown $\lambda$; you cannot do Gaussian elimination on symbols without dividing by expressions that might be zero, but you can expand by cofactors. Cofactor expansion is also how the $2\times 2$ and $3\times 3$ closed-form formulas (next section) are derived once and for all. So the formula earns its place — just not as the everyday numerical method.
Warning — Cofactor expansion is computationally infeasible for large $n$. Expanding an $n \times n$ determinant produces $n$ sub-determinants of size $(n-1)$, each of which produces $(n-1)$ sub-determinants, and so on — a recursion that fans out to roughly $n!$ (n-factorial) multiplications. The numbers are not close to practical: a $20 \times 20$ determinant by cofactors needs about $20! \approx 2.4 \times 10^{18}$ operations, which even at a billion operations per second would take roughly 77 years. A $30\times 30$ would outlast the age of the universe many times over. By contrast, computing the same determinant by reduction to triangular form (LU, Chapter 10) costs about $n^3/3$ operations — only about $2{,}666$ for $n = 20$, finishing in microseconds. Never use cofactor expansion for numerical work beyond about $3\times 3$ or $4\times 4$. This is exactly the divide between a beautiful formula and a usable algorithm, and it is why our toolkit implements both
det_cofactor(to understand the formula) anddet_via_lu(to actually compute).
11.8 Where do the 2×2 and 3×3 formulas come from?
The familiar closed-form formulas are not separate facts to memorize — they are simply cofactor expansion carried out symbolically for the smallest cases. We derive both so you understand them as consequences, never as definitions.
The $2\times 2$ formula. Expand $\det\begin{bmatrix} a & b \\ c & d \end{bmatrix}$ along the first row. The minor of $a$ is the $1\times 1$ determinant $\det[d] = d$; the minor of $b$ is $\det[c] = c$. With signs $+, -$: $$\det\begin{bmatrix} a & b \\ c & d \end{bmatrix} = +a(d) - b(c) = ad - bc.$$ This is the same $ad - bc$ we derived geometrically in §11.3 as the signed area — two routes, one answer, which is the whole point of this book: geometry and algebra are two views of one object.
The $3\times 3$ formula. Expand $\det\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}$ along the first row, using the three $2\times 2$ minors: $$\det = a\det\begin{bmatrix} e & f \\ h & i \end{bmatrix} - b\det\begin{bmatrix} d & f \\ g & i \end{bmatrix} + c\det\begin{bmatrix} d & e \\ g & h \end{bmatrix} = a(ei - fh) - b(di - fg) + c(dh - eg).$$ Multiplying out gives the six-term form $aei + bfg + cdh - ceg - afh - bdi$, which is the basis of the popular "diagonals" mnemonic (Sarrus's rule [verify]) — three products going down-right minus three going down-left.
Common Pitfall — Trying to extend the diagonals mnemonic to $4\times 4$. The "down-right minus down-left" diagonal trick (Sarrus) works only for $3\times 3$ matrices. There is no $4\times 4$ diagonals rule; the $4\times 4$ determinant has $24$ terms, not $8$, and they do not arrange along clean diagonals. For $4\times 4$ and up, use cofactor expansion (choosing a row or column rich in zeros) or, for numbers, reduce to triangular form. The Sarrus diagonal picture is a $3\times 3$-only convenience, and assuming it generalizes is a classic and costly mistake.
The deepest and most practical formula, though, is not a closed form at all — it is the triangular shortcut, which we have used implicitly and now state explicitly because it is the foundation of every fast determinant algorithm.
The Key Insight — The determinant of a triangular matrix is the product of its diagonal entries. For an upper- or lower-triangular matrix $T$, $$\det(T) = t_{11}\,t_{22}\,\cdots\,t_{nn}.$$ Why: expand by cofactors along the first column of an upper-triangular matrix — only the top entry $t_{11}$ is nonzero in that column, so $\det(T) = t_{11} \times (\text{the determinant of the smaller upper-triangular block})$, and the recursion peels off the diagonal one entry at a time. This is the punchline of §11.5: row-reduce to triangular form, multiply the diagonal pivots, fix up for swaps and scalings, and you have the determinant in $O(n^3)$ instead of $O(n!)$. The identity $\det(I) = 1$ is the simplest special case — all diagonal entries are $1$, product $1$.
Let us confirm the triangular shortcut on a concrete matrix.
# Triangular determinant = product of the diagonal. (Off-triangle entries don't matter.)
import numpy as np
T = np.array([[2, 7, -1],
[0, 3, 5],
[0, 0, 4]], dtype=float)
print("product of diagonal =", 2 * 3 * 4) # 24
print("numpy det =", round(float(np.linalg.det(T))))
product of diagonal = 24
numpy det = 24
Both give $24 = 2 \cdot 3 \cdot 4$: the entries above the diagonal ($7, -1, 5$) contribute nothing, because the matrix never tilts a basis direction onto another in a way that changes volume — a triangular matrix is, in disguise, a sequence of shears (which preserve volume) layered on a diagonal scaling (which sets it). This is the property that makes LU decomposition so powerful for determinants: once $A = LU$ with $L$ unit-lower-triangular ($\det L = 1$) and $U$ upper-triangular, multiplicativity gives $\det(A) = \det(L)\det(U) = 1 \cdot \prod u_{kk}$, the product of $U$'s pivots — adjusted by $(-1)^{(\#\text{swaps})}$ if a permutation $P$ was needed (Chapter 10).
Real-World Application — The change-of-variables factor in probability and machine learning (data science). When a random variable $\mathbf{x}$ is transformed by an invertible map and you want the probability density of the result, you must multiply by the absolute value of the determinant of the transformation's derivative matrix — this is the Jacobian factor, and it is exactly the local volume-scaling factor this chapter is about. It appears in the change-of-variables formula for integrals, in the reparameterization of probability distributions, and at the heart of modern normalizing-flow generative models, where a neural network is deliberately built from layers whose Jacobian determinants are cheap to compute (often triangular, so the determinant is a product of a diagonal — exactly §11.8). The determinant you are learning to read as "how much does this stretch volume?" is the same number that tells a probabilistic model how density concentrates or spreads under a transformation. The full machinery is developed in the Jacobian and change of variables; linear algebra supplies its beating heart, the determinant.
Build Your Toolkit — Implement two functions in
toolkit/determinant.py, both from scratch in pure Python (numpy only to verify). First,det_cofactor(A): a recursive Laplace expansion along the first row — base cases for $1\times 1$ and $2\times 2$, and for larger $n$ a loop that builds each minor by deleting row $0$ and column $j$, attaches the sign $(-1)^{j}$, and addsA[0][j] * det_cofactor(minor). This is the $O(n!)$ formula made literal. Second,det_via_lu(A): forward-eliminate with partial pivoting (reuse the elimination logic fromtoolkit/linear_systems.py), multiply the pivots as you go, and track asignthat flips on every row swap; returnsign * product_of_pivots. This is the $O(n^3)$ algorithm real software uses. Verify both againstnp.linalg.deton random matrices — they should agree to floating-point tolerance — and time them on a $10\times 10$ matrix to feel the gap between $O(n!)$ and $O(n^3)$. You will be implementing, in twenty lines, the exact reason this chapter says "use LU, not cofactors."
11.9 Putting it together: reading a transformation through its determinant
You can now extract a remarkable amount of information from a single number. Given any square matrix $A$, the determinant answers four questions at once: Is $A$ invertible? (Yes iff $\det(A) \neq 0$.) Does $A$ preserve or destroy information? (Preserves iff $\det(A) \neq 0$; a zero determinant flags a collapse.) Does $A$ flip orientation? (Yes iff $\det(A) < 0$.) By how much does $A$ scale volume? ($|\det(A)|$.) None of these requires knowing where individual points go — they are global verdicts about the transformation, read off one scalar.
Return one final time to the visualizer's title, which has shown a determinant in every figure of this book. In Chapter 1 it was a mysterious annotation; you can now read it fluently. det = 1.00 (the identity, every rotation, every shear): area preserved, orientation preserved, invertible. det = 2.00: area doubled, orientation preserved, invertible. det = -1.00 (a reflection): area preserved, orientation flipped, invertible. det = 0.00 (a projection): area destroyed, space collapsed, not invertible. The number was telling you the whole story all along; this chapter simply taught you the language.
Real-World Application — Unique market equilibrium in economics. A simple linear economic model — supply-and-demand across several interacting markets, or Leontief's input–output model of an economy — takes the form $A\mathbf{p} = \mathbf{b}$, where $\mathbf{p}$ is a vector of prices (or production levels) and $A$ encodes how the markets influence one another. The model has a unique equilibrium exactly when $A$ is invertible, i.e. exactly when $\det(A) \neq 0$. A zero determinant is the economist's warning that the markets are degenerate — they do not pin down a single price vector, because some markets are redundant combinations of others (the columns are dependent), so either no equilibrium exists or infinitely many do. The determinant thus serves as a one-number diagnostic for "is this economy well-posed?", the same role it plays in every linear system since Chapter 3. The magnitude even carries meaning: a determinant close to zero signals an economy near degeneracy, where tiny shifts in conditions cause wild swings in equilibrium prices — the economic face of the ill-conditioning we formalize in Chapter 38.
Computational Note —
np.linalg.detdoes not compute a cofactor expansion; under the hood it performs an LU decomposition (Chapter 10) and multiplies the pivots, then applies the permutation sign — exactly the $O(n^3)$det_via_luyou build in this chapter's toolkit. That is why it returns a float even for an all-integer matrix (note our snippets wrap it inround(...)to recover the clean integer): the LU pivots are computed in floating point, so a determinant you know is an exact integer can arrive with a trailing rounding error like...0004instead of landing cleanly — which integer matrices happen to do depends on the elimination path, and you should never rely on exact equality. For matrices with very large or very small determinants, the product of pivots can also overflow or underflow, which is why scipy offersscipy.linalg.slogdet, returning the sign and the log of the absolute determinant separately — the numerically safe way to compare determinants that span many orders of magnitude (common in statistics, where $\log\det$ of a covariance matrix appears directly in the Gaussian likelihood).Check Your Understanding — A $3\times 3$ matrix $A$ has $\det(A) = -4$. Answer four questions: Is $A$ invertible? Does it preserve volume? Does it flip orientation? If $B$ is a $3\times3$ matrix with $\det(B) = \tfrac{1}{2}$, what is $\det(AB)$ and $\det(A^{-1})$?
Answer
Invertible? Yes — $\det(A) = -4 \neq 0$. Preserves volume? No — it scales volume by $|{-4}| = 4$, quadrupling it. Flips orientation? Yes — the sign is negative, so $A$ turns 3D space inside out (right-handed becomes left-handed). $\det(AB)$? By multiplicativity, $\det(A)\det(B) = (-4)(\tfrac{1}{2}) = -2$. $\det(A^{-1})$? The reciprocal, $\tfrac{1}{\det(A)} = -\tfrac{1}{4}$ — the inverse must shrink volumes by a factor of $4$ and flip orientation back. Every answer came from the determinant alone, with no knowledge of $A$'s entries.
Historical Note — Determinants are actually older than matrices. The idea appears in the work of Seki Takakazu in Japan (1683) and Gottfried Wilhelm Leibniz in Europe (1693), both studying when systems of linear equations have solutions — long before anyone wrote down a matrix as such [verify]. Cauchy gave the modern systematic treatment and the name "determinant" in 1812, and the geometric reading as a volume is essentially due to the same era's work on multiple integrals and the Jacobian [verify]. It is a charming inversion of how the subject is taught: historically the determinant came first, as a test for solvability, and the matrix it determines came after. We have spent this book insisting that the transformation is primary and the determinant a derived measurement — which is the modern, geometric view, and the better one for understanding, even if history ran the other way.
11.10 Summary: the determinant is a volume verdict
Strip away the formulas and the determinant is one idea: it is the signed volume-scaling factor of a transformation. Its magnitude says how much areas and volumes grow or shrink; its sign says whether space is flipped; its vanishing says the transformation has collapsed a dimension and is therefore singular and irreversible. Everything computational — the $2\times 2$ and $3\times 3$ formulas, cofactor expansion, the triangular shortcut, the row-operation rules, multiplicativity — serves that geometric meaning, either by computing it or by explaining how it behaves.
The properties form a tight, memorable web, all of them statements about volume: $\det(AB) = \det(A)\det(B)$ (scalings compose by multiplication), $\det(A^{\mathsf{T}}) = \det(A)$ (rows and columns enclose the same volume), $\det(A^{-1}) = 1/\det(A)$ (undoing a scaling is the reciprocal scaling), $\det(I) = 1$ (doing nothing preserves volume), and the triangular product rule (shears are free, the diagonal sets the scale). For computing a determinant you have two honest tools and a clear rule for choosing between them: cofactor expansion for small or symbolic matrices (and for deriving the closed forms), and reduction to triangular form via LU for everything numerical, because cofactors cost $O(n!)$ while LU costs $O(n^3)$.
This chapter is also a clean illustration of two of the book's recurring themes. Geometry and algebra are two views of one object (Theme 2): the determinant is simultaneously a messy alternating sum of products and a single clean statement about volume, and the best linear algebraists hold both views at once — they compute $ad - bc$ while seeing a parallelogram's area. And computation validates theory while theory guides computation (Theme 3): we proved multiplicativity rigorously, checked every determinant against numpy, and will implement both algorithms from scratch in the toolkit, with the $O(n!)$-versus-$O(n^3)$ contrast showing exactly why a correct formula is not the same as a usable one. The determinant also quietly previews the four fundamental subspaces of Part III: $\det(A) = 0$ is the precise boundary at which the column space drops below full dimension and the null space becomes nontrivial — the collapse picture is the four-subspaces picture in miniature, seen for square matrices.
We close Part II's exploration of matrices-as-transformations here. We have seen a matrix as a function (Chapter 7), composed them (Chapter 8), undone them (Chapter 9), factored them efficiently (Chapter 10), and now measured how much they stretch and whether they flip space (this chapter). The determinant's most important role still lies ahead: in Chapter 24 it produces the characteristic polynomial $\det(A - \lambda I) = 0$, whose roots are the eigenvalues — the numbers that reveal what a matrix really does, stripped of any coordinate system. The volume verdict you learned to read here becomes, there, the key that unlocks the heart of the book. First, though, Chapter 12 cashes in everything from Part II at once, building the rotation, scaling, and translation matrices behind every frame of computer graphics — where, as you now know, the determinant silently guards orientation so that no triangle is accidentally drawn inside out.