Part of hex, a computer algebra
library for Lean 4. The aim is fast executable code, fully verified, built
with spec-driven development.
The Mathlib correspondence and tactic layer for
hex-primality. It identifies
the Mathlib-free prime predicate with Mathlib's Nat.Prime, transports the
certificate and segment theorems, extends primality, and provides an
explicitly opted-in bounded norm_num policy.
[[require]]
name = "hex-primality-mathlib"
git = "https://github.com/leanprover/hex-primality-mathlib.git"
rev = "main"import HexPrimalityMathlib
example : Hex.Nat.Prime 65537 ↔ Nat.Prime 65537 :=
Hex.Nat.prime_iff
example : Nat.Prime 2147483647 := by primalityprime_iffis the headline equivalence betweenHex.Nat.PrimeandNat.Prime.natPrime_of_checkPrimeandnatPrime_of_checkPrimeAttransport accepted Pocklington certificates directly into Mathlib's vocabulary.isPrime_iff_natPrime,millerRabin_refutes_natPrime, andnextPrime?_natPrimetransport the executable decision and search results.primeTable_spec,primesIn_spec,filter_prime_range, andforall_prime_ltexpose the proved table and segment API through Mathlib.primalityhandles closedNat.Primegoals. Theuse_hex_primality_norm_numcommand selects a bounded, thresholdednorm_numpolicy for the current module without replacing Mathlib's global prime-decision instance.
The bridge introduces no new primality search or decision procedure. Positive
proofs replay hex-primality certificates; negative norm_num proofs validate
a proper factor before using Mathlib's proof constructor. Unsupported inputs
and bounded-search exhaustion decline without an unbounded fallback.
theorem prime_iff {n : Nat} :
Hex.Nat.Prime n ↔ Nat.Prime n
theorem primeTable_spec :
∀ n < primeTableBound, (n ∈ primeTable ↔ Nat.Prime n)
theorem natPrime_of_checkPrimeAt {n : Nat} {c : PrimeCert}
(h : (c.subject == n && checkPrime c) = true) : Nat.Prime nUse hex-primality alone for
Mathlib-free computation. See the
SPEC for tactic registration, thresholds,
failure semantics, and resource bounds.
Development happens in the
hex-dev monorepo, not in this published
mirror. Contributions are welcome as pull requests to the SPEC/ directory:
describe the behavior you want and leave the implementation to the maintainer.