Trial-division primality test
DefinitionErdosProblems_Erdos251_KernelDenominatorFloorerdos-251formalizationprime-series
Defines the finite Boolean trial-division test used by the prime-prefix certificate, including its recursive search for a small divisor. The separate correctness theorem relates its output to mathematical primality.
Definition code
import Definitions.Def_ErdosProblems_Erdos251_PrimeGapDyadicTail
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Data.Nat.Periodic
import Mathlib.Data.Nat.Prime.Factorial
import Mathlib.Data.Nat.Prime.Nth
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Data.Rat.Lemmas
import Mathlib.NumberTheory.Bertrand
import Mathlib.NumberTheory.PowModTotient
import Mathlib.NumberTheory.PrimeCounting
import Mathlib.NumberTheory.Real.Irrational
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
import Mathlib.Topology.Algebra.InfiniteSum.NatInt
/-!
# Erdős #251: a kernel-decided denominator floor
`S = Σ_{i ≥ 0} p_i / 2^{i+1}` is the prime series (zero-based, `p_0 = 2`).
This module proves inside the Lean kernel, with `decide +kernel` and no
`native_decide`, that every rational `a/b` equal to `S` has `b ≥ 2^589 > 10^177`,
and the same for the prime-gap series `S - 2` of Erdős #251.
The mechanism is elementary and every step is checked:
1. `primeSumLoop c X` runs a trial-division sieve over `m < X` inside the
kernel and returns `(π(X), Σ_{i < π(X)} p_i 2^{c-1-i})`. Its semantics
(`primeSumLoop_fst`, `primeSumLoop_snd`) are proved from `Nat.nth_count`.
2. `prime0_le_polynomial` (`p_i ≤ 1250 (i+1)^4`, already in the development)
and `pow_four_mul_two_pow_le` (`(c+1+j)^4 2^j ≤ (c+1)^4 3^j` for `c ≥ 9`)
bound the omitted tail by `5000 (c+1)^4 / 2^{c+1}`.
3. `den_ge_of_between`: if `u/v < x < u'/v'` with `u'v - uv' = 1`, every
rational `a/b = x` has `b ≥ v + v'`.
4. `certCheck` packages the four integer inequalities; `den_bound_of_certCheck`
turns `certCheck = true` into the floor; the instance is `decide +kernel`.
The Python receipt in the packet (`q ≥ 2^39997 > 10^12040`, 23369 certified
partial quotients) is far larger: bit length `39998` is not an exponent.
Nothing here bears on irrationality. The point is the evidence class: this
floor is a theorem of the kernel, not a receipt.
-/
open Finset
namespace ErdosProblems.Erdos251
/-! ## Kernel-evaluable trial division -/
/-- `noSmallDivisor m fuel k = true` iff no `j` with `k ≤ j < k + fuel` and
`j * j ≤ m` divides `m`. -/
def noSmallDivisor (m : ℕ) : ℕ → ℕ → Bool
| 0, _ => true
| fuel + 1, k =>
if m < k * k then true
else if m % k == 0 then false
else noSmallDivisor m fuel (k + 1)
/-- Trial-division primality test, kernel-evaluable. -/
def isPrimeTD (m : ℕ) : Bool := decide (2 ≤ m) && noSmallDivisor m m 2
/-! ## The kernel sieve and its semantics -/
/-! ## The tail bound -/
/-! ## Farey neighbours -/
/-! ## The certificate -/
/-! ## The `X = 10^4` instance and the unconditional floor
The literals are generated by
`formal_math/probes/erdos251_kernel_denominator_certificate.py --X 10000`. -/
end ErdosProblems.Erdos251
Source
Pinned retained Lean definitions: https://github.com/wcook04/plectis-erdos-lean/blob/d92f079c981c66a7652eb85297d506e61616c062/ErdosProblems/Erdos251/KernelDenominatorFloor.lean#L38-L43; https://github.com/wcook04/plectis-erdos-lean/blob/d92f079c981c66a7652eb85297d506e61616c062/ErdosProblems/Erdos251/KernelDenominatorFloor.lean#L83