Algorithm Search⌘K

Proofs: Determinant by Gaussian elimination

These are the human proofs of Determinant by Gaussian elimination, at full length.

Elimination returns the determinant full

This proof shows: correctness, termination.

Let A0A_0 be the input, an n×nn \times n matrix over a field KK, and let AA be the working matrix. Indices start at 00, as in the pseudocode. For 0≤k≤n0 \le k \le n, let SkS_k be the submatrix of the working matrix in rows k,…,n−1k, \dots, n-1 and columns k,…,n−1k, \dots, n-1; SnS_n is the 0×00 \times 0 matrix, with determinant 11.

Claim. DET-ELIM(A0)(A_0) stops and returns det⁡A0\det A_0.

Termination. Line L2 runs kk over nn values, and the loops of lines L3, L7 and L9 have at most nn steps each. Line L4 may stop the algorithm earlier.

Lemma. Let TT be a square matrix of size s≥1s \ge 1 whose first column is (t,0,…,0)T(t, 0, \dots, 0)^T, and let T′T' be TT without its first row and first column. Then det⁡T=t⋅det⁡T′\det T = t \cdot \det T'.

Proof. In the Leibniz formula det⁡T=∑σsgn⁡(σ)∏jTσ(j)j\det T = \sum_\sigma \operatorname{sgn}(\sigma) \prod_j T_{\sigma(j) j}, the factor for column 11 is 00 unless σ(1)=1\sigma(1) = 1. The permutations with σ(1)=1\sigma(1) = 1 are the permutations of {2,…,s}\{2, \dots, s\}, with the same sign and the same remaining factors, so the sum is t⋅det⁡T′t \cdot \det T'. □\square

Invariant. At the start of the iteration of line L2 with index kk:

det⁡A0=d⋅det⁡Sk.(∗)\det A_0 = d \cdot \det S_k. \qquad (\ast)

Initialization. For k=0k = 0, d=1d = 1 and S0S_0 is the whole working matrix, which equals A0A_0.

Maintenance. Assume (∗)(\ast) at the start of iteration kk.

If line L3 finds no index i≥ki \ge k with A[i,k]≠0A[i, k] \ne 0, then the first column of SkS_k is zero, so det⁡Sk=0\det S_k = 0 (the determinant is linear in that column). By (∗)(\ast), det⁡A0=0\det A_0 = 0, and line L4 returns 00, which is correct.

Otherwise line L5 swaps rows kk and pp of AA when p≠kp \ne k. Both rows meet SkS_k, so this swaps two rows of SkS_k, which negates det⁡Sk\det S_k. Line L5 also negates dd, so the product d⋅det⁡Skd \cdot \det S_k does not change. Now A[k,k]≠0A[k, k] \ne 0.

For each i>ki > k, lines L8 and L9 subtract f=A[i,k]/A[k,k]f = A[i, k]/A[k, k] times row kk from row ii, in the columns t>kt > k. Consider the matrix Sk′S'_k that this step would give if it also updated column kk. Adding a multiple of one row to another row does not change a determinant, so det⁡Sk′=det⁡Sk\det S'_k = \det S_k. In Sk′S'_k the first column is (A[k,k],0,…,0)T(A[k, k], 0, \dots, 0)^T, because A[i,k]−fA[k,k]=0A[i, k] - f A[k, k] = 0. By the lemma, det⁡Sk′=A[k,k]⋅det⁡Sk+1′\det S'_k = A[k, k] \cdot \det S'_{k+1}, where Sk+1′S'_{k+1} is Sk′S'_k without its first row and column. The matrix Sk+1′S'_{k+1} is exactly the new Sk+1S_{k+1}, since line L9 updates all columns t>kt > k of the rows i>ki > k and line L9 never needs column kk again. Line L6 multiplied dd by A[k,k]A[k, k]. So after the iteration,

dnew⋅det⁡Sk+1=d⋅A[k,k]⋅det⁡Sk+1=d⋅det⁡Sk=det⁡A0,d_{\text{new}} \cdot \det S_{k+1} = d \cdot A[k, k] \cdot \det S_{k+1} = d \cdot \det S_k = \det A_0,

which is (∗)(\ast) for k+1k + 1.

End. If line L4 never returns, the loop ends with k=nk = n. Then SnS_n is empty with determinant 11, so (∗)(\ast) gives det⁡A0=d\det A_0 = d, and line L10 returns dd. ■\blacksquare

Remark. The proof also shows that dd is, up to the sign (−1)s(-1)^s for ss swaps, the product of the pivots, and that each pivot A[k,k]A[k, k] after step kk is the quotient det⁡Ak/det⁡Ak−1\det A_k / \det A_{k-1} of two leading principal minors of the row-permuted input. This is the fact that bounds the sizes of the numbers over Q\mathbb{Q}.

Back to Determinant by Gaussian elimination