NLA-lib Explorer

Lanczos with full reorthogonalization

Implementation of Lanczos process

Mathematical method

Definition

Readable pseudocode and the implementation definition will be filled from reviewed source metadata.

Operations and Storage

Operation counts, work assumptions, and storage bounds are not curated on this page yet.

Accuracy

Arithmetic-model choices and checked execution-to-accuracy links will be added here. No model switch is shown until a coherent implementation and theorem are linked.

Results

Theorem (The symmetric backward model).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, with \mathbf{U} = NLAlib.polarFactor \mathbf{V}_{k+1} and \mathbf{U}_k its first k columns, some symmetric \mathbf{E} with \|\mathbf{E}\|_{\mathsf F} \le NLAlib.LanczosReorthRun.backwardRadius satisfies (\mathbf{H} + \mathbf{E})\mathbf{U}_k = \mathbf{U}_k\mathbf{T}_k + (\beta_k\mathbf{u}_{k+1})\mathbf{e}_{k-1}^{\mathsf{T}} exactly. [Paige1971, §6.1] (the backward form (\mathbf{A} + \delta\mathbf{P})\mathbf{V} = \mathbf{V}\mathbf{T} there); the completion is that of Kahan, Parlett and Jiang (1982).

Lean statement and details
NLAlib.LanczosReorthRun.exists_backward {n k : ℕ} (L : LanczosReorthRun n k) (hη : L.η₀ ≤ 1 / 100)
  (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀) (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) :
  ∃ E,
    Eᵀ = E ∧
      frobNorm E ≤ L.backwardRadius ∧
        (L.H + E) * (polarFactor (LanczosReorthRun.basisOf L.v (k + 1))).submatrix id Fin.castSucc =
          (polarFactor (LanczosReorthRun.basisOf L.v (k + 1))).submatrix id Fin.castSucc *
              L.toLanczosData.tridiagonal +
            vecMulVec
              (L.β k • fun i ↦ polarFactor (LanczosReorthRun.basisOf L.v (k + 1)) i (Fin.last k))
              (Pi.single L.toLanczosData.lastIndex 1)

Full source on GitHub

Copy link

Theorem (Exact full reorthogonalization changes nothing for Hermitian matrices).

for Hermitian \mathbf{A}, every \mathbf{b} and every j, the state of the reorthogonalized recurrence restricts to the Lanczos state, and its stored vectors are the Lanczos vectors \mathbf{q}_0, \dots, \mathbf{q}_j (zero beyond j). No breakdown hypothesis: after breakdown every vector involved is zero. [Paige1970, §2, (2.1)–(2.7)]; [Parlett1998, §13.1] for the exact orthogonality.

Lean statement and details
Matrix.IsHermitian.lanczosReorthState_toLanczosState.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜]
  {n : Type u_2} [Fintype n] {A : Matrix n n 𝕜} (hA : A.IsHermitian) (b : n → 𝕜) (j : ℕ) :
  (lanczosReorthState A b j).toLanczosState = lanczosState A b j ∧
    ∀ (i : ℕ), (lanczosReorthState A b j).vecs i = if i ≤ j then (lanczosState A b i).cur else 0

Full source on GitHub

Copy link

Theorem (Transfer to \mathbf{b}^{\mathsf{T}}f(\mathbf{H})\mathbf{b}).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, if \mathbf{b} \ne \mathbf{0} and \|\mathbf{b}/\|\mathbf{b}\| - \mathbf{v}_1\| \le \delta_b, some symmetric \mathbf{H}' with \|\mathbf{H}' - \mathbf{H}\|_{\mathsf F} \le e + 3\|\mathbf{H}\|_2(\delta_b + 2\sqrt{3(k+1)}\,\mu) (e = NLAlib.LanczosReorthRun.backwardRadius) has Lanczos tridiagonal \mathbf{T}_k from \mathbf{b} and, for every 1-Lipschitz f, \lvert\mathbf{b}^{\mathsf{T}}f(\mathbf{H}')\mathbf{b} - \mathbf{b}^{\mathsf{T}}f(\mathbf{H})\mathbf{b}\rvert \le \|\mathbf{b}\|^2\|\mathbf{H}' - \mathbf{H}\|_{\mathsf F}, so the exact quadrature error theory for (\mathbf{H}', \mathbf{b}) transfers with that additive term. [Kittaneh1985, abstract].

Lean statement and details
NLAlib.LanczosReorthRun.exists_pure_backward_abs_quadForm_cfc_sub_le {n k : ℕ}
  (L : LanczosReorthRun n k) (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀)
  (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) {b : Fin n → ℝ} (hb : b ≠ 0) {δb : ℝ}
  (hδ : ‖WithLp.toLp 2 (‖WithLp.toLp 2 b‖⁻¹ • b - L.v 1)‖ ≤ δb) :
  ∃ H',
    H'ᵀ = H' ∧
      frobNorm (H' - L.H) ≤
          L.backwardRadius + 3 * specNorm L.H * (δb + 2 * √(3 * (↑k + 1)) * L.orthLevel) ∧
        lanczosTridiagonal H' b k = L.toLanczosData.tridiagonal ∧
          ∀ (f : ℝ → ℝ),
            LipschitzWith 1 f →
              |b ⬝ᵥ cfc f H' *ᵥ b - b ⬝ᵥ cfc f L.H *ᵥ b| ≤
                ‖WithLp.toLp 2 b‖ ^ 2 * frobNorm (H' - L.H)

Full source on GitHub

Copy link

Theorem (Ritz values interlace from below up to e).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, \lambda_{i + n - k}(\mathbf{H}) - e \le \theta_i for i < k (and k \le n by NLAlib.LanczosReorthRun.succ_le_card), with e = NLAlib.LanczosReorthRun.backwardRadius. [HornJohnson2013, Corollary 4.3.37] for the exact case.

Lean statement and details
NLAlib.LanczosReorthRun.eigenvalue_sub_le_eigenvalue_tridiagonal {n k : ℕ}
  (L : LanczosReorthRun n k) (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀)
  (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) {i : ℕ} (hi : i < k) :
  eigenvalue L.H (i + (n - k)) - L.backwardRadius ≤ eigenvalue L.toLanczosData.tridiagonal i

Full source on GitHub

Copy link

Theorem (Kaniel–Paige–Saad for the backward model).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, some symmetric \mathbf{E} with \|\mathbf{E}\|_{\mathsf F} \le e (NLAlib.LanczosReorthRun.backwardRadius) has \lvert\lambda_0(\mathbf{H} + \mathbf{E}) - \lambda_0(\mathbf{H})\rvert \le e, and the bound Matrix.IsHermitian.eigenvalue_sub_eigenvalue_conjTranspose_mul_mul_le holds for (\mathbf{H} + \mathbf{E}, \mathbf{u}_1), \mathbf{u}_1 the first column of the polar factor of \mathbf{V}_{k+1}, with \mathbf{T}_k in place of the compression. The tangent is that of \mathbf{H} + \mathbf{E}. [Saad2011, Theorem 6.4] for the exact bound.

Lean statement and details
NLAlib.LanczosReorthRun.exists_backward_kaniel_paige_saad {n k : ℕ} (L : LanczosReorthRun n k)
  (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀)
  (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) :
  ∃ E,
    Eᵀ = E ∧
      frobNorm E ≤ L.backwardRadius ∧
        |eigenvalue (L.H + E) 0 - eigenvalue L.H 0| ≤ L.backwardRadius ∧
          ∀ {a c : ℝ},
            a < c →
              c < eigenvalue (L.H + E) 0 →
                spectrum ℝ (L.H + E) ⊆ Set.Icc a c ∪ {eigenvalue (L.H + E) 0} →
                  0 <
                      (spectralMeasure (L.H + E)
                            (LanczosReorthRun.colSeq
                              (polarFactor (LanczosReorthRun.basisOf L.v (k + 1))) 1)).real
                        {eigenvalue (L.H + E) 0} →
                    eigenvalue (L.H + E) 0 - eigenvalue L.toLanczosData.tridiagonal 0 ≤
                      4 * (eigenvalue (L.H + E) 0 - a) *
                          spectralTangentSq (L.H + E)
                            (LanczosReorthRun.colSeq
                              (polarFactor (LanczosReorthRun.basisOf L.v (k + 1))) 1)
                            (eigenvalue (L.H + E) 0) *
                        ((√(eigenvalue (L.H + E) 0 - a) - √(eigenvalue (L.H + E) 0 - c)) /
                            (√(eigenvalue (L.H + E) 0 - a) + √(eigenvalue (L.H + E) 0 - c))) ^
                          (2 * (k - 1))

Full source on GitHub

Copy link

Theorem (Orthogonality of the computed basis on the admissible prefix).

under the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0 \le 1/100, for every m \le k + 1, \|\mathbf{V}_m^{\mathsf{T}}\mathbf{V}_m - \mathbf{I}\|_{\mathsf F} \le \sqrt{3m}\,\mu. [Paige1971, §6.1, (6.9)] for Lanczos with reorthogonalization; [GiraudLangouRozloznikVandenEshof2005, Theorem 2] for the CGS2 kernel constants.

Lean statement and details
NLAlib.LanczosReorthRun.frobNorm_transpose_mul_self_sub_one_le {n k : ℕ} (L : LanczosReorthRun n k)
  (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀) (m : ℕ) :
  m ≤ k + 1 →
    frobNorm ((LanczosReorthRun.basisOf L.v m)ᵀ * LanczosReorthRun.basisOf L.v m - 1) ≤
      √(3 * ↑m) * L.orthLevel

Full source on GitHub

Copy link

Theorem (The perturbed Lanczos relation of a reorthogonalized run).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, with the discarded coefficients in the residual, \|\mathbf{F}_k\|_{\mathsf F} \le 30(k+1)\,(\mu + \varepsilon + \varepsilon_2)\,\|\mathbf{H}\|_2; the relation itself is NLAlib.LanczosData.mul_basis. [Paige1971, §6.1, (6.8)] for the reorthogonalized relation; [Paige1976, §2, (15)–(19)] for the rounding part.

Lean statement and details
NLAlib.LanczosReorthRun.frobNorm_residual_le {n k : ℕ} (L : LanczosReorthRun n k)
  (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀)
  (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) :
  frobNorm L.toLanczosData.residual ≤ 30 * (↑k + 1) * L.recLevel * specNorm L.H

Full source on GitHub

Copy link

Theorem (Converged Ritz values are not duplicated).

under \eta_0 \le 1/100, the fixed-point condition \sqrt{3(k+1)}\,\mu \le \eta_0, \mu + \varepsilon + \varepsilon_2 \le 1/100 and \tau \le 1, for r orthonormal eigenvectors \mathbf{y}_i of \mathbf{T}_k with eigenvalues \theta_i \in [a, b] and residuals \beta_k\lvert\mathbf{e}_{k-1}^{\mathsf{T}}\mathbf{y}_i\rvert < (g - 2e)/\sqrt r, g > 2e (e = NLAlib.LanczosReorthRun.backwardRadius), the matrix \mathbf{H} has at least r eigenvalues in (a - g, b + g). With [a, b] a window around a simple isolated eigenvalue this forbids two converged copies; the residual condition cannot be dropped (docs/design/Krylov-LanczosReorth.md §3.2, counterexample \operatorname{diag}(1,0,-1)). The phenomenon: [Paige1971, §9.2], [Parlett1998, Ch. 13]; this statement: no printed source.

Lean statement and details
NLAlib.LanczosReorthRun.card_le_card_eigenvalue_mem {n k : ℕ} (L : LanczosReorthRun n k)
  (hη : L.η₀ ≤ 1 / 100) (hsmall : √(3 * (↑k + 1)) * L.orthLevel ≤ L.η₀)
  (hrec : L.recLevel ≤ 1 / 100) (hτ : L.τ ≤ 1) {r : ℕ} {Y : Matrix (Fin k) (Fin r) ℝ}
  (hY : HasOrthonormalCols Y) {θ : Fin r → ℝ}
  (hTY : ∀ (i : Fin r), (L.toLanczosData.tridiagonal *ᵥ fun c ↦ Y c i) = θ i • fun c ↦ Y c i)
  {a b g : ℝ} (hθ : ∀ (i : Fin r), θ i ∈ Set.Icc a b) (hg : 2 * L.backwardRadius < g)
  (hres :
    ∀ (i : Fin r), L.β k * |Y L.toLanczosData.lastIndex i| < (g - 2 * L.backwardRadius) / √↑r) :
  r ≤ {i ∈ Finset.range n | eigenvalue L.H i ∈ Set.Ioo (a - g) (b + g)}.card

Full source on GitHub

Copy link

Theorem (Scalar Lanczos with full reorthogonalization in rounded arithmetic: termination, operation count, orthogonality and Ritz values).

Let \mathbf{A} \in \mathbb{R}^{n \times n} be symmetric, stored entry by entry, let \mathbf{b} \in \mathbb{R}^n and let k be the iteration cap. The program is the Lanczos recurrence started from \mathbf{b} in which each new vector is orthogonalized twice against all stored vectors (classical Gram–Schmidt, two passes) before it is normalized, with every matrix-vector product and every vector operation written out as scalar loops. Its arithmetic is any scalar machine in the standard model with unit roundoff u (each of +, -, \times, /, \sqrt{\cdot} exact up to a factor 1 + \delta, \lvert\delta\rvert \le u, no overflow or underflow, exact comparisons), and E \le 1/100 is an allowance that dominates the rounding of one scalar operation, of one dot product, vector update and scaling of length n, and of one matrix-vector product (Lanczos.Rounded.Precision).

Then for every such input, every interpretation of the scalar operations that meets the model, and every tape, the run succeeds, and

* it executes at most 33 n^{2} k + 92 n k^{2} + 152 k^{2} + 269 n k + 581 k + 58 n + 179 instructions (scalar operations, comparisons, index arithmetic, operand addressing, loop control and allocation, each of unit cost); * it performs some number m \le k of steps and leaves in memory the vectors \mathbf{v}_1, \dots, \mathbf{v}_{m+1}, the coefficients \alpha_j, \beta_j and, for each step, the norm \nu_j of the new vector before reorthogonalization (Lanczos.Reorth.Rounded.Output); if m < k, the last computed \beta_m (or the computed norm of \mathbf{b}) is exactly zero; * for every threshold 0 < \tau \le 1 and tolerances 0 \le \eta, c \le 1/100 that satisfy the three conditions hbudget, hsmall and hrec below, let r \le m be the number of leading steps with \beta_j > \tau \nu_j (no severe cancellation), and e = 100 (r + 1)\, \delta\, \|\mathbf{A}\|_2 with \delta = 2(2c + 2(\eta + c)^2/\tau + E) + E + 3c. If r \ge 1, then with \mathbf{V}_r = [\mathbf{v}_1, \dots, \mathbf{v}_r] and \theta_0 \ge \dots \ge \theta_{r-1} the eigenvalues of the stored tridiagonal matrix \mathbf{T}_r, \|\mathbf{V}_r^{\mathsf{T}} \mathbf{V}_r - \mathbf{I}\|_2 \le \eta, \qquad \lambda_{i + n - r}(\mathbf{A}) - e \le \theta_i \le \lambda_i(\mathbf{A}) + e \quad (i < r).

The conditions on \tau, \eta and c involve only n, k, u and E: hbudget asks that c dominate the accumulated rounding of one two-pass orthogonalization against at most k vectors, hsmall is the fixed-point condition \sqrt{3(k+1)}\,\cdot 2(2c + 2(\eta + c)^2/\tau + E) \le \eta, and hrec is \delta \le 1/100. The prefix r may be shorter than the run, and is empty when the first step already has \beta_1 \le \tau \nu_1; nothing is claimed beyond it. The count is an upper bound read off the fixed program (NLAlib.Ops.Program.countPoly). Orthogonality: [Paige1971, §6.1, (6.9)]; interlacing: [HornJohnson2013, Corollary 4.3.37] for the exact case.

Standard rounding

Lean statement and details
NLAlib.Krylov.Lanczos.Reorth.Rounded.Stored.Certification.exec_scalarProgram_work_le_and_spectral
  {domain : (Fin 2 → ℕ) → Prop} {admitted : ∃ d, domain d} (M : Ops.Machine ℝ) (u : ℝ)
  (hM : Ops.StdModel u id M) (hu : 0 ≤ u) (E : (Fin 2 → ℕ) → ℝ)
  (hprec :
    ∀ (d : Fin 2 → ℕ),
      domain d →
        Krylov.Lanczos.Rounded.Precision (Ops.ScalarProducts.roundoff u (d 0) * √↑(d 0)) u (E d)
          (Ops.Blas.seq.err u) (d 0))
  {d : Fin 2 → ℕ} (hd : domain d)
  (x : (Krylov.Lanczos.Reorth.Rounded.Stored.Certification.problem domain admitted).Input d)
  (I : Ops.Interp Ops.ScalarOp Ops.CmpTst ℝ)
  (hI :
    (Ops.RoundedScalarBlas.model
          (Krylov.Lanczos.Reorth.Rounded.Stored.Certification.problem domain admitted) M).contracts
      d x I)
  (τ : Ops.Tape ℝ) :
  ∃ st,
    Ops.Reference.Execution Krylov.Lanczos.Reorth.Rounded.Stored.Certification.scalarProgram I
        Ops.RoundedScalarBlas.resources
        (Krylov.Lanczos.Reorth.Rounded.Stored.Certification.problem domain admitted).formats τ d
        ((Krylov.Lanczos.Reorth.Rounded.Stored.Certification.problem domain admitted).initial d x)
        st ∧
      Ops.RoundedScalarBlas.resources.work st.cost ≤
          33 * d 0 ^ 2 * d 1 + 92 * d 0 * d 1 ^ 2 + 152 * d 1 ^ 2 + 269 * d 0 * d 1 + 581 * d 1 +
              58 * d 0 +
            179 ∧
        ∃ vs cs,
          st.mem.store.readBlock 2 0 ((d 1 + 1) * d 0) = some vs ∧
            st.mem.store.readBlock 3 0 (3 * d 1 + 2) = some cs ∧
              ∀ (thr η c : ℝ),
                0 < thr →
                  thr ≤ 1 →
                    0 ≤ η →
                      η ≤ 1 / 100 →
                        0 ≤ c →
                          c ≤ 1 / 100 →
                            (∀ j < d 1,
                                (↑j + 1 + 1) * (Ops.Blas.seq.err u).dot (d 0) * (1 + η) ^ 2 +
                                    ((1 + (Ops.Blas.seq.err u).axpy) ^ (j + 1) - 1) *
                                      (1 +
                                        (↑j + 1) * (1 + (Ops.Blas.seq.err u).dot (d 0)) *
                                          (1 + η) ^ 2) ≤
                                  c) →
                              √(3 * (↑(d 1) + 1)) * (2 * (2 * c + 2 * (η + c) ^ 2 / thr + E d)) ≤
                                  η →
                                2 * (2 * c + 2 * (η + c) ^ 2 / thr + E d) + E d + 3 * c ≤ 1 / 100 →
                                  ∃ done ≤ d 1,
                                    ∃ z nus,
                                      Krylov.Lanczos.Reorth.Rounded.History id (↑x).1.1 (↑x).1.2
                                          (Ops.ScalarProducts.roundoff u (d 0) * √↑(d 0)) u (E d)
                                          (Ops.Blas.seq.err u) done z nus ∧
                                        Krylov.Lanczos.Reorth.Rounded.PackedOutput id (d 1) done z
                                            nus vs cs ∧
                                          (done < d 1 →
                                              (if done = 0 then z.initialNorm else z.beta done) =
                                                0) ∧
                                            ∃ r ≤ done,
                                              (∀ j < r, thr * nus (j + 1) < z.beta (j + 1)) ∧
                                                (r < done → z.beta (r + 1) ≤ thr * nus (r + 1)) ∧
                                                  (r = 0 ∨
                                                    specNorm
                                                          ((Krylov.Lanczos.basisMatrix id (d 0) vs
                                                                  r)ᵀ *
                                                              Krylov.Lanczos.basisMatrix id (d 0) vs
                                                                r -
                                                            1) ≤
                                                        η ∧
                                                      ∀ i < r,
                                                        eigenvalue (↑x).1.1 (i + (d 0 - r)) -
                                                              100 * (↑r + 1) *
                                                                  (2 *
                                                                        (2 * c +
                                                                            2 * (η + c) ^ 2 / thr +
                                                                          E d) +
                                                                      E d +
                                                                    3 * c) *
                                                                specNorm (↑x).1.1 ≤
                                                            eigenvalue
                                                              (Krylov.Lanczos.tridiagonalMatrix id
                                                                (d 1) cs r)
                                                              i ∧
                                                          eigenvalue
                                                              (Krylov.Lanczos.tridiagonalMatrix id
                                                                (d 1) cs r)
                                                              i ≤
                                                            eigenvalue (↑x).1.1 i +
                                                              100 * (↑r + 1) *
                                                                  (2 *
                                                                        (2 * c +
                                                                            2 * (η + c) ^ 2 / thr +
                                                                          E d) +
                                                                      E d +
                                                                    3 * c) *
                                                                specNorm (↑x).1.1)

Full source on GitHub

Copy link