The rank computed by row reduction agrees with Mathlib's Matrix.rank.
Proven by rank-nullity: the m - D.rank independent nullspace basis vectors pin
the kernel dimension, and the complement is the matrix rank.
20.5. The Mathlib correspondence
HexRowReduce computes with the length-indexed Hex.Matrix type and
stays Mathlib-free. The public HexRowReduceTheory umbrella transports its
certified output through HexMatrixTheory.matrixEquiv and
HexMatrixTheory.vectorEquiv; users reason with the named theorems
below and need not unfold either equivalence or the elimination loop.
The computed rank is exactly Mathlib's matrix rank.
HexMatrixTheory.rank_eq.{u} {R : Type u} {n m : ℕ} [Field R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) : D.rank = (HexMatrixTheory.matrixEquiv M).rankHexMatrixTheory.rank_eq.{u} {R : Type u} {n m : ℕ} [Field R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) : D.rank = (HexMatrixTheory.matrixEquiv M).rank
The Boolean span test characterizes membership in the Mathlib span of the
original rows, while the computed nullspace spans precisely the kernel of
Mathlib's mulVec linear map.
HexMatrixTheory.spanContains_iff_mem_span.{u} {R : Type u} {n m : ℕ} [Field R] [DecidableEq R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) (v : Vector R m) : ⋯.spanContains v = true ↔ HexMatrixTheory.vectorEquiv v ∈ Submodule.span R (Set.range (HexMatrixTheory.matrixEquiv M).row)HexMatrixTheory.spanContains_iff_mem_span.{u} {R : Type u} {n m : ℕ} [Field R] [DecidableEq R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) (v : Vector R m) : ⋯.spanContains v = true ↔ HexMatrixTheory.vectorEquiv v ∈ Submodule.span R (Set.range (HexMatrixTheory.matrixEquiv M).row)
The executable span-membership test spanContains is correct: it returns
true exactly when the Mathlib image of v lies in the R-span of the rows of
M. The decision procedure agrees with Mathlib's Submodule.span.
HexMatrixTheory.nullspace_span_eq_ker.{u} {R : Type u} {n m : ℕ} [Field R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) : Submodule.span R (Set.range fun k => HexMatrixTheory.vectorEquiv (E.nullspace.get k)) = (HexMatrixTheory.matrixEquiv M).mulVecLin.kerHexMatrixTheory.nullspace_span_eq_ker.{u} {R : Type u} {n m : ℕ} [Field R] {M : Hex.Matrix R n m} {D : Hex.Matrix.RowEchelonData R n m} (E : M.IsRowReduced D) : Submodule.span R (Set.range fun k => HexMatrixTheory.vectorEquiv (E.nullspace.get k)) = (HexMatrixTheory.matrixEquiv M).mulVecLin.ker
The computed nullspace basis spans exactly the kernel of M: the span of
the executable basis vectors equals Mathlib's LinearMap.ker (mulVecLin M).
This is the completeness counterpart to nullspace_mem_ker.
These results consume Hex.Matrix.IsRowReduced, the certificate returned
by the executable driver. They do not depend on accidental definitional
equality between Hex and Mathlib matrices.