Classical and Modified Gram-Schmidt Orthogonalization #
This file formalizes the algorithmic variants of Gram-Schmidt orthogonalization:
the classical Gram-Schmidt (CGS) process operating on lists, and the modified
Gram-Schmidt (MGS) process operating on matrices indexed by Fin m.
Mathlib already provides the abstract mathematical Gram-Schmidt process
(gramSchmidt in Mathlib.Analysis.InnerProductSpace.GramSchmidtOrtho), which uses
well-founded recursion over an arbitrary linearly ordered index type. The definitions
here are complementary: they model the specific computational procedures as
implemented in practice, and prove their correctness properties (orthogonality, span
preservation, nonzero outputs) directly. A bridging theorem connecting classicalGS
to Mathlib's gramSchmidt is a natural next step.
Origin #
Translated from the Rocq/MathComp formalization in Gram_Schmidt/GS_functional_mathcomp.v.
The original defines classical and modified GS over 'cV[R]_n.+1 (real column vectors)
using MathComp's dotmul. This Lean version works over a general real inner product
space E with @inner ℝ E _ as the inner product.
Main definitions #
projection u v: orthogonal projection ofvonto the direction ofu, equal to(⟪u, v⟫ / ⟪u, u⟫) • u.computeUk orthVecs vk: the CGS stepvk - Σ projection(uᵢ, vk).classicalGSAux,classicalGS: the list-based classical Gram-Schmidt process.modifiedGSAux',modifiedGSAux,matrixConstruction,modifiedGS: the matrix-based modified Gram-Schmidt process.
Main results #
classicalGS_orthogonal: the classical GS output is pairwise orthogonal and preserves successive spans (gram_schmidt).nonzeroResultVecHelper: the main inductive lemma — firstkCGS output vectors are nonzero, pairwise orthogonal, and span the same subspace as the firstkinputs.orthoLinInd: pairwise orthogonal nonzero vectors are linearly independent.
Admitted / sorry status #
The following items use sorry, matching Admitted in the original Rocq source:
nonzeroVec: nonzero vector has nonzero squared inner productprojCreatesOrtho: residuala - projection b ais orthogonal toborthoProj: projection onto orthogonal direction is zerocgsAuxUk: characterization of the k-th CGS auxiliary output vectormgsLemmaOne: MGS matrix entry characterizationmgsLemmaM: MGS output characterizationgsEquiv: CGS and MGS equivalence (commented out /Admittedin Rocq)
References #
- [Trefethen and Bau, Numerical Linear Algebra][trefethen1997], Chapter 8
- [Golub and Van Loan, Matrix Computations][golub2013], Section 5.2.8
Projection #
Orthogonal projection of v onto the direction of u:
projection u v = (⟪u, v⟫ / ⟪u, u⟫) • u.
This is the vector projection (not the subspace projection); it is the component
of v in the direction of u.
Instances For
Classical Gram-Schmidt #
Compute the k-th orthogonal vector: vk - Σ projection(uᵢ, vk).
This is one step of the classical Gram-Schmidt process.
Equations
- NumLib.LinearAlgebra.GramSchmidt.computeUk orthVecs vk = vk - (List.map (fun (u : E) => NumLib.LinearAlgebra.GramSchmidt.projection u vk) orthVecs).sum
Instances For
Auxiliary classical GS recursion. Processes remaining input vectors, appending orthogonalized results to the accumulator.
Equations
Instances For
The classical Gram-Schmidt process: given a list of vectors, produces a list of pairwise orthogonal vectors with the same successive spans.
Equations
Instances For
Modified Gram-Schmidt #
The modified Gram-Schmidt process uses matrices of vectors (Fin m → Fin m → E).
It is numerically more stable than the classical variant in floating-point arithmetic,
though mathematically equivalent in exact arithmetic.
Inner loop of modified GS: given a matrix, a row index, and an iteration count, update entries by subtracting projections.
Equations
Instances For
Outer loop of modified GS: iterate through rows.
Equations
Instances For
Construct the MGS matrix from input vectors by running the full modified GS process.
Equations
- NumLib.LinearAlgebra.GramSchmidt.matrixConstruction initVec = NumLib.LinearAlgebra.GramSchmidt.modifiedGSAux m fun (i j : Fin m) => if ↑i = 0 then initVec j else 0
Instances For
The modified Gram-Schmidt process: returns diagonal of the constructed matrix.
Equations
Instances For
Normalized modified GS: normalize each output vector to unit length.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Helper lemmas #
Algebraic lemmas about sums and projections that support the main theorems.
Where Mathlib provides a direct equivalent (e.g. inner_sub_right, inner_add_right,
inner_zero_right, real_inner_comm), we use it inline rather than wrapping it.
If all summands indexed by a predicate P are ≥ 0, the sum is ≥ 0.
If all summands indexed by a predicate P are 0, the sum is 0.
A nonzero vector has nonzero inner product with itself. Admitted in the original Rocq source.
Projection distributes over subtraction in the second argument.
If b ≠ 0, then a - projection b a is orthogonal to b:
⟪b, a - projection b a⟫ = 0.
Admitted in the original Rocq source.
If ⟪a, b⟫ = 0, then projection a (projection b x) = 0.
Admitted in the original Rocq source.
Projection orthogonality #
Given pairwise orthogonal nonzero vectors, the residual a - Σ projection(vᵢ, a) is
orthogonal to each vector vₓ in the collection. This is the key step in showing that
each new Gram-Schmidt output is orthogonal to all previous outputs.
Linear independence and span lemmas #
List.take X.length (X ++ [a]) = X.
(X ++ [a])[X.length] = a.
Pairwise orthogonal nonzero vectors are linearly independent. This is a standard result: take the inner product of any dependency relation with a single vector to isolate its coefficient.
Main CGS theorems #
The auxiliary GS function produces output of length |vs| + |rs|.
The classical GS output has the same length as the input.
Characterization of the k-th CGS output vector as the input vector minus the sum of projections onto all previous output vectors. Admitted in the original Rocq source.
Direct characterization for classicalGS: the k-th output vector equals the k-th
input vector minus the sum of projections onto all previous output vectors.
Main inductive lemma. For k ≤ |initVec|, the first k CGS output vectors are
(1) nonzero, (2) pairwise orthogonal, and (3) span the same subspace as the first k
input vectors. The proof follows the Rocq original by induction on k.
Corollary: orthogonality and span preservation for the first k CGS output vectors.
The classical Gram-Schmidt theorem. Given linearly independent input vectors,
classicalGS produces a list of pairwise orthogonal vectors with the same successive
spans.
Modified GS partial results #
These are attempts toward MGS characterization and the CGS/MGS equivalence proof.
All are Admitted in the original Rocq source.
MGS matrix entry characterization. Admitted in the original Rocq source.
MGS diagonal characterization: the diagonal entry M[k,k] equals the input vector
minus the sum of projections onto all previous diagonal entries.
MGS output characterization and pairwise orthogonality. Admitted in the original Rocq source.
CGS and MGS produce the same result in exact arithmetic. Admitted in the original Rocq source (commented out).