Documentation

CslibFrontier.Algorithms.LinearAlgebra.BareissElimination

Executable Bareiss–Jordan elimination over ℚ and coefficient bit-length bounds #

This module provides executable list-matrix Bareiss–Jordan elimination over ℤ and ℚ, proved equivalent to the minor-scaled Bareiss–Jordan matrix Matrix.bareissMatrix from CslibFrontier.Foundations.LinearAlgebra.Matrix.Bareiss.

References and local adaptations #

Main definitions #

Main results #

Explicit table and elimination record types #

@[reducible, inline]

Explicit row-major integer matrix.

@[reducible, inline]

Explicit row-major rational matrix.

Intermediate state of column-by-column Bareiss–Jordan integer elimination.

  • table : IntTable

    Current minor-scaled integer table.

  • pivotDet : ℤ

    Current nonzero pivot determinant (1 initially).

  • pivotRows : List ℕ

    Ordered distinct pivot row indices selected so far.

  • pivotCols : List ℕ

    Strictly increasing pivot column indices selected so far.

Instances For

    Complete output of Bareiss–Jordan elimination on a rational matrix.

    • rref : RatTable

      Reduced row echelon rational matrix of the same shape, pivot rows first.

    • rank : ℕ

      Exact rank (= pivotRows.length = pivotCols.length).

    • pivotRows : List ℕ

      Pivot row indices in the original matrix forming a basis of the row space.

    • pivotCols : List ℕ

      Strictly increasing pivot column indices.

    • nonPivotCols : List ℕ

      Non-pivot column indices in ascending order.

    • kernelBasis : List (List ℚ)

      Kernel basis vectors, one per non-pivot column.

    Instances For

      Input linear system A x = b over ℚ.

      • matrix : RatTable

        Coefficient matrix A.

      • rhs : List ℚ

        Right-hand side vector b.

      Instances For

        Output of Bareiss–Jordan linear solving for A x = b.

        • solution : Option (List ℚ)

          Canonical solution vector supported on pivot columns if consistent, or none.

        • pivotRows : List ℕ

          Pivot row indices selected during elimination.

        • pivotCols : List ℕ

          Pivot column indices selected during elimination.

        Instances For

          Row denominator clearing #

          Product of denominators of all entries in a rational row.

          Scale a rational row by rowDenomProd r, producing an exact integer row.

          Normalized rational row extracted at row index i of length M.numCols.

          Normalize and clear row denominators of a RatTable, unconditionally producing a well-formed IntTable of identical dimensions.

          Per-row positive integer multiplier produced by clearDenoms M.

          theorem Cslib.LinearAlgebra.cast_clearRow_mem {r : List ℚ} {q : ℚ} (hq : q ∈ r) :
          ↑(q.num * Int.ofNat (rowDenomProd r / q.den)) = ↑(rowDenomProd r) * q
          theorem Cslib.LinearAlgebra.rowDenomProd_le_pow {r : List ℚ} {b : ℕ} (hb : ∀ q ∈ r, q.den ≤ 2 ^ b) :
          theorem Cslib.LinearAlgebra.clearDenoms_abs_le (M : RatTable) {b : ℕ} (hb : ∀ (i : Fin M.numRows) (j : Fin M.numCols), (RowTable.toMatrix M i j).num.natAbs ≤ 2 ^ b ∧ (RowTable.toMatrix M i j).den ≤ 2 ^ b) (i : Fin M.numRows) (j : Fin M.numCols) :
          |RowTable.toMatrix (clearDenoms M) i j| ≤ ↑(2 ^ ((M.numCols + 1) * b))

          Executable Bareiss–Jordan elimination over ℤ #

          Find the first unpivoted row index < st.table.numRows with a nonzero entry in column c.

          Perform one column step of Bareiss–Jordan elimination on column c.

          Initial state of Bareiss–Jordan elimination on an integer table.

          Run Bareiss–Jordan elimination across columns 0, …, colLimit - 1.

          Run full Bareiss–Jordan elimination across all columns of T.

          def Cslib.LinearAlgebra.finSel {m k : ℕ} (idxs : List ℕ) (hk : k = idxs.length) (hidxs : ∀ i ∈ idxs, i < m) :
          Fin k → Fin m

          Map a bounded list of row or column indices to Fin k → Fin m.

          structure Cslib.LinearAlgebra.BareissInv (T : IntTable) (stepCols : ℕ) (st : BareissState) :

          Loop invariant linking BareissState to Matrix.bareissMatrix.

          theorem Cslib.LinearAlgebra.bareissInv_step {T : IntTable} {c : ℕ} (hc : c < T.numCols) {st : BareissState} (hinv : BareissInv T c st) :
          BareissInv T (c + 1) (bareissStep st c)
          theorem Cslib.LinearAlgebra.bareissElimCols_inv {T : IntTable} (hT : RowTable.WellFormed T) {colLimit : ℕ} (hlim : colLimit ≤ T.numCols) :
          BareissInv T colLimit (bareissElimCols T colLimit)

          Correctness invariant for bareissElimCols across columns < colLimit ≤ T.numCols.

          Executable rational RREF, rank, row basis, kernel basis, and linear solver #

          Build a rational row from an IntTable row divided by Δ.

          Extract normalized original rows of M at row indices idxs.

          Non-pivot column indices < n in ascending order.

          Kernel basis vector associated with non-pivot column j.

          Complete Bareiss–Jordan elimination on a rational matrix M: RREF, rank, row basis indices, pivot/non-pivot columns, and kernel basis.

          Executable rational reduced row echelon form.

          Exact rational matrix rank via Bareiss–Jordan elimination.

          Linearly independent spanning subset of rows of M.

          Linearly independent spanning basis of ker M.toMatrix.mulVecLin.

          Augmented matrix [A | b] of shape A.numRows × (A.numCols + 1).

          Solve A x = b canonically via augmented Bareiss–Jordan elimination.

          Row-scaling invariance and correctness of rationalElim / ratSolve #

          Convenience projection: ratRank M = M.toMatrix.rank.

          theorem Cslib.LinearAlgebra.ratSolve_spec (sys : LinearSystemInput) :
          have A := sys.matrix; have b := fun (i : Fin A.numRows) => sys.rhs.getD (↑i) 0; have res := ratSolve sys; (∀ (x : List ℚ), res.solution = some x → x.length = A.numCols ∧ ((RowTable.toMatrix A).mulVec fun (j : Fin A.numCols) => x.getD (↑j) 0) = b) ∧ (res.solution = none ↔ ¬∃ (x : Fin A.numCols → ℚ), (RowTable.toMatrix A).mulVec x = b)

          Soundness and completeness of ratSolve sys with respect to sys.matrix.toMatrix *ᵥ x = b.

          Bit-length and magnitude bounds #

          Uniform Hadamard/factorial upper bound (min m n + 1)! * (B + 1) ^ (min m n + 1).

          theorem Cslib.LinearAlgebra.stageEntryBound_mono_left {m n₁ n₂ B : ℕ} (h : n₁ ≤ n₂) :
          theorem Cslib.LinearAlgebra.size_stageEntryBound_le (m n B : ℕ) :
          (stageEntryBound m n B).size ≤ (min m n + 1) * ((min m n + 1).size + (B + 1).size) + 2
          theorem Cslib.LinearAlgebra.bareissInv_entry_bound {T : IntTable} {c : ℕ} {st : BareissState} (hinv : BareissInv T c st) {B : ℕ} (hB : ∀ (i : Fin T.numRows) (j : Fin T.numCols), |RowTable.toMatrix T i j| ≤ ↑B) :

          Every entry and pivot determinant in any state satisfying BareissInv T c st is bounded in magnitude by stageEntryBound T.numRows T.numCols B.

          theorem Cslib.LinearAlgebra.rationalElim_entry_bounds (M : RatTable) {b : ℕ} (hb : ∀ (i : Fin M.numRows) (j : Fin M.numCols), (RowTable.toMatrix M i j).num.natAbs ≤ 2 ^ b ∧ (RowTable.toMatrix M i j).den ≤ 2 ^ b) :
          have B := stageEntryBound M.numRows M.numCols (2 ^ ((M.numCols + 1) * b)); (∀ r ∈ (rationalElim M).rref.rows, ∀ q ∈ r, q.num.natAbs ≤ B ∧ q.den ≤ B) ∧ ∀ v ∈ (rationalElim M).kernelBasis, ∀ q ∈ v, q.num.natAbs ≤ B ∧ q.den ≤ B

          Every rational entry produced in (rationalElim M).rref and (rationalElim M).kernelBasis has magnitude and denominator bounded by stageEntryBound M.numRows M.numCols (2^((n+1)*b)).

          theorem Cslib.LinearAlgebra.ratSolve_entry_bounds (sys : LinearSystemInput) {b : ℕ} (hbA : ∀ (i : Fin sys.matrix.numRows) (j : Fin sys.matrix.numCols), (RowTable.toMatrix sys.matrix i j).num.natAbs ≤ 2 ^ b ∧ (RowTable.toMatrix sys.matrix i j).den ≤ 2 ^ b) (hb_rhs : ∀ (i : Fin sys.matrix.numRows), (sys.rhs.getD (↑i) 0).num.natAbs ≤ 2 ^ b ∧ (sys.rhs.getD (↑i) 0).den ≤ 2 ^ b) :
          have B := stageEntryBound sys.matrix.numRows (sys.matrix.numCols + 1) (2 ^ ((sys.matrix.numCols + 2) * b)); ∀ (x : List ℚ), (ratSolve sys).solution = some x → ∀ q ∈ x, q.num.natAbs ≤ B ∧ q.den ≤ B

          Every entry of the canonical solution returned by ratSolve sys has numerator magnitude and denominator bounded by stageEntryBound m (n + 1) (2 ^ ((n + 2) * b)).