Lean / janjarosz05/0kwas / Erdos1094Struct.lean
Lean readerKwas/Erdos1094Struct.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Kwas.Erdos1093, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import Kwas.Erdos1093/-! Erdős Problem 1094: Struct (continues namespace Erdos1093). -/namespace Erdos1093/-! ## Structure of an exception of Erdős problem 1094 -//-- **Residue windows.** For an exception `(n, k)` and every prime `q ≤ max (n / k) k`: `k mod q ≤ n mod q`.For `k < q ≤ n / k` this reads `k ≤ n mod q`; for `k / 2 < q ≤ k` it reads `k - q ≤ n mod q`. -/theorem exc_mod_le {n k q : ℕ} (he : (n, k) ∈ Exc) (hq : q.Prime) (hle : q ≤ max (n / k) k) :k % q ≤ n % q := byobtain ⟨-, -, hmin⟩ := hehave hnd : ¬ q ∣ n.choose k := byintro hdhave := Nat.minFac_le_of_dvd hq.two_le hdomegahave hpass := (not_dvd_choose_iff_passes hq k n).1 hndhave := passes_mod_pow hq.two_le 1 n k hpasssimpa using this/-- **Every term is (`k`-smooth) × (primes above `n / k`).** For an exception `(n, k)`, a prime dividing one of`n, n - 1, …, n - k + 1` is either `≤ k` or `> n / k`. -/theorem exc_term_prime {n k j q : ℕ} (he : (n, k) ∈ Exc) (hj : j < k) (hq : q.Prime) (hd : q ∣ n - j) :q ≤ k ∨ n / k < q := byby_contra hconpush Not at hconobtain ⟨hk, hn, hmin⟩ := hehave hterm : q ∣ n.descFactorial k := byrw [Nat.descFactorial_eq_prod_range]exact dvd_trans hd (Finset.dvd_prod_of_mem _ (Finset.mem_range.2 hj))rw [Nat.descFactorial_eq_factorial_mul_choose] at htermhave hc : q ∣ n.choose k := byrcases (hq.dvd_mul).1 hterm with h1 | h1· exact absurd ((hq.dvd_factorial).1 h1) (by omega)· exact h1have := Nat.minFac_le_of_dvd hq.two_le hchave := le_max_left (n / k) komega/-- For an exception with `n ≥ k^2`, a term has at most one prime factor above `n / k` (two would exceed `n`):if primes `q₁ q₂ > n / k` satisfy `q₁ * q₂ ∣ n - j`, contradiction. -/theorem exc_term_one_large {n k j q₁ q₂ : ℕ} (he : (n, k) ∈ Exc) (hn2 : k ^ 2 ≤ n) (hjn : j < n)(h1 : n / k < q₁) (h2 : n / k < q₂) (hd : q₁ * q₂ ∣ n - j) : False := byobtain ⟨hk, hn, -⟩ := hehave hle : q₁ * q₂ ≤ n - j := Nat.le_of_dvd (by omega) hdhave hq : (n / k + 1) * (n / k + 1) ≤ q₁ * q₂ := Nat.mul_le_mul h1 h2have hkk : k ≤ n / k := byrw [Nat.le_div_iff_mul_le hk]nlinarith [hn2]have hlt : n < k * (n / k + 1) := byhave := Nat.div_add_mod n khave := Nat.mod_lt n hknlinarithhave : k * (n / k + 1) ≤ (n / k + 1) * (n / k + 1) := Nat.mul_le_mul_right _ (by omega)omega/-- **Floor-prime theorem.** In an exception of Erdős 1094 with `n ≥ k²`, for every `m` with `k/2 < m ≤ k`the quotient `n / m` is a prime, unless the term `m * (n / m)` is `k`-smooth. -/theorem exc_floor_prime {n k m : ℕ} (he : (n, k) ∈ Exc) (hn2 : k * k ≤ n) (hm1 : k < 2 * m)(hm2 : m ≤ k) : (n / m).Prime ∨ ∀ q : ℕ, q.Prime → q ∣ m * (n / m) → q ≤ k := byby_contra hconpush Not at hconobtain ⟨hnp, q, hq, hqd, hqk⟩ := hconhave hk : 0 < k := he.1have hm : 0 < m := by omegahave hmod : n % m < m := Nat.mod_lt n hmhave hT : m * (n / m) = n - n % m := by have := Nat.mod_add_div n m; omegahave hlarge : n / k < q := byrcases exc_term_prime he (j := n % m) (by omega) hq (hT ▸ hqd) with h | h· omega· exact hhave hnq : n < q * k := byhave := (Nat.div_lt_iff_lt_mul hk).1 hlargeexact thishave hqm : ¬ q ∣ m := fun h => by have := Nat.le_of_dvd hm h; omegahave hqt : q ∣ n / m := (hq.dvd_mul.1 hqd).resolve_left hqmobtain ⟨s, hs⟩ := hqthave hle : m * (n / m) ≤ n := Nat.mul_div_le n mrw [hs] at hlehave hms : m * s < k := byby_contra hpush Not at hhave h1 : q * k ≤ q * (m * s) := Nat.mul_le_mul_left q hhave h2 : m * (q * s) = q * (m * s) := by ringomegahave hs2 : s < 2 := byby_contra hpush Not at hhave : m * 2 ≤ m * s := Nat.mul_le_mul_left m homegahave hpos : 0 < n / m := Nat.div_pos (by nlinarith) hmhave hs1 : s = 1 := byrcases Nat.lt_or_ge s 1 with h | h· have : s = 0 := by omegarw [this] at hs; omega· omegarw [hs1, mul_one] at hsexact hnp (hs ▸ hq)/-- **Structure of the multiples of `u`.** In an exception with `n ≥ k²`, for every `u` and every `s < k / u`,the term `u * (n / u - s)` is `k`-smooth, or `n / u - s = b * q` with `q` a prime `> n / k` and `u * b < k`. -/theorem exc_floor_struct {n k u s : ℕ} (he : (n, k) ∈ Exc) (hn2 : k * k ≤ n) (hs : s < k / u) :(∀ q : ℕ, q.Prime → q ∣ u * (n / u - s) → q ≤ k) ∨∃ q b : ℕ, q.Prime ∧ n / k < q ∧ n / u - s = b * q ∧ u * b < k := byby_contra hconpush Not at hconobtain ⟨⟨q, hq, hqd, hqk⟩, hno⟩ := hconhave hk : 0 < k := he.1have hu : 0 < u := byrcases Nat.eq_zero_or_pos u with h | h· subst h; simp at hs· exact hhave huk : u * (k / u) ≤ k := Nat.mul_div_le k uhave hus : u * s + u ≤ u * (k / u) := byhave : u * (s + 1) ≤ u * (k / u) := Nat.mul_le_mul_left u hslinarith [Nat.mul_succ u s]have hule : u ≤ k := by nlinarithhave hmod : n % u < u := Nat.mod_lt n huhave hdm := Nat.mod_add_div n uhave hkt : k ≤ n / u := byrw [Nat.le_div_iff_mul_le hu]nlinarithhave hsk : s < k := lt_of_lt_of_le hs (Nat.div_le_self k u)have hT : u * (n / u - s) = n - (n % u + u * s) := byrw [Nat.mul_sub]have : u * s ≤ u * (n / u) := Nat.mul_le_mul_left u (by omega)omegahave hlarge : n / k < q := byrcases exc_term_prime he (j := n % u + u * s) (by omega) hq (hT ▸ hqd) with h | h· omega· exact hhave hnq : n < q * k := (Nat.div_lt_iff_lt_mul hk).1 hlargehave hqu : ¬ q ∣ u := fun h => by have := Nat.le_of_dvd hu h; omegahave hqt : q ∣ n / u - s := (hq.dvd_mul.1 hqd).resolve_left hquobtain ⟨b, hb⟩ := hqthave h := hno q b hq hlarge (by rw [hb, Nat.mul_comm])have hle : u * (n / u - s) ≤ n := by rw [hT]; omegarw [hb] at hlehave h1 : q * k ≤ q * (u * b) := Nat.mul_le_mul_left q hhave h2 : u * (q * b) = q * (u * b) := by ringomegaend Erdos1093#print axioms Erdos1093.exc_floor_prime#print axioms Erdos1093.exc_floor_struct