Algorithm Search⌘K

Proofs: Berkowitz algorithm

These are the human proofs of Berkowitz algorithm, at full length.

The Berkowitz recurrence returns the characteristic polynomial full

This proof shows: correctness, termination.

Let RR be a commutative ring and AA an n×nn \times n matrix over RR, indexed from 00 as in the pseudocode. For 0≤r≤n−10 \le r \le n - 1 let ArA_r be the trailing principal block in rows and columns r,…,n−1r, \dots, n-1, of size n−rn - r. Polynomials are stored as coefficient lists, highest degree first.

Claim. BERKOWITZ(A)(A) stops and returns the coefficients of χA(x)=det⁡(xI−A)\chi_A(x) = \det(xI - A).

Termination. Line L3 runs rr over n−1n - 1 values, the loop of line L6 has s≤n−1s \le n - 1 steps, and every other line is a finite computation on lists of length at most n+1n + 1.

Lemma 1 (adjugate of xI−SxI - S). Let SS be an s×ss \times s matrix over RR with s≥1s \ge 1 and χS(x)=∑k=0sckxk\chi_S(x) = \sum_{k=0}^{s} c_k x^k. Then

adj⁡(xI−S)=∑k=1sck∑j=0k−1xk−1−jSj.\operatorname{adj}(xI - S) = \sum_{k=1}^{s} c_k \sum_{j=0}^{k-1} x^{k-1-j} S^j.

Proof. Call the right side Y(x)Y(x), a matrix over R[x]R[x]. For each kk, (xI−S)∑j=0k−1xk−1−jSj=xkI−Sk(xI - S)\sum_{j=0}^{k-1} x^{k-1-j} S^j = x^k I - S^k, a telescoping sum. So (xI−S) Y(x)=∑k=1sck(xkI−Sk)(xI - S)\,Y(x) = \sum_{k=1}^{s} c_k (x^k I - S^k). The term for k=0k = 0 would be c0(I−I)=0c_0(I - I) = 0, so this sum equals ∑k=0sck(xkI−Sk)=χS(x)I−χS(S)\sum_{k=0}^{s} c_k (x^k I - S^k) = \chi_S(x) I - \chi_S(S), and χS(S)=0\chi_S(S) = 0 by the Cayley-Hamilton theorem, which holds over every commutative ring. Let M=xI−SM = xI - S. Multiply MY=χS(x)IM Y = \chi_S(x) I on the left by adj⁡(M)\operatorname{adj}(M); since adj⁡(M)M=det⁡(M)I=χS(x)I\operatorname{adj}(M) M = \det(M) I = \chi_S(x) I, we get χS(x) Y=χS(x)adj⁡(M)\chi_S(x)\, Y = \chi_S(x) \operatorname{adj}(M). The polynomial χS\chi_S is monic, and a monic polynomial is not a zero divisor in R[x]R[x] (the leading coefficient of a product χS⋅f\chi_S \cdot f with f≠0f \ne 0 is the leading coefficient of ff). So Y=adj⁡(M)Y = \operatorname{adj}(M). □\square

Lemma 2 (bordered determinant). Let α∈R\alpha \in R, β\beta a row vector and γ\gamma a column vector of length ss, and DD an s×ss \times s matrix over RR. Then

det⁡(αβγD)=αdet⁡D−βadj⁡(D) γ.\det \begin{pmatrix} \alpha & \beta \\ \gamma & D \end{pmatrix} = \alpha \det D - \beta \operatorname{adj}(D)\, \gamma.

Proof. Both sides are polynomials with integer coefficients in the (s+1)2(s+1)^2 entries, so it suffices to prove the identity when the entries are independent indeterminates over Z\mathbb{Z}; every other case follows by substituting ring elements. In that case the entries lie in the field of fractions FF of the polynomial ring, and det⁡D≠0\det D \ne 0 because it is a nonzero polynomial. Row reduction with DD gives (1−βD−10I)(αβγD)=(α−βD−1γ0γD)\begin{pmatrix} 1 & -\beta D^{-1} \\ 0 & I \end{pmatrix} \begin{pmatrix} \alpha & \beta \\ \gamma & D \end{pmatrix} = \begin{pmatrix} \alpha - \beta D^{-1} \gamma & 0 \\ \gamma & D \end{pmatrix}. The first factor has determinant 11, and the last matrix is block lower triangular, so the determinant is (α−βD−1γ)det⁡D=αdet⁡D−βadj⁡(D)γ(\alpha - \beta D^{-1}\gamma)\det D = \alpha \det D - \beta \operatorname{adj}(D) \gamma, using D−1=adj⁡(D)/det⁡DD^{-1} = \operatorname{adj}(D)/\det D from Cramer's rule. □\square

Lemma 3 (one step). Write Ar=(aργS)A_r = \begin{pmatrix} a & \rho \\ \gamma & S \end{pmatrix} with a=A[r,r]a = A[r, r], ρ\rho the rest of row rr, γ\gamma the rest of column rr and S=Ar+1S = A_{r+1} of size s=n−r−1≥1s = n - r - 1 \ge 1. Let mj=ρSjγm_j = \rho S^j \gamma for j≥0j \ge 0, and let q=(q0,…,qs+1)=(1,−a,−m0,−m1,…,−ms−1)q = (q_0, \dots, q_{s+1}) = (1, -a, -m_0, -m_1, \dots, -m_{s-1}). If p=(p0,…,ps)p = (p_0, \dots, p_s) holds the coefficients of χS\chi_S, highest first, then the coefficients of χAr\chi_{A_r}, highest first, are

pi′=∑tqt pi−t(0≤i≤s+1),p'_i = \sum_{t} q_t\, p_{i - t} \qquad (0 \le i \le s + 1),

where the sum runs over the tt with 0≤t≤s+10 \le t \le s + 1 and 0≤i−t≤s0 \le i - t \le s.

Proof. Apply Lemma 2 to xI−ArxI - A_r over the ring R[x]R[x], with α=x−a\alpha = x - a, β=−ρ\beta = -\rho, γ′=−γ\gamma' = -\gamma and D=xI−SD = xI - S:

χAr(x)=(x−a)χS(x)−ρadj⁡(xI−S) γ.\chi_{A_r}(x) = (x - a)\chi_S(x) - \rho \operatorname{adj}(xI - S)\, \gamma.

By Lemma 1, with χS=∑kckxk\chi_S = \sum_k c_k x^k, ρadj⁡(xI−S)γ=∑k=1sck∑j=0k−1xk−1−jmj\rho \operatorname{adj}(xI - S) \gamma = \sum_{k=1}^{s} c_k \sum_{j=0}^{k-1} x^{k-1-j} m_j. The coefficient of xex^e in it is ∑j≥0ce+1+j mj\sum_{j \ge 0} c_{e+1+j}\, m_j, with ck=0c_k = 0 for k>sk > s. So the coefficient of xex^e in χAr\chi_{A_r} is

ce−1−a ce−∑j=0s−1ce+1+j mj,c_{e-1} - a\, c_e - \sum_{j=0}^{s-1} c_{e+1+j}\, m_j,

with c−1=0c_{-1} = 0. Put e=s+1−ie = s + 1 - i and pk=cs−kp_k = c_{s-k}. The three parts become q0piq_0 p_i, q1pi−1q_1 p_{i-1} and ∑jqj+2 pi−2−j\sum_j q_{j+2}\, p_{i-2-j}, where a term is absent when its index of pp is outside 0,…,s0, \dots, s. Their sum is ∑tqtpi−t\sum_t q_t p_{i-t}. □\square

Invariant. After line L2, and after each iteration of line L3 with index rr, the list pp holds the coefficients of χAr′\chi_{A_{r'}}, where r′r' is n−1n - 1 after line L2 and rr after the iteration.

Initialization. An−1A_{n-1} is the 1×11 \times 1 matrix (A[n−1,n−1])(A[n-1, n-1]), whose characteristic polynomial is x−A[n−1,n−1]x - A[n-1, n-1], the list (1,−A[n−1,n−1])(1, -A[n-1, n-1]) of line L2.

Maintenance. In the iteration with index rr, line L5 starts q=(1,−a)q = (1, -a) and v=ρv = \rho. Before the step kk of line L6, v=ρSkv = \rho S^k: true for k=0k = 0, and line L8 multiplies vv on the right by SS. So line L7 appends −vγ=−ρSkγ=−mk-v\gamma = -\rho S^k \gamma = -m_k, and after the loop qq is exactly the vector of Lemma 3. The loop skips the last product vSvS, which is never used. By the invariant before the iteration, pp holds χS=χAr+1\chi_S = \chi_{A_{r+1}}, and line L9 forms the sums pi′p'_i of Lemma 3. So pp now holds χAr\chi_{A_r}.

End. If n=0n = 0, line L1 returns (1)(1), the characteristic polynomial of the empty matrix. Otherwise, after the last iteration (r=0r = 0, or no iteration when n=1n = 1), pp holds χA0=χA\chi_{A_0} = \chi_A, which line L10 returns. Only additions, subtractions and multiplications in RR were used. ■\blacksquare

Remark. Since χA(0)=det⁡(−A)=(−1)ndet⁡A\chi_A(0) = \det(-A) = (-1)^n \det A, the last coefficient times (−1)n(-1)^n is the determinant, which is how the implementation's berkowitz_determinant gets it.

Back to Berkowitz algorithm