Lean / janjarosz05/0kwas / Erdos1094Gap2.lean
Lean readerKwas/Erdos1094Gap2.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Kwas.Erdos1094Gap, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import Kwas.Erdos1094Gap/-! Erdős Problem 1094: the gap criterion for every `n ≥ 2k` (continues namespace Erdos1093).`not_exc_of_gap` needs `4k ≤ n`. Here the same conclusion is proved from `2k ≤ n`, which is the wholerange of the problem. -/namespace Erdos1093/-- **Gap criterion on the whole range `n ≥ 2k`.** Suppose every interval `(a, a + L]` with`k < 2 (a + 1)` and `a + L ≤ k` contains a prime. If `2 * k ≤ n` and `8 * n * (L + 1) ≤ k * k`,then `(n, k)` is not an exception of Erdős problem 1094. -/theorem not_exc_of_gap_two {n k L : ℕ} (h2 : 2 * k ≤ n) (hL : 8 * n * (L + 1) ≤ k * k)(hgap : ∀ a : ℕ, k < 2 * (a + 1) → a + L ≤ k → ∃ p : ℕ, p.Prime ∧ a < p ∧ p ≤ a + L) :(n, k) ∉ Exc := byintro hehave hk : 0 < k := he.1have hM1 : (2 * n / k) * k ≤ 2 * n := Nat.div_mul_le_self _ _have hM2 : 2 * n < (2 * n / k + 1) * k := byhave := Nat.lt_succ_iff.2 (le_refl (2 * n / k))exact (Nat.div_lt_iff_lt_mul hk).1 thishave hM4 : 4 ≤ 2 * n / k := byrw [Nat.le_div_iff_mul_le hk]; omegaobtain ⟨m, hm⟩ : ∃ m, 2 * n / k = m + 4 := ⟨2 * n / k - 4, by omega⟩rw [hm] at hM1 hM2obtain ⟨d, rfl⟩ : ∃ d, n = k + d := ⟨n - k, by omega⟩have hNpos : 0 < m + 2 := by omega-- window ((n-k)/(m+2), n/(m+3)]have ha1 : (d / (m + 2)) * (m + 2) ≤ d := Nat.div_mul_le_self _ _have ha2 : d < (d / (m + 2) + 1) * (m + 2) := byhave := Nat.lt_succ_iff.2 (le_refl (d / (m + 2)))exact (Nat.div_lt_iff_lt_mul hNpos).1 thisgeneralize d / (m + 2) = a at ha1 ha2have e1 : (m + 4) * k = k * m + 4 * k := by ringhave e2 : (m + 4 + 1) * k = k * m + 5 * k := by ringhave hi : k * m + 2 * k ≤ 2 * d := by linarithhave hii : 2 * d < k * m + 3 * k := by linarithhave h2a : k < 2 * (a + 1) := byby_contra hpush Not at hhave h1 : 2 * (a + 1) * (m + 2) ≤ k * (m + 2) := Nat.mul_le_mul_right _ hhave h3 : 2 * (a + 1) * (m + 2) = 2 * ((a + 1) * (m + 2)) := by ringhave h4 : k * (m + 2) = k * m + 2 * k := by ringomega-- 4 (m + 4) (L + 1) ≤ khave hG : 4 * (m + 4) * (L + 1) ≤ k := byhave h1 : 4 * (m + 4) * (L + 1) * k ≤ k * k := bycalc 4 * (m + 4) * (L + 1) * k = 4 * (L + 1) * ((m + 4) * k) := by ring_ ≤ 4 * (L + 1) * (2 * (k + d)) := Nat.mul_le_mul_left _ hM1_ = 8 * (k + d) * (L + 1) := by ring_ ≤ k * k := hLexact Nat.le_of_mul_le_mul_right h1 hk-- the window is at least L long: 2 L (m+3)(m+2) ≤ (m+1) khave hW : 2 * (L * (m + 3) * (m + 2)) ≤ (m + 1) * k := bycalc 2 * (L * (m + 3) * (m + 2))≤ 2 * (L * (m + 3) * (m + 2))+ (2 * L * m * m + 10 * L * m + 4 * L + 4 * m * m + 20 * m + 16) := Nat.le_add_right _ __ = (m + 1) * (4 * (m + 4) * (L + 1)) := by ring_ ≤ (m + 1) * k := Nat.mul_le_mul_left _ hGhave e3 : (m + 1) * k = k * m + k := by ringhave e4 : k * (m + 2) = k * m + 2 * k := by ringhave hkey : d + L * (m + 3) * (m + 2) ≤ k * (m + 2) := by linarithhave hkey2 : (a + L) * (m + 3) * (m + 2) ≤ (k + d) * (m + 2) := byhave h5 : a * (m + 2) * (m + 3) ≤ d * (m + 3) := Nat.mul_le_mul_right _ ha1have e5 : (a + L) * (m + 3) * (m + 2) = a * (m + 2) * (m + 3) + L * (m + 3) * (m + 2) := by ringhave e6 : d * (m + 3) = d * (m + 2) + d := by ringhave e7 : (k + d) * (m + 2) = k * (m + 2) + d * (m + 2) := by ringlinarithhave hlen : (a + L) * (m + 3) ≤ k + d := Nat.le_of_mul_le_mul_right hkey2 hNposhave hb : a + L ≤ k := byby_contra hpush Not at hhave h1 : (k + 1) * (m + 3) ≤ (a + L) * (m + 3) := Nat.mul_le_mul_right _ hhave h3 : (k + 1) * (m + 3) = k * m + 3 * k + m + 3 := by ringlinarithobtain ⟨p, hp, hap, hpL⟩ := hgap a h2a hbrefine exc_no_window (N := m + 3) he hp (by omega) (by omega) ?_ ?_· calc (m + 3) * p ≤ (m + 3) * (a + L) := Nat.mul_le_mul_left _ hpL_ = (a + L) * (m + 3) := Nat.mul_comm _ __ ≤ k + d := hlen· have h1 : (a + 1) * (m + 2) ≤ p * (m + 2) := Nat.mul_le_mul_right _ haphave e : (m + 3) * p = p * (m + 2) + p := by ringomega/-- The same statement with the hypothesis phrased through consecutive primes: if every prime `q < k`is followed by a prime at distance at most `L`, then there is no exception with `2k ≤ n` and`8 n (L + 1) ≤ k²`. -/theorem not_exc_of_prime_gap {n k L : ℕ} (h2 : 2 * k ≤ n) (hL : 8 * n * (L + 1) ≤ k * k)(hgap : ∀ q : ℕ, q.Prime → q < k → ∃ p : ℕ, p.Prime ∧ q < p ∧ p ≤ q + L) :(n, k) ∉ Exc := byintro hehave hk : 0 < k := he.1have hk16 : 16 ≤ k := byby_contra hpush Not at hhave h1 : 8 * (2 * k) * 1 ≤ 8 * n * (L + 1) :=Nat.mul_le_mul (Nat.mul_le_mul_left 8 h2) (by omega)have h3 : k * k ≤ 15 * k := Nat.mul_le_mul_right k (by omega)omegahave hL1 : 1 ≤ L := byobtain ⟨p, _, h2p, hpL⟩ := hgap 2 Nat.prime_two (by omega)omegarefine not_exc_of_gap_two h2 hL ?_ heintro a ha haLhave ha2 : 2 ≤ a := by omegahave hq : (Nat.findGreatest Nat.Prime a).Prime := Nat.findGreatest_spec ha2 Nat.prime_twohave hqa : Nat.findGreatest Nat.Prime a ≤ a := Nat.findGreatest_le ahave hmax : ∀ r : ℕ, r.Prime → r ≤ a → r ≤ Nat.findGreatest Nat.Prime a :=fun r hr hra => Nat.le_findGreatest hra hrgeneralize Nat.findGreatest Nat.Prime a = q at hq hqa hmaxobtain ⟨p, hp, hqp, hpq⟩ := hgap q hq (by omega)refine ⟨p, hp, ?_, by omega⟩by_contra hpush Not at hhave := hmax p hp homegaend Erdos1093#print axioms Erdos1093.not_exc_of_gap_two#print axioms Erdos1093.not_exc_of_prime_gap