Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Theorem 5:1, eq. (5:3c) — (pi,rj)=0(p_i,r_j)=0(pi​,rj​)=0 for i<ji<ji<j and (pi,rj)=∣ri∣2(p_i,r_j)=|r_i|^2(pi​,rj​)=∣ri​∣2 for i≥ji\ge ji≥j

Proved
ConjGrad.Termination.cg_direction_residual

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

conjugate-gradientnumerical-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,x0∈Rnk, x_0 \in \mathbb{R}^nk,x0​∈Rn, and let rir_iri​, pip_ipi​ be the residuals and directions produced by the conjugate gradient method (3:1) started at x0x_0x0​. Then

(pi,rj)=0(i<j),(pi,rj)=∣ri∣2(i≥j).(p_i, r_j) = 0 \quad (i < j), \qquad (p_i, r_j) = |r_i|^2 \quad (i \ge j).(pi​,rj​)=0(i<j),(pi​,rj​)=∣ri​∣2(i≥j).

With j=ij = ij=i this gives (pi,ri)=∣ri∣2(p_i, r_i) = |r_i|^2(pi​,ri​)=∣ri​∣2, which is why the cg step length (3:1b) coincides with the cd step length (4:1a).

Formalization Note The statement is for all indices; after the method reaches the solution the residuals and directions are 000.

Preamble
import Mathlib
import Definitions.Def_ConjGrad_Termination_cgIter

open Matrix
Formal statement
namespace ConjGrad.Termination

/-- Theorem 5:1, eq. (5:3c) (Hestenes–Stiefel 1952, p. 414). For a symmetric positive
definite `A`, the directions and residuals of the cg-method (3:1) satisfy `(pᵢ, rⱼ) = 0`
for `i < j` and `(pᵢ, rⱼ) = |rᵢ|²` for `i ≥ j`. -/
theorem cg_direction_residual {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) (hA : A.PosDef)
    (k x₀ : Fin n → ℝ) :
    (∀ i j, i < j → (cgIter A k x₀ i).p ⬝ᵥ (cgIter A k x₀ j).r = 0) ∧
    (∀ i j, j ≤ i →
      (cgIter A k x₀ i).p ⬝ᵥ (cgIter A k x₀ j).r = (cgIter A k x₀ i).r ⬝ᵥ (cgIter A k x₀ i).r) := by sorry

end ConjGrad.Termination
Source
Hestenes & Stiefel, Methods of Conjugate Gradients for Solving Linear Systems, J. Res. Natl. Bur. Stand. 49(6) (1952), https://doi.org/10.6028/jres.049.044, p. 414, Theorem 5:1, eq. (5:3c)
Read-back

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

Setting. Let n∈Nn \in \mathbb{N}n∈N and let AAA be a real n×nn\times nn×n matrix that is positive definite in this sense:

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

Here ⟨u,v⟩=∑lulvl\langle u,v\rangle = \sum_l u_l v_l⟨u,v⟩=∑l​ul​vl​. Let k,x0∈Rnk, x_0 \in \mathbb{R}^nk,x0​∈Rn be arbitrary.

The iteration. Let (xi,ri,pi)i∈N(x_i, r_i, p_i)_{i \in \mathbb{N}}(xi​,ri​,pi​)i∈N​ be the sequence defined recursively as follows. Start with

r0=p0=k−Ax0.r_0 = p_0 = k - A x_0 .r0​=p0​=k−Ax0​.

Then, for every i≥0i \ge 0i≥0,

ai=⟨ri,ri⟩⟨pi,Api⟩,xi+1=xi+aipi,ri+1=ri−aiApi,a_i = \frac{\langle r_i, r_i\rangle}{\langle p_i, A p_i\rangle}, \quad x_{i+1} = x_i + a_i p_i, \quad r_{i+1} = r_i - a_i A p_i,ai​=⟨pi​,Api​⟩⟨ri​,ri​⟩​,xi+1​=xi​+ai​pi​,ri+1​=ri​−ai​Api​, bi=⟨ri+1,ri+1⟩⟨ri,ri⟩,pi+1=ri+1+bipi.b_i = \frac{\langle r_{i+1}, r_{i+1}\rangle}{\langle r_i, r_i\rangle}, \quad p_{i+1} = r_{i+1} + b_i p_i .bi​=⟨ri​,ri​⟩⟨ri+1​,ri+1​⟩​,pi+1​=ri+1​+bi​pi​.

Every quotient with a zero denominator is 000, and the recursion never stops.

Conclusion. The theorem asserts both of the following:

  1. For all i,j∈Ni, j \in \mathbb{N}i,j∈N with i<ji < ji<j,
⟨pi,rj⟩=0.\langle p_i, r_j\rangle = 0 .⟨pi​,rj​⟩=0.
  1. For all i,j∈Ni, j \in \mathbb{N}i,j∈N with j≤ij \le ij≤i,
⟨pi,rj⟩=⟨ri,ri⟩.\langle p_i, r_j\rangle = \langle r_i, r_i\rangle .⟨pi​,rj​⟩=⟨ri​,ri​⟩.

In part 2 the right-hand side is the squared length of rir_iri​, the residual carrying the same index as the direction. It is not the squared length of rjr_jrj​.

Degenerate cases.

  • Unbounded indices. Both parts cover all natural-number indices, including those beyond nnn.
  • n=0n = 0n=0. Every dot product is 000 and both parts hold trivially.
  • k=Ax0k = A x_0k=Ax0​. All rir_iri​ and pip_ipi​ are 000, and both sides of each equation are 000.
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