Algorithm Search⌘K

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: BB is the current matrix, ci=∑j≠i∣bji∣c_i = \sum_{j \ne i} |b_{ji}|, ri=∑j≠i∣bij∣r_i = \sum_{j \ne i} |b_{ij}|, S(B)=∑i≠j∣bij∣S(B) = \sum_{i \ne j} |b_{ij}|, β≥2\beta \ge 2 the radix (an integer power of 2 in the implementation, so that it is the machine radix or a power of it), and di=βeid_i = \beta^{e_i}. Lemmas 2 to 5 use exact values of cc and rr; 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 D−1ADD^{-1} A D exactly, with D=diag⁡(d)D = \operatorname{diag}(d), and det⁡(tI−B)=det⁡(tI−A)\det(tI - B) = \det(tI - A).

Proof. Line L9 multiplies the entries of column ii by f=βmf = \beta^m and divides those of row ii by ff; the diagonal entry biib_{ii} 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 BB by F−1BFF^{-1} B F exactly, with F=diag⁡(1,…,f,…,1)F = \operatorname{diag}(1, \dots, f, \dots, 1) in position ii, and multiplies did_i by ff, again exactly. By induction the stored matrix is D−1ADD^{-1} A D with D=diag⁡(d)D = \operatorname{diag}(d). Finally det⁡(tI−D−1AD)=det⁡(D−1(tI−A)D)=det⁡(tI−A)\det(tI - D^{-1} A D) = \det(D^{-1} (tI - A) D) = \det(tI - A). □\square

Lemma 2 (the choice of f). Let c,r>0c, r > 0. Line L7 returns the power f=βmf = \beta^m with r/β≤cf2<rβr / \beta \le c f^2 < r \beta, and this ff minimizes g(f)=cf+r/fg(f) = c f + r / f over all integer powers of β\beta.

Proof. Let c0=cc_0 = c. The first loop multiplies ff by β\beta and cc by β2\beta^2 while c<r/βc < r / \beta, so at its end c=c0f2≥r/βc = c_0 f^2 \ge r / \beta; if it ran at least once, the value before the last step was below r/βr / \beta, so c0f2<rβc_0 f^2 < r \beta. The second loop divides ff by β\beta and cc by β2\beta^2 while c≥rβc \ge r \beta; if it runs, the first loop did not, and it stops at the first value below rβr \beta, which is at least rβ/β2=r/βr \beta / \beta^2 = r / \beta. Both loops stop after finitely many steps, since each multiplies cc by β±2\beta^{\pm 2}. In all cases r/β≤c0f2<rβr / \beta \le c_0 f^2 < r \beta.

For optimality write x=c0f2/rx = c_0 f^2 / r, so g(f)=(r/f)(x+1)=c0r h(x)g(f) = (r / f)(x + 1) = \sqrt{c_0 r} \, h(x) with h(x)=x+1/xh(x) = \sqrt x + 1 / \sqrt x. The function hh is decreasing on (0,1](0, 1], increasing on [1,∞)[1, \infty) and satisfies h(x)=h(1/x)h(x) = h(1 / x), so h(x)≤h(y)h(x) \le h(y) whenever ∣log⁡x∣≤∣log⁡y∣|\log x| \le |\log y|. The other powers of β\beta give y=xβ2jy = x \beta^{2j} with j≠0j \ne 0. Since ∣log⁡x∣≤log⁡β|\log x| \le \log \beta and ∣log⁡x+2jlog⁡β∣≥2∣j∣log⁡β−∣log⁡x∣≥log⁡β|\log x + 2 j \log \beta| \ge 2 |j| \log\beta - |\log x| \ge \log \beta, every other power gives a value at least g(f)g(f). □\square

Lemma 3 (descent). An accepted step at index ii lowers SS by more than 0.05(ci+ri)>00.05 (c_i + r_i) > 0.

Proof. The step changes only the off-diagonal entries of column ii (multiplied by ff) and of row ii (divided by ff); these sets are disjoint and their masses are cic_i and rir_i. All other off-diagonal entries are unchanged. So SS changes by (cif+ri/f)−(ci+ri)(c_i f + r_i / f) - (c_i + r_i), which is below −0.05(ci+ri)-0.05 (c_i + r_i) by the test of line L8. Line L6 ensures ci,ri>0c_i, r_i > 0. □\square

Theorem 4 (correctness). When the algorithm returns, B=D−1ADB = D^{-1} A D exactly, DD has powers of β\beta on the diagonal, spec⁡(B)=spec⁡(A)\operatorname{spec}(B) = \operatorname{spec}(A) with multiplicities, S(B)≤S(A)S(B) \le S(A), and if yy is an eigenvector of BB then DyD y is an eigenvector of AA for the same eigenvalue. If it returns CONVERGED, then for every ii with ciri≠0c_i r_i \ne 0 and every integer mm, ciβm+riβ−m≥0.95(ci+ri)c_i \beta^m + r_i \beta^{-m} \ge 0.95 (c_i + r_i).

Proof. The first statements are Lemma 1 and Lemma 3. If By=λyB y = \lambda y then A(Dy)=DBy=λDyA (D y) = D B y = \lambda D y, and Dy≠0Dy \ne 0. On CONVERGED the last sweep accepted no step, so the matrix did not change during it, and for every ii with ciri≠0c_i r_i \ne 0 the test of line L8 failed for the ff of line L7: cif+ri/f≥0.95(ci+ri)c_i f + r_i / f \ge 0.95 (c_i + r_i). By Lemma 2 every other power of β\beta gives a value at least as large. □\square

Theorem 5 (termination). The algorithm returns after at most maxsweeps\mathrm{maxsweeps} sweeps, each of which takes finitely many operations. If AA 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 maxsweeps\mathrm{maxsweeps} times, and each sweep runs nn iterations of line L4, each finite by Lemma 2. Now let AA be irreducible. Every matrix that occurs is B=D−1ADB = D^{-1} A D with bjk=ajkβek−ejb_{jk} = a_{jk} \beta^{e_k - e_j}, so BB is determined by the integer differences ek−eje_k - e_j. For an edge j→kj \to k of the graph of AA (ajk≠0a_{jk} \ne 0, j≠kj \ne k), Lemma 3 gives ∣ajk∣βek−ej≤S(B)≤S(A)|a_{jk}| \beta^{e_k - e_j} \le S(B) \le S(A), so ek−ej≤Mjk=log⁡β(S(A)/∣ajk∣)e_k - e_j \le M_{jk} = \log_\beta (S(A) / |a_{jk}|). Since AA is irreducible, for any j≠kj \ne k there are paths j→⋯→kj \to \dots \to k and k→⋯→jk \to \dots \to j in the graph, and summing the bounds along them bounds ek−eje_k - e_j from above and from below by constants that depend only on AA. So only finitely many matrices BB can occur. By Lemma 3, SS 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. □\square

Remark (rounding in the norms). The implementation computes cc and rr in floating point, with relative errors at most (n−1)u(n - 1) u to first order. The test of line L8 then holds for the computed values only if the exact values satisfy cf+r/f<0.95 (1+2nu)/(1−2nu) (c+r)c f + r / f < 0.95 \, (1 + 2 n u) / (1 - 2 n u) \, (c + r), which is still below c+rc + r for nu<0.01n u < 0.01, so Lemma 3 holds with 0.050.05 replaced by a slightly smaller constant, and Theorem 5 is unaffected. Lemma 1 does not depend on the norms at all.

Back to Matrix balancing