Total conjugate-gradient iteration
DefinitionVectorSpaceOpt_conjugate_gradientFor a real inner-product space, IsRealSelfAdjoint Q expresses symmetry of a continuous linear operator, and IsCoerciveBetween Q m M records its lower and upper quadratic bounds. A conjugate-gradient state stores an iterate x, residual r, and direction p. Starting from r₀ = p₀ = b - Q x₀, an active step uses
If p = 0, the state is returned unchanged. Thus conjugateGradientIterate is a total natural-number sequence with explicit exact-termination semantics, and conjugateGradientEnergy records the quadratic error energy used in convergence. The stop/stutter convention is essential for auditing every later denominator.
import Mathlib
open Filter Set
open scoped RealInnerProductSpace
namespace VectorSpaceOpt
/-- A real continuous linear operator is self-adjoint when it can be moved across the inner product. -/
def IsRealSelfAdjoint
{H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
(Q : H →L[ℝ] H) : Prop :=
∀ x y : H, ⟪Q x, y⟫ = ⟪x, Q y⟫
/-- The lower and upper quadratic bounds used throughout §§10.5–10.8. -/
def IsCoerciveBetween
{H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
(Q : H →L[ℝ] H) (m M : ℝ) : Prop :=
∀ x : H, m * ‖x‖ ^ 2 ≤ ⟪x, Q x⟫ ∧ ⟪x, Q x⟫ ≤ M * ‖x‖ ^ 2
/-- The three vectors carried by one conjugate-gradient iteration. -/
structure ConjugateGradientState (H : Type*) where
x : H
r : H
p : H
/-- One conjugate-gradient step, explicitly stuttering after `p = 0`. -/
noncomputable def conjugateGradientStep
{H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
(Q : H →L[ℝ] H) (b : H) (s : ConjugateGradientState H) :
ConjugateGradientState H :=
letI := Classical.decEq H
if s.p = 0 then s
else
let alpha : ℝ := ⟪s.r, s.p⟫ / ⟪s.p, Q s.p⟫
let xNext : H := s.x + alpha • s.p
let rNext : H := b - Q xNext
let beta : ℝ := ⟪rNext, Q s.p⟫ / ⟪s.p, Q s.p⟫
{ x := xNext, r := rNext, p := rNext - beta • s.p }
/-- The total conjugate-gradient sequence, with initial direction equal to the initial residual. -/
noncomputable def conjugateGradientIterate
{H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
(Q : H →L[ℝ] H) (b x₀ : H) (n : ℕ) : ConjugateGradientState H :=
(conjugateGradientStep Q b)^[n]
{ x := x₀, r := b - Q x₀, p := b - Q x₀ }
/-- The quadratic error energy used in the convergence proof. -/
def conjugateGradientEnergy
{H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H]
(Q : H →L[ℝ] H) (xStar x : H) : ℝ :=
⟪x - xStar, Q (x - xStar)⟫
end VectorSpaceOptRead-back
What the Lean code literally says, in plain math · gpt-5
IsRealSelfAdjoint. For any type carrying a normed additive commutative-group structure and a real inner-product-space structure, and any continuous real-linear map , this predicate means that for every , . It imposes neither completeness nor positivity.
IsCoerciveBetween. For such an , a continuous real-linear , and arbitrary real numbers , this predicate means that every simultaneously satisfies and . The definition itself does not require , , or completeness; it also includes .
ConjugateGradientState. For an arbitrary type , a state is exactly a record of three elements of , named , , and ; the structure itself assumes no algebraic operations on .
conjugateGradientStep. Given a real inner-product space , a continuous real-linear , a vector , and a state , one step first tests equality . If , it returns the identical state, so every later application also stutters. If , it sets , , , , and returns . This total definition has no hypothesis that is nonzero: real division by zero is defined, yielding and when that denominator is zero.
conjugateGradientIterate. Given and , this is the result of applying the preceding step exactly times to the initial state . At it is exactly that initial state; if any step reaches , all subsequent states are the same by the step definition.
conjugateGradientEnergy. Given and vectors , the energy is the real number . Without additional assumptions on , this definition does not assert that the value is nonnegative.
Confirmed by the mission captain (proposal self-audit).