A pedagogical introduction to the determinant
Motivation
The determinant of a matrix is typically introduced in an undergraduate linear algebra course via either the Leibniz Formula or a recurrence relation arising from the Leibniz Formula. Pedagogically, it is better to introduce the determinant as a mapping which satisfies some desirable properties and only then show that it is equivalent to the Leibniz Formula. This short expository post attempts to do just that.
Determinant
A determinant function is a mapping
- If the matrix
is obtained by swapping two rows of , then . - If the matrix
is obtained by multiplying a single row of by a constant , then . - If the matrix
is obtained by adding a multiple of a row of to another (not the same) row, then . .
The first three points above correspond to the three elementary row operations.
Proposition.
Let
Proof.
In this case, we can perform a sequence of elementary row operations (excluding multiplying a row by
Indeed, by performing elimination to reduce the matrix into either the identity or a matrix with at least one row of zeros, we can unambiguously define a determinant function (note that we have not yet proven that such a function is unique). The code below does just that, proving the existence of a determinant function. For now, we refer to this as the canonical determinant.
Remark. The code below operates on floating point numbers. The definition of the canonical determinant should be understood to be the “algebraic” version of this code that runs without deference to floating point error.
View code
def det(mat: np.ndarray) -> float:
"""Computes a determinant.
This algorithm works by eliminating the strict lower triangular part of the
matrix and then eliminating the strict upper triangular part of the matrix.
This elimination is done using row operations, while keeping track of any
swaps that may change the sign parity of the determinant.
If you are already familiar with the determinant, you will note that
eliminating the strict upper triangular part is not necessary. Even if this
algorithm was optimized to remove that step, this is still not a performant
way to compute determinants!
Parameters
----------
mat
A matrix
Returns
-------
Determinant
"""
m, n = mat.shape
assert m == n
mat = mat.copy()
sign = 1
for _ in range(2):
for j in range(n):
# Find pivot element
p = -1
for i in range(j, n):
if not np.isclose(mat[i, j], 0.0):
p = i
break
if p < 0:
continue
# Swap
if j != p:
r = mat[p].copy()
mat[p] = mat[j]
mat[j] = r
sign *= -1
# Eliminate
for i in range(j + 1, n):
if not np.isclose(mat[i, j], 0.0):
mat[i] -= mat[p] * mat[i, j] / mat[p, j]
mat = mat.T
return float(sign) * np.diag(mat).prod().item()
Alternating multilinear maps
Notation.
For a set
Definition (Alternating multilinear map).
Let
Notation.
Let
Proposition (Transposition parity).
Let
Proof.
Let
It follows that
and hence
Corollary.
Let
Proof.
Let
Corollary.
Let
Proof.
The result follows from the fact that a permutation can be written as a composition of transpositions.
Proposition.
A multilinear map
Proof.
Suppose the map is alternating multilinear. Let
The converse is trivial.
The Leibniz formula
Notation.
If
Proposition (Uniqueness).
Let
where
Proof. First, note that
Since
Since
Using the assumption
Remark.
Proposition. A determinant function is multilinear.
Proof.
Let
Suppose the rows of
and
as desired.
Suppose the rows of
Corollary. A determinant function is an alternating multilinear map.
Corollary.
There is only one determinant function and it is given by the
Determinant properties
We can now use the
Proposition.
Proof.
Notation.
For a matrix
Lemma.
Proof.
We demonstrate the idea for a
Using multilinearity,
Moreover, by the Leibniz Formula,
The remaining terms are handled similarly.
Proposition (Cofactor expansion).
For any
Proof.
Recalling that the determinant flips signs when any two rows are swapped, we can perform a sequence of
Corollary.
If
Proof.
First, note that it is sufficient to consider the lower triangular case since the transpose of an upper triangular matrix is lower triangular.
The result then follows from performing a cofactor expansion along the first row inductively.
Proposition.
Proof.
If either
As with the construction of the canonical determinant, we can write
where
Corollary.
The determinant of an
Proof.
Let