Algorithm Search⌘K

Proofs: Bareiss algorithm

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

The Bareiss algorithm returns the determinant, with exact divisions full

This proof shows: correctness, termination.

Let A0A_0 be the input, an n×nn \times n matrix over an integral domain RR with field of fractions FF, and let AA be the working matrix. Indices start at 00, as in the pseudocode. Line L7 swaps two rows of AA at or below row kk; let A′A' be the input with its rows in the current order, so that A′A' is A0A_0 with the same swaps applied. For 0≤k≤n0 \le k \le n let dkd_k be the leading principal minor of order kk of A′A', with d0=1d_0 = 1. For k≤i,j≤n−1k \le i, j \le n - 1 let

mk(i,j)=det⁡A′[{0,…,k−1,i},{0,…,k−1,j}],m_k(i, j) = \det A'[\{0, \dots, k-1, i\}, \{0, \dots, k-1, j\}],

the minor of A′A' in the first kk rows plus row ii and the first kk columns plus column jj. Note that mk(k,k)=dk+1m_k(k, k) = d_{k+1} and m0(i,j)=A′[i,j]m_0(i, j) = A'[i, j].

Claim. BAREISS(A0)(A_0) stops, every division on line L10 is exact in RR, and the result is det⁡A0\det A_0.

Termination. Line L3 runs kk over at most n−1n - 1 values, and the loops on lines L5, L8 and L9 have fewer than nn steps each.

Lemma (the Bareiss identity, a case of Sylvester's identity). If dk≠0d_k \ne 0, then for all i,ji, j with k<i,j≤n−1k < i, j \le n - 1,

dk⋅mk+1(i,j)=mk(k,k) mk(i,j)−mk(i,k) mk(k,j).d_k \cdot m_{k+1}(i, j) = m_k(k, k)\, m_k(i, j) - m_k(i, k)\, m_k(k, j).

Proof. Let CC be the (k+2)×(k+2)(k+2) \times (k+2) submatrix of A′A' in the rows 0,…,k,i0, \dots, k, i and the columns 0,…,k,j0, \dots, k, j, so that det⁡C=mk+1(i,j)\det C = m_{k+1}(i, j). Let BB be its leading k×kk \times k block, with det⁡B=dk≠0\det B = d_k \ne 0. Since BB is invertible over FF, we can subtract from row kk and from row ii of CC combinations of the first kk rows so that both rows become zero in the first kk columns. Call the result C′C'. It has the block form

C′=(BX0S),S=(skkskjsiksij).C' = \begin{pmatrix} B & X \\ 0 & S \end{pmatrix}, \qquad S = \begin{pmatrix} s_{kk} & s_{kj} \\ s_{ik} & s_{ij} \end{pmatrix}.

Adding to a row a combination of other rows does not change a determinant. The same row operations, applied to the submatrix of CC in the rows 0,…,k−1,i′0, \dots, k-1, i' and the columns 0,…,k−1,j′0, \dots, k-1, j' for i′∈{k,i}i' \in \{k, i\} and j′∈{k,j}j' \in \{k, j\}, turn it into (B∗0si′j′)\begin{pmatrix} B & * \\ 0 & s_{i'j'} \end{pmatrix}, which has determinant dk si′j′d_k\, s_{i'j'}. So mk(i′,j′)=dk si′j′m_k(i', j') = d_k\, s_{i'j'} for these four pairs. Also det⁡C=det⁡C′=dkdet⁡S\det C = \det C' = d_k \det S. Hence

mk(k,k) mk(i,j)−mk(i,k) mk(k,j)=dk2(skksij−sikskj)=dk2det⁡S=dkdet⁡C=dk mk+1(i,j).□m_k(k, k)\, m_k(i, j) - m_k(i, k)\, m_k(k, j) = d_k^2 (s_{kk} s_{ij} - s_{ik} s_{kj}) = d_k^2 \det S = d_k \det C = d_k\, m_{k+1}(i, j). \qquad \square

Invariant. At the start of the iteration of line L3 with index kk, and also when the loop ends, with k=n−1k = n - 1:

  • (J1) det⁡A0=s⋅det⁡A′\det A_0 = s \cdot \det A'.
  • (J2) dk≠0d_k \ne 0, and prev=dk\mathit{prev} = d_k.
  • (J3) A[i,j]=mk(i,j)A[i, j] = m_k(i, j) for all k≤i,j≤n−1k \le i, j \le n - 1.
  • (J4) A[t,j]=mt(t,j)A[t, j] = m_t(t, j) for all t<kt < k and t≤j≤n−1t \le j \le n - 1.

Initialization. For k=0k = 0, no swap has happened, so A′=A0A' = A_0 and s=1s = 1. Also prev=1=d0\mathit{prev} = 1 = d_0, and m0(i,j)=A0[i,j]=A[i,j]m_0(i, j) = A_0[i, j] = A[i, j]. (J4) is empty.

Maintenance. Assume the invariant at the start of iteration k≤n−2k \le n - 2. By (J3), A[i,k]=mk(i,k)A[i, k] = m_k(i, k) for i≥ki \ge k.

Case 1: lines L4 to L6 return 00. Then mk(i,k)=0m_k(i, k) = 0 for every i≥ki \ge k. Apply to all of A′A' the row operations of the lemma: subtract from every row i≥ki \ge k the combination of the first kk rows that clears its first kk entries. The result is (BX0S)\begin{pmatrix} B & X \\ 0 & S \end{pmatrix} with an (n−k)×(n−k)(n-k) \times (n-k) block SS, and as in the lemma mk(i,j)=dk Sijm_k(i, j) = d_k\, S_{ij}. So the first column of SS is zero, det⁡S=0\det S = 0, and det⁡A′=dkdet⁡S=0\det A' = d_k \det S = 0. By (J1), det⁡A0=0\det A_0 = 0, and the return value 00 is correct.

Case 2: line L7 swaps rows kk and p>kp > k. This swaps two rows of A′A' that are not among the first kk, so dkd_k does not change, and the entries of the rows kk and pp of AA are exchanged exactly as the minors mk(k,⋅)m_k(k, \cdot) and mk(p,⋅)m_k(p, \cdot) of the new A′A' require. So (J3) and (J4) still hold. The swap negates det⁡A′\det A' and line L7 negates ss, so (J1) still holds.

After lines L4 to L7, A[k,k]=mk(k,k)=dk+1≠0A[k, k] = m_k(k, k) = d_{k+1} \ne 0. For k<i,j≤n−1k < i, j \le n - 1, line L10 computes

A[k,k] A[i,j]−A[i,k] A[k,j]prev=mk(k,k) mk(i,j)−mk(i,k) mk(k,j)dk=mk+1(i,j)\frac{A[k, k]\, A[i, j] - A[i, k]\, A[k, j]}{\mathit{prev}} = \frac{m_k(k, k)\, m_k(i, j) - m_k(i, k)\, m_k(k, j)}{d_k} = m_{k+1}(i, j)

by the lemma. The value mk+1(i,j)m_{k+1}(i, j) is a minor of an integral domain matrix, so it is an element of RR. In an integral domain, dk≠0d_k \ne 0 divides the numerator with a unique quotient, so the division is exact and gives this minor. Line L10 reads A[i,k]A[i, k] and A[k,j]A[k, j], which it does not change in the iteration, so the order of the updates does not matter. Row kk is not changed, so it holds mk(k,j)m_k(k, j) for j≥kj \ge k, which gives (J4) for k+1k + 1. Line L11 sets prev=A[k,k]=dk+1≠0\mathit{prev} = A[k, k] = d_{k+1} \ne 0, which gives (J2) for k+1k + 1. So the invariant holds at the start of iteration k+1k + 1.

End. If n=0n = 0, line L1 returns 1=det⁡A01 = \det A_0. Otherwise, if no return happens inside the loop, the loop ends with k=n−1k = n - 1. By (J3), A[n−1,n−1]=mn−1(n−1,n−1)=dn=det⁡A′A[n-1, n-1] = m_{n-1}(n-1, n-1) = d_n = \det A', and by (J1) line L12 returns sdet⁡A′=s2det⁡A0=det⁡A0s \det A' = s^2 \det A_0 = \det A_0. ■\blacksquare

Remark. The proof shows more than the claim. Every number that the algorithm stores is a minor of the row-permuted input, and every numerator on line L10 is dkd_k times such a minor. This is the fact that bounds the sizes of the numbers by the Hadamard bound.

Back to Bareiss algorithm