Executable Gram-Schmidt orthogonalization kernel for hex-gram-schmidt.
This module is the rational core that the rest of the library builds on. It
defines the projection primitives (projectionCoeff, subtractProjection),
the per-row reduction reduceAgainstBasis, the left-to-right orthogonalization
basisRows/basisMatrix, the coefficient matrix coeffMatrix, and the
supporting entry/prefix helpers (entry, castIntMatrix, prefixCombination,
prefixRows, prefixSpan). It also proves the foundational facts the
correspondence proofs consume: pairwise orthogonality of basisRows, the
residual/projection reconstruction identity, the leading-row equation, and the
zero-norm degeneracy lemmas (a Rat vector with zero self-dot-product is the
zero vector).
Coefficient of the orthogonal projection of row onto basisRow.
When the basis row has zero norm we use 0, which matches the degenerate
case of Gram-Schmidt where the corresponding projection term vanishes.
Equations
- Hex.GramSchmidt.projectionCoeff row basisRow = if basisRow.dotProduct basisRow = 0 then 0 else row.dotProduct basisRow / basisRow.dotProduct basisRow
Instances For
Subtract the projection of row onto basisRow.
Equations
- Hex.GramSchmidt.subtractProjection row basisRow = row - Hex.GramSchmidt.projectionCoeff row basisRow • basisRow
Instances For
Over Rat, a vector whose self-dot-product is zero is the zero vector, so
its dot product with any other row also vanishes. Used to discharge the
degenerate zero-norm basis row case when reasoning about orthogonality.
Reduce a row against the previously constructed orthogonal basis rows.
Equations
- Hex.GramSchmidt.reduceAgainstBasis basisRev row = List.foldl Hex.GramSchmidt.subtractProjection row basisRev
Instances For
Left-to-right Gram-Schmidt orthogonalization on a list of rows.
Equations
- Hex.GramSchmidt.basisRowsAux basisRev [] = basisRev.reverse
- Hex.GramSchmidt.basisRowsAux basisRev (row :: rows) = Hex.GramSchmidt.basisRowsAux (Hex.GramSchmidt.reduceAgainstBasis basisRev row :: basisRev) rows
Instances For
Left-to-right Gram-Schmidt orthogonalization on a matrix's rows.
Equations
Instances For
Rebuild a matrix from its row list after Gram-Schmidt orthogonalization.
Equations
- Hex.GramSchmidt.basisMatrix b = { data := Vector.ofFn fun (i : Fin n) => (Hex.GramSchmidt.basisRows b.rows.toList)[↑i]! }
Instances For
Gram-Schmidt coefficient matrix for an already-cast rational input.
Equations
- Hex.GramSchmidt.coeffMatrix rows basis = Hex.Matrix.ofFn fun (i j : Fin n) => if _hlt : ↑j < ↑i then Hex.GramSchmidt.projectionCoeff (rows.getRow i) (basis.getRow j) else if i = j then 1 else 0
Instances For
Cast an integer matrix into the rational matrix space used by Gram-Schmidt.
Equations
- Hex.GramSchmidt.castIntMatrix b = { data := Vector.map (fun (row : Vector Int m) => Vector.map (fun (x : Int) => ↑x) row) b.rows }
Instances For
Executable row-span membership in the first i + 1 rows of a matrix.
Equations
- Hex.GramSchmidt.prefixSpan M i hi v = ∃ (c : Vector Rat (i + 1)), Hex.Matrix.vecMul c (Hex.GramSchmidt.prefixRows M i hi) = v