Lean / Reader
Lean reader

SophieGermainCounterexample.lean

181 lines21 declarationsno sorryimports Mathlib LeanClassics.FibCubes

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports LeanClassics.FibCubes, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import Mathlib
  2. import LeanClassics.FibCubes
  3. /-!
  4. # A counterexample in Goel, *Sophie Germain Primes and the Totient of Fibonacci Numbers*
  5. Reference: arXiv:2604.17847v3 (22 Apr 2026).
  6. For an odd prime `q`, the paper defines `S(q)` as the set of residues `r mod π(q)` such that
  7. `q ∣ φ(F_m)` for every `m ≡ r (mod π(q))`, where `π(q)` is the Pisano period. The paper conjectures
  8. that `k = 2` in Theorem 4.2 (OQ2). It also states, for every odd prime `q ≤ 50000`, that `S(q) ≠ ∅`
  9. holds only for Sophie Germain primes `q`.
  10. Take `q = 2837` and `p = 761882591401 = 268552200 · 2837 + 1`. This file checks:
  11. * `p` and `q` are prime, and `2q + 1 = 5675` is not, so `q` is not a Sophie Germain prime;
  12. * `p ∣ F_258`;
  13. * `π(2837) = 5676 = 22 · 258`, that is, `5676` is the least positive `n` with `F_n ≡ 0` and
  14. `F_{n+1} ≡ 1 (mod 2837)`;
  15. * `0 ∈ S(2837)`, that is, `2837 ∣ φ(F_m)` whenever `5676 ∣ m`.
  16. So `p = kq + 1` with `z(p) ∣ π(q)` and `k = 268552200 ≠ 2`, and `S(2837) ≠ ∅` although `2837` is not a
  17. Sophie Germain prime.
  18. -/
  19. namespace SophieGermainCounterexample
  20. open Nat
  21. theorem zmod_pow_eq_one_iff {p a n : ℕ} (hp : 1 < p) :
  22. ((a : ZMod p) ^ n = 1) ↔ a ^ n % p = 1 := by
  23. rw [← Nat.cast_pow, ← Nat.cast_one, ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hp]
  24. theorem q_prime : Nat.Prime 2837 := by norm_num
  25. theorem not_sophie_germain : ¬ Nat.Prime (2 * 2837 + 1) := by norm_num
  26. /-- `p = 761882591401` is prime: a Lucas certificate with witness `17`. Here
  27. `p - 1 = 2³ · 3 · 5² · 7 · 43 · 1487 · 2837`. -/
  28. theorem p_prime : Nat.Prime 761882591401 := by
  29. apply lucas_primality _ 17
  30. · show (17 : ZMod 761882591401) ^ 761882591400 = 1
  31. reduce_mod_char
  32. · intro l hl hdiv
  33. rw [show 761882591401 - 1 = 2 ^ 3 * 3 * 5 ^ 2 * 7 * 43 * 1487 * 2837 by norm_num] at hdiv
  34. simp only [hl.dvd_mul] at hdiv
  35. have e : ∀ r : ℕ, r.Prime → l ∣ r → l = r := fun r hr h => (Nat.prime_dvd_prime_iff_eq hl hr).1 h
  36. rcases hdiv with (((((h | h) | h) | h) | h) | h) | h
  37. · rw [e 2 Nat.prime_two (hl.dvd_of_dvd_pow h)]
  38. show (17 : ZMod 761882591401) ^ 380941295700 ≠ 1; reduce_mod_char; decide
  39. · rw [e 3 Nat.prime_three h]
  40. show (17 : ZMod 761882591401) ^ 253960863800 ≠ 1; reduce_mod_char; decide
  41. · rw [e 5 Nat.prime_five (hl.dvd_of_dvd_pow h)]
  42. show (17 : ZMod 761882591401) ^ 152376518280 ≠ 1; reduce_mod_char; decide
  43. · rw [e 7 (by norm_num) h]
  44. show (17 : ZMod 761882591401) ^ 108840370200 ≠ 1; reduce_mod_char; decide
  45. · rw [e 43 (by norm_num) h]
  46. show (17 : ZMod 761882591401) ^ 17718199800 ≠ 1; reduce_mod_char; decide
  47. · rw [e 1487 (by norm_num) h]
  48. show (17 : ZMod 761882591401) ^ 512362200 ≠ 1; reduce_mod_char; decide
  49. · rw [e 2837 q_prime h]
  50. show (17 : ZMod 761882591401) ^ 268552200 ≠ 1; reduce_mod_char; decide
  51. theorem p_eq : 761882591401 = 268552200 * 2837 + 1 := by norm_num
  52. theorem p_dvd_fib : 761882591401 ∣ fib 258 := by
  53. rw [Nat.dvd_iff_mod_eq_zero]; norm_num [Nat.fib_add_two]
  54. /-! ## The Pisano period of `2837` -/
  55. /-- `n` is a period of the Fibonacci sequence modulo `q`. -/
  56. def IsPer (q n : ℕ) : Prop := (fib n : ZMod q) = 0 ∧ (fib (n + 1) : ZMod q) = 1
  57. theorem isPer_zero (q : ℕ) : IsPer q 0 := by simp [IsPer]
  58. theorem isPer_add_mul {q T : ℕ} (hT : IsPer q T) (j c : ℕ) : IsPer q (j + c * T) ↔ IsPer q j := by
  59. unfold IsPer
  60. rw [FibCubes.fib_add_mul_period hT.1 hT.2, show j + c * T + 1 = (j + 1) + c * T by ring,
  61. FibCubes.fib_add_mul_period hT.1 hT.2]
  62. theorem isPer_mod {q a b : ℕ} (hb : IsPer q b) : IsPer q a ↔ IsPer q (a % b) := by
  63. conv_lhs => rw [← Nat.mod_add_div a b, mul_comm]
  64. exact isPer_add_mul hb _ _
  65. theorem isPer_gcd {q a b : ℕ} (ha : IsPer q a) (hb : IsPer q b) : IsPer q (Nat.gcd a b) := by
  66. induction a, b using Nat.gcd.induction with
  67. | H0 n => simpa using hb
  68. | H1 m n hm ih =>
  69. rw [Nat.gcd_rec]
  70. exact ih ((isPer_mod ha).1 hb) ha
  71. theorem isPer_of_dvd {q T n : ℕ} (hT : IsPer q T) (h : T ∣ n) : IsPer q n := by
  72. obtain ⟨c, rfl⟩ := h
  73. have := (isPer_add_mul hT 0 c).2 (isPer_zero q)
  74. simpa [mul_comm] using this
  75. theorem natCast_zmod_eq {q a b : ℕ} (hb : b < q) : (a : ZMod q) = b ↔ a % q = b := by
  76. rw [ZMod.natCast_eq_natCast_iff', Nat.mod_eq_of_lt hb]
  77. theorem isPer_5676 : IsPer 2837 5676 := by
  78. constructor
  79. · have h : fib 5676 % 2837 = 0 := by norm_num [Nat.fib_add_two]
  80. exact (ZMod.natCast_eq_zero_iff _ _).2 (Nat.dvd_of_mod_eq_zero h)
  81. · have h : fib 5677 % 2837 = 1 := by norm_num [Nat.fib_add_two]
  82. have := (natCast_zmod_eq (q := 2837) (a := fib 5677) (b := 1) (by norm_num)).2 h
  83. rw [Nat.cast_one] at this; exact this
  84. theorem not_isPer_2838 : ¬ IsPer 2837 2838 := by
  85. rintro ⟨-, h⟩
  86. have h' : fib 2839 % 2837 = 1 := (natCast_zmod_eq (q := 2837) (a := fib 2839) (b := 1)
  87. (by norm_num)).1 (by rw [Nat.cast_one]; exact h)
  88. norm_num [Nat.fib_add_two] at h'
  89. theorem not_isPer_1892 : ¬ IsPer 2837 1892 := by
  90. rintro ⟨h, -⟩
  91. have h' : fib 1892 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h)
  92. norm_num [Nat.fib_add_two] at h'
  93. theorem not_isPer_516 : ¬ IsPer 2837 516 := by
  94. rintro ⟨h, -⟩
  95. have h' : fib 516 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h)
  96. norm_num [Nat.fib_add_two] at h'
  97. theorem not_isPer_132 : ¬ IsPer 2837 132 := by
  98. rintro ⟨h, -⟩
  99. have h' : fib 132 % 2837 = 0 := Nat.mod_eq_zero_of_dvd ((ZMod.natCast_eq_zero_iff _ _).1 h)
  100. norm_num [Nat.fib_add_two] at h'
  101. /-- **`π(2837) = 5676`.** `5676` is a period, and no smaller positive `n` is. -/
  102. theorem pisano_2837 : IsPer 2837 5676 ∧ ∀ n, 0 < n → n < 5676 → ¬ IsPer 2837 n := by
  103. refine ⟨isPer_5676, fun n hn0 hn h => ?_⟩
  104. have hg := isPer_gcd h isPer_5676
  105. set g := Nat.gcd n 5676
  106. have hg0 : 0 < g := Nat.gcd_pos_of_pos_left _ hn0
  107. have hgle : g < 5676 := lt_of_le_of_lt (Nat.gcd_le_left _ hn0) hn
  108. have key : ∀ d, d ∣ 5676 → d < 5676 → d ∣ 2838 ∨ d ∣ 1892 ∨ d ∣ 516 ∨ d ∣ 132 := by
  109. intro d hd hlt
  110. obtain ⟨c, hc⟩ := hd
  111. have hc1 : c ≠ 1 := by rintro rfl; omega
  112. obtain ⟨l, hl, hlc⟩ := Nat.exists_prime_and_dvd hc1
  113. have hl5676 : l ∣ 5676 := by rw [hc]; exact Dvd.dvd.mul_left hlc d
  114. have hdl : d * l ∣ 5676 := by rw [hc]; exact Nat.mul_dvd_mul_left d hlc
  115. rw [show (5676 : ℕ) = 2 ^ 2 * 3 * 11 * 43 by norm_num] at hl5676
  116. simp only [hl.dvd_mul] at hl5676
  117. have e : ∀ r : ℕ, r.Prime → l ∣ r → l = r :=
  118. fun r hr h => (Nat.prime_dvd_prime_iff_eq hl hr).1 h
  119. rcases hl5676 with ((h | h) | h) | h
  120. · rw [e 2 Nat.prime_two (hl.dvd_of_dvd_pow h)] at hdl
  121. left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 2)
  122. · rw [e 3 Nat.prime_three h] at hdl
  123. right; left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 3)
  124. · rw [e 11 (by norm_num) h] at hdl
  125. right; right; left; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 11)
  126. · rw [e 43 (by norm_num) h] at hdl
  127. right; right; right; exact (Nat.dvd_div_of_mul_dvd (by rwa [mul_comm] at hdl) : d ∣ 5676 / 43)
  128. rcases key g (Nat.gcd_dvd_right _ _) hgle with h1 | h1 | h1 | h1
  129. · exact not_isPer_2838 (isPer_of_dvd hg h1)
  130. · exact not_isPer_1892 (isPer_of_dvd hg h1)
  131. · exact not_isPer_516 (isPer_of_dvd hg h1)
  132. · exact not_isPer_132 (isPer_of_dvd hg h1)
  133. /-- **`0 ∈ S(2837)`.** If `π(2837) = 5676` divides `m`, then `2837 ∣ φ(F_m)`. -/
  134. theorem zero_mem_S (m : ℕ) (hm : 5676 ∣ m) : 2837 ∣ Nat.totient (fib m) := by
  135. have h258 : 258 ∣ m := dvd_trans (by norm_num) hm
  136. have hp : 761882591401 ∣ fib m := dvd_trans p_dvd_fib (Nat.fib_dvd _ _ h258)
  137. have htot : Nat.totient 761882591401 ∣ Nat.totient (fib m) := Nat.totient_dvd_of_dvd hp
  138. rw [Nat.totient_prime p_prime] at htot
  139. exact dvd_trans ⟨268552200, by norm_num⟩ htot
  140. /-- **Summary.** `q = 2837` is prime but not a Sophie Germain prime. Its Pisano period is `5676`,
  141. and `S(2837) ∋ 0`. The prime `p = 268552200 · q + 1` satisfies `p ∣ F_258` with `258 ∣ π(q)`, so the
  142. rank of apparition `z(p)` divides `π(q)`, yet `k = 268552200 ≠ 2`. -/
  143. theorem counterexample :
  144. Nat.Prime 2837 ∧ ¬ Nat.Prime (2 * 2837 + 1) ∧ Nat.Prime 761882591401 ∧
  145. 761882591401 = 268552200 * 2837 + 1 ∧ 761882591401 ∣ fib 258 ∧ 258 ∣ 5676 ∧
  146. (IsPer 2837 5676 ∧ ∀ n, 0 < n → n < 5676 → ¬ IsPer 2837 n) ∧
  147. (∀ m, 5676 ∣ m → 2837 ∣ Nat.totient (fib m)) :=
  148. ⟨q_prime, not_sophie_germain, p_prime, p_eq, p_dvd_fib, by norm_num, pisano_2837, zero_mem_S⟩
  149. end SophieGermainCounterexample