Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Theorem 6:3 — each cg step shortens the error vector, with the exact decrease (6:5)

Proved
ConjGrad.ErrorDecrease.error_vector_decreases

by mikedeng1 · Sep 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

conjugate-gradienterror-analysisnumerical-linear-algebrap2o-batch-p100ap2o-gran-per-chapterp2o-plan-paperp2o-v1

Let AAA be a real symmetric positive definite n×nn\times nn×n matrix, let k∈Rnk\in\mathbb{R}^nk∈Rn, and let hhh be the solution of Ah=kAh=kAh=k. Run the cg-method (5:1) from an arbitrary starting point x0x_0x0​, producing estimates xix_ixi​, residuals rir_iri​ and direction vectors pip_ipi​. Write yi=h−xiy_i=h-x_iyi​=h−xi​ for the error vector of xix_ixi​, f(x)=(h−x,A(h−x))f(x)=(h-x,A(h-x))f(x)=(h−x,A(h−x)) for the error function (4:5) and μ(z)=(z,Az)/∣z∣2\mu(z)=(z,Az)/|z|^2μ(z)=(z,Az)/∣z∣2 for the Rayleigh quotient (4:12).

For every index iii with ri≠0r_i\neq 0ri​=0 (that is, every step xi→xi+1x_i\to x_{i+1}xi​→xi+1​ that the algorithm actually performs), the step reduces the Euclidean length of the error vector, and the reduction is exactly

∣yi∣2−∣yi+1∣2=f(xi+1)+f(xi)μ(pi),and∣yi+1∣<∣yi∣.|y_i|^2 - |y_{i+1}|^2 = \frac{f(x_{i+1}) + f(x_i)}{\mu(p_i)}, \qquad\text{and}\qquad |y_{i+1}| < |y_i| .∣yi​∣2−∣yi+1​∣2=μ(pi​)f(xi+1​)+f(xi​)​,and∣yi+1​∣<∣yi​∣.

This is Theorem 6:3 of Hestenes and Stiefel, whose step from xi−1x_{i-1}xi−1​ to xix_ixi​ is written here with the index shifted by one. The cg-method minimizes the AAA-weighted error fff, not the Euclidean error; the theorem shows that the Euclidean distance ∣h−xi∣|h-x_i|∣h−xi​∣ to the solution also decreases strictly at every step, although the residual ∣ri∣|r_i|∣ri​∣ need not. This justifies stopping the algorithm before the final step.

Formalization Note The hypothesis ri≠0r_i\neq 0ri​=0 says that step i+1i+1i+1 takes place (the paper's range i≤mi\le mi≤m); it is needed, since after termination both sides of the identity are 000 and the strict inequality fails. Termination itself (xm=hx_m=hxm​=h for some m≤nm\le nm≤n) is not assumed. The strict decrease is stated for the squared lengths (y,y)(y,y)(y,y), which is equivalent because lengths are nonnegative.

Preamble
import Mathlib
import Definitions.Def_ConjGrad_ErrorDecrease_cgIter
import Definitions.Def_ConjGrad_ErrorDecrease_errorFun
import Definitions.Def_ConjGrad_ErrorDecrease_rayleigh

open Matrix
Formal statement
namespace ConjGrad.ErrorDecrease

theorem error_vector_decreases {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) (hA : A.PosDef)
    (k x₀ h : Fin n → ℝ) (hh : A *ᵥ h = k) (i : ℕ) (hr : (cgIter A k x₀ i).r ≠ 0) :
    (h - (cgIter A k x₀ i).x) ⬝ᵥ (h - (cgIter A k x₀ i).x) -
        (h - (cgIter A k x₀ (i + 1)).x) ⬝ᵥ (h - (cgIter A k x₀ (i + 1)).x) =
      (errorFun A h (cgIter A k x₀ (i + 1)).x + errorFun A h (cgIter A k x₀ i).x) /
        rayleigh A (cgIter A k x₀ i).p ∧
    (h - (cgIter A k x₀ (i + 1)).x) ⬝ᵥ (h - (cgIter A k x₀ (i + 1)).x) <
      (h - (cgIter A k x₀ i).x) ⬝ᵥ (h - (cgIter A k x₀ i).x) := by sorry

end ConjGrad.ErrorDecrease
Source
Hestenes & Stiefel, Methods of Conjugate Gradients for Solving Linear Systems, J. Res. Natl. Bur. Stand. 49(6) (1952), p. 416, Theorem 6:3, eq. (6:5)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Let n∈Nn \in \mathbb{N}n∈N, and let AAA be an n×nn \times nn×n matrix with real entries, where the rows and columns are indexed by {0,…,n−1}\{0,\dots,n-1\}{0,…,n−1}. The theorem assumes AAA is positive definite in Mathlib's sense:

  • AAA is symmetric, A⊤=AA^{\top} = AA⊤=A;
  • v⊤Av>0v^{\top} A v > 0v⊤Av>0 for every nonzero v∈Rnv \in \mathbb{R}^nv∈Rn.

It also takes three arbitrary vectors k,x0,h∈Rnk, x_0, h \in \mathbb{R}^nk,x0​,h∈Rn and assumes

Ah=k,A h = k,Ah=k,

so hhh solves the linear system with right-hand side kkk. Since AAA is positive definite and therefore invertible, hhh is exactly A−1kA^{-1}kA−1k. The starting vector x0x_0x0​ is not restricted in any way. Finally, the theorem takes an index i∈Ni \in \mathbb{N}i∈N.

The statement uses three definitions from the bundle, cgIter\mathrm{cgIter}cgIter, errorFun\mathrm{errorFun}errorFun and rayleigh\mathrm{rayleigh}rayleigh. Their Lean code was not given to me, so the only facts below are what this statement itself shows about them:

  • cgIter(A,k,x0,j)\mathrm{cgIter}(A, k, x_0, j)cgIter(A,k,x0​,j) is a record indexed by j∈Nj \in \mathbb{N}j∈N, built from AAA, kkk and x0x_0x0​, with at least three vector fields. Write them xjx_jxj​, rjr_jrj​ and pjp_jpj​ (the fields .x, .r and .p). The names suggest an iterate, a residual and a search direction, but nothing visible here fixes what they are. In particular, it is not visible whether x0x_0x0​ is the given starting vector or whether rjr_jrj​ equals k−Axjk - A x_jk−Axj​.
  • E(y):=errorFun(A,h,y)E(y) := \mathrm{errorFun}(A, h, y)E(y):=errorFun(A,h,y) is a real number that depends on AAA, hhh and a vector yyy. Its formula is not visible.
  • R(p):=rayleigh(A,p)R(p) := \mathrm{rayleigh}(A, p)R(p):=rayleigh(A,p) is a real number that depends on AAA and a vector ppp. Its formula is not visible.

The last hypothesis is that the rrr-field of the iii-th record is nonzero:

ri≠0.r_i \neq 0.ri​=0.

Under all of these hypotheses, the theorem asserts that the following two statements hold together. Here ∥v∥2=v⋅v=∑jvj2\|v\|^2 = v \cdot v = \sum_j v_j^2∥v∥2=v⋅v=∑j​vj2​ is the ordinary Euclidean squared norm, not a norm weighted by AAA.

  1. An exact identity:
∥h−xi∥2−∥h−xi+1∥2  =  E(xi+1)+E(xi)R(pi).\|h - x_i\|^2 - \|h - x_{i+1}\|^2 \;=\; \frac{E(x_{i+1}) + E(x_i)}{R(p_i)}.∥h−xi​∥2−∥h−xi+1​∥2=R(pi​)E(xi+1​)+E(xi​)​.
  1. A strict decrease:
∥h−xi+1∥2  <  ∥h−xi∥2.\|h - x_{i+1}\|^2 \;<\; \|h - x_i\|^2.∥h−xi+1​∥2<∥h−xi​∥2.

Degenerate cases:

  • n=0n = 0n=0: R0\mathbb{R}^0R0 has only the zero vector, so the hypothesis ri≠0r_i \neq 0ri​=0 can never hold, and the theorem is vacuously true.
  • Iterations that have already stopped: for any nnn, the theorem says nothing about an index iii with ri=0r_i = 0ri​=0.
  • Division by zero: division is total, and dividing by 000 gives 000. If R(pi)=0R(p_i) = 0R(pi​)=0, conclusion 1 therefore asserts ∥h−xi∥2=∥h−xi+1∥2\|h - x_i\|^2 = \|h - x_{i+1}\|^2∥h−xi​∥2=∥h−xi+1​∥2. That contradicts conclusion 2, so in that case the theorem amounts to claiming the hypotheses cannot all hold together. Whether R(pi)R(p_i)R(pi​) can actually be 000, or can be negative, depends on the hidden definition of rayleigh\mathrm{rayleigh}rayleigh.
  • What is covered: the statement holds for every i≥0i \ge 0i≥0, including i=0i = 0i=0, and for every starting vector x0x_0x0​. Nothing is said about how many iterations are run.
Human review
  • Endorsed by Shuze Chen · Sep 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 27, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me