Proofs: Matrix balancing
These are the human proofs of Matrix balancing, at full length.
Balancing is an exact similarity, lowers the off-diagonal mass at every step, and terminates full
This proof shows: correctness, termination.
Notation of the page: is the current matrix, , , , the radix (an integer power of 2 in the implementation, so that it is the machine radix or a power of it), and . Lemmas 2 to 5 use exact values of and ; the remark at the end covers their rounding.
Lemma 1 (exact similarity). Suppose no entry overflows or underflows. After any number of accepted steps, the stored matrix equals exactly, with , and .
Proof. Line L9 multiplies the entries of column by and divides those of row by ; the diagonal entry is multiplied and divided, so it is unchanged. Multiplying a binary floating-point number by a power of 2 changes only its exponent, so in the absence of overflow and underflow every such product is exact. The step therefore replaces by exactly, with in position , and multiplies by , again exactly. By induction the stored matrix is with . Finally .
Lemma 2 (the choice of f). Let . Line L7 returns the power with , and this minimizes over all integer powers of .
Proof. Let . The first loop multiplies by and by while , so at its end ; if it ran at least once, the value before the last step was below , so . The second loop divides by and by while ; if it runs, the first loop did not, and it stops at the first value below , which is at least . Both loops stop after finitely many steps, since each multiplies by . In all cases .
For optimality write , so with . The function is decreasing on , increasing on and satisfies , so whenever . The other powers of give with . Since and , every other power gives a value at least .
Lemma 3 (descent). An accepted step at index lowers by more than .
Proof. The step changes only the off-diagonal entries of column (multiplied by ) and of row (divided by ); these sets are disjoint and their masses are and . All other off-diagonal entries are unchanged. So changes by , which is below by the test of line L8. Line L6 ensures .
Theorem 4 (correctness). When the algorithm returns, exactly, has powers of on the diagonal, with multiplicities, , and if is an eigenvector of then is an eigenvector of for the same eigenvalue. If it returns CONVERGED, then for every with and every integer , .
Proof. The first statements are Lemma 1 and Lemma 3. If then , and . On CONVERGED the last sweep accepted no step, so the matrix did not change during it, and for every with the test of line L8 failed for the of line L7: . By Lemma 2 every other power of gives a value at least as large.
Theorem 5 (termination). The algorithm returns after at most sweeps, each of which takes finitely many operations. If is irreducible, there is a finite number of sweeps after which it returns CONVERGED, independent of the cap.
Proof. The outer loop of line L2 runs at most times, and each sweep runs iterations of line L4, each finite by Lemma 2. Now let be irreducible. Every matrix that occurs is with , so is determined by the integer differences . For an edge of the graph of (, ), Lemma 3 gives , so . Since is irreducible, for any there are paths and in the graph, and summing the bounds along them bounds from above and from below by constants that depend only on . So only finitely many matrices can occur. By Lemma 3, strictly decreases at each accepted step, so no matrix occurs twice, and the number of accepted steps is finite. After the last accepted step, the next full sweep accepts nothing and line L10 returns CONVERGED.
Remark (rounding in the norms). The implementation computes and in floating point, with relative errors at most to first order. The test of line L8 then holds for the computed values only if the exact values satisfy , which is still below for , so Lemma 3 holds with replaced by a slightly smaller constant, and Theorem 5 is unaffected. Lemma 1 does not depend on the norms at all.