Documentation

HexGramSchmidt.Int.Core

Executable array/loop machinery for the integer scaled Gram-Schmidt pass in hex-gram-schmidt.

This module defines the integer-determinant surface (gramDet and independent, the leading Gram matrices (leadingGramMatrixInt/Rat), scaledCoeffMatrix, lattice membership memLattice, and the no-pivot Bareiss determinant reader gramDetVecEntry) together with the mutable row-major array kernel that computes the scaled coefficients fraction-free. The kernel includes the nested-array storage (gramRows, zeroRows, getArrayEntry/setArrayEntry, rowsToMatrix), the Bareiss-style elimination sweep stepScaledRows and column-writer writeScaledColumn, the driver scaledCoeffArrayLoop, the two formulations scaledCoeffRows (reference) and scaledCoeffRowsSchur (live per-row Schur recurrence, with schurSigma/schurScaledCoeffEntry), and a large body of frame/size bookkeeping lemmas plus the per-step correspondence rowsToMatrix_stepScaledRows_eq between the array update and Matrix.stepMatrix.

def Hex.GramSchmidt.liftFinLE {k n : Nat} (i : Fin k) (hk : k n) :
Fin n

Promote an index into a shorter prefix to the ambient matrix height.

Equations
Instances For
    def Hex.GramSchmidt.leadingGramMatrixInt {n m : Nat} (b : Matrix Int n m) (k : Nat) (hk : k n) :

    Leading principal Gram matrix of the first k rows of an integer basis.

    Equations
    Instances For

      The Gram-Schmidt leading Gram matrix is the leading prefix of the full Gram matrix. This is the shape equation between the public gramDet API and the one-pass gramDetVec implementation.

      def Hex.GramSchmidt.leadingGramMatrixRat {n m : Nat} (b : Matrix Rat n m) (k : Nat) (hk : k n) :

      Leading principal Gram matrix of the first k rows of a rational basis.

      Equations
      Instances For
        def Hex.GramSchmidt.scaledCoeffMatrix {n m : Nat} (b : Matrix Int n m) (i j : Fin n) (hji : j < i) :
        Matrix Int (j + 1) (j + 1)

        Determinant matrix used by the integral scaledCoeffs entry formula: take the leading j + 1 Gram matrix and replace its last column by the inner products with row i.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Hex.GramSchmidt.Int.memLattice {n m : Nat} (b : Matrix Int n m) (v : Vector Int m) :

          Integer lattice membership in the row span of b. This mirrors the LLL predicate without making hex-gram-schmidt depend on the downstream LLL library.

          Equations
          Instances For
            def Hex.GramSchmidt.Int.gramDet {n m : Nat} (b : Matrix Int n m) (k : Nat) (hk : k n := by omega) :

            The k-th Gram determinant: the determinant of the k × k leading principal Gram matrix of the integer input.

            The bound hk : k ≤ n defaults to by omega, so callers with a concrete k and n (as in #guards and examples) can omit it.

            Equations
            Instances For

              Linear independence of the row prefix determinants used by the Gram-Schmidt theorem surface, stated over the Mathlib-free executable gramDet data.

              Equations
              Instances For
                noncomputable def Hex.GramSchmidt.Int.gramSchmidtNormProduct {n m : Nat} (b : Matrix Int n m) (k : Nat) (hk : k n) :

                Product of the squared Gram-Schmidt basis norms along the first k rows.

                Equations
                Instances For
                  def Hex.GramSchmidt.Int.bareissDiagNat {n : Nat} (data : Matrix.BareissData n) (r : Nat) (hr : r < n) :

                  Read a diagonal entry from a Bareiss elimination matrix as a natural determinant value.

                  Equations
                  Instances For

                    Read the k-th leading-principal determinant from one no-pivot Bareiss elimination pass over the full Gram matrix. This helper is only used for Gram matrices: once a leading row prefix is singular, every larger leading prefix is also singular, so all later leading determinants are zero.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      Specialization of the encoded zero-tail fact to the no-pivot executable data used by the Gram determinant vector pass.

                      Mutable loop state for the integer scaled Gram-Schmidt pass: the current step, the working matrix and coefficient arrays, and the previous Bareiss pivot.

                      Instances For
                        @[inline]

                        Read entry (row, col) from a row-major nested array as rows[row]![col]!.

                        Equations
                        Instances For

                          An n × n row-major nested array initialised to all zeros.

                          Equations
                          Instances For

                            The Gram matrix of b packaged as a row-major nested integer array.

                            Equations
                            Instances For

                              Reconstruct an n × n integer matrix from a row-major nested array, reading entry (i, j) as rows[i]![j]! (getArrayEntry). This converts the executable array passes back to the Matrix API; for the Gram rows it inverts gramRows, so rowsToMatrix (gramRows b) n = gramMatrix b.

                              Equations
                              Instances For
                                def Hex.GramSchmidt.Int.setArrayEntry (rows : Array (Array Int)) (row col : Nat) (value : Int) :

                                Write value into entry (row, col) of a row-major nested array.

                                Equations
                                Instances For

                                  Write column k of the coefficient array, copying the matrix-column values from row k downward.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    def Hex.GramSchmidt.Int.stepScaledRows (rows : Array (Array Int)) (n k : Nat) (pivot prevPivot : Int) :
                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      Equations
                                      Instances For

                                        Run one no-pivot fraction-free Gram elimination and record each scaled coefficient column immediately before the elimination step zeroes it.

                                        This is the reference formulation of the scaled-coefficient matrix, kept for proofs rather than execution. The live algorithm runs scaledCoeffRowsSchur (the per-row Schur recurrence below); getArrayEntry_scaledCoeffRowsSchur_eq proves the two agree entry-for-entry, and that bridge is what connects scaledCoeffRowsSchur to gramDet / scaledCoeffs. Do not remove this formulation as "unused": deleting it breaks the correctness proof of the live path.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Schur-complement σ-chain for the fraction-free scaled Gram-Schmidt recurrence. Each step divides by the previous diagonal pivot rows[p-1][p-1] via Matrix.exactDiv; that division is exact — the fraction-free Bareiss invariant guarantees the numerator is divisible by the pivot, so sigma stays an integer bounded by a minor determinant rather than growing as an unreduced fraction.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For
                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Per-row Schur-complement scaled Gram-Schmidt coefficient kernel.

                                              Rows are filled from top to bottom; within row i, entries 0..i are written left to right. For j < i this writes the scaled coefficient ν[i][j]; for j = i the same recurrence writes the diagonal Gram determinant d_{i+1}.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For