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 be the input, an matrix over a field , and let be the working matrix. Rows and columns are indexed from , as in the pseudocode.
Claim. GAUSSIAN-ELIMINATION stops after iterations of line L2 and returns such that for an invertible matrix , is in echelon form with exactly nonzero rows, and lists the column of the leading entry of rows of . Hence and is the column rank profile of .
Termination. Line L2 runs over the values . Lines L3 and L6 to L8 are loops over at most and values. So the algorithm stops.
Invariant. At the start of the iteration of line L2 with column (and at the end, with ):
- (G1) for some invertible matrix .
- (G2) has entries, , and for each , row of has and for all .
- (G3) For each row and each column , .
Initialization. For , and is empty. (G1) holds with , and (G2) and (G3) hold because there is no row and no column .
Maintenance. Assume (G1) to (G3) at the start of the iteration for column .
Case 1: line L3 finds no row with . Then column is zero in rows . Together with (G3) for columns , this gives (G3) for columns . Nothing else changes, so (G1) and (G2) hold for .
Case 2: line L3 finds with . Line L5 swaps rows and . Both rows have index at least , so (G2) is not affected, and by (G3) both rows are zero in columns . Now . For each , lines L7 and L8 subtract times row from row . 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 , which is enough, because row is zero in columns . After the update, . Rows do not change. So after the loop of line L6:
- row is zero in columns and , so its leading column is , and by (G2);
- each row is zero in columns (it was before, and those columns did not change) and in column .
Line L9 appends to and line L10 adds to . With the new values, (G2) holds by the first point, and (G3) holds for columns by the second point.
End. At the end, . By (G3), each row is zero in all columns. By (G2), rows are nonzero and their leading columns increase. This is the definition of echelon form with nonzero rows, and by (G1) the result is an echelon form of . The theorem on the echelon form page shows that the number of nonzero rows and the pivot columns of any echelon form of are the rank and the column rank profile of .
Lemma (SOLVE). SOLVE returns a vector with when one exists, and reports that there is no solution otherwise.
Proof. Let be the result of the elimination of the augmented matrix , which has columns. By (G1), with invertible, where is the last column of the result. So holds exactly when holds, where is the first columns. This is because and both map the residual to and back.
If the last pivot column is , the column of , then row is zero in columns and has . Its equation reads , so there is no solution.
Otherwise all pivots lie in columns . Rows are zero including column , so their equations read . Back substitution sets each free variable (a column not in ) to and visits the pivot rows . Row reads , because the entries left of are zero. When row is visited, each with already has its final value: a free variable is , and a pivot variable with has , so it was set earlier. The algorithm sets , which is defined since and makes equation true. Later steps change only with , which do not occur in equation . So at the end each equation of holds, and .