The Set of Primes is Supernatural: A Lean Formalization
Summary (Overview)
- This paper presents a complete formalization in Lean 4 of the mathematical paper "[3]" (titled "The Set of Primes is Supernatural") using the Mathlib library.
- The formalization covers every definition, example, remark, proposition, and experimental table row from the original paper, with no
sorryor unproved axioms. - The central conjecture (Conjecture 2.1) is stated as a named
Propwithout proof, deliberately preserving its open status. - The formalization extends the original work by implementing Remark 3.4's suggested extensions: Knuth arrows, factorial, and truncated subtraction in a single inductive class.
- All 89 experimental table rows are proved, with the largest primality checks handled by kernel-verified Lucas certificates.
Introduction and Theoretical Foundation
Background
The original paper [3] concerns natural functions on positive integers (denoted or ): functions built from the identity and constant functions using finitely many applications of pointwise addition (), multiplication (), and exponentiation (). The central conjecture states:
Conjecture 2.1 ([3]): No non-constant natural function maps every positive integer to a prime.
The paper develops a theory of elevation structures — algebraic structures axiomatizing the compatibilities between , , and — and proves several partial results toward the conjecture.
Elevation Structures
An elevation structure is a 4-tuple where is a set and all three operations are binary maps satisfying seven axioms:
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
Crucially, itself need be neither commutative nor associative. The convention fixes right-associativity: means .
Key Examples
- with as ordinary exponentiation is an elevation structure.
- where is the set of functions with pointwise operations is an elevation structure. The evaluation map , , is a morphism.
Natural Functions
Let consist of the identity map and all constant maps. For , define (resp. , ) as together with all (resp. , ) for . Writing for the set of finite words in the alphabet , the set of natural functions is:
The length of a natural function is the least length of a word with .
Formalization Approach
Two Encodings of Natural Functions
The formalization uses two equivalent encodings:
First encoding (word machinery): An inductive type OpLetter with constructors plus, mul, elev. Words are lists of letters acting on sets of functions by composition. FNatural is the union over all words.
inductive OpLetter : Type
| plus | mul | elev
def OpLetter.apply : OpLetter → Set (N+ → N+) → Set (N+ → N+) := ...
abbrev Word := List OpLetter
def Word.apply (σ : Word) (P : Set (N+ → N+)) : Set (N+ → N+) := ...
def FNatural : Set (N+ → N+) := ∪ σ : Word, Word.apply σ Fs
Second encoding (inductive predicate): A direct inductive predicate IsNatural on functions:
inductive IsNatural : (N+ → N+) → Prop
| id : IsNatural (fun n => n)
| const (c : N+) : IsNatural (fun _ => c)
| add {f g} (hf : IsNatural f) (hg : IsNatural g) : IsNatural (fun n => f n + g n)
| mul {f g} (hf : IsNatural f) (hg : IsNatural g) : IsNatural (fun n => f n * g n)
| elev {f g} (hf : IsNatural f) (hg : IsNatural g) : IsNatural (fun n => (f n) ^ (g n : N))
The two encodings are proved equivalent, giving for free the induction principle the paper obtains from the word definition.
Category Formalization
The paper's sentence "we obtain a category" is fully formalized: identity, composition, and the three category laws hold definitionally (rfl). The category is also registered as an instance of Mathlib's Category class.
Key Theorems Formalized
Proposition 1.6: Natural Functions are Constant or Strictly Increasing
def ConstOrStrictMono (f : N+ → N+) : Prop := (∃ c, ∀ n, f n = c) ∨ StrictMono f
theorem isNatural_constOrStrictMono {f : N+ → N+} (hf : IsNatural f) : ConstOrStrictMono f
The proof follows the paper's structure via three closure lemmas (Lemmas 1.8–1.10), with the elevation case carrying the base-1 exception:
theorem lemma_1_10 {h : N+ → N+} (c : N+) (hh : StrictMono h) :
(1 < c → StrictMono (fun n => c ^ (h n : N))) ∧
(c = 1 → ∀ n, c ^ (h n : N) = 1)
Remark 1.11: Why the Domain is Positive Integers
On , the map is neither constant nor strictly increasing ( while ). Both halves are formalized, showing why the theory uses not .
Proposition 2.2: Proved Cases of the Conjecture
Case (i) — Polynomial functions: Uses the fact that for integer polynomials to show that for a prime , we get with , so is a proper divisor.
Case (ii) — Functions of form : Uses Fermat's little theorem to handle the case where .
Case (iii) — Fermat's function: Euler's factorization of the fifth Fermat number is kernel-checked:
theorem fermatFn_five_eq : (fermatFn 5 : N) = 641 * 6700417 := by decide
Proposition 3.1: Consequences of the Conjecture
The paper asserts that if is natural and , then is natural. This requires an auxiliary lemma:
theorem IsNatural.comp {f g : N+ → N+} (hf : IsNatural f) (hg : IsNatural g) :
IsNatural (f ∘ g)
theorem isNatural_shift (k : N+) : IsNatural (fun n : N+ => n + k)
Corollary 3.2: Infinitely Many Composite Fermat Numbers
Formalized as a conditional theorem:
theorem corollary_3_2 (hconj : Conjecture_2_1) :
{n : N+ | ¬ Nat.Prime (fermatFn n : N)}.Infinite
The Extended Class (Remark 3.4)
The formalization implements a substantial extension combining three new features:
- Knuth arrows whose level is itself a function in the class
- Factorial
- Truncated subtraction, admitted only under pointwise hypothesis
Mathlib's hyperoperation indexes the hierarchy: index 0 = successor, 1 = addition, 2 = multiplication, 3 = exponentiation (the paper's elevation ), 4 = tetration, etc. Knuth's arrows begin at exponentiation, so arrows correspond to index :
inductive IsNaturalKnuthFactorialSub : (N+ → N+) → Prop
| id | const | add | mul
| knuth {f g h} (hf : IsNaturalKnuthFactorialSub f) (hg : ...) (hh : ...) :
IsNaturalKnuthFactorialSub (fun n =>
⟨hyperoperation ((g n : N) + 2) (f n) (h n), hyperoperation_pos_of_three_le ...⟩)
| fact {f} (hf : ...) :
IsNaturalKnuthFactorialSub (fun n => ⟨(f n : N).factorial, ...⟩)
| sub {f g} (hf : ...) (hg : ...) (hlt : ∀ n, (g n : N) < (f n : N)) :
IsNaturalKnuthFactorialSub (fun n => ⟨(f n : N) - (g n : N), ...⟩)
The embedding theorem IsNatural.toKnuthFactorialSub verifies that the extension genuinely extends the original class.
The Experimental Tables (§4)
All 89 table rows are formalized as theorems. Each row states that values are prime at each earlier point and not prime at the reported point, proved by norm_num.
The Large Primality Challenge
The paper highlights as beating Fermat's function: values are prime for . The corresponding theorem must certify primality of . Similarly, Table 3 has a row of the same weight.
A norm_num proof would be a kernel-checked trial division with about steps, costing about an hour of build time. Instead, Lucas certificates are used: to certify prime, exhibit a witness with:
- for each prime
Mathlib supplies lucas_primality and the reduce_mod_char tactic. The only project-level glue is a lemma converting an explicit factorization of into lucas_primality's quantification:
theorem lucasCert (p a : N) (l : List N)
(h1 : ∀ q ∈ l, Nat.Prime q)
(hprod : p - 1 = l.prod)
(h1 : (a : ZMod p) ^ (p - 1) = 1)
(h2 : ∀ q ∈ l, (a : ZMod p) ^ ((p - 1) / q) ≠ 1) :
Nat.Prime p
Sixteen certificates chain recursively down to primes small enough for norm_num's trial division, culminating in:
theorem prime_18446744073709551709 : Nat.Prime 18446744073709551709 := ...
Correspondence Table
| [3] | SPCL.lean | Status |
|---|---|---|
| Def. 1.1 (elevation structure) | ElevationStructure | formalized |
| — (morphism) | ElevationHom | formalized |
| — ("we obtain a category") | ElevationHom.id, .comp, laws, Category ElevCat instance | proved |
| Ex. 1.2, | instance : ElevationStructure N+ | formalized |
| Ex. 1.2, , | instance : ElevationStructure (N+ → N+), Eval | formalized |
| Def. 1.3 () | OpLetter, OpLetter.apply | formalized |
| Def. 1.4 (, ) | Word, Word.apply, Fs, FNatural | formalized |
| — (inductive counterpart) | IsNatural; equivalence | proved |
| — ( elevation structure) | FNatural_eq, instance : ElevationStructure {f // IsNatural f} | formalized |
| Ex. 1.5 (a) | Fs_subset_FNatural | proved |
| Ex. 1.5 (b) polynomials | FPolynomial, FPolynomial_subset_words, FPolynomial_subset_FNatural | proved |
| Ex. 1.5 (c) Fermat's word | fermatFn_mem_word | proved |
| Ex. 1.5 (d) four samples | example_1_5_selfPow, _sevenPow, _big, _tower | proved |
| Prop. 1.6 | isNatural_constOrStrictMono | proved |
| Def. 1.7 (length) | natLength, natLength_spec | proved |
| Lemmas 1.8, 1.9, 1.10 | lemma_1_8, lemma_1_9, lemma_1_10 | proved |
| Remark 1.11 | remark_1_11_* (four statements) | proved |
| Conjecture 2.1 | Conjecture_2_1 | stated (open) |
| §2.2 (supernatural sets) | IsNaturalSet, IsSupernatural, conjecture_2_1_iff_supernatural, IsNaturalSet.infinite | proved |
| Prop. 2.2(i) | prop_2_2_i | proved |
| Prop. 2.2(ii) | prop_2_2_ii | proved |
| Prop. 2.2(iii) | fermatFn_five_eq, fermatFn_five_not_prime | proved |
| Prop. 2.2(iv) | the 89 table theorems | proved |
| — | IsNatural.comp | proved (auxiliary for 3.1) |
| Prop. 3.1 | proposition_3_1; printed form proposition_3_1_values | proved (conditional) |
| Cor. 3.2 | corollary_3_2 | proved (conditional) |
| Prop. 3.3 | exists_all_prime_of_not_conjecture | proved |
| Remark 3.4 (extended class) | IsNaturalKnuthFactorialSub, IsNatural.toKnuthFactorialSub, Conjecture_KnuthFactorialSub | stated (extension), embedding proved |
| §4, Table 1 | table1_row1 – table1_row10 | proved |
| §4, Table 2 (k = 1,...,59) | table2_row1 – table2_row59 | proved |
| §4, Table 3 (c = 2501,...,2539) | table3_row2501 – table3_row2539 | proved |
| — (primality certificates) | Pratt.lucasCert, sixteen Pratt.prime_* theorems | proved |
| §4, question (i) | Question_i | stated (open) |
| §4, question (ii) | not a determinate proposition as printed | not encoded |
Conclusion
This formalization demonstrates a complete, rigorous verification of a substantial mathematical paper's content. Key achievements include:
- Full coverage: Every mathematical statement from the paper is formalized, with open questions deliberately left as unproved
Propstatements. - Faithful reproduction: Proofs follow the paper's structure, including the subtle base-1 exception in Lemma 1.10.
- Kernel-verified computation: All experimental results are checked by the Lean kernel, with the largest primality proofs using efficient Lucas certificates rather than naive trial division.
- Principled extension: The extended class of Remark 3.4 is implemented and proved to genuinely extend the original class.
- Dependency transparency: Every conditional theorem takes its hypotheses explicitly, making the logical structure of dependencies visible in each statement.
Related papers
- Mixture-of-Experts Serving
This paper introduces the first formal model for Mixture-of-Experts serving, providing an optimal online algorithm with a tight competitive ratio and a 2-approximation for the static case.
- Data Mixing as Mixture Experiment: Response Surface Methodology and Optimal Design for Large Language Model Pretraining
This paper reframes LLM data mixing as a mixture experiment, showing that sparse Scheffé models with I-optimal designs recover optimal domain proportions using 25% fewer proxy runs.
- Massive Activations in Hybrid Linear Attention Large Language Models: Pre-Attention Spikes and Inter-Spike Plateaus
Massive activations in hybrid linear attention LLMs spike before full attention layers (PAS) and persist through linear layers (ISP), governed by hybridization ratio and cancellation timing.