Lean / janjarosz05/0kwas / Erdos1094Gap.lean
Lean readerKwas/Erdos1094Gap.lean
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.
import Kwas.Erdos1094Window/-! Erdős Problem 1094: prime gaps of length `L` in `(k/2, k]` exclude exceptions with `4k ≤ n` and`8 n (L + 1) ≤ k²` (continues namespace Erdos1093). -/namespace Erdos1093/-- **Gap criterion.** Suppose every interval `(a, a + L]` with `k < 2 (a + 1)` and `a + L ≤ k` contains a prime.If `4 * 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 {n k L : ℕ} (h4 : 4 * 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 hM8 : 8 ≤ 2 * n / k := byrw [Nat.le_div_iff_mul_le hk]; omegaobtain ⟨N, hN⟩ : ∃ N, 2 * n / k = N + 1 + 1 := ⟨2 * n / k - 2, by omega⟩rw [hN] at hM1 hM2have hNpos : 0 < N := by omegaobtain ⟨d, rfl⟩ : ∃ d, n = k + d := ⟨n - k, by omega⟩-- window ((n-k)/N, n/(N+1)] = (d/N, (k+d)/(N+1)]have ha1 : (d / N) * N ≤ d := Nat.div_mul_le_self _ _have ha2 : d < (d / N + 1) * N := byhave := Nat.lt_succ_iff.2 (le_refl (d / N))exact (Nat.div_lt_iff_lt_mul hNpos).1 thisgeneralize d / N = a at ha1 ha2have e1 : (N + 1 + 1) * k = k * N + 2 * k := by ringhave e2 : (N + 1 + 1 + 1) * k = k * N + 3 * k := by ringhave hka : k * N ≤ 2 * d := by linarithhave hkN : k ≤ k * N := Nat.le_mul_of_pos_right k hNposhave h2a : k < 2 * (a + 1) := byby_contra hpush Not at hhave h1 : 2 * (a + 1) * N ≤ k * N := Nat.mul_le_mul_right N hhave h2 : 2 * (a + 1) * N = 2 * ((a + 1) * N) := by ringomega-- size: 2 (L+1)(N+1) N ≤ nhave hA : (N + 1) * k ≤ 2 * (k + d) := by linarith [show (N + 1) * k = k * N + k by ring]have hB : N * k ≤ 2 * (k + d) := by linarith [show N * k = k * N by ring]have hC : (L + 1) * ((N + 1) * k) * (N * k) ≤ (L + 1) * (2 * (k + d)) * (2 * (k + d)) :=Nat.mul_le_mul (Nat.mul_le_mul_left _ hA) hBhave hD : (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 ≤ (k + d) * (k * k) := bycalc (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 = (k + d) * (8 * (k + d) * (L + 1)) := by ring_ ≤ (k + d) * (k * k) := Nat.mul_le_mul_left _ hLhave hE : ((L + 1) * (N + 1) * N * 2) * (k * k) ≤ (k + d) * (k * k) := bycalc ((L + 1) * (N + 1) * N * 2) * (k * k) = (L + 1) * ((N + 1) * k) * (N * k) * 2 := by ring_ ≤ (L + 1) * (2 * (k + d)) * (2 * (k + d)) * 2 := Nat.mul_le_mul_right 2 hC_ ≤ (k + d) * (k * k) := hDhave hF : (L + 1) * (N + 1) * N * 2 ≤ k + d := Nat.le_of_mul_le_mul_right hE (Nat.mul_pos hk hk)have e3 : (L + 1) * (N + 1) * N = L * (N + 1) * N + N * N + N := by ring-- right end: (a + L)(N+1) ≤ nhave key : (a + L) * (N + 1) * N ≤ (k + d) * N := byhave e4 : (a + L) * (N + 1) * N = a * N * N + a * N + L * (N + 1) * N := by ringhave e5 : (k + d) * N = k * N + d * N := by ringhave h5 : a * N * N ≤ d * N := Nat.mul_le_mul_right N ha1have h6 : (L * (N + 1) * N + N * N + N) * 2 ≤ k + d := by rw [← e3]; exact hF-- need a N + L (N+1) N ≤ k N ; a N ≤ d and k N > 2 d - k ... use 2n < (N+3)khave h7 : 2 * (k + d) < k * N + 3 * k := by linarithhave h8 : 0 ≤ N * N := Nat.zero_le _linarithhave hlen : (a + L) * (N + 1) ≤ k + d := Nat.le_of_mul_le_mul_right key hNposhave hb : a + L ≤ k := byby_contra hpush Not at hhave h1 : (k + 1) * (N + 1) ≤ (a + L) * (N + 1) := Nat.mul_le_mul_right _ hhave h2 : (k + 1) * (N + 1) = k * N + k + N + 1 := by ringlinarithobtain ⟨p, hp, hap, hpL⟩ := hgap a h2a hbrefine exc_no_window (N := N + 1) he hp (by omega) (by omega) ?_ ?_· calc (N + 1) * p ≤ (N + 1) * (a + L) := Nat.mul_le_mul_left _ hpL_ = (a + L) * (N + 1) := Nat.mul_comm _ __ ≤ k + d := hlen· have h1 : (a + 1) * N ≤ p * N := Nat.mul_le_mul_right _ haphave e : (N + 1) * p = p * N + p := by ringomegaend Erdos1093#print axioms Erdos1093.not_exc_of_gap