/-
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 FormalConjecturesUtilLerch quotients of odd primes
The Lerch quotient of an odd prime $p$ is given by $$L_p = \frac{\left(\sum_{k=1}^{p-1} q_p(k)\right) - w_p}{p}$$ where $q_p(k) = (k^{p-1}-1)/p$ is the Fermat quotient and $w_p = ((p-1)!+1)/p$ is the Wilson quotient. For $n > 1$, $a(n)$ is the Lerch quotient of the $n$-th prime $p_n$.
References:
@[expose] public sectionnamespace OeisA197630The Fermat quotient $q_p(k) = (k^{p-1}-1)/p$.
def fermatQuotient (k p : ℕ) : ℤ :=
((k : ℤ) ^ (p - 1) - 1) / (p : ℤ)The Wilson quotient $w_p = ((p-1)!+1)/p$.
def wilsonQuotient (p : ℕ) : ℤ :=
((p - 1).factorial + 1 : ℤ) / (p : ℤ)The Lerch quotient of $p$: $\frac{(\sum_{k=1}^{p-1} q_p(k)) - w_p}{p}$.
def lerchQuotient (p : ℕ) : ℕ :=
let sumQ : ℤ := ∑ k ∈ Finset.Ico 1 p, fermatQuotient k p
((sumQ - wilsonQuotient p) / (p : ℤ)).natAbsLerch quotients of odd primes: $a(n)$ is the Lerch quotient of the $n$-th prime $p_n$ for $n > 1$, and $0$ for $n \le 1$.
noncomputable def a (n : ℕ) : ℕ :=
if 1 < n then
lerchQuotient (Nat.nth Nat.Prime (n - 1))
else
0@[category test, AMS 11]
theorem a_2 : a 2 = 0 := ⊢ a 2 = 0
⊢ (if 1 < 2 then lerchQuotient 3 else 0) = 0
All goals completed! 🐙@[category test, AMS 11]
theorem a_3 : a 3 = 13 := ⊢ a 3 = 13
⊢ (if 1 < 3 then lerchQuotient 5 else 0) = 13
All goals completed! 🐙@[category test, AMS 11]
theorem a_4 : a 4 = 1356 := ⊢ a 4 = 1356
⊢ (if 1 < 4 then lerchQuotient 7 else 0) = 1356
All goals completed! 🐙@[category test, AMS 11]
theorem a_5 : a 5 = 123229034 := ⊢ a 5 = 123229034
⊢ (if 1 < 5 then lerchQuotient 11 else 0) = 123229034
All goals completed! 🐙@[category test, AMS 11]
theorem a_6 : a 6 = 79417031713 := ⊢ a 6 = 79417031713
⊢ (if 1 < 6 then lerchQuotient 13 else 0) = 79417031713
All goals completed! 🐙"Is $13$ the only Lerch quotient that is itself prime?"
@[category research open, question, AMS 11]
theorem conjecture : ∀ n : ℕ, 1 < n → (a n).Prime → a n = 13 := ⊢ ∀ (n : ℕ), 1 < n → Nat.Prime (OeisA197630.a n) → OeisA197630.a n = 13
All goals completed! 🐙end OeisA197630