NLA-lib Explorer

Conjugate gradient (CG)

Solve a symmetric positive-definite system \mathbf{A}\mathbf{x}=\mathbf{b} using a short Krylov recurrence.

Implementation guides

Implementations

Mathematical CG in exact arithmetic

Let \mathbf{A} be symmetric positive definite, let \mathbf{A}\mathbf{x}_\star=\mathbf{b}, and write \mathbf{x}_k for the mathematical CG iterate from \mathbf{x}_0. The energy norm is \|\mathbf{v}\|_\mathbf{A}^2=\mathbf{v}^{\mathsf{T}}\mathbf{A}\mathbf{v}.

Theorem (Energy optimality). The mathematical CG iterate minimizes the energy error over the initial guess plus its Krylov space:

\mathbf{x}_k\in\operatorname*{arg\,min}_{\mathbf{y}\in\mathbf{x}_0+\mathcal{K}_k(\mathbf{A},\mathbf{r}_0)}\|\mathbf{x}_\star-\mathbf{y}\|_\mathbf{A}^2.

Here \mathcal{K}_k(\mathbf{A},\mathbf{r}_0)=\operatorname{span}\{\mathbf{r}_0,\mathbf{A}\mathbf{r}_0,\ldots,\mathbf{A}^{k-1}\mathbf{r}_0\}. The energy error cannot increase as the search space grows.

Lean statement and details
Matrix.PosDef.isMinOn_cgIterate.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜] {n : Type u_2} [Fintype n]
  [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef) {b xs : n → 𝕜} (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜)
  (q : ℕ) :
  IsMinOn (fun y ↦ RCLike.re (quadForm A (xs - y)))
    (↑(AffineSubspace.mk' x₀ (krylovSpace A (b - A *ᵥ x₀) q))) (cgIterate A b x₀ q)

Full source on GitHub

Copy link

Theorem (Chebyshev convergence). If the eigenvalues of \mathbf{A} lie in [a,a^{\prime}], a>0, then

\|\mathbf{x}_\star-\mathbf{x}_k\|_\mathbf{A}^2\le4\left(\frac{\sqrt\kappa-1}{\sqrt\kappa+1}\right)^{2k}\|\mathbf{x}_\star-\mathbf{x}_0\|_\mathbf{A}^2,\qquad\kappa=\frac{a^{\prime}}a.

The positive spectral interval controls the rate. The implementation pages connect this mathematical result to stored solver outputs.

Lean statement and details
Matrix.IsHermitian.re_quadForm_sub_cgIterate_le_four_mul_pow.{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') {b xs : n → 𝕜} (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜)
  (q : ℕ) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ q)) ≤
    4 * ((√(a' / a) - 1) / (√(a' / a) + 1)) ^ (2 * q) * RCLike.re (quadForm A (xs - x₀))

Full source on GitHub

Copy link

Theorem (Polynomial error bound). For every polynomial p of degree at most k with p(0)=1,

\|\mathbf{x}_\star-\mathbf{x}_k\|_\mathbf{A}^2\le\|p(\mathbf{A})(\mathbf{x}_\star-\mathbf{x}_0)\|_\mathbf{A}^2.

A polynomial small on the spectrum therefore yields a small CG error.

Lean statement and details
Matrix.PosDef.re_quadForm_sub_cgIterate_le.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜] {n : Type u_2}
  [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef) {s : Set ℝ} (hs : spectrum ℝ A ⊆ s)
  {b xs : n → 𝕜} (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜) {q : ℕ} {p : Polynomial ℝ} (hp : p.degree ≤ ↑q)
  (hp₀ : Polynomial.eval 0 p = 1) {η : ℝ} (hη : ∀ x ∈ s, |Polynomial.eval x p| ≤ η) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ q)) ≤ η ^ 2 * RCLike.re (quadForm A (xs - x₀))

Full source on GitHub

Copy link

Theorem (Finite termination). Let g be the dimension of the Krylov space generated by the initial residual. Once k\ge g, the mathematical iterate satisfies \mathbf{x}_k=\mathbf{x}_\star. In dimension n, at most n exact-arithmetic steps suffice.

Lean statement and details
Matrix.PosDef.cgIterate_eq_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.PosDef) {b xs : n → 𝕜} (hxs : A *ᵥ xs = b)
  (x₀ : n → 𝕜) {q : ℕ} (h : krylovGrade A (b - A *ᵥ x₀) ≤ q) : cgIterate A b x₀ q = xs

Full source on GitHub

Copy link

Used by other algorithms

Further mathematical results

Theorem (CG attains the Chebyshev value).

for 0 < a < a', on the Chebyshev extrema matrix \mathbf{A} with solution \mathbf{x}_\star = chebyshevErrorVector and the zero start, \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{A}\mathbf{x}_\star, \mathbf{0}, q)\|_{\mathbf{A}}^2 = T_q\Bigl(\frac{a' + a}{a' - a}\Bigr)^{-2}\|\mathbf{x}_\star\|_{\mathbf{A}}^2 \,. The error is p(\mathbf{A})\mathbf{x}_\star for a residual polynomial p, of squared \mathbf{A}-norm \sum_k\omega_k\lvert p(\xi_k)\rvert^2 \ge 1/\sum_k\omega_k by Cauchy–Schwarz against \sum_k(-1)^k\omega_k p(\xi_k) = 1; chebyshevResidual attains it. [Greenbaum1997, §3.1]; locator to verify.

Lean statement and details
NLAlib.re_quadForm_sub_cgIterate_chebyshevExtremaMatrix.{u_1} {𝕜 : Type u_1} [RCLike 𝕜] {a a' : ℝ}
  (ha : 0 < a) (haa : a < a') (q : ℕ) :
  RCLike.re
      (quadForm (chebyshevExtremaMatrix 𝕜 a a' q)
        (chebyshevErrorVector 𝕜 a a' q -
          cgIterate (chebyshevExtremaMatrix 𝕜 a a' q)
            (chebyshevExtremaMatrix 𝕜 a a' q *ᵥ chebyshevErrorVector 𝕜 a a' q) 0 q)) =
    (Polynomial.eval ((a' + a) / (a' - a)) (Polynomial.Chebyshev.T ℝ ↑q))⁻¹ ^ 2 *
      RCLike.re (quadForm (chebyshevExtremaMatrix 𝕜 a a' q) (chebyshevErrorVector 𝕜 a a' q))

Full source on GitHub

Copy link

Theorem (The CG error is a Gauss quadrature error).

for positive definite \mathbf{A}, \mathbf{A}\mathbf{x}_\star = \mathbf{b}, every \mathbf{x}_0 and q, with \mathbf{r}_0 = \mathbf{b} - \mathbf{A}\mathbf{x}_0 and \mathbf{x}_q = \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q), \|\mathbf{x}_\star - \mathbf{x}_q\|_{\mathbf{A}}^2 = \int x^{-1}\,d\mu_{\mathbf{A},\mathbf{r}_0} - \int x^{-1}\,d\,\mathsf{gaussQuadrature}(\mu_{\mathbf{A},\mathbf{r}_0}, q)\,. [GolubMeurant2010, Ch. 12]; [GolubStrakos1994, §3] (locators to check).

Lean statement and details
Matrix.PosDef.re_quadForm_sub_cgIterate_eq_integral_sub.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜]
  {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef) {b xs : n → 𝕜}
  (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜) (q : ℕ) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ q)) =
    ∫ (x : ℝ), x⁻¹ ∂spectralMeasure A (b - A *ᵥ x₀) -
      ∫ (x : ℝ), x⁻¹ ∂gaussQuadrature (spectralMeasure A (b - A *ᵥ x₀)) q

Full source on GitHub

Copy link

Theorem (The Gauss–Radau upper bound on the CG error).

for positive definite \mathbf{A} with spectrum in [a, a'], 0 < a < a', \mathbf{A}\mathbf{x}_\star = \mathbf{b}, every \mathbf{x}_0 and q, with \mathbf{r}_0 = \mathbf{b} - \mathbf{A}\mathbf{x}_0 and \mu = \mu_{\mathbf{A},\mathbf{r}_0}, \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q)\|_{\mathbf{A}}^2 \le \int x^{-1}\,d\,\mathsf{radauQuadrature}(\mu, a, q) - \int x^{-1}\,d\,\mathsf{gaussQuadrature}(\mu, q)\,: the left Radau rule with q free nodes overestimates \int x^{-1}\,d\mu because (x^{-1})^{(2q+1)} < 0. [GolubMeurant2010, Ch. 12]; [GolubStrakos1994, §3] (locators to check).

Lean statement and details
Matrix.PosDef.re_quadForm_sub_cgIterate_le_integral_radauQuadrature_sub.{u_1, u_2} {𝕜 : Type u_1}
  [RCLike 𝕜] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef)
  {a a' : ℝ} (ha : 0 < a) (haa' : a < a') (hs : spectrum ℝ A ⊆ Set.Icc a a') {b xs : n → 𝕜}
  (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜) (q : ℕ) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ q)) ≤
    ∫ (x : ℝ), x⁻¹ ∂radauQuadrature (spectralMeasure A (b - A *ᵥ x₀)) a q -
      ∫ (x : ℝ), x⁻¹ ∂gaussQuadrature (spectralMeasure A (b - A *ᵥ x₀)) q

Full source on GitHub

Copy link

Theorem (The Galerkin condition).

for positive definite \mathbf{A} the residual of the CG iterate is orthogonal to \mathcal{K}_q(\mathbf{A}, \mathbf{r}_0), \mathbf{r}_0 = \mathbf{b} - \mathbf{A}\mathbf{x}_0: \mathbf{K}_q(\mathbf{A}, \mathbf{r}_0)^{\mathsf{H}}(\mathbf{b} - \mathbf{A}\,\mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q)) = \mathbf{0}. [Saad2003, §6.7]; there CG is the orthogonal projection method onto \mathcal{K}_q(\mathbf{A}, \mathbf{r}_0), whose defining condition is this one ([Saad2003, (5.3)] with \mathcal{L} = \mathcal{K}), stated for real symmetric \mathbf{A}.

Lean statement and details
Matrix.PosDef.conjTranspose_krylovMatrix_mulVec_sub_mulVec_cgIterate_eq_zero.{u_1, u_2}
  {𝕜 : Type u_1} [RCLike 𝕜] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜}
  (hA : A.PosDef) (b x₀ : n → 𝕜) (q : ℕ) :
  (krylovMatrix A (b - A *ᵥ x₀) q)ᴴ *ᵥ (b - A *ᵥ cgIterate A b x₀ q) = 0

Full source on GitHub

Copy link

Theorem (CG is $\mathbf{x}_0 + \mathbf{Q}(\mathbf{Q}^{\mathsf{H}}\mathbf{A}\mathbf{Q})^{-1}\mathbf{Q}^{\mathsf{H}}\mathbf{r}_0$ for any orthonormal basis \mathbf{Q} of the Krylov space).

, for positive definite \mathbf{A}: \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q) = \mathbf{x}_0 + \mathbf{Q}(\mathbf{Q}^{\mathsf{H}}\mathbf{A}\mathbf{Q})^{-1}\mathbf{Q}^{\mathsf{H}}\mathbf{r}_0, \mathbf{r}_0 = \mathbf{b} - \mathbf{A}\mathbf{x}_0. [Saad2003, §6.7].

Lean statement and details
Matrix.PosDef.cgIterate_eq.{u_1, u_2, u_3} {𝕜 : Type u_1} [RCLike 𝕜] {n : Type u_2} {r : Type u_3}
  [Fintype n] [DecidableEq n] [Fintype r] [DecidableEq r] {A : Matrix n n 𝕜} (hA : A.PosDef)
  {Q : Matrix n r 𝕜} (hQ : HasOrthonormalCols Q) {b x₀ : n → 𝕜} {q : ℕ}
  (hK : Q.mulVecLin.range = krylovSpace A (b - A *ᵥ x₀) q) :
  cgIterate A b x₀ q = x₀ + Q *ᵥ (Qᴴ * A * Q)⁻¹ *ᵥ Qᴴ *ᵥ (b - A *ᵥ x₀)

Full source on GitHub

Copy link

Theorem (The Lanczos recurrence yields CG).

for Hermitian \mathbf{A} and every q, \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q + 1) = \mathbf{x}_0 + \|\mathbf{r}_0\|\,\mathbf{Q}\mathbf{T}^{+}\mathbf{e}_0 with \mathbf{Q} and \mathbf{T} computed by q + 1 steps of the recurrence from \mathbf{r}_0; past the grade the recurrence has frozen at zero and the iterate is unchanged. [Saad2003, §6.7.1].

Lean statement and details
Matrix.IsHermitian.cgIterate_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) (b x₀ : n → 𝕜) (q : ℕ) :
  cgIterate A b x₀ (q + 1) =
    x₀ +
      ↑‖WithLp.toLp 2 (b - A *ᵥ x₀)‖ •
        lanczosMatrix A (b - A *ᵥ x₀) (q + 1) *ᵥ
          pinv (lanczosTridiagonal A (b - A *ᵥ x₀) (q + 1)) *ᵥ Pi.single 0 1

Full source on GitHub

Copy link

Theorem (Near-optimality of CG in the \mathbf{A}^\alpha-norms).

for Hermitian \mathbf{A} with spectrum in [a, a'], 0 < a, \mathbf{A}\mathbf{x}_\star = \mathbf{b}, a start \mathbf{x}_0 with \mathbf{r}_0 = \mathbf{b} - \mathbf{A}\mathbf{x}_0, real \alpha, E = \max(\alpha, 1 - \alpha) and every \mathbf{y} \in \mathbf{x}_0 + \mathcal{K}_q(\mathbf{A}, \mathbf{r}_0), \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q)\|_{\mathbf{A}^\alpha}^2 \le \Bigl(\frac{(a'/a)^{E/2} + (a'/a)^{-E/2}}{2}\Bigr)^2 \|\mathbf{x}_\star - \mathbf{y}\|_{\mathbf{A}^\alpha}^2 \,. At \alpha = 1 CG is optimal (Matrix.PosDef.isMinOn_cgIterate), so this bound is useful for \alpha \ne 1. [ChenPersson2026, Theorem 1 and (5)].

Lean statement and details
Matrix.IsHermitian.re_quadForm_rpow_sub_cgIterate_le.{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) (hσ : spectrum ℝ A ⊆ Set.Icc a a') (α : ℝ) {b xs : n → 𝕜} (hxs : A *ᵥ xs = b)
  (x₀ : n → 𝕜) {q : ℕ} {y : n → 𝕜}
  (hy : y ∈ AffineSubspace.mk' x₀ (krylovSpace A (b - A *ᵥ x₀) q)) :
  RCLike.re (quadForm (A ^ α) (xs - cgIterate A b x₀ q)) ≤
    (((a' / a) ^ (max α (1 - α) / 2) + (a' / a) ^ (-(max α (1 - α) / 2))) / 2) ^ 2 *
      RCLike.re (quadForm (A ^ α) (xs - y))

Full source on GitHub

Copy link

Theorem (The Euclidean factor for CG cannot be improved).

for positive definite \mathbf{A} with at least q + 1 \ge 2 distinct eigenvalues, \kappa = \kappa(\mathbf{A}) and 0 < \eta \le 1, there is \mathbf{x}_\star such that, for \mathbf{b} = \mathbf{A}\mathbf{x}_\star and the zero start, the CG error is nonzero and some \mathbf{y} \in \mathcal{K}_q(\mathbf{A}, \mathbf{b}) has (1 - \eta)\,\frac{\sqrt\kappa + 1/\sqrt\kappa}{2}\,\|\mathbf{x}_\star - \mathbf{y}\| \le \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{0}, q)\| \,. So the factor of Matrix.IsHermitian.norm_sub_cgIterate_le_mul_norm_sub is optimal. The instance is that of Matrix.PosDef.exists_inv_add_le_re_quadForm_cfc_cfc_mulVec_sub_lanczosFA with \nu = 1, s = 0 and the extreme eigenvalues, where Lanczos-FA for z^{-1} is CG (Matrix.IsHermitian.lanczosFA_inv_eq_cgIterate). [ChenPersson2026, Remark 3].

Lean statement and details
Matrix.PosDef.exists_le_norm_sub_cgIterate.{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η : 0 < η) (hη₁ : η ≤ 1) :
  ∃ xs,
    0 < ‖WithLp.toLp 2 (xs - cgIterate A (A *ᵥ xs) 0 q)‖ ∧
      ∃ y ∈ krylovSpace A (A *ᵥ xs) q,
        (1 - η) * ((√(pseudoConditionNumber A) + (√(pseudoConditionNumber A))⁻¹) / 2) *
            ‖WithLp.toLp 2 (xs - y)‖ ≤
          ‖WithLp.toLp 2 (xs - cgIterate A (A *ᵥ xs) 0 q)‖

Full source on GitHub

Copy link

Theorem (CG: orthogonal residuals and conjugate directions).

, for positive definite \mathbf{A}: \mathbf{p}_j^{\mathsf{H}}\mathbf{A}\mathbf{p}_k = 0 for j < k. [HestenesStiefel1952, Theorem 5:1]; [TrefethenBau1997, Theorem 38.1]. It is (5:3b) there, for real symmetric \mathbf{A}.

Lean statement and details
Matrix.PosDef.star_cgState_p_dotProduct_mulVec_eq_zero.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜]
  {n : Type u_2} [Fintype n] {A : Matrix n n 𝕜} {b x₀ : n → 𝕜} (hA : A.PosDef) {j k : ℕ}
  (hjk : j < k) : star (cgState A b x₀ j).p ⬝ᵥ A *ᵥ (cgState A b x₀ k).p = 0

Full source on GitHub

Copy link

Theorem (Large outliers cost one step each).

if every outlier is at least a', the outlier bound holds with C = 1, \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, m + d)\|_{\mathbf{A}}^2 \le 4\Bigl(\frac{\sqrt{a'/a} - 1}{\sqrt{a'/a} + 1}\Bigr)^{2d} \|\mathbf{x}_\star - \mathbf{x}_0\|_{\mathbf{A}}^2 \,. [Greenbaum1997, §3.1]; locator to verify.

Lean statement and details
Matrix.PosDef.re_quadForm_sub_cgIterate_le_four_mul_pow_of_forall_le.{u_1, u_2} {𝕜 : Type u_1}
  [RCLike 𝕜] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef)
  {a a' : ℝ} (ha : 0 < a) {T : Finset ℝ} (hs : spectrum ℝ A ⊆ Set.Icc a a' ∪ ↑T)
  (hT : ∀ t ∈ T, a' ≤ t) {b xs : n → 𝕜} (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜) (d : ℕ) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ (T.card + d))) ≤
    4 * ((√(a' / a) - 1) / (√(a' / a) + 1)) ^ (2 * d) * RCLike.re (quadForm A (xs - x₀))

Full source on GitHub

Copy link

Theorem (The Hestenes–Stiefel iterates are the CG iterates).

for positive definite \mathbf{A} and every k, with no breakdown hypothesis, \mathbf{x}_k = \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, k). [HestenesStiefel1952, Theorem 6:1]; [TrefethenBau1997, Theorem 38.1]. Hestenes and Stiefel show that \mathbf{x}_k minimises the \mathbf{A}-norm error on the plane through \mathbf{x}_0, \dots, \mathbf{x}_k, which is \mathbf{x}_0 + \mathcal{K}_k(\mathbf{A}, \mathbf{r}_0) (Matrix.PosDef.span_cgState_p), for real symmetric \mathbf{A} and up to termination; here every k.

Lean statement and details
Matrix.PosDef.cgState_x_eq.{u_1, u_2} {𝕜 : Type u_1} [RCLike 𝕜] {n : Type u_2} [Fintype n]
  [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef) (b x₀ : n → 𝕜) (k : ℕ) :
  (cgState A b x₀ k).x = cgIterate A b x₀ k

Full source on GitHub

Copy link

Theorem (The spectrum-optimal bound for CG).

for positive definite \mathbf{A} and \mathbf{A}\mathbf{x}_\star = \mathbf{b}, \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q)\|_{\mathbf{A}}^2 \le \mathsf{residualMinimax}(\sigma(\mathbf{A}), q)^2 \|\mathbf{x}_\star - \mathbf{x}_0\|_{\mathbf{A}}^2 \,, where \mathsf{residualMinimax}(\sigma(\mathbf{A}), q) = \min_{p}\max_{\lambda \in \sigma(\mathbf{A})}\lvert p(\lambda) \rvert, the minimum over real p with \deg p \le q, p(0) = 1. Every other bound of this file follows from it by bounding the minimax value. For each \mathbf{A} some \mathbf{b} attains it (Greenbaum): Matrix.PosDef.exists_re_quadForm_sub_cgIterate_eq_residualMinimax_sq_mul and Matrix.PosDef.isGreatest_re_quadForm_sub_cgIterate_div in NLAlib.Krylov.LinearSystems.WorstCase. [Greenbaum1997, §3.1]; locator to verify. [Saad2003, Theorem 6.29]; its proof gives this bound, with the maximum over the eigenvalues, before passing to an interval, for real symmetric \mathbf{A}.

Lean statement and details
Matrix.PosDef.re_quadForm_sub_cgIterate_le_residualMinimax_sq_mul.{u_1, u_2} {𝕜 : Type u_1}
  [RCLike 𝕜] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef)
  {b xs : n → 𝕜} (hxs : A *ᵥ xs = b) (x₀ : n → 𝕜) (q : ℕ) :
  RCLike.re (quadForm A (xs - cgIterate A b x₀ q)) ≤
    residualMinimax (spectrum ℝ A) q ^ 2 * RCLike.re (quadForm A (xs - x₀))

Full source on GitHub

Copy link

Theorem (The spectrum-minimax bound for CG is attained).

(Greenbaum): for n nonempty and positive definite \mathbf{A}, every start \mathbf{x}_0 and every q there is a solution \mathbf{x}_\star \ne \mathbf{x}_0 with, for \mathbf{b} = \mathbf{A}\mathbf{x}_\star, \|\mathbf{x}_\star - \mathsf{cgIterate}(\mathbf{A}, \mathbf{b}, \mathbf{x}_0, q)\|_{\mathbf{A}}^2 = \mathsf{residualMinimax}(\sigma(\mathbf{A}), q)^2 \|\mathbf{x}_\star - \mathbf{x}_0\|_{\mathbf{A}}^2 \,, where \mathsf{residualMinimax}(\sigma(\mathbf{A}), q) = \min_{p}\max_{\lambda \in \sigma(\mathbf{A})}\lvert p(\lambda) \rvert, the minimum over real p with \deg p \le q, p(0) = 1. So Matrix.PosDef.re_quadForm_sub_cgIterate_le_residualMinimax_sq_mul cannot be improved for any spectrum. The interval case with an explicit instance is re_quadForm_sub_cgIterate_chebyshevExtremaMatrix. The initial error carries the dual weights w_\lambda of exists_residualMinimax_sq_le_sum_mul_norm_sq, divided by \lambda, as its spectral weights. [Greenbaum1979]; [Greenbaum1997, §3.1]; locators to verify.

General form: sizes are index types

Lean statement and details
Matrix.PosDef.exists_re_quadForm_sub_cgIterate_eq_residualMinimax_sq_mul.{u_1, u_2} {𝕜 : Type u_1}
  [RCLike 𝕜] {n : Type u_2} [Fintype n] [DecidableEq n] {A : Matrix n n 𝕜} (hA : A.PosDef)
  [Nonempty n] (x₀ : n → 𝕜) (q : ℕ) :
  ∃ xs,
    xs ≠ x₀ ∧
      RCLike.re (quadForm A (xs - cgIterate A (A *ᵥ xs) x₀ q)) =
        residualMinimax (spectrum ℝ A) q ^ 2 * RCLike.re (quadForm A (xs - x₀))

Full source on GitHub

Copy link

Mathematical background

Appears under these tasks

Family