Lean / janjarosz05/0kwas / Erdos1094Gap.lean
Lean reader

Kwas/Erdos1094Gap.lean

84 lines1 declarationsno sorryimports Kwas.Erdos1094Window

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

  1. import Kwas.Erdos1094Window
  2. /-! Erdős Problem 1094: prime gaps of length `L` in `(k/2, k]` exclude exceptions with `4k ≤ n` and
  3. `8 n (L + 1) ≤ k²` (continues namespace Erdos1093). -/
  4. namespace Erdos1093
  5. /-- **Gap criterion.** Suppose every interval `(a, a + L]` with `k < 2 (a + 1)` and `a + L ≤ k` contains a prime.
  6. If `4 * k ≤ n` and `8 * n * (L + 1) ≤ k * k`, then `(n, k)` is not an exception of Erdős problem 1094. -/
  7. theorem not_exc_of_gap {n k L : ℕ} (h4 : 4 * k ≤ n) (hL : 8 * n * (L + 1) ≤ k * k)
  8. (hgap : ∀ a : ℕ, k < 2 * (a + 1) → a + L ≤ k → ∃ p : ℕ, p.Prime ∧ a < p ∧ p ≤ a + L) :
  9. (n, k) ∉ Exc := by
  10. intro he
  11. have hk : 0 < k := he.1
  12. have hM1 : (2 * n / k) * k ≤ 2 * n := Nat.div_mul_le_self _ _
  13. have hM2 : 2 * n < (2 * n / k + 1) * k := by
  14. have := Nat.lt_succ_iff.2 (le_refl (2 * n / k))
  15. exact (Nat.div_lt_iff_lt_mul hk).1 this
  16. have hM8 : 8 ≤ 2 * n / k := by
  17. rw [Nat.le_div_iff_mul_le hk]; omega
  18. obtain ⟨N, hN⟩ : ∃ N, 2 * n / k = N + 1 + 1 := ⟨2 * n / k - 2, by omega⟩
  19. rw [hN] at hM1 hM2
  20. have hNpos : 0 < N := by omega
  21. obtain ⟨d, rfl⟩ : ∃ d, n = k + d := ⟨n - k, by omega⟩
  22. -- window ((n-k)/N, n/(N+1)] = (d/N, (k+d)/(N+1)]
  23. have ha1 : (d / N) * N ≤ d := Nat.div_mul_le_self _ _
  24. have ha2 : d < (d / N + 1) * N := by
  25. have := Nat.lt_succ_iff.2 (le_refl (d / N))
  26. exact (Nat.div_lt_iff_lt_mul hNpos).1 this
  27. generalize d / N = a at ha1 ha2
  28. have e1 : (N + 1 + 1) * k = k * N + 2 * k := by ring
  29. have e2 : (N + 1 + 1 + 1) * k = k * N + 3 * k := by ring
  30. have hka : k * N ≤ 2 * d := by linarith
  31. have hkN : k ≤ k * N := Nat.le_mul_of_pos_right k hNpos
  32. have h2a : k < 2 * (a + 1) := by
  33. by_contra h
  34. push Not at h
  35. have h1 : 2 * (a + 1) * N ≤ k * N := Nat.mul_le_mul_right N h
  36. have h2 : 2 * (a + 1) * N = 2 * ((a + 1) * N) := by ring
  37. omega
  38. -- size: 2 (L+1)(N+1) N ≤ n
  39. have hA : (N + 1) * k ≤ 2 * (k + d) := by linarith [show (N + 1) * k = k * N + k by ring]
  40. have hB : N * k ≤ 2 * (k + d) := by linarith [show N * k = k * N by ring]
  41. have hC : (L + 1) * ((N + 1) * k) * (N * k) ≤ (L + 1) * (2 * (k + d)) * (2 * (k + d)) :=
  42. Nat.mul_le_mul (Nat.mul_le_mul_left _ hA) hB
  43. have hD : (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 ≤ (k + d) * (k * k) := by
  44. calc (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 = (k + d) * (8 * (k + d) * (L + 1)) := by ring
  45. _ ≤ (k + d) * (k * k) := Nat.mul_le_mul_left _ hL
  46. have hE : ((L + 1) * (N + 1) * N * 2) * (k * k) ≤ (k + d) * (k * k) := by
  47. calc ((L + 1) * (N + 1) * N * 2) * (k * k) = (L + 1) * ((N + 1) * k) * (N * k) * 2 := by ring
  48. _ ≤ (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 := Nat.mul_le_mul_right 2 hC
  49. _ ≤ (k + d) * (k * k) := hD
  50. have hF : (L + 1) * (N + 1) * N * 2 ≤ k + d := Nat.le_of_mul_le_mul_right hE (Nat.mul_pos hk hk)
  51. have e3 : (L + 1) * (N + 1) * N = L * (N + 1) * N + N * N + N := by ring
  52. -- right end: (a + L)(N+1) ≤ n
  53. have key : (a + L) * (N + 1) * N ≤ (k + d) * N := by
  54. have e4 : (a + L) * (N + 1) * N = a * N * N + a * N + L * (N + 1) * N := by ring
  55. have e5 : (k + d) * N = k * N + d * N := by ring
  56. have h5 : a * N * N ≤ d * N := Nat.mul_le_mul_right N ha1
  57. have h6 : (L * (N + 1) * N + N * N + N) * 2 ≤ k + d := by rw [← e3]; exact hF
  58. -- need a N + L (N+1) N ≤ k N ; a N ≤ d and k N > 2 d - k ... use 2n < (N+3)k
  59. have h7 : 2 * (k + d) < k * N + 3 * k := by linarith
  60. have h8 : 0 ≤ N * N := Nat.zero_le _
  61. linarith
  62. have hlen : (a + L) * (N + 1) ≤ k + d := Nat.le_of_mul_le_mul_right key hNpos
  63. have hb : a + L ≤ k := by
  64. by_contra h
  65. push Not at h
  66. have h1 : (k + 1) * (N + 1) ≤ (a + L) * (N + 1) := Nat.mul_le_mul_right _ h
  67. have h2 : (k + 1) * (N + 1) = k * N + k + N + 1 := by ring
  68. linarith
  69. obtain ⟨p, hp, hap, hpL⟩ := hgap a h2a hb
  70. refine exc_no_window (N := N + 1) he hp (by omega) (by omega) ?_ ?_
  71. · calc (N + 1) * p ≤ (N + 1) * (a + L) := Nat.mul_le_mul_left _ hpL
  72. _ = (a + L) * (N + 1) := Nat.mul_comm _ _
  73. _ ≤ k + d := hlen
  74. · have h1 : (a + 1) * N ≤ p * N := Nat.mul_le_mul_right _ hap
  75. have e : (N + 1) * p = p * N + p := by ring
  76. omega
  77. end Erdos1093
  78. #print axioms Erdos1093.not_exc_of_gap