This implementation extends a stored basis \mathbf{Q} (k columns of length n) by a block \mathbf{W} of \ell columns (the Lean statements name the block width b). Each column of the block is reduced twice, by classical Gram–Schmidt passes, against the stored basis followed by the new columns already written. A reduced column whose norm falls below a threshold relative to the input column is dropped: a zero column is stored. It is the orthogonalization scheme the library supplies for block Golub–Kahan bidiagonalization.
Definition (Column-wise two-pass classical Gram–Schmidt with threshold deflation). The dimensions are [n,k,\ell]; the inputs are the stored basis \mathbf{Q} and the block \mathbf{W}; the outputs are the new block \mathbf{Q}', the reduced block (overwriting \mathbf{W}), and the coefficient block \mathbf{C} with k+\ell rows. The threshold \tau is a rational literal of the implementation. The new block is stored directly after the basis, so the basis and the new columns already written form one contiguous block.
For each column c=0,\ldots,\ell-1:
Save \nu=\|\mathbf{w}_c\|.
Set rows k,\ldots,k+\ell-1 of column c of \mathbf{C} to zero.
First pass: compute the coefficients of \mathbf{w}_c against the k+c stored columns, write them to rows 0,\ldots,k+c-1 of column c of \mathbf{C}, and reduce \mathbf{w}_c in place.
Second pass: compute coefficients against the same columns into scratch and reduce \mathbf{w}_c in place again.
Add the second coefficients to the first.
Compute \beta=\|\mathbf{w}_c\| for the reduced column.
If \beta\le\tau\nu, store a zero column \mathbf{q}'_c and leave the diagonal coefficient zero.
Otherwise store \mathbf{q}'_c=\mathbf{w}_c/\beta and the diagonal coefficient C_{k+c,c}=\beta.
At \tau=0 the test is the exact zero guard. A dropped column remains a zero column of the basis. The scratch is k+\ell coefficient cells and three scalar cells.
The program uses scalar operations, level-one vector operations (dot product, vector update, norm, scaling, copy), and comparisons. The statements below are for two models: exact real arithmetic with exact level-one operations, where the threshold is 0; and the standard model of rounded arithmetic with level-one error contracts and exact comparisons, where the threshold is positive. Scalars are real.
Accuracy
The exact contract (an exact extension of a basis by a block) is defined on the Golub–Kahan process page, and the rounded contract with parameters (\eta_0,\mu,\varepsilon) on its implementation page. The first statement of each pair below is about decoded matrices; the second is about the program.
Theorem (Two exact passes give an exact extension). Let \mathbf{Q} be an arbitrary real or complex matrix with k columns, \mathbf{W} a block of \ell columns, and write \operatorname{su}(\mathbf{M}) for the strictly upper triangular part of \mathbf{M}. Suppose
and that each column of \mathbf{Q}' is the corresponding column \mathbf{w} of \mathbf{W}_2 divided by its norm, or the zero column when \mathbf{w}=\mathbf 0. Then \mathbf{Q}' with coefficients \mathbf{H}_1+\mathbf{H}_2 and \mathbf{R}_1+\mathbf{R}_2+\mathbf{D}, where \mathbf{D} is the diagonal matrix of the norms of the columns of \mathbf{W}_2, is an exact extension of \mathbf{Q} by \mathbf{W}.
No hypothesis is made on \mathbf{Q}. Orthonormality of its nonzero columns enters only through the clause of the contract that preserves it.
Theorem (The program meets the exact contract at threshold zero). Under exact scalar arithmetic, exact level-one operations at every length, and exact comparisons, the implementation with threshold \tau=0 runs on all admitted operands of the extension operation, and its decoded basis, block, new block, and coefficients satisfy the exact extension contract. The stored basis is arbitrary: it may contain zero columns and need not be orthonormal on its support.
Lean statement and details
Exact arithmetic
NLAlib.CGS2.cgs2ExtendRoutine_meets_exact {K Op Tst : Type} [Inhabited K] [Ops.Has Ops.ScalarOp Op]
[Ops.Has Ops.Blas1Op Op] [Ops.Has Ops.CmpTst Tst] {M : Ops.Machine K} {dec : K → ℝ}
{okB : ℕ → Prop} {I : Ops.Interp Op Tst K} (hS : Ops.IsScalar M I) (hM : Ops.ExactModel dec M)
(hB : Ops.IsExactBlas1 dec okB I) (hok : ∀ (n : ℕ), okB n) (hCmp : Ops.IsCmp dec I) :
(CGS2.cgs2ExtendRoutine 0).Meets I (Ops.exactExtendSpec dec)
Theorem (Column guarantees give the rounded contract). Let \mathbf{Q} be a real basis, \mathbf{W} the block, \mathbf{W}' the reduced block, \mathbf{Q}' the new block, and \mathbf{H}, \mathbf{R} the coefficients, with \mathbf{R} upper triangular. For every column c assume:
the step from \mathbf{w}_c to \mathbf{w}'_c, with coefficients (\mathbf{H}_c,\mathbf{R}_{<c,c}), meets the single-vector guarantee on the support with parameters (\eta_0,\varepsilon_1,\varepsilon_2,\varepsilon_3) for the basis \mathbf{V}_c=[\mathbf{Q},\mathbf{Q}'_{<c}]: whenever the Gram defect on the support of \mathbf{V}_c has spectral norm at most \eta_0, \|\mathbf{w}_c-\mathbf{V}_c\mathbf{h}-\mathbf{w}'_c\|\le\varepsilon_2\|\mathbf{w}_c\| and \|\mathbf{V}_c^{\mathsf{T}}\mathbf{w}'_c\|\le\varepsilon_1\|\mathbf{w}'_c\|+\varepsilon_3\|\mathbf{w}_c\|;
a zero \mathbf{w}_c gives a zero \mathbf{w}'_c;
the computed norms satisfy |\nu_c-\|\mathbf{w}_c\||\le E\|\mathbf{w}_c\| and |\beta_c-\|\mathbf{w}'_c\||\le E\|\mathbf{w}'_c\|;
either the column is dropped, with \beta_c\le\tfrac32\tau\nu_c, \mathbf{q}'_c=\mathbf 0, and r_{cc}=0; or it is kept, with \tfrac12\tau\nu_c<\beta_c, r_{cc}=\beta_c, and \|\beta_c\mathbf{q}'_c-\mathbf{w}'_c\|\le E\|\mathbf{w}'_c\|.
If \eta_0\le1/100, 0\le\varepsilon_1,\varepsilon_2,\varepsilon_3\le1/10, 0\le E\le1/100, and \tau>0, then (\mathbf{Q}',\mathbf{H},\mathbf{R}) is a rounded extension of \mathbf{Q} by \mathbf{W} with window \eta_0 and parameters
Theorem (The program meets the rounded contract). Assume the standard model of rounded arithmetic with unit roundoff u, the level-one contracts with dot-product error e_d(n), update error e_a, square-root error e_s, and scaling error e_c, with e_a,e_s\ge0, and exact comparisons. Let 0\le\eta_0\le1/100, c\le1/100, u\ge0, 4u\le c, 0\le E\le1/100, and let \tau>0 be the rational threshold of the implementation. At every admitted dimension (n,k,\ell) assume that the level-one operations admit the length n, that e_d(n)\ge0, that the pass budget of k+\ell columns holds,
and that the computed norms are accurate to E: e_d(n)+e_s(1+e_d(n))\le E. Assume also e_c\le E. Then the implementation runs on all admitted operands and its decoded output is a rounded extension with window \eta_0 and parameters
Here c is the budget of one classical pass against all stored columns and E the relative accuracy of the computed norms and of the scaling. The bound on a kept column is absolute, so the guarantee covers every returned column.
Lean statement and details
Standard roundingRelative-error BLAS
NLAlib.CGS2.cgs2ExtendRoutine_meets {K Op Tst : Type} [Inhabited K] [Ops.Has Ops.ScalarOp Op]
[Ops.Has Ops.Blas1Op Op] [Ops.Has Ops.CmpTst Tst] {M : Ops.Machine K} {dec : K → ℝ} {u η₀ c E : ℝ}
{τ : ℚ} {ε : Ops.Blas1Err} {okB : ℕ → Prop} {ok : ℕ → ℕ → ℕ → Prop} {I : Ops.Interp Op Tst K}
(hS : Ops.IsScalar M I) (hM : Ops.StdModel u dec M) (hB : Ops.IsBlas1 dec ε okB I)
(hCmp : Ops.IsCmp dec I) (hu : 0 ≤ u) (hu₁ : 4 * u ≤ c) (hη₀ : 0 ≤ η₀) (hη : η₀ ≤ 1 / 100)
(hc : c ≤ 1 / 100) (hE : 0 ≤ E) (hE' : E ≤ 1 / 100) (hτ : 0 < τ) (ha : 0 ≤ ε.axpy)
(hs : 0 ≤ ε.sqrt) (hscal : ε.scal ≤ E) (hokB : ∀ (n k b : ℕ), ok n k b → okB n)
(hdot : ∀ (n k b : ℕ), ok n k b → 0 ≤ ε.dot n)
(hbudget :
∀ (n k b : ℕ),
ok n k b →
(↑(k + b) + 1) * ε.dot n * (1 + η₀) ^ 2 +
((1 + ε.axpy) ^ (k + b) - 1) * (1 + ↑(k + b) * (1 + ε.dot n) * (1 + η₀) ^ 2) ≤
c)
(hnorm : ∀ (n k b : ℕ), ok n k b → ε.dot n + ε.sqrt * (1 + ε.dot n) ≤ E) :
(CGS2.cgs2ExtendRoutine τ).Meets I
(Ops.extendSpec dec η₀ (cgs2ExtendMu (2 * c) (2 * (η₀ + c) ^ 2) E ↑τ)
(cgs2ExtendEps (3 * c) E ↑τ) ok)
These statements certify the extension program against its two contracts. The certificate of the block Golub–Kahan driver linked with this program is not stated in the library; see the Scope section of the block Golub–Kahan implementation page.
Results on the extension contracts
Theorem (One block step of the loss of orthogonality).
let \mathbf{D}(\cdot) be the Gram defect on the support, \mathbf{D}(\mathbf{Q}) = \mathbf{Q}^{\mathsf{T}}\mathbf{Q} - \operatorname{diag}(\mathbf{s}) with s_j = 0 at a zero column of \mathbf{Q} and s_j = 1 otherwise. If (\mathbf{Q}', \mathbf{H}, \mathbf{R}) is a rounded extension (NLAlib.IsBasisExtensionErr) of the real basis \mathbf{Q} with parameters (\eta_0, \mu, \varepsilon), \mathbf{Q}' has b columns and \mathbf{Q} is in the window, \sqrt{\|\mathbf{D}(\mathbf{Q})\|_{\mathsf{F}}^2 + 3b\mu^2} \le \eta_0, then \|\mathbf{D}([\mathbf{Q}, \mathbf{Q}'])\|_{\mathsf{F}}^2 \le \|\mathbf{D}(\mathbf{Q})\|_{\mathsf{F}}^2 + 3b\mu^2\,. No printed source.
Lean statement and details
NLAlib.IsBasisExtensionErr.frobNorm_gramDefect_fromCols_sq_le {n k b : ℕ} {η₀ μ ε : ℝ}
{Q : Matrix (Fin n) (Fin k) ℝ} {W Q' : Matrix (Fin n) (Fin b) ℝ} {H : Matrix (Fin k) (Fin b) ℝ}
{R : Matrix (Fin b) (Fin b) ℝ} (hE : IsBasisExtensionErr η₀ μ ε Q W Q' H R)
(hw : ExtensionWindow η₀ μ b Q) :
frobNorm (gramDefect (Q.fromCols Q')) ^ 2 ≤ frobNorm (gramDefect Q) ^ 2 + 3 * ↑b * μ ^ 2
Theorem (The Gram defect on the support bounds the distance to the range projector, Frobenius
norm).
for every matrix \mathbf{Q}, with zero columns allowed, \mathbf{Q}\mathbf{Q}^{\mathsf{H}} differs from the orthogonal projector \mathbf{P}_{\mathbf{Q}} onto the column space of \mathbf{Q} by at most the Gram defect on the support \mathbf{D} = \mathbf{Q}^{\mathsf{H}}\mathbf{Q} - \operatorname{diag}(\mathbf{s}) (s_j = 0 at a zero column, s_j = 1 otherwise), \|\mathbf{Q}\mathbf{Q}^{\mathsf{H}} - \mathbf{P}_{\mathbf{Q}}\|_{\mathsf{F}} \le \|\mathbf{D}\|_{\mathsf{F}}\,. No printed source.