Repository navigation
Description
library: HexGroebner
Current state
The finite-field F4 SPEC and its HexGroebnerTheory companion contract merged in #10986. Contract clarifications are in #10988. The implementation and theory libraries are registered as planned, with no Lean source or Lake targets yet.
HexMvPoly supplies interchange polynomials, explicit lawful monomial orders and kernel term lists. HexArith supplies wide arithmetic, Barrett/Montgomery reduction and delayed-reduction foundations. HexModArith, HexGFqField and HexGF2 supply coefficient representations. The production F4 implementation needs its own compact representation and specialized linear algebra rather than using tree-map polynomials or generic boxed arrays in hot loops.
The required eventual goal is a state-of-the-art finite-field F4 implementation: the fastest fully open-source implementation, ideally the fastest available including GamBa and proprietary systems. Useful intermediate PRs can land before leadership is reached. Keep this issue open until the SPEC's correctness, finite-field coverage and fastest-open-source milestone are demonstrated. Record the remaining gap to overall-fastest performance and continue to revisit compiler/runtime limitations as Lean improvements ship. Temporary limitations are not grounds for weakening the goal.
Useful @[extern] implementations are expressly authorized, including packed buffers, batched monomial operations, SIMD arithmetic, sparse/dense row updates and whole matrix elimination. Follow the SPEC's contracts, portable implementations, ownership and testing requirements. Do not wait for upstream compiler support before implementing useful native operations.
Deliverables
- Activate
HexGroebnerwith genuine F4 operations and intended complexity. Implement canonical input/output, explicit field/order metadata, prime evidence, conversions toHex.MvPoly, and the zero/unit-ideal conventions. - Implement compact typed coefficient/index/exponent storage, stable monomial interning, exact collision handling, overflow-safe widening, divisibility masks, reducer lookup and reusable workspaces. Provide the approved native operations where measurements justify them.
- Implement degree/sugar batching, symbolic preprocessing, Buchberger/Gebauer-Möller pair criteria, new-row extraction, basis updates and final interreduction. Cover homogeneous, inhomogeneous, positive-dimensional and elimination systems.
- Implement specialized mixed sparse/dense elimination with known reducer pivots, delayed reduction, coefficient-width specialization, exact SIMD kernels and multithreading. Establish deterministic reference behavior and bounded native calls.
- Add checked probabilistic computation with explicit advanced random state, rejection/retry/fallback semantics and independent final certification. Provide validated F4 trace learning/reuse. Unchecked candidates must remain distinct from completed checked results.
- Implement
computeWith,certifyWith,basisWith, division, normal forms and positive/negative membership. Preserve invalid-input, rejection, exhaustion and resumable-state distinctions and charge nested work to parent budgets. - Deliver the optimized prime-field route for all prime
2 ≤ p < 2^31, generic explicit finite-extension adapters and packed characteristic-two adapters. Pursue wider-prime and extension-field optimizations with lawful representations rather than bypassing existing bounds. Ordinary𝔽₂polynomials must not silently usex² = x. - Implement complete basis certificates proving both ideal containments, all final S-pair obligations and reducedness. Support efficient shared derivations and separate certificate generation. Arbitrary S-pair ideal-membership identities are not sufficient to prove the Gröbner property.
- Complete
HexGroebnerTheoryunder the same SPEC:checkBasis_sound,basisWith_sound, deterministicf4_specand termination,normalForm_spec,checkMember_soundandcheckNonmember_sound. Construct the Hex-to-Mathlib monomial-order correspondence and leading-term agreement, supply the Gröbner-basis predicate, and prove Buchberger's criterion and reduced-basis uniqueness using existing polynomial correspondences and division results. Deliver kernel-checkable examples withoutnative_decideor new axioms. - Add independent conformance oracles, malformed-certificate and representation-boundary tests, native/portable comparisons and downstream kernel replay examples. Extend the existing CI job and oracle runner.
- Register meaningful lean-bench kernels and full-system cases. Publish matched single-thread and parallel sweeps against current msolve, Groebner.jl, Giac and Singular, any faster fully open-source implementation, and GamBa/Magma/FGb where usable. Include the SPEC's hard families, field widths, fixed balanced suite, held-out inputs, raw samples, failures, memory, variability and correct output comparisons.
- Separate candidate production, certificate generation, independent native verification and kernel checking in results. Demonstrate the fastest-open-source milestone under the SPEC's solved-coverage and family-balanced geometric-mean/per-family requirements. Attribute remaining gaps to work performed, representation, generated code or runtime facilities.
- Track upstream compiler/runtime requests with reproductions and measured costs. Rebenchmark unchanged inputs as improvements ship, replace native workarounds when competitive, and keep useful native kernels. Complete the manual examples and required project phase checks.
Library placement
The governing SPEC is hex-groebner, §Scope and library placement:
The executable F4 implementation, field adapters, packed storage, monomial tables, matrix construction, elimination, certificate data and Boolean checkers belong in
HexGroebner/.
Mathlib ideal semantics, the Buchberger criterion, correspondence proofs and certificate soundness belong in
HexGroebnerTheory/.
- Governing section: the quoted placement, plus §Certificates, checking and headline theorems and §Approved native operations and compiler evolution. Native sources live under
HexGroebner/ffi/; this one SPEC governs the companion work too. - Mathlib: executable algorithms and Boolean checkers remain Mathlib-free. Ideal theory, termination through Mathlib's monomial theory, and correspondence/soundness proofs belong in
HexGroebnerTheory, never in the executable dependency graph. - Upstream reuse: inspect the pinned Mathlib and open upstream work for Gröbner/division/monomial-ideal results before proving missing statements. Reuse committed results or inline applicable open work with attribution under project conventions. Do not assume a missing criterion already exists, or wait for an upstream merge unnecessarily.
- Infrastructure: packed storage, specialized Macaulay elimination, certificate replay and F4 proofs are explicit deliverables of this SPEC. The prime-field implementation does not depend on the unimplemented shared finite-field interface. Keep reusable upstream changes in their owning libraries and record concrete prerequisites here before crossing library boundaries.
Context
- Finite-field F4 and companion SPEC, including the references and performance acceptance requirements.
- SPEC PR.
- Design principles.
- Multivariate polynomial contract.
- Arithmetic contract.
- Conformance, benchmarking, and CI.
- Assignment, placement, FFI and phase conventions.
- GamBa, msolve, Groebner.jl, GBLA, and Demin's probabilistic-elimination/Las Vegas paper.
Verification
Use lake build for the implemented libraries and appropriate project build targets. Run the conformance profiles with independent basis/normal-form oracles, malformed-certificate and overflow/retry/exhaustion tests, native-versus-portable comparisons, downstream kernel replay and axiom audits. Run scripts/check_dag.py, scripts/check_phase4.py and scripts/release/check_released_manifest.py as applicable.
Collect scientific timing evidence manually on the shared host using lean-bench and matched comparator sweeps. Retain completed samples, alternate adjacent AB/BA comparisons, report thread/ISA/toolchain/field/order/output contracts and failures, and keep kernel checking distinct from native verification. Scientific performance claims must not depend on CI timings. Correctness completion alone does not satisfy the performance milestone.
Out of scope
Rational reconstruction over ℚ, FGLM and root solving, a specialized Boolean quotient library, F5/signature-based algorithms, modules and noncommutative bases. Do not wrap another full F4 engine as the implementation, weaken the mathematical contract to make proofs easier, or close this issue merely because an intermediate implementation builds.
Activity
kim-em commentedon Oct 31, 2026
PR #10989 implements the first executable slice: deterministic packed prime-field Macaulay elimination, with sparse reducer pivots, a reusable dense accumulator/pivot table, canonical 8/16/32-bit residue storage, bounded work and optional shared row provenance. Local conformance includes 154 independent row-space/reducer-space/derivation checks across seven primes through
2^31 - 1, malformed representations, all resource categories, and ordinary-kernel byte decoding.The issue remains open. Full polynomial metadata/conversions, monomial interning, symbolic preprocessing, degree/sugar batches and pair criteria, basis operations, complete certificates and theory, extension-field adapters, delayed/SIMD/parallel kernels, probabilistic computation/trace reuse and the full comparator programme remain outstanding. No phase completion is claimed.
The committed shared-host Cauchy kernel sweeps retain every completed sample, source manifests, host activity, variability and memory. The timing verdict is inconclusive; the first sweep was below the harness signal floor and is retained too. There are no matched full-system comparator measurements. The gaps to fastest-open-source and overall-fastest F4 remain unmeasured, and neither milestone is demonstrated.
kim-em commentedon Oct 31, 2026
Merged #10989 (
a76c5fbd57c3a0f5484fb3ff42e92cf5096d839a) after the final revision's full CI passed: libraries/benchmarks, conformance/fixtures, architecture experiments, manual, benchmark verification, oracle runner and BZ gates. The issue remains open and assigned tokim-em.Implemented: the packed prime-field Macaulay kernel, direct installation of sparse reducer pivots, bounded active-range dense accumulation, monic echelon extraction with reducer/target rank separation, shared provenance, and explicit invalid-input/resource distinctions. Verification includes 175 independent row-space/reducer-space/derivation cases across seven primes through
2^31 - 1, malformed-width and exact-budget tests, retained failure counters, and ordinary-kernel byte decoding. Two Opus reviews led to trace-ownership and sparse-scan fixes and expanded tests.The four shared-host benchmark families cover dense elimination with/without provenance and clustered/spread sparse supports. Clustered and spread families match their linear/quadratic source models over the measured range; dense timing verdicts remain inconclusive. All samples, source manifests, variability, memory and host context are retained in
reports/bench-results/hexgroebner-cauchy.mdand its linked records. Interval scans over widely separated supports and checked byte-access overhead remain explicit optimization targets. These are kernel measurements, not full F4 or comparator evidence.Still required: full polynomial/order metadata and conversions, monomial storage/interning/reducer lookup, symbolic preprocessing, degree/sugar batching and pair criteria, basis operations, complete certificates/checkers and theory, finite extensions, delayed/SIMD/parallel kernels, checked probabilistic computation and trace reuse, manual examples and matched full-system comparator sweeps. No phase completion is claimed. The gaps to fastest-open-source and overall-fastest F4 remain unmeasured; neither performance milestone is demonstrated.
kim-em commentedon Oct 31, 2026
The matrix kernel is merged in #10989; deterministic prime-field F4 candidate production is in #10990. The latter now passes 567 complete reduced-basis comparisons with both SymPy F5B and Singular over seven primes and three orders, with identical results at batch size one. It includes packed stable monomial interning, checked widening, sugar batches, symbolic preprocessing, product/chain criteria, canonical interreduction and sealed cumulative-budget resumption. The output remains explicitly unchecked.
The Opus review identified resource and performance concerns. The PR now has distinct internal failures, cumulative matrix-row limits, indexed chain tests, shared reducer indices, all resource-category exhaustion tests and an exhaustive small-example work-boundary/resume check.
packedBytesis explicitly a cumulative packed-payload allowance; live heap metadata accounting remains outstanding.The issue remains open. Complete certificates/checkers and theory, finite extensions and block orders, Gebauer–Möller installation, probabilistic/learning routes, reusable workspaces, native/SIMD/parallel optimization, and the full matched performance acceptance programme are not complete. Initial paired msolve measurements expose substantial portable-engine losses, including eco-10 timeouts; they motivate further work and do not support a language-impossibility conclusion.
kim-em commentedon Oct 31, 2026
The complete certificate checker needs one additional reusable coefficient bridge before its leading-term proof: for the existing
HexMvPolyTheory.Kernel.residueEquiv, transporting a polynomial and then reading the coefficient atmonoEquiv mmust equal transporting its Hex coefficient atmthroughHexModArithTheory.ZMod64.equiv. The existing ring equivalence and monomial/addition results provide the proof, but its definition is intentionally opaque across modules.I will add this coefficient equation in its owning
HexMvPolyTheory/KernelResidue.leanmodule and reuse it fromHexGroebnerTheory. This keeps the existing denotation and the executable/Mathlib split; no new polynomial interpretation or assumption is needed. The current issue remains open.kim-em commentedon Oct 31, 2026
#10994 has merged checked division, normal forms and both membership outcomes. #10995 adds automatic complete certificate generation and checked F4 basis computation, with exact-original-input receipts and ordinary-kernel downstream examples. It remains under CI/review; neither PR closes this issue.
One concrete remaining certification gap is candidate-only early checking: the current
certifyWithvalidates external candidate data, reruns traced F4, compares canonical output and independently replays its generated certificate. Supplied complete certificates are checked without rerunning F4. Candidate-first shape, reverse-containment and S-pair checks, together with forward-witness generation without requiring complete recomputation, remain required under the existing independent-candidate contract.Deterministic producer invariants/termination, wider and extension-field adapters, checked probabilistic computation and validated trace reuse, compressed S-pair witnesses, optimized SIMD/parallel elimination and the matched performance acceptance milestone remain open. Native scan and exact SIMD work is continuing; no compiler/runtime impossibility or performance leadership has been established. The original SPEC and fastest-open-source completion criteria remain in force.
kim-em commentedon Nov 1, 2026
#11000 merged the multiplied-pair-row matrix construction. #11001 adds a separate exact Mersenne SIMD dispatch and matched benchmarks; two fresh Opus reviews found no correctness blocker, and the requested evidence/coverage fixes are implemented. The final PR still awaits CI.
A fresh manual comparison with current msolve
3672113ee2c696a2ac9c637636e0f7214f500ba1retains all 64 processes in each mode and matches all 32 complete reduced bases per mode. On the 16-input development diagnostic suite, the family-balanced Hex/msolve whole-process ratio is 2.6697 for exact-l 2and 2.8101 for probabilistic-l 42. Both use one thread, grevlex, identical fields and full reduced-basis output. Startup, parsing and output are included consistently; certificate generation and kernel checking are excluded. The measured Hex executable is the separate-dispatch implementation, source familyb1e96ea920dd, byte-identical to timedd1278bde9bd5. These are development observations, not held-out or leadership evidence. Raw samples, failures, source manifests, memory and full-output comparisons are retained for the separate performance-evidence PR.Compact interning and delayed-reduction prototypes are retained as experiments after regressions against the current baseline. A bounded zero-scan prototype preserves native/portable state and work/quantum prefixes and is being measured independently. The fastest-open-source milestone and the remaining SPEC deliverables are still outstanding; keep this issue open.
kim-em commentedon Nov 1, 2026
The standalone-driver work in #11004 includes a correction to earlier comparator observations. Executing msolve through its libtool shell wrapper added fixed overhead only to the competitor. The older build also requested
-march=native, but Nix stripped that flag. Those completed samples remain retained historical observations; they do not establish the current performance gap.The replacement campaigns execute msolve's ELF directly and use a rebuild whose engine records effective native-tuned Clang commands. On the 16-input, seven-family development suite, equal-family Hex/msolve process geometric means are 2.1939 exact and 2.3790 probabilistic. Each campaign has 32/32 agreeing complete reduced-basis pairs and no process failures/timeouts. Eco and Reimer still have substantial gaps. These are unchecked candidate-production measurements; certificate generation, independent final certification and kernel checking are excluded. This suite is not the fixed balanced/held-out acceptance milestone.
#11004 is awaiting CI. A packed reducer-trie implementation has passed the full relevant conformance/theory build, both CLI corpora, independent matrix/basis/division oracles, and Clang/GCC sanitizer checks. Its separate matched development comparisons show a 0.9237 candidate-time ratio; it has not merged yet. Sparse-first joint target ordering is also promising, while retaining sugar scheduling; its independent final normal forms preserve input order, and traced certificate integration is being checked.
This issue remains open. Correctness/coverage/proof deliverables and the fastest-open-source milestone are not complete. No impossibility without compiler or language changes has been established; the existing SDK initialization workaround and useful bounded native kernels are being used while algorithmic work is reduced.
kim-em commentedon Nov 2, 2026
Merged scheduling support in #11008 and packed monomial indexing/joint target ordering in #11010. Both degree and sugar scheduling are explicit choices; the mathematical and certification obligations remain intact.
#11011 adds bounded native prime-field matrix elimination with exact portable-reference rows, sugars and counters. Local validation includes the full library/theory build, independent oracles, kernel examples, eight Clang/GCC sanitizer variants, ownership and resource-boundary tests. Scientific candidate timing, certificate production, independent final verification and kernel checking remain separate. The PR includes all raw samples, regressions, failures, source blobs and build variants.
The performance milestone remains unmet. The latest experimental build's balanced medium process ratios against the recorded native msolve build are about 3.56/3.44 for modes 2/42; earlier observations use different builds and are kept separate. The corpus is developmental, not held out acceptance coverage. Large matrices often exceed the native route's current shape bounds. I am testing larger scan/gather chunks before implementing a more extensive continuation engine.
This issue remains open for fastest-open-source evidence and the remaining finite-field, parallel, probabilistic/trace and theory requirements. There is no basis for a language-change impossibility conclusion.
kim-em commentedon Nov 3, 2026
Merged #11027: characteristic-two scalar subtraction now uses exact XOR after the existing validation. All twelve Clang/GCC ASan+UBSan variants, all nine local project gates, independent basis oracles and final CI passed; the fresh Opus review findings were addressed before merge.
The source-bound report is hexgroebner-xor.md. On the ordinary-F2 development inputs, process time is 0.881637 of the preceding implementation by input and 0.934809 with equal family weights. The current matched msolve comparison still has a 1.234546 family-weighted Hex/msolve ratio; compiler/tuning differences are recorded. The last matched 14-input prime-field comparison remains approximately 1.914 times msolve. These development observations do not establish the fixed-suite, held-out, parallel or fastest-open-source milestone.
The issue remains open and assigned. There is no measured language-level impossibility. Unselected matrix/cache experiments are retained separately; current work is testing bounded monomial batching using measured operation and fallback counts, while preserving the exact scalar table state and budgets.
kim-em commentedon Nov 9, 2026
🤖 Claude says:
A full 90-system fixed-primary msolve sweep of the current main build (#11043) gives an equal-family Hex/msolve process ratio of 1.144, with no loss of solved coverage. Per family: cyclic 1.31, kat 1.16, eco 1.42, noon 1.55, reimer 1.18, minrank 1.09, sparse-structured 0.82, dense-quadratic 1.15, triangular 1.01, positive-dimensional 0.94. Cyclic-10 and Katsura-14/15 and Eco-15 over odd primes time out for both programs at 300 s.
#11044 disables transparent huge pages in the F4 drivers. The Lean runtime's mimalloc arena is reserved with
MADV_HUGEPAGE; under the host'sdefrag=madvisepolicy, first touches compact memory synchronously and zero whole 2 MiB pages. This was most of the driver's startup cost and, depending on host memory pressure, a large share of medium and large runs. On the matched first-size selection the candidate/process ratios are 0.5947/0.6643 of main, with identical outputs and counters in all 64 pairs. The held-out msolve sweep with this change is 1.0837 (dense-quadratic 1.42, positive-dimensional 0.95, sparse-structured 0.95). #11045 revives the additive monomial hash: two matched campaigns (the first inconclusive) pool to 0.9659/0.9541.Cross-day msolve ratios are not reliable on the shared host. Block 0 of today's fixed-primary sweep with the THP change gives 1.41, against 1.144 for main on 2026-11-05. Comparing each program with itself across the two days, msolve ran 1.11× slower and Hex 1.21× slower: Hex is more sensitive to host load, consistent with its much larger memory traffic (Reimer-8 allocates 6.4 GB; held-out peak RSS is 1.39 GB against msolve's 266 MB). The full sweep is still running and will be reported with its records, but a leadership claim will need repeated matched sweeps, and reducing allocation volume is itself a performance target.
Attribution of the remaining gap, from instrumented runs of both engines on the same matrices:
No impossibility without language changes has been established: every identified cost can be addressed with algorithmic changes or approved native operations. Runtime/compiler requests with measured costs:
prctl(PR_SET_THP_DISABLE)in the drivers (above).true; the Hex driver takes 3.8 ms with 1,339 module initializers (including proof-only…Lemmasmodules), eager runtime threads and io_uring setup. msolve completes the smallest corpus inputs in about 3 ms in total. Skipping initializers for modules without runtime content, and starting runtime services lazily, would remove most of this.The issue remains open.