NLA-lib Explorer

Lanczos matrix-function approximation

Run Lanczos, evaluate f on the small tridiagonal matrix, and lift the result to approximate f(\mathbf{A})\mathbf{b}.

Definition

Definition (Lanczos matrix-function approximation). For Hermitian \mathbf{A}, nonzero \mathbf{b}, and a Lanczos basis whose first column is \mathbf{b}/\|\mathbf{b}\|_2, approximate the matrix-function action by

f(\mathbf{A})\mathbf{b}\approx\|\mathbf{b}\|_2\mathbf{Q}_k f(\mathbf{T}_k)\mathbf{e}_1.

Here \mathbf{T}_k=\mathbf{Q}_k^{\mathsf{H}}\mathbf{A}\mathbf{Q}_k. If the Krylov space becomes invariant earlier, use the generated nonzero prefix. Evaluating the function on the compression is an additional step beyond the Lanczos process.

Lean statement and details
NLAlib.lanczosFA.{u_1, u_2} {π•œ : Type u_1} [RCLike π•œ] {n : Type u_2} [Fintype n] [DecidableEq n]
  (A : Matrix n n π•œ) (f : ℝ β†’ ℝ) (b : n β†’ π•œ) (q : β„•) : n β†’ π•œ

Full source on GitHub

Copy link

Components

Mathematical guarantees

Theorem (Polynomial approximation controls the error). Let \mathbf{A} be Hermitian with spectrum in [a,\mathbf{b}], and let f be continuous on that interval. With q+1 mathematical Lanczos steps,

\|f(\mathbf{A})\mathbf{b}-\mathsf{lanczosfa}(\mathbf{A},f,\mathbf{b},q+1)\|_2\le2E_q(f;[a,\mathbf{b}])\|\mathbf{b}\|_2,

where E_q is the best uniform approximation error among polynomials of degree at most q. A good low-degree approximation to f therefore gives an accurate matrix-function action.

Lean statement and details
Matrix.IsHermitian.norm_cfc_mulVec_sub_lanczosFA_le_of_continuousOn.{u_1, u_2} {π•œ : Type u_1}
  [RCLike π•œ] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.IsHermitian)
  {a a' : ℝ} (hs : spectrum ℝ A βŠ† Set.Icc a a') {f : ℝ β†’ ℝ} (hf : ContinuousOn f (Set.Icc a a'))
  (b : n β†’ π•œ) (q : β„•) :
  β€–WithLp.toLp 2 (cfc f A *α΅₯ b - lanczosFA A f b (q + 1))β€– ≀
    2 * minimaxError f (Set.Icc a a') q * β€–WithLp.toLp 2 bβ€–

Full source on GitHub

Copy link

Further results

Theorem (CG is Lanczos-FA for the inverse).

, for every Hermitian \mathbf{A}: \mathsf{lanczosFA}(\mathbf{A}, x \mapsto x^{-1}, \mathbf{b}, q) = \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{0}, q) (CG from the zero start), with Lean's 0^{-1} = 0 matching the pseudoinverse junk value of galerkinInverse. [ChenPersson2026, Β§1.1]; [Saad2003, Β§6.7].

Lean statement and details
Matrix.IsHermitian.lanczosFA_inv_eq_cgIterate.{u_1, u_2} {π•œ : Type u_1} [RCLike π•œ] {n : Type u_2}
  [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.IsHermitian) (b : n β†’ π•œ) (q : β„•) :
  lanczosFA A (fun x ↦ x⁻¹) b q = cgIterate A b 0 q

Full source on GitHub

Copy link

Theorem (Exactness of Lanczos-FA).

for Hermitian \mathbf{A} and \nu \le q, \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q) = f(\mathbf{A})\mathbf{b}, since the Krylov space is then invariant. [Saad1992, Β§3.2].

Lean statement and details
Matrix.IsHermitian.lanczosFA_eq_cfc_mulVec_of_krylovGrade_le.{u_1, u_2} {π•œ : Type u_1} [RCLike π•œ]
  {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.IsHermitian) (f : ℝ β†’ ℝ)
  {b : n β†’ π•œ} {q : β„•} (h : krylovGrade A b ≀ q) : lanczosFA A f b q = cfc f A *α΅₯ b

Full source on GitHub

Copy link

Theorem (Frame form of the compressed function).

, for every \mathbf{A}: for \mathbf{Q} with orthonormal columns spanning the column space of \mathbf{X}, \mathsf{compressedCfc}(\mathbf{A}, f, \mathbf{X}) = \mathbf{Q}f(\mathbf{Q}^{\mathsf{H}}\mathbf{A}\mathbf{Q})\mathbf{Q}^{\mathsf{H}}; when \mathbf{Q}^{\mathsf{H}}\mathbf{A}\mathbf{Q} is not Hermitian both sides are \mathbf{0}. No printed source: the projector form of compressedCfc is the library's definition, and this bridge identifies it with the frame form in which the literature writes Lanczos-FA.

Lean statement and details
NLAlib.HasOrthonormalCols.compressedCfc_eq.{u_1, u_2, u_3, u_4} {π•œ : Type u_1} [RCLike π•œ]
  {n : Type u_2} {p : Type u_3} {r : Type u_4} [Fintype n] [DecidableEq n] [Fintype p] [Fintype r]
  [DecidableEq r] {Q : Matrix n r π•œ} (hQ : HasOrthonormalCols Q) {X : Matrix n p π•œ}
  (h : Q.mulVecLin.range = X.mulVecLin.range) (A : Matrix n n π•œ) (f : ℝ β†’ ℝ) :
  compressedCfc A f X = Q * cfc f (Qα΄΄ * A * Q) * Qα΄΄

Full source on GitHub

Copy link

Theorem (Lanczos-FA is interpolation at the Ritz values).

for Hermitian \mathbf{A}, a frame \mathbf{Q} of \mathcal{K}_q(\mathbf{A}, \mathbf{b}) and a real polynomial p of degree less than q that agrees with f on the spectrum of \mathbf{Q}^{\mathsf{H}}\mathbf{A}\mathbf{Q}, \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q) = p(\mathbf{A})\mathbf{b}. The Lagrange interpolant at the Ritz values is such a p. [ChenPersson2026, (9)].

Lean statement and details
NLAlib.HasOrthonormalCols.lanczosFA_eq_aeval_mulVec.{u_1, u_2, u_4} {π•œ : Type u_1} [RCLike π•œ]
  {n : Type u_2} {r : Type u_4} [Fintype n] [DecidableEq n] [Fintype r] [DecidableEq r]
  {Q : Matrix n r π•œ} (hQ : HasOrthonormalCols Q) {A : Matrix n n π•œ} (hA : A.IsHermitian) {b : n β†’ π•œ}
  {q : β„•} (hK : Q.mulVecLin.range = krylovSpace A b q) {f : ℝ β†’ ℝ} {p : Polynomial ℝ}
  (hp : p.degree < ↑q) (hf : βˆ€ x ∈ spectrum ℝ (Qα΄΄ * A * Q), Polynomial.eval x p = f x) :
  lanczosFA A f b q = (Polynomial.aeval A) p *α΅₯ b

Full source on GitHub

Copy link

Theorem (The same with a kernel bound for every t \ge 0).

, uniform over Stieltjes functions: for positive definite \mathbf{A}, f or f(z)/z Stieltjes, \nu > 0 on the spectrum with \nu(x)(y + t) \le R\,\nu(y)(x + t) for all eigenvalues x, y and all t \ge 0, \|f(\mathbf{A})\mathbf{b} - \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q)\|_{\nu(\mathbf{A})}^2 \le \frac{(R + 1)^2}{4R}\,\|f(\mathbf{A})\mathbf{b} - \mathbf{y}\|_{\nu(\mathbf{A})}^2 for every \mathbf{y} \in \mathcal{K}_q(\mathbf{A}, \mathbf{b}). A corollary of Matrix.PosDef.re_quadForm_cfc_cfc_mulVec_sub_lanczosFA_le_of_hasStieltjesMeasure, which is sharper for a given f. [ChenPersson2026, Theorem 5].

Lean statement and details
Matrix.PosDef.re_quadForm_cfc_cfc_mulVec_sub_lanczosFA_le.{u_1, u_2} {π•œ : Type u_1} [RCLike π•œ]
  {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.PosDef) {f : ℝ β†’ ℝ}
  (hf : IsStieltjes f ∨ IsStieltjes fun z ↦ f z / z) {Ξ½ : ℝ β†’ ℝ} {R : ℝ}
  (hΞ½ : βˆ€ x ∈ spectrum ℝ A, 0 < Ξ½ x)
  (hR :
    βˆ€ x ∈ spectrum ℝ A, βˆ€ y ∈ spectrum ℝ A, βˆ€ (t : ℝ), 0 ≀ t β†’ Ξ½ x * (y + t) ≀ R * (Ξ½ y * (x + t)))
  (b : n β†’ π•œ) {q : β„•} {y : n β†’ π•œ} (hy : y ∈ krylovSpace A b q) :
  RCLike.re (quadForm (cfc Ξ½ A) (cfc f A *α΅₯ b - lanczosFA A f b q)) ≀
    (R + 1) ^ 2 / (4 * R) * RCLike.re (quadForm (cfc Ξ½ A) (cfc f A *α΅₯ b - y))

Full source on GitHub

Copy link

Theorem (Near-optimality in the Euclidean norm).

for Hermitian \mathbf{A} with spectrum in [a, a'], 0 < a, f or f(z)/z Stieltjes and every \mathbf{y} \in \mathcal{K}_q(\mathbf{A}, \mathbf{b}), \|f(\mathbf{A})\mathbf{b} - \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q)\| \le \frac{\sqrt{a'/a} + 1/\sqrt{a'/a}}{2}\,\|f(\mathbf{A})\mathbf{b} - \mathbf{y}\| \,, the case \alpha = 0 (E = 1). [ChenPersson2026, Theorem 1].

Lean statement and details
Matrix.IsHermitian.norm_cfc_mulVec_sub_lanczosFA_le_mul_norm_sub.{u_1, u_2} {π•œ : Type u_1}
  [RCLike π•œ] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.IsHermitian)
  {a a' : ℝ} (ha : 0 < a) (hs : spectrum ℝ A βŠ† Set.Icc a a') {f : ℝ β†’ ℝ}
  (hf : IsStieltjes f ∨ IsStieltjes fun z ↦ f z / z) (b : n β†’ π•œ) {q : β„•} {y : n β†’ π•œ}
  (hy : y ∈ krylovSpace A b q) :
  β€–WithLp.toLp 2 (cfc f A *α΅₯ b - lanczosFA A f b q)β€– ≀
    (√(a' / a) + (√(a' / a))⁻¹) / 2 * β€–WithLp.toLp 2 (cfc f A *α΅₯ b - y)β€–

Full source on GitHub

Copy link

Theorem (The factor (R + 1)^2/(4R) is attained for a shifted inverse).

for positive definite \mathbf{A} with at least q + 1 \ge 2 distinct eigenvalues, \nu > 0 on the spectrum, a shift s \ge 0, any two eigenvalues x_1, x_2 and 0 < \eta \le 1, there is \mathbf{b} such that, for f(z) = (z + s)^{-1}, the Lanczos-FA error \mathbf{e} = f(\mathbf{A})\mathbf{b} - \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q) is nonzero and some \mathbf{y} \in \mathcal{K}_q(\mathbf{A}, \mathbf{b}) has (1 - \eta)^2\,\frac{(R + 1)^2}{4R}\,\|f(\mathbf{A})\mathbf{b} - \mathbf{y}\|_{\nu(\mathbf{A})}^2 \le \|\mathbf{e}\|_{\nu(\mathbf{A})}^2 \,, \qquad R = \frac{\nu(x_1)(x_2 + s)}{\nu(x_2)(x_1 + s)} \,, written in the statement as (\nu(x_1)(x_2 + s) + \nu(x_2)(x_1 + s))^2/(4\,\nu(x_1)(x_2 + s)\,\nu(x_2)(x_1 + s)). For the pair maximising R this is the factor of Matrix.PosDef.re_quadForm_cfc_cfc_mulVec_sub_lanczosFA_le_of_hasStieltjesMeasure for \mu = \delta_s: the near-optimality factor cannot be improved, for any \nu and any s. The vector \mathbf{b} lives on q + 1 eigenvalues containing x_1, x_2, with spectral weights for which the error ratio is [ChenPersson2026, (15)]. [ChenPersson2026, proof of Theorem 2]; the method is Greenbaum's [Greenbaum1979].

Lean statement and details
Matrix.PosDef.exists_inv_add_le_re_quadForm_cfc_cfc_mulVec_sub_lanczosFA.{u_1, u_2} {π•œ : Type u_1}
  [RCLike π•œ] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.PosDef) {q : β„•}
  (hq : 0 < q) (hcard : q + 1 ≀ (spectrum ℝ A).ncard) {Ξ½ : ℝ β†’ ℝ} (hΞ½ : βˆ€ x ∈ spectrum ℝ A, 0 < Ξ½ x)
  {s : ℝ} (hs : 0 ≀ s) {x₁ xβ‚‚ : ℝ} (hx₁ : x₁ ∈ spectrum ℝ A) (hxβ‚‚ : xβ‚‚ ∈ spectrum ℝ A) {Ξ· : ℝ}
  (hΞ· : 0 < Ξ·) (hη₁ : Ξ· ≀ 1) :
  βˆƒ b,
    0 <
        RCLike.re
          (quadForm (cfc Ξ½ A)
            (cfc (fun x ↦ (x + s)⁻¹) A *α΅₯ b - lanczosFA A (fun x ↦ (x + s)⁻¹) b q)) ∧
      βˆƒ y ∈ krylovSpace A b q,
        (1 - Ξ·) ^ 2 *
              ((Ξ½ x₁ * (xβ‚‚ + s) + Ξ½ xβ‚‚ * (x₁ + s)) ^ 2 /
                (4 * (Ξ½ x₁ * (xβ‚‚ + s)) * (Ξ½ xβ‚‚ * (x₁ + s)))) *
            RCLike.re (quadForm (cfc Ξ½ A) (cfc (fun x ↦ (x + s)⁻¹) A *α΅₯ b - y)) ≀
          RCLike.re
            (quadForm (cfc Ξ½ A)
              (cfc (fun x ↦ (x + s)⁻¹) A *α΅₯ b - lanczosFA A (fun x ↦ (x + s)⁻¹) b q))

Full source on GitHub

Copy link

Theorem (The Lanczos recurrence computes Lanczos-FA).

, for Hermitian \mathbf{A} and every q: \mathsf{lanczosFA}(\mathbf{A}, f, \mathbf{b}, q + 1) = \|\mathbf{b}\|\,\mathbf{Q}f(\mathbf{T})\mathbf{e}_0 with \mathbf{Q} and \mathbf{T} from q + 1 steps of the recurrence. [Saad1992, Β§2].

Lean statement and details
Matrix.IsHermitian.lanczosFA_eq_lanczosMatrix.{u_1, u_2} {π•œ : Type u_1} [RCLike π•œ] {n : Type u_2}
  [Fintype n] [DecidableEq n] {A : Matrix n n π•œ} (hA : A.IsHermitian) (f : ℝ β†’ ℝ) (b : n β†’ π•œ)
  (q : β„•) :
  lanczosFA A f b (q + 1) =
    ↑‖WithLp.toLp 2 bβ€– β€’
      lanczosMatrix A b (q + 1) *α΅₯ cfc f (lanczosTridiagonal A b (q + 1)) *α΅₯ Pi.single 0 1

Full source on GitHub

Copy link

Mathematical background

Appears under these tasks