lean-normal-forms
Executable Hermite normal form and Smith-normal-form infrastructure in Lean 4 over Euclidean domains, with certified matrix certificates and a semantic PID bridge to mathlib's quotient/decomposition results.
Status
🌟 Zero Warnings Milestone: The entire codebase currently builds with zero warnings and zero errors (lake build), signifying complete logical verification of the implemented layers and strong proof stability.
This repository currently contains a buildable NormalForms Lean library with a
completed recursive row-style Hermite layer, a completed executable Smith layer
with public correctness, uniqueness, and unimodularity extraction theorems, a
semantic PID quotient bridge layer, an initial full-rank Int
witness-list interoperability layer closed at the example level via structural
counting, and a completed Phase 5 Int presentation-matrix application layer.
- Public API for
IsHermiteNormalForm,IsSmithNormalForm,HNFResult,SNFResult,smithInvariantFactors,smithColumnSpan,SNFResult.ofCertificate, andSNFResult.toCertificate - Executable recursive row-style HNF over Euclidean domains, with first-column elimination, lower-right recursion, top-row reduction, and
HNFResult.toCertificate - Internal HNF recursion carries explicit unimodular left certificates end-to-end, and the public theorem
hermiteNormalForm_unimodularexposes that certificate fromhermiteNormalForm - HNF correctness and uniqueness are now proved, via
hermiteNormalForm_isHermiteandisHermiteNormalForm_unique_of_left_equiv CanonicalModinstances are available for bothIntandPolynomial RatNormalForms.Matrix.Hermiteis now split acrossDefs,Transform,Bezout,Algorithm, andBasic, separating predicates, transform certificates, Bezout gadgets, the recursive Fin kernel, and the public wrapper layerNormalForms.Matrix.Smithis now split acrossDefs,Transform,Algorithm, andBasic, so the public Smith specification, two-sided transport layer, recursive executable kernel, and result-packaging API no longer live in one monolithic fileNormalForms.Matrix.Smith.Uniquenessnow proves uniqueness from equal invariant factors, preservation of the first invariant factor under explicit two-sided unimodular equivalence, the completed decomposeddiagPrefixProduct/ minor-divisibility chain, the internal theoremisSmithNormalFormFin_unique_of_two_sided_equiv, and the public theoremisSmithNormalForm_unique_of_two_sided_equivNormalForms.Bridge.MathlibPID.Basicnow exposes raw bridge helpers together with executable-side and mathlib-side normalizedIntcoefficient-list readouts, includingpidExecutableSmithCoeffNatAbsListandpidFullRankMathlibSmithCoeffNatAbsListNormalForms.Bridge.MathlibPID.Quotientnow proves the semantic PID bridge: executable invariant-factor readout, quotient transport through the chosen executableSNFResult, quotient decomposition into torsion-plus-free parts,ℤ-specificZModspecialization, the full-rank count theorempidExecutableInvariantFactorCount_eq_card_rows_of_finrank_eq_card, and full-rank compatibility equivalences with mathlib'squotientEquivPiSpan/quotientEquivDirectSum/quotientEquivPiZModNormalForms.Applications.AbelianGroupsnow exposes the public Phase 5 application API overIntpresentation matrices:presentationSubmodule,presentationQuotient,presentationInvariantFactorCount,presentationInvariantFactorFn,presentationInvariantFactors,presentationFreeRank,presentationQuotientEquivPiZModProd, and the full-rank specializationpresentationQuotientEquivPiZMod_of_fullRank- Elementary row/column operations, mixed-log certificate helpers, and a reusable 2x2 Bezout reduction gadget
- Smoke examples over
IntandQ[X], including public HNF certificate checks, internal Smith diagonal-spec, invariant-factor, and same-size-step checks, publicSNFResult.ofCertificatepackaging smoke, semantic quotient/direct-sum/PiZModbridge instantiations, and example-level executable-vs-mathlib normalized coefficient-list equality proofs for the current full-rankIntshowcase matrices, together with public Phase 5 quotient-decomposition smoke forpresentationMatrixZ,mixedTorsionFreeMatrixZ, andunitBoundaryMatrixZ, plus the local plan inPLAN.md - GitHub Actions, citation metadata, Zenodo metadata, and an axiom-audit smoke script
The current Lean files compute recursive HNF, package explicit certificates, and
prove public HNF correctness and uniqueness. The former monolithic Hermite and
Smith implementation files are now physically split by concern, so the public
facades sit on top of dedicated definition, transform, Bezout, and algorithm
submodules. On the Smith side, the public predicate and invariant-factor reader
are real, the executable recursive kernel and public
smithNormalForm existence/isSmith/unimodularity/uniqueness theorems are in
place, and the same-size lead-clearing, lead-preparation, stabilization, and
single-step nondivisible pivot-improvement layers are verified over both Int
and Q[X]. The Smith Phase 3 uniqueness closure is now done, and the current
PID bridge now consists of two layers: a semantic quotient/decomposition layer
and an example-level coefficient-facing layer for full-rank Int matrices.
Quotients
are transported to the executable Smith result and decomposed into torsion
factors plus a free part; full-rank cases are related back to mathlib's PID
quotient theorems via PiSpan, DirectSum, and PiZMod equivalences; and the
bridge now exposes normalized natAbs coefficient-list readouts on both the
executable and mathlib sides together with example-level structural-counting
proofs that these lists agree for the current full-rank Int showcase
matrices. No abstract theorem
pidFullRankMathlibSmithCoeffNatAbsList_eq_executable landed: the remaining
generic blocker is that mathlib does not yet expose a canonicality theorem for
its chosen smithNormalFormCoeffs witness list. On top of that bridge, the
repository now also contains a dedicated Phase 5 application layer in
NormalForms.Applications.AbelianGroups: for finite Int presentation
matrices it packages the presentation quotient ℤ^m / im(A), the executable
invariant-factor readout, the free-rank readout, the torsion-plus-free
decomposition
((m → Int) ⧸ presentationSubmodule A) ≃+ ((Fin k → ZMod dᵢ) × (Fin r → Int)),
and the full-rank torsion specialization. For the current repository scope,
that completes the planned Int abelian-group application milestone.
One deliberate implementation boundary is worth calling out: the public Smith
wrappers over arbitrary Fintype indices are defined by reindexing through
Fintype.equivFin, but the library intentionally does not expose global [simp]
bridge lemmas that try to collapse that reindexing on concrete Fin matrices.
Those simplifications can trigger very expensive elaboration. As a result, the
example layer keeps concrete Smith computation and same-size step smoke on the
internal Fin definitions and reserves the public layer for stable packaging
and API checks.
Build
lake exe cache get
lake build # Must output 0 warnings
lake env lean scripts/AxiomAudit.lean
lake env lean NormalForms/Matrix/Hermite/Algorithm.lean
lake env lean NormalForms/Matrix/Hermite/Basic.lean
lake env lean NormalForms/Matrix/Smith/Defs.lean
lake env lean NormalForms/Matrix/Smith/Algorithm.lean
lake env lean NormalForms/Matrix/Smith/Basic.lean
lake env lean NormalForms/Matrix/Smith/Uniqueness.lean
lake env lean NormalForms/Bridge/MathlibPID/Basic.lean
lake env lean NormalForms/Bridge/MathlibPID/Quotient.lean
lake env lean NormalForms/Applications/AbelianGroups/Basic.lean
lake env lean NormalForms/Examples/AbelianGroups/Basic.lean
The committed lake-manifest.json pins a compatible mathlib snapshot. On a fresh machine, Lake will still need network access the first time it materializes .lake/packages.
Layout
NormalForms/Matrix/Elementary: row and column operation skeletons, logs, and replay semanticsNormalForms/Matrix/Hermite: split HNF stack withDefs,Transform,Bezout,Algorithm,Basic, andUniquenessNormalForms/Matrix/Smith: split SNF stack withDefs,Transform,Algorithm,Basic, andUniquenessNormalForms/Matrix/Certificates: reusable certificate shapes and unimodularity lemmasNormalForms/Bridge/MathlibPID: raw PID bridge helpers and normalized coefficient-list readouts inBasic, plus semantic quotient/decomposition and full-rank executable-vs-mathlib compatibility equivalences inQuotient; the example-level normalized coefficient-list equality proofs live inNormalForms/Examples/AbelianGroupsNormalForms/Applications/AbelianGroups: publicIntpresentation-matrix application API, including quotient, invariant-factor, free-rank, and quotient-decomposition wrappersNormalForms/Examples/AbelianGroups: sample matrices, executable HNF smoke checks, internalIntandQ[X]Smith spec/invariant-factor/same-size-step smoke, public Smith certificate/result packaging smoke, and the current bridge-facing and application-facing examplespaper/: manuscript planning notesartifact/: artifact packaging notes
Scope
- Executable algorithms are scoped to
EuclideanDomain - Exact executable canonicality statements use a lightweight
CanonicalModmixin to capture canonical Euclidean remainders - PID-level statements are scoped to specifications and bridge theorems; the
currently completed bridge includes semantic quotient/direct-sum results and
example-level normalized
Intwitness-list equality via structural counting; direct generic coefficient-list equality against mathlib's chosensmithNormalFormCoeffsremains blocked on upstream witness canonicality - The initial research application is finitely generated abelian groups over
Z
For the full roadmap, milestones, and submission strategy, see PLAN.md.