| | @@ -0,0 +1,169 @@ |
| 1 | +import FormalConjectures.ErdosProblems.«1055» |
| 2 | +import Mathlib.NumberTheory.LSeries.PrimesInAP |
| 3 | + |
| 4 | +/-! Every positive class in Erdős problem 1055 contains a prime. -/ |
| 5 | + |
| 6 | +namespace ErdosSwarm.Erdos1055 |
| 7 | + |
| 8 | +open _root_.Erdos1055 (IsOfClass) |
| 9 | + |
| 10 | +private theorem class_one {p : ℕ} : |
| 11 | + IsOfClass 1 p ↔ (p + 1).primeFactors ⊆ {2, 3} := by |
| 12 | + unfold IsOfClass PNat.caseStrongInductionOn |
| 13 | + rw [PNat.strongInductionOn] |
| 14 | + rfl |
| 15 | + |
| 16 | +private theorem two_class_one : IsOfClass 1 2 := by |
| 17 | + apply class_one.mpr |
| 18 | + change (3 : ℕ).primeFactors ⊆ {2, 3} |
| 19 | + rw [Nat.prime_three.primeFactors] |
| 20 | + simp |
| 21 | + |
| 22 | +private theorem three_class_one : IsOfClass 1 3 := by |
| 23 | + apply class_one.mpr |
| 24 | + change ((2 : ℕ) ^ 2).primeFactors ⊆ {2, 3} |
| 25 | + rw [Nat.primeFactors_prime_pow (by decide) Nat.prime_two] |
| 26 | + simp |
| 27 | + |
| 28 | +private theorem five_class_one : IsOfClass 1 5 := by |
| 29 | + apply class_one.mpr |
| 30 | + change ((2 : ℕ) * 3).primeFactors ⊆ {2, 3} |
| 31 | + rw [Nat.primeFactors_mul (by decide) (by decide)] |
| 32 | + simp [Nat.prime_two.primeFactors, Nat.prime_three.primeFactors] |
| 33 | + |
| 34 | +private theorem class_succ {n : ℕ+} {p : ℕ} : |
| 35 | + IsOfClass (n + 1) p ↔ |
| 36 | + (∀ m : ℕ+, m ≤ n → ¬ IsOfClass m p) ∧ |
| 37 | + (∀ q ∈ (p + 1).primeFactors, ∃ m : ℕ+, m ≤ n ∧ IsOfClass m q) ∧ |
| 38 | + (∃ q ∈ (p + 1).primeFactors, ∀ m : ℕ+, m ≤ n → IsOfClass m q → m = n) := by |
| 39 | + obtain ⟨n, hn⟩ := n |
| 40 | + cases n with |
| 41 | + | zero => omega |
| 42 | + | succ n => |
| 43 | + let k : ℕ+ := ⟨n + 1, hn⟩ |
| 44 | + have unroll : |
| 45 | + IsOfClass (k + 1) p ↔ |
| 46 | + (∀ (m : ℕ+) (_ : m ≤ k), ¬ IsOfClass m p) ∧ |
| 47 | + (∀ q ∈ (p + 1).primeFactors, |
| 48 | + ∃ (m : ℕ+) (_ : m ≤ k), IsOfClass m q) ∧ |
| 49 | + (∃ q ∈ (p + 1).primeFactors, |
| 50 | + ∀ (m : ℕ+) (_ : m ≤ k), IsOfClass m q → m = k) := by |
| 51 | + conv_lhs => |
| 52 | + unfold IsOfClass PNat.caseStrongInductionOn |
| 53 | + rw [PNat.strongInductionOn] |
| 54 | + rfl |
| 55 | + simpa only [exists_prop] using unroll |
| 56 | + |
| 57 | +private theorem class_unique {i j : ℕ+} {p : ℕ} |
| 58 | + (hi : IsOfClass i p) (hj : IsOfClass j p) : i = j := by |
| 59 | + have not_lt {a b : ℕ+} (ha : IsOfClass a p) (hb : IsOfClass b p) : ¬ a < b := by |
| 60 | + revert hb |
| 61 | + induction b using PNat.recOn with |
| 62 | + | one => exact fun _ h => (not_lt_of_ge (bot_le (a := a))) h |
| 63 | + | succ n _ => |
| 64 | + exact fun h hlt => (class_succ.mp h).1 a (PNat.lt_add_one_iff.mp hlt) ha |
| 65 | + exact le_antisymm (le_of_not_gt (not_lt hj hi)) (le_of_not_gt (not_lt hi hj)) |
| 66 | + |
| 67 | +private theorem factor_lt {p q : ℕ} (hp : p.Prime) (h₂ : p ≠ 2) |
| 68 | + (hq : q ∈ (p + 1).primeFactors) : q < p := by |
| 69 | + obtain ⟨hqprime, hqdvd, _⟩ := Nat.mem_primeFactors.mp hq |
| 70 | + have hle := Nat.le_of_dvd (Nat.succ_pos p) hqdvd |
| 71 | + have hne : q ≠ p := by |
| 72 | + intro heq |
| 73 | + subst q |
| 74 | + have := Nat.dvd_sub hqdvd (dvd_refl p) |
| 75 | + have hone : p ∣ 1 := by simpa using this |
| 76 | + exact hp.ne_one (Nat.dvd_one.mp hone) |
| 77 | + have hne' : q ≠ p + 1 := by |
| 78 | + intro heq |
| 79 | + subst q |
| 80 | + rcases hqprime.eq_two_or_odd with h | h |
| 81 | + · have := hp.two_le |
| 82 | + omega |
| 83 | + · have hodd := (hp.eq_two_or_odd.resolve_left h₂) |
| 84 | + omega |
| 85 | + omega |
| 86 | + |
| 87 | +private theorem has_class (p : ℕ) (hp : p.Prime) : ∃ n : ℕ+, IsOfClass n p := by |
| 88 | + classical |
| 89 | + induction p using Nat.strong_induction_on with |
| 90 | + | h p ih => |
| 91 | + by_cases hbase : IsOfClass 1 p |
| 92 | + · exact ⟨1, hbase⟩ |
| 93 | + have hp₂ : p ≠ 2 := by |
| 94 | + rintro rfl |
| 95 | + exact hbase two_class_one |
| 96 | + let factors := (p + 1).primeFactors |
| 97 | + let rank (q : ℕ) := if hq : q ∈ factors then |
| 98 | + (ih q (factor_lt hp hp₂ hq) (Nat.mem_primeFactors.mp hq).1).choose else 1 |
| 99 | + have hrank (q : ℕ) (hq : q ∈ factors) : IsOfClass (rank q) q := by |
| 100 | + simpa only [rank, dif_pos hq] using |
| 101 | + (ih q (factor_lt hp hp₂ hq) (Nat.mem_primeFactors.mp hq).1).choose_spec |
| 102 | + have hnonempty : factors.Nonempty := by |
| 103 | + by_contra h |
| 104 | + exact hbase (class_one.mpr (by simp [factors, Finset.not_nonempty_iff_eq_empty.mp h])) |
| 105 | + obtain ⟨q, hq, hmax⟩ := factors.exists_max_image rank hnonempty |
| 106 | + refine ⟨rank q + 1, class_succ.mpr ⟨?_, ?_, ?_⟩⟩ |
| 107 | + · intro m hm hmp |
| 108 | + induction m using PNat.recOn with |
| 109 | + | one => exact hbase hmp |
| 110 | + | succ k _ => |
| 111 | + obtain ⟨j, hj, hclass⟩ := (class_succ.mp hmp).2.1 q hq |
| 112 | + have heq := class_unique hclass (hrank q hq) |
| 113 | + exact (not_lt_of_ge hm) (PNat.lt_add_one_iff.mpr (heq ▸ hj)) |
| 114 | + · exact fun a ha => ⟨rank a, hmax a ha, hrank a ha⟩ |
| 115 | + · exact ⟨q, hq, fun m _ hm => class_unique hm (hrank q hq)⟩ |
| 116 | + |
| 117 | +private theorem exists_class_of_le (k : ℕ+) (n : ℕ+) (hn : k ≤ n) |
| 118 | + (p : ℕ) (hp : p.Prime) (hc : IsOfClass n p) : |
| 119 | + ∃ q, q.Prime ∧ IsOfClass k q := by |
| 120 | + induction n using PNat.recOn generalizing p with |
| 121 | + | one => |
| 122 | + have : k = 1 := le_antisymm hn bot_le |
| 123 | + exact ⟨p, hp, this.symm ▸ hc⟩ |
| 124 | + | succ n ih => |
| 125 | + rcases eq_or_lt_of_le hn with heq | hlt |
| 126 | + · exact ⟨p, hp, heq.symm ▸ hc⟩ |
| 127 | + obtain ⟨q, hq, htop⟩ := (class_succ.mp hc).2.2 |
| 128 | + obtain ⟨j, hj, hclass⟩ := (class_succ.mp hc).2.1 q hq |
| 129 | + have hclass' : IsOfClass n q := htop j hj hclass ▸ hclass |
| 130 | + exact ih (PNat.lt_add_one_iff.mp hlt) q (Nat.mem_primeFactors.mp hq).1 hclass' |
| 131 | + |
| 132 | +theorem exists_prime_of_class (r : ℕ+) : ∃ p, p.Prime ∧ IsOfClass r p := by |
| 133 | + suffices ∃ p > 3, p.Prime ∧ IsOfClass r p by |
| 134 | + obtain ⟨p, _, hp, hc⟩ := this |
| 135 | + exact ⟨p, hp, hc⟩ |
| 136 | + induction r using PNat.recOn with |
| 137 | + | one => exact ⟨5, by decide, by decide, five_class_one⟩ |
| 138 | + | succ r ih => |
| 139 | + obtain ⟨q, hq, hqprime, hclass⟩ := ih |
| 140 | + have hcoprime : IsCoprime (-1 : ℤ) (q : ℤ) := |
| 141 | + ⟨-1, 0, by ring⟩ |
| 142 | + obtain ⟨p, _, hp, hmod⟩ := Nat.forall_exists_prime_gt_and_zmodEq q hqprime.ne_zero hcoprime |
| 143 | + have hdvd : q ∣ p + 1 := by |
| 144 | + have h := Int.modEq_iff_dvd.mp hmod.symm |
| 145 | + have heq : (p : ℤ) - (-1) = ((p + 1 : ℕ) : ℤ) := by push_cast; ring |
| 146 | + rw [heq] at h |
| 147 | + exact_mod_cast h |
| 148 | + have hqmem : q ∈ (p + 1).primeFactors := |
| 149 | + Nat.mem_primeFactors.mpr ⟨hqprime, hdvd, by omega⟩ |
| 150 | + obtain ⟨k, hk⟩ := has_class p hp |
| 151 | + have hle : r + 1 ≤ k := by |
| 152 | + cases k using PNat.recOn with |
| 153 | + | one => |
| 154 | + have h := class_one.mp hk hqmem |
| 155 | + simp at h |
| 156 | + omega |
| 157 | + | succ k => |
| 158 | + obtain ⟨j, hj, hclass'⟩ := (class_succ.mp hk).2.1 q hqmem |
| 159 | + have heq := class_unique hclass' hclass |
| 160 | + exact add_le_add_left (heq ▸ hj) 1 |
| 161 | + obtain ⟨a, ha, hac⟩ := exists_class_of_le (r + 1) k hle p hp hk |
| 162 | + refine ⟨a, ?_, ha, hac⟩ |
| 163 | + have hne : r + 1 ≠ 1 := ne_of_gt (PNat.lt_add_one_iff.mpr (bot_le : 1 ≤ r)) |
| 164 | + have h₂ : a ≠ 2 := fun h => hne (class_unique (h ▸ hac) two_class_one) |
| 165 | + have h₃ : a ≠ 3 := fun h => hne (class_unique (h ▸ hac) three_class_one) |
| 166 | + have := ha.two_le |
| 167 | + omega |
| 168 | + |
| 169 | +end ErdosSwarm.Erdos1055 |