Theorems 4:2 and 5:2 — the cg-method reaches the solution in at most n steps
ProvedConjGrad.Termination.cg_terminates_in_n_stepsLet be a real symmetric positive definite matrix, let , and let be the solution of . Let be an arbitrary initial estimate, and let be the estimates produced by the conjugate gradient method (3:1):
Then there is an with
This is the finite-termination property announced in the paper's abstract ("The solution is given in steps") and in Section 3: "If no rounding-off error is encountered, one will reach an estimate () at which . This estimate is the desired solution ." It is Theorem 4:2 for the method of conjugate directions, applied to the cg-method by Theorem 5:2.
Formalization Note Vectors are Fin n → ℝ, the solution is given by the hypothesis , and the iteration is total: Lean's division by zero makes it stay at once (no stopping test and no reference to or inside the iteration). Exact real arithmetic is assumed, as in the paper's "if no rounding-off errors are encountered".
import Mathlib import Definitions.Def_ConjGrad_Termination_cgIter open Matrix
namespace ConjGrad.Termination
/-- Theorems 4:2 and 5:2 (Hestenes–Stiefel 1952, pp. 410, 412, 415): for a symmetric
positive definite `n × n` matrix `A`, a right-hand side `k` with solution `h` (`Ah = k`) and
an arbitrary initial estimate `x₀`, the cg-method (3:1) reaches the solution after at most
`n` steps: some estimate `xₘ` with `m ≤ n` equals `h`. -/
theorem cg_terminates_in_n_steps {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) (hA : A.PosDef)
(k h : Fin n → ℝ) (hh : A *ᵥ h = k) (x₀ : Fin n → ℝ) :
∃ m ≤ n, (cgIter A k x₀ m).x = h := by sorry
end ConjGrad.Termination
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Let be a natural number. Vectors are functions , so they are elements of . The statement takes the following data:
- an real matrix ;
- a hypothesis that is positive definite in Mathlib's sense:
- is Hermitian, which for a real matrix means symmetric: ;
- for every nonzero ;
- two vectors with ;
- an arbitrary vector .
Because is positive definite it is invertible. So the hypothesis says exactly that , the unique solution of . It places no further restriction on .
The conclusion uses an externally defined function . It comes from the imported module Definitions.Def_ConjGrad_Termination_cgIter, and its definition is not shown in this declaration. All the code itself shows is this:
- takes the matrix , the vector , the vector and a natural number .
- It returns a value with a component , and that component is a vector in . Write this component as .
Nothing here fixes what is: which recurrence produces it, how divisions by zero are handled, or what the other components are. An auditor has to read the imported definition to learn that. The docstring calls it the Hestenes–Stiefel conjugate-gradient iteration, but the statement does not check that description.
The theorem asserts:
In words: some index between and inclusive has an -th output whose -component equals the solution exactly. The statement:
- makes no claim that is the first such index;
- makes no claim that later iterates stay equal to ;
- makes no claim about any other component of 's output, such as residuals or search directions;
- makes no claim about how many steps are needed beyond the bound .
Degenerate cases:
- . has exactly one element, and the empty matrix counts as positive definite because it has no nonzero vectors. The only allowed index is , and holds automatically since is a single point. The statement is then trivially true, whatever does.
- is allowed for every . For example, if , the conclusion can be witnessed by provided . Whether that equation holds depends on the unseen definition.
- . Then , and the claim is that some with is the zero vector.
- Junk values. If divides by a quantity that becomes zero, Lean's convention gives . The theorem is then a claim about whatever vectors that convention produces, not about an iteration that "stops". Which quantities are divided, and when they can vanish, cannot be told from this declaration.
- Hypotheses always satisfiable. The hypotheses can be met for every : take and . So the statement is not vacuous.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.