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

Kwas/Erdos1094Struct.lean

149 lines5 declarationsno sorryimports Kwas.Erdos1093

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.

  1. import Kwas.Erdos1093
  2. /-! Erdős Problem 1094: Struct (continues namespace Erdos1093). -/
  3. namespace Erdos1093
  4. /-! ## Structure of an exception of Erdős problem 1094 -/
  5. /-- **Residue windows.** For an exception `(n, k)` and every prime `q ≤ max (n / k) k`: `k mod q ≤ n mod q`.
  6. For `k < q ≤ n / k` this reads `k ≤ n mod q`; for `k / 2 < q ≤ k` it reads `k - q ≤ n mod q`. -/
  7. theorem exc_mod_le {n k q : ℕ} (he : (n, k) ∈ Exc) (hq : q.Prime) (hle : q ≤ max (n / k) k) :
  8. k % q ≤ n % q := by
  9. obtain ⟨-, -, hmin⟩ := he
  10. have hnd : ¬ q ∣ n.choose k := by
  11. intro hd
  12. have := Nat.minFac_le_of_dvd hq.two_le hd
  13. omega
  14. have hpass := (not_dvd_choose_iff_passes hq k n).1 hnd
  15. have := passes_mod_pow hq.two_le 1 n k hpass
  16. simpa using this
  17. /-- **Every term is (`k`-smooth) × (primes above `n / k`).** For an exception `(n, k)`, a prime dividing one of
  18. `n, n - 1, …, n - k + 1` is either `≤ k` or `> n / k`. -/
  19. theorem exc_term_prime {n k j q : ℕ} (he : (n, k) ∈ Exc) (hj : j < k) (hq : q.Prime) (hd : q ∣ n - j) :
  20. q ≤ k ∨ n / k < q := by
  21. by_contra hcon
  22. push Not at hcon
  23. obtain ⟨hk, hn, hmin⟩ := he
  24. have hterm : q ∣ n.descFactorial k := by
  25. rw [Nat.descFactorial_eq_prod_range]
  26. exact dvd_trans hd (Finset.dvd_prod_of_mem _ (Finset.mem_range.2 hj))
  27. rw [Nat.descFactorial_eq_factorial_mul_choose] at hterm
  28. have hc : q ∣ n.choose k := by
  29. rcases (hq.dvd_mul).1 hterm with h1 | h1
  30. · exact absurd ((hq.dvd_factorial).1 h1) (by omega)
  31. · exact h1
  32. have := Nat.minFac_le_of_dvd hq.two_le hc
  33. have := le_max_left (n / k) k
  34. omega
  35. /-- For an exception with `n ≥ k^2`, a term has at most one prime factor above `n / k` (two would exceed `n`):
  36. if primes `q₁ q₂ > n / k` satisfy `q₁ * q₂ ∣ n - j`, contradiction. -/
  37. theorem exc_term_one_large {n k j q₁ q₂ : ℕ} (he : (n, k) ∈ Exc) (hn2 : k ^ 2 ≤ n) (hjn : j < n)
  38. (h1 : n / k < q₁) (h2 : n / k < q₂) (hd : q₁ * q₂ ∣ n - j) : False := by
  39. obtain ⟨hk, hn, -⟩ := he
  40. have hle : q₁ * q₂ ≤ n - j := Nat.le_of_dvd (by omega) hd
  41. have hq : (n / k + 1) * (n / k + 1) ≤ q₁ * q₂ := Nat.mul_le_mul h1 h2
  42. have hkk : k ≤ n / k := by
  43. rw [Nat.le_div_iff_mul_le hk]
  44. nlinarith [hn2]
  45. have hlt : n < k * (n / k + 1) := by
  46. have := Nat.div_add_mod n k
  47. have := Nat.mod_lt n hk
  48. nlinarith
  49. have : k * (n / k + 1) ≤ (n / k + 1) * (n / k + 1) := Nat.mul_le_mul_right _ (by omega)
  50. omega
  51. /-- **Floor-prime theorem.** In an exception of Erdős 1094 with `n ≥ k²`, for every `m` with `k/2 < m ≤ k`
  52. the quotient `n / m` is a prime, unless the term `m * (n / m)` is `k`-smooth. -/
  53. theorem exc_floor_prime {n k m : ℕ} (he : (n, k) ∈ Exc) (hn2 : k * k ≤ n) (hm1 : k < 2 * m)
  54. (hm2 : m ≤ k) : (n / m).Prime ∨ ∀ q : ℕ, q.Prime → q ∣ m * (n / m) → q ≤ k := by
  55. by_contra hcon
  56. push Not at hcon
  57. obtain ⟨hnp, q, hq, hqd, hqk⟩ := hcon
  58. have hk : 0 < k := he.1
  59. have hm : 0 < m := by omega
  60. have hmod : n % m < m := Nat.mod_lt n hm
  61. have hT : m * (n / m) = n - n % m := by have := Nat.mod_add_div n m; omega
  62. have hlarge : n / k < q := by
  63. rcases exc_term_prime he (j := n % m) (by omega) hq (hT ▸ hqd) with h | h
  64. · omega
  65. · exact h
  66. have hnq : n < q * k := by
  67. have := (Nat.div_lt_iff_lt_mul hk).1 hlarge
  68. exact this
  69. have hqm : ¬ q ∣ m := fun h => by have := Nat.le_of_dvd hm h; omega
  70. have hqt : q ∣ n / m := (hq.dvd_mul.1 hqd).resolve_left hqm
  71. obtain ⟨s, hs⟩ := hqt
  72. have hle : m * (n / m) ≤ n := Nat.mul_div_le n m
  73. rw [hs] at hle
  74. have hms : m * s < k := by
  75. by_contra h
  76. push Not at h
  77. have h1 : q * k ≤ q * (m * s) := Nat.mul_le_mul_left q h
  78. have h2 : m * (q * s) = q * (m * s) := by ring
  79. omega
  80. have hs2 : s < 2 := by
  81. by_contra h
  82. push Not at h
  83. have : m * 2 ≤ m * s := Nat.mul_le_mul_left m h
  84. omega
  85. have hpos : 0 < n / m := Nat.div_pos (by nlinarith) hm
  86. have hs1 : s = 1 := by
  87. rcases Nat.lt_or_ge s 1 with h | h
  88. · have : s = 0 := by omega
  89. rw [this] at hs; omega
  90. · omega
  91. rw [hs1, mul_one] at hs
  92. exact hnp (hs ▸ hq)
  93. /-- **Structure of the multiples of `u`.** In an exception with `n ≥ k²`, for every `u` and every `s < k / u`,
  94. 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`. -/
  95. theorem exc_floor_struct {n k u s : ℕ} (he : (n, k) ∈ Exc) (hn2 : k * k ≤ n) (hs : s < k / u) :
  96. (∀ q : ℕ, q.Prime → q ∣ u * (n / u - s) → q ≤ k) ∨
  97. ∃ q b : ℕ, q.Prime ∧ n / k < q ∧ n / u - s = b * q ∧ u * b < k := by
  98. by_contra hcon
  99. push Not at hcon
  100. obtain ⟨⟨q, hq, hqd, hqk⟩, hno⟩ := hcon
  101. have hk : 0 < k := he.1
  102. have hu : 0 < u := by
  103. rcases Nat.eq_zero_or_pos u with h | h
  104. · subst h; simp at hs
  105. · exact h
  106. have huk : u * (k / u) ≤ k := Nat.mul_div_le k u
  107. have hus : u * s + u ≤ u * (k / u) := by
  108. have : u * (s + 1) ≤ u * (k / u) := Nat.mul_le_mul_left u hs
  109. linarith [Nat.mul_succ u s]
  110. have hule : u ≤ k := by nlinarith
  111. have hmod : n % u < u := Nat.mod_lt n hu
  112. have hdm := Nat.mod_add_div n u
  113. have hkt : k ≤ n / u := by
  114. rw [Nat.le_div_iff_mul_le hu]
  115. nlinarith
  116. have hsk : s < k := lt_of_lt_of_le hs (Nat.div_le_self k u)
  117. have hT : u * (n / u - s) = n - (n % u + u * s) := by
  118. rw [Nat.mul_sub]
  119. have : u * s ≤ u * (n / u) := Nat.mul_le_mul_left u (by omega)
  120. omega
  121. have hlarge : n / k < q := by
  122. rcases exc_term_prime he (j := n % u + u * s) (by omega) hq (hT ▸ hqd) with h | h
  123. · omega
  124. · exact h
  125. have hnq : n < q * k := (Nat.div_lt_iff_lt_mul hk).1 hlarge
  126. have hqu : ¬ q ∣ u := fun h => by have := Nat.le_of_dvd hu h; omega
  127. have hqt : q ∣ n / u - s := (hq.dvd_mul.1 hqd).resolve_left hqu
  128. obtain ⟨b, hb⟩ := hqt
  129. have h := hno q b hq hlarge (by rw [hb, Nat.mul_comm])
  130. have hle : u * (n / u - s) ≤ n := by rw [hT]; omega
  131. rw [hb] at hle
  132. have h1 : q * k ≤ q * (u * b) := Nat.mul_le_mul_left q h
  133. have h2 : u * (q * b) = q * (u * b) := by ring
  134. omega
  135. end Erdos1093
  136. #print axioms Erdos1093.exc_floor_prime
  137. #print axioms Erdos1093.exc_floor_struct