Algorithm Search⌘K

Proofs: Gauss-Jordan elimination

These are the human proofs of Gauss-Jordan elimination, at full length.

Gauss-Jordan elimination returns the reduced row echelon form 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. Indices start at 00, as in the pseudocode. For 0≤j≤n0 \le j \le n, write A<jA_{<j} for the submatrix of AA in all rows and columns 0,…,j−10, \dots, j-1.

Claim. GAUSS-JORDAN(A0)(A_0) stops and returns the reduced row echelon form EE of A0A_0, its rank rr, and the list PP of its pivot columns.

Termination. Line L2 runs jj over nn values. In each iteration, line L3 looks at most mm entries, and the loops of lines L6, L7 and L9 have at most mm and nn steps. So the algorithm stops after O(mnmin⁡(m,n)+mn)O(mn \min(m, n) + mn) steps.

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

  • (I1) A=TA0A = T A_0 for an invertible m×mm \times m matrix TT.
  • (I2) r=∣P∣r = |P|, the list PP is increasing, and its entries are less than jj.
  • (I3) A<jA_{<j} is in reduced row echelon form, its pivot columns are the entries of PP, and the rows r,…,m−1r, \dots, m-1 of A<jA_{<j} are zero.

Initialization. For j=0j = 0, T=IT = I, r=0r = 0 and PP is empty. The matrix A<0A_{<0} has no columns, so (I3) holds.

Maintenance. Assume the invariant at the start of iteration jj.

If line L3 finds no row i≥ri \ge r with A[i,j]≠0A[i, j] \ne 0, then line L4 skips to the next column. Column jj is zero in the rows r,…,m−1r, \dots, m-1, so the rows r,…,m−1r, \dots, m-1 of A<j+1A_{<j+1} are zero. The rows 0,…,r−10, \dots, r-1 of A<jA_{<j} already have their leading entries in the columns of PP, so column jj adds no new leading entry. Hence A<j+1A_{<j+1} is in reduced row echelon form with the same pivot columns, and (I1) to (I3) hold for j+1j + 1.

Otherwise line L5 swaps rows rr and pp, line L6 divides row rr by the nonzero c=A[r,j]c = A[r, j], and lines L7 to L9 subtract f=A[i,j]f = A[i, j] times row rr from every other row ii. Each of these steps multiplies AA on the left by an invertible elementary matrix, so (I1) holds after the iteration. By (I3), row rr is zero in the columns 0,…,j−10, \dots, j-1 before the iteration, because rr is one of the zero rows of A<jA_{<j}, and row p≥rp \ge r is zero there too. So the code changes nothing in the columns less than jj when it updates only the columns t≥jt \ge j: the skipped updates subtract a multiple of 00. After the iteration:

  • Column jj is the unit vector ere_r. Row rr has A[r,j]=c/c=1A[r, j] = c / c = 1, and each row i≠ri \ne r has A[i,j]−f⋅1=0A[i, j] - f \cdot 1 = 0.
  • The columns of PP do not change, because row rr is zero in them. So they are still unit vectors e0,…,er−1e_0, \dots, e_{r-1}.
  • Row rr is zero in the columns less than jj and has the entry 11 in column jj. Its leading entry is in column jj, to the right of the leading entries of the rows 0,…,r−10, \dots, r-1, which are in the columns of PP, all less than jj.
  • The rows r+1,…,m−1r+1, \dots, m-1 are zero in the columns 0,…,j−10, \dots, j-1 and now in column jj too.

Line L10 appends jj to PP and increments rr. So A<j+1A_{<j+1} is in reduced row echelon form with pivot columns PP, its rows r,…,m−1r, \dots, m-1 are zero, and (I2) and (I3) hold for j+1j + 1.

End. The loop ends with j=nj = n. By (I3), A=A<nA = A_{<n} is in reduced row echelon form, with pivot columns PP and exactly rr nonzero rows. By (I1), A=TA0A = T A_0 with TT invertible, so AA and A0A_0 have the same row space: each row of AA is a combination of the rows of A0A_0, and each row of A0=T−1AA_0 = T^{-1} A is a combination of the rows of AA. A matrix in reduced row echelon form is determined by its row space (the uniqueness theorem on the echelon form page), so AA is the reduced row echelon form of A0A_0. Its nonzero rows are linearly independent, so rr is the rank of A0A_0. Line L11 returns AA, rr and PP. ■\blacksquare

The inverse. Let A0A_0 be n×nn \times n and run the algorithm on [A0∣I][A_0 \mid I]. The algorithm handles the columns from left to right, and the decisions in the first nn columns depend only on those columns, so the pivots among 0,…,n−10, \dots, n-1 are the pivots of A0A_0. If A0A_0 is invertible, its rank is nn, so the pivots are exactly 0,…,n−10, \dots, n-1. Then the result is T[A0∣I]=[TA0∣T]T [A_0 \mid I] = [T A_0 \mid T], and its left half is a reduced row echelon form with nn pivots in nn columns, which is II. So TA0=IT A_0 = I and the right half TT is A0−1A_0^{-1}. If A0A_0 is singular, its rank is less than nn, so some column less than nn is not a pivot, and INVERSE returns NONE. ■\blacksquare

The solution. Run the algorithm on [A0∣b][A_0 \mid b] and get [E∣c][E \mid c] with E=TA0E = T A_0 and c=Tbc = T b. The systems A0x=bA_0 x = b and Ex=cE x = c have the same solutions, since TT is invertible. If column nn is a pivot, then some row of [E∣c][E \mid c] is (0,…,0,1)(0, \dots, 0, 1), which is the equation 0=10 = 1, so there is no solution. Otherwise, the rows r,…,m−1r, \dots, m-1 are zero, and row i<ri < r is the equation xPi+∑t∉PE[i,t] xt=cix_{P_i} + \sum_{t \notin P} E[i, t]\, x_t = c_i. With the free variables xt=0x_t = 0 for t∉Pt \notin P, this gives xPi=cix_{P_i} = c_i, which is what SOLVE returns. ■\blacksquare

Back to Gauss-Jordan elimination