Algorithm Search⌘K

Proofs: Gaussian elimination

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

Gaussian elimination returns an echelon form, the rank and the pivot columns full

This proof shows: correctness, termination.

Let A0A_0 be the input, an m×nm \times n matrix over a field KK, and let AA be the working matrix. Rows and columns are indexed from 00, as in the pseudocode.

Claim. GAUSSIAN-ELIMINATION(A0)(A_0) stops after nn iterations of line L2 and returns (E,r,P)(E, r, P) such that E=UA0E = U A_0 for an invertible m×mm \times m matrix UU, EE is in echelon form with exactly rr nonzero rows, and P=(P0,…,Pr−1)P = (P_0, \dots, P_{r-1}) lists the column of the leading entry of rows 0,…,r−10, \dots, r-1 of EE. Hence r=rank⁡A0r = \operatorname{rank} A_0 and PP is the column rank profile of A0A_0.

Termination. Line L2 runs jj over the nn values 0,…,n−10, \dots, n-1. Lines L3 and L6 to L8 are loops over at most mm and nn values. So the algorithm stops.

Invariant. At the start of the iteration of line L2 with column jj (and at the end, with j=nj = n):

  • (G1) A=UA0A = U A_0 for some invertible matrix UU.
  • (G2) PP has rr entries, P0<P1<⋯<Pr−1<jP_0 < P_1 < \cdots < P_{r-1} < j, and for each k<rk < r, row kk of AA has A[k,Pk]≠0A[k, P_k] \ne 0 and A[k,t]=0A[k, t] = 0 for all t<Pkt < P_k.
  • (G3) For each row i≥ri \ge r and each column t<jt < j, A[i,t]=0A[i, t] = 0.

Initialization. For j=0j = 0, r=0r = 0 and PP is empty. (G1) holds with U=IU = I, and (G2) and (G3) hold because there is no row k<0k < 0 and no column t<0t < 0.

Maintenance. Assume (G1) to (G3) at the start of the iteration for column jj.

Case 1: line L3 finds no row p≥rp \ge r with A[p,j]≠0A[p, j] \ne 0. Then column jj is zero in rows r,…,m−1r, \dots, m-1. Together with (G3) for columns t<jt < j, this gives (G3) for columns t<j+1t < j+1. Nothing else changes, so (G1) and (G2) hold for j+1j + 1.

Case 2: line L3 finds p≥rp \ge r with A[p,j]≠0A[p, j] \ne 0. Line L5 swaps rows rr and pp. Both rows have index at least rr, so (G2) is not affected, and by (G3) both rows are zero in columns t<jt < j. Now A[r,j]≠0A[r, j] \ne 0. For each i>ri > r, lines L7 and L8 subtract f=A[i,j]/A[r,j]f = A[i, j]/A[r, j] times row rr from row ii. A row swap and the addition of a multiple of one row to another are left multiplications by invertible elementary matrices, so (G1) still holds. Line L8 changes only columns t≥jt \ge j, which is enough, because row rr is zero in columns t<jt < j. After the update, A[i,j]=A[i,j]−(A[i,j]/A[r,j])A[r,j]=0A[i, j] = A[i, j] - (A[i, j]/A[r, j]) A[r, j] = 0. Rows 0,…,r−10, \dots, r-1 do not change. So after the loop of line L6:

  • row rr is zero in columns t<jt < j and A[r,j]≠0A[r, j] \ne 0, so its leading column is jj, and j>Pr−1j > P_{r-1} by (G2);
  • each row i>ri > r is zero in columns t<jt < j (it was before, and those columns did not change) and in column jj.

Line L9 appends jj to PP and line L10 adds 11 to rr. With the new values, (G2) holds by the first point, and (G3) holds for columns t<j+1t < j + 1 by the second point.

End. At the end, j=nj = n. By (G3), each row i≥ri \ge r is zero in all nn columns. By (G2), rows 0,…,r−10, \dots, r-1 are nonzero and their leading columns P0<⋯<Pr−1P_0 < \cdots < P_{r-1} increase. This is the definition of echelon form with rr nonzero rows, and by (G1) the result is an echelon form of A0A_0. The theorem on the echelon form page shows that the number of nonzero rows and the pivot columns of any echelon form of A0A_0 are the rank and the column rank profile of A0A_0. ■\blacksquare

Lemma (SOLVE). SOLVE(A0,b)(A_0, b) returns a vector xx with A0x=bA_0 x = b when one exists, and reports that there is no solution otherwise.

Proof. Let (E,r,P)(E, r, P) be the result of the elimination of the augmented matrix [A0∣b][A_0 \mid b], which has n+1n + 1 columns. By (G1), [E∣c]=U[A0∣b][E \mid c] = U [A_0 \mid b] with UU invertible, where cc is the last column of the result. So A0x=bA_0 x = b holds exactly when E′x=cE' x = c holds, where E′E' is the first nn columns. This is because UU and U−1U^{-1} both map the residual A0x−bA_0 x - b to E′x−cE' x - c and back.

If the last pivot column is nn, the column of bb, then row r−1r - 1 is zero in columns 0,…,n−10, \dots, n-1 and has cr−1≠0c_{r-1} \ne 0. Its equation reads 0=cr−10 = c_{r-1}, so there is no solution.

Otherwise all pivots lie in columns 0,…,n−10, \dots, n-1. Rows r,…,m−1r, \dots, m-1 are zero including column nn, so their equations read 0=00 = 0. Back substitution sets each free variable (a column not in PP) to 00 and visits the pivot rows k=r−1,r−2,…,0k = r-1, r-2, \dots, 0. Row kk reads ∑t≥PkE[k,t]xt=ck\sum_{t \ge P_k} E[k, t] x_t = c_k, because the entries left of PkP_k are zero. When row kk is visited, each xtx_t with t>Pkt > P_k already has its final value: a free variable is 00, and a pivot variable xPk′x_{P_{k'}} with Pk′>PkP_{k'} > P_k has k′>kk' > k, so it was set earlier. The algorithm sets xPk=(ck−∑t>PkE[k,t]xt)/E[k,Pk]x_{P_k} = (c_k - \sum_{t > P_k} E[k, t] x_t)/E[k, P_k], which is defined since E[k,Pk]≠0E[k, P_k] \ne 0 and makes equation kk true. Later steps change only xtx_t with t<Pkt < P_k, which do not occur in equation kk. So at the end each equation of E′x=cE' x = c holds, and A0x=bA_0 x = b. ■\blacksquare

Back to Gaussian elimination