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 be the input, an matrix over a field , and let be the working matrix. Indices start at , as in the pseudocode. For , write for the submatrix of in all rows and columns .
Claim. GAUSS-JORDAN stops and returns the reduced row echelon form of , its rank , and the list of its pivot columns.
Termination. Line L2 runs over values. In each iteration, line L3 looks at most entries, and the loops of lines L6, L7 and L9 have at most and steps. So the algorithm stops after steps.
Invariant. At the start of the iteration of line L2 with index :
- (I1) for an invertible matrix .
- (I2) , the list is increasing, and its entries are less than .
- (I3) is in reduced row echelon form, its pivot columns are the entries of , and the rows of are zero.
Initialization. For , , and is empty. The matrix has no columns, so (I3) holds.
Maintenance. Assume the invariant at the start of iteration .
If line L3 finds no row with , then line L4 skips to the next column. Column is zero in the rows , so the rows of are zero. The rows of already have their leading entries in the columns of , so column adds no new leading entry. Hence is in reduced row echelon form with the same pivot columns, and (I1) to (I3) hold for .
Otherwise line L5 swaps rows and , line L6 divides row by the nonzero , and lines L7 to L9 subtract times row from every other row . Each of these steps multiplies on the left by an invertible elementary matrix, so (I1) holds after the iteration. By (I3), row is zero in the columns before the iteration, because is one of the zero rows of , and row is zero there too. So the code changes nothing in the columns less than when it updates only the columns : the skipped updates subtract a multiple of . After the iteration:
- Column is the unit vector . Row has , and each row has .
- The columns of do not change, because row is zero in them. So they are still unit vectors .
- Row is zero in the columns less than and has the entry in column . Its leading entry is in column , to the right of the leading entries of the rows , which are in the columns of , all less than .
- The rows are zero in the columns and now in column too.
Line L10 appends to and increments . So is in reduced row echelon form with pivot columns , its rows are zero, and (I2) and (I3) hold for .
End. The loop ends with . By (I3), is in reduced row echelon form, with pivot columns and exactly nonzero rows. By (I1), with invertible, so and have the same row space: each row of is a combination of the rows of , and each row of is a combination of the rows of . A matrix in reduced row echelon form is determined by its row space (the uniqueness theorem on the echelon form page), so is the reduced row echelon form of . Its nonzero rows are linearly independent, so is the rank of . Line L11 returns , and .
The inverse. Let be and run the algorithm on . The algorithm handles the columns from left to right, and the decisions in the first columns depend only on those columns, so the pivots among are the pivots of . If is invertible, its rank is , so the pivots are exactly . Then the result is , and its left half is a reduced row echelon form with pivots in columns, which is . So and the right half is . If is singular, its rank is less than , so some column less than is not a pivot, and INVERSE returns NONE.
The solution. Run the algorithm on and get with and . The systems and have the same solutions, since is invertible. If column is a pivot, then some row of is , which is the equation , so there is no solution. Otherwise, the rows are zero, and row is the equation . With the free variables for , this gives , which is what SOLVE returns.