/-
Copyright 2026 The Formal Conjectures Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
module
public import FormalConjecturesUtilStern Primes
As recounted by Laurent Hodges (1993), Christian Goldbach proposed in a 1752 letter to Euler that
every odd integer greater than $1$ equals $p + 2 b^2$ with $b \ge 0$ (counting $1$ as prime); for
modern primes, its nontrivial content is the Goldbach–Stern conjecture that every odd composite
equals $p + 2 b^2$ with $p$ prime and $b \ge 1$. Moritz Abraham Stern (1856) refuted this via the
counterexamples $5777$ and $5993$ (OEIS A060003).
A prime $q$ admitting no decomposition $q = p + 2 b^2$ with $p$ prime and $b \ge 1$ is called a
Stern prime (OEIS A042978). Only eight examples are known ($2, 3, 17, 137, 227, 977, 1187$, and
$1493$); Euler noted heuristically that larger primes acquire more decompositions $p + 2 b^2$,
suggesting that Stern primes form a finite set and that $1493$ may be the largest.
References:
M. A. Stern, Sur une assertion de Goldbach relative aux nombres impairs, Nouv. Ann. Math. 15 (1856), 23–24.
L. Hodges, A lesser-known Goldbach conjecture, Math. Mag. 66 (1993), no. 1, 45–47.
@[expose] public sectionnamespace SternPrimePredicate asserting that $n = p + 2 b^2$ for some prime $p$ and integer $b \ge 1$.
def HasPrimePlusTwiceSquare (n : ℕ) : Prop :=
∃ p b : ℕ, p.Prime ∧ 1 ≤ b ∧ n = p + 2 * b ^ 2
Predicate asserting that $q$ is prime and fails HasPrimePlusTwiceSquare.
def IsSternPrime (q : ℕ) : Prop :=
q.Prime ∧ ¬ HasPrimePlusTwiceSquare qmpr p:ℕb:ℕhp:Nat.Prime phb:1 ≤ bhp_pos:0 < phb_sqrt:b ≤ (p + 2 * b ^ 2).sqrt⊢ ∃ b_1 < (p + 2 * b ^ 2).sqrt + 1, 1 ≤ b_1 ∧ 2 * b_1 ^ 2 < p + 2 * b ^ 2 ∧ Nat.Prime (p + 2 * b ^ 2 - 2 * b_1 ^ 2)
exact ⟨b, by p:ℕb:ℕhp:Nat.Prime phb:1 ≤ bhp_pos:0 < phb_sqrt:b ≤ (p + 2 * b ^ 2).sqrt⊢ b < (p + 2 * b ^ 2).sqrt + 1 omega All goals completed! 🐙, hb, by p:ℕb:ℕhp:Nat.Prime phb:1 ≤ bhp_pos:0 < phb_sqrt:b ≤ (p + 2 * b ^ 2).sqrt⊢ 2 * b ^ 2 < p + 2 * b ^ 2 omega All goals completed! 🐙, by p:ℕb:ℕhp:Nat.Prime phb:1 ≤ bhp_pos:0 < phb_sqrt:b ≤ (p + 2 * b ^ 2).sqrt⊢ Nat.Prime (p + 2 * b ^ 2 - 2 * b ^ 2) simpa using hp All goals completed! 🐙⟩instance (q : ℕ) : Decidable (IsSternPrime q) :=
inferInstanceAs (Decidable (q.Prime ∧ ¬ HasPrimePlusTwiceSquare q))Verifies that all eight known examples $2, 3, 17, 137, 227, 977, 1187, 1493$ are Stern primes.
@[category test, AMS 11]
theorem isSternPrime_known_examples :
∀ q ∈ ([2, 3, 17, 137, 227, 977, 1187, 1493] : List ℕ), IsSternPrime q := by ⊢ ∀ q ∈ [2, 3, 17, 137, 227, 977, 1187, 1493], IsSternPrime q
decide +kernel All goals completed! 🐙
Checks that $5 = 3 + 2 \cdot 1^2$ and $11 = 3 + 2 \cdot 2^2$ satisfy HasPrimePlusTwiceSquare
and hence are not Stern primes.
@[category test, AMS 11]
theorem not_isSternPrime_five_and_eleven :
HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧
¬ IsSternPrime 5 ∧ ¬ IsSternPrime 11 := by ⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11
have h5 : HasPrimePlusTwiceSquare 5 := ⟨3, 1, by ⊢ Nat.Prime 3 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 norm_num All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11, by ⊢ 1 ≤ 1 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 omega All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11, by ⊢ 5 = 3 + 2 * 1 ^ 2 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 norm_num All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11⟩ h5:HasPrimePlusTwiceSquare 5⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11
have h11 : HasPrimePlusTwiceSquare 11 := ⟨3, 2, by h5:HasPrimePlusTwiceSquare 5⊢ Nat.Prime 3 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 norm_num All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11, by h5:HasPrimePlusTwiceSquare 5⊢ 1 ≤ 2 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 omega All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11, by h5:HasPrimePlusTwiceSquare 5⊢ 11 = 3 + 2 * 2 ^ 2 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11 norm_num All goals completed! 🐙 h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11⟩ h5:HasPrimePlusTwiceSquare 5h11:HasPrimePlusTwiceSquare 11⊢ HasPrimePlusTwiceSquare 5 ∧ HasPrimePlusTwiceSquare 11 ∧ ¬IsSternPrime 5 ∧ ¬IsSternPrime 11
exact ⟨h5, h11, fun h => h.2 h5, fun h => h.2 h11⟩ All goals completed! 🐙Is the set of Stern primes finite? Euler's representation heuristic suggests that only finitely many primes avoid the form $p + 2 b^2$.
@[category research open, question, AMS 11]
theorem stern_primes_finite : {q : ℕ | IsSternPrime q}.Finite := by ⊢ {q | IsSternPrime q}.Finite
sorry All goals completed! 🐙
Does ${2, 3, 17, 137, 227, 977, 1187, 1493}$ exhaust all Stern primes? No ninth example appears
among the first $100{,}000$ primes (McCranie) or below $2 \times 10^{13}$ (Chaffin, OEIS A042978).
@[category research open, question, AMS 11]
theorem isSternPrime_iff :
∀ q : ℕ, IsSternPrime q ↔ q ∈ ({2, 3, 17, 137, 227, 977, 1187, 1493} : Set ℕ) := by ⊢ ∀ (q : ℕ), IsSternPrime q ↔ q ∈ {2, 3, 17, 137, 227, 977, 1187, 1493}
sorry All goals completed! 🐙end SternPrime