refactor(bz): migrate HexBerlekampZassenhaus to the module system - #8597
Merged
Conversation
Migrate the executable Berlekamp-Zassenhaus library onto the Lean 4 module system (module / public import / public section), the prerequisite for splitting the 19k-line Basic.lean monolith. Works around two lean4 module-system reduction bugs found in the process: - Array.instDecidableEqImpl is not @[expose], so decide/rfl over Array equality does not reduce in the kernel under the module system for nonempty arrays. Worked around with import all Init.Data.Array.DecidableEq (keeping the efficient Array instance); upstream fix in leanprover/lean4#14270. - Array.back? does not reduce under the module system; reimplement DensePoly.leadingCoeff as coeffs.getD (size - 1) 0 (equal, reducible). Adds public meta imports for the #guards, the backward.{proofsInPublic, privateInPublic} options, @[expose] on the executable defs exported defeq proofs reduce through, and de-privatises the leaked GcdLaws Rat instance. No runtime performance regression (only leadingCoeff's compiled body changes, equal-or-faster; DecidableEq unchanged). See progress/20260704T000000Z_bz-module-migration-phase1a.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 4, 2026
kim-em
enabled auto-merge (squash)
July 4, 2026 11:56
…vers The DensePoly.leadingCoeff reimplementation (coeffs.getD (size-1) 0 instead of coeffs.back?.getD 0) broke the monic-witness proofs in the bench exe and emit-fixture drivers, which the module-migration commit missed because a plain `lake build` does not build the bench/conformance sub-projects (CI does). Rewrite the `change ...back?.getD 0 = 1` proofs to close the getD form via Array.getElem_push. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
kim-em
added a commit
that referenced
this pull request
Jul 4, 2026
…tem (#8600) Migrate the Mathlib-side Berlekamp-Zassenhaus correspondence library (the 13 files under `HexBerlekampZassenhausMathlib/` plus the umbrella) onto the Lean 4 module system, the Phase-1b follow-up to #8597 and the prerequisite for the Phase-2 split of the 22k-line `Basic.lean`. Per file: `module`, `public import`, `public section`, and the `backward.{proofsInPublic,privateInPublic}` crutch where private decls are referenced in public. The bridge proves correctness by unfolding executable and Mathlib-side defs, so it needs a large `@[expose]` pass (89 defs, driven outward from each "not an exposed body" / "not unfolded because not exposed" error until green) spanning the executable `HexBerlekampZassenhaus`/`HexHensel` layers, the `HexBerlekampMathlib`/`HexPolyZMathlib` bridges, and the library's own defs. The `irreducible_cert` tactic and its tests need their elaboration-time helpers marked `meta` (`public meta import` for the reifier), and the certificate kernel replay reduces `checkIrreducibleCertLinear` and its Berlekamp pow-chain plus `Array`/`DensePoly` `==` through `import all` of the executable checker modules and `Init.Data.Array.DecidableEq`. Two proof-text repairs in the `monicModPImage`-zero branch adapt to module reduction (a `simp` that started leaving a spurious `SemigroupWithZero` metavariable, and a `dvd_zero` on `toMathlibPolynomial 0`); no theorem statements change. See progress/20260704T141029Z_bz-mathlib-module-migration-phase1b.md. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR migrates the executable
HexBerlekampZassenhauslibrary onto the Lean 4 module system (module/public import/public section), the prerequisite for splitting its 19k-lineBasic.leanmonolith into dependency-ordered leaves.The migration surfaced two genuine lean4 module-system reduction bugs, both diagnosed to root and worked around locally (each with a
-- revert once upstream landscomment):Array.instDecidableEqImplis not@[expose], sodecide/rfloverArrayequality does not reduce in the kernel under the module system for two nonempty arrays (Array.instDecidableEqinlines the empty cases but delegates the nonempty case to the opaque impl). Worked around withimport all Init.Data.Array.DecidableEq, keeping the efficientArrayinstance rather than switching to a slowerList-based one. Upstream fix: fix: expose Array equality for kernel reduction leanprover/lean4#14270.Array.back?does not reduce under the module system, soDensePoly.leadingCoeffis reimplemented ascoeffs.getD (size - 1) 0instead ofcoeffs.back?.getD 0(definitionally equal, kernel-reducible, and it avoids anOptionallocation).The remaining changes are the standard migration mechanics:
public meta imports so the 117#guardcompile-time checks evaluate, thebackward.{proofsInPublic,privateInPublic}options for private-in-public references,@[expose]on the executable defs that exporteddecide/rfl/unfoldproofs reduce through (including the shallowfactor 0constant-branch closure), de-privatising the leakedGcdLaws Ratinstance, and exposingSquareFreeRat. TheleadingCoeffreimplementation rippled into about a dozenleadingCoeff = coeff (size - 1)re-proofs across HexPoly/HexHensel/HexBerlekamp/HexPolyFp/HexPolyZ/HexPolyMathlib/HexBerlekampZassenhausMathlib, all rewritten to thesimp [leadingCoeff, coeff, size]form.There is no runtime performance regression: the only change to compiled code is
leadingCoeff(equal or marginally faster), and theDecidableEqinstance is unchanged. Fulllake build(4088 jobs) is green,check_dag.pypasses, and nosorry/axiomis introduced.🤖 Prepared with Claude Code