| | @@ -0,0 +1,218 @@ |
| 1 | +import ErdosSwarm.Erdos530RowWindows |
| 2 | +import ErdosSwarm.Erdos30Lower |
| 3 | + |
| 4 | +/-! |
| 5 | +# The binary rows of Theorem 1 (Erdős Problem 530): the pullback lower bound |
| 6 | + |
| 7 | +Lean version of the lower-bound half of Theorem 1 of |
| 8 | +`experiments/erdos530/lower-middle-energy/NOTES.md` §1 for the rows |
| 9 | +`A_k = {2 L 2^i + j : i < k, j < L}`: "an equal sum in `A_k` has equal offset sums, which lie in |
| 10 | +`[0, 2L - 2]`, and then equal sums of two powers of two. Binary expansion determines the unordered |
| 11 | +row pair. Consequently `2 L 2^i + j ↦ i L + j` is a bijection onto `[0, k L)` preserving equal |
| 12 | +pair sums." |
| 13 | + |
| 14 | +* `two_pow_add_two_pow_inj`: `2^a + 2^b = 2^c + 2^d` determines the unordered pair `{a, b}`. |
| 15 | +* `binaryRows_sum_eq`: an equal pair sum in `A_k` has equal offset sums and the same unordered |
| 16 | + pair of rows. |
| 17 | +* `exists_sidon_binaryRows`: a Sidon set `T ⊆ [0, k L)` of integers pulls back to a Sidon subset |
| 18 | + of `A_k` of the same size. |
| 19 | +* `exists_sidon_binaryRows_card_h`: so `A_k` has a Sidon subset of size `h (k L)`, the largest |
| 20 | + size of a Sidon subset of `{1, …, k L}` (Formal Conjectures' `Erdos30.h`). |
| 21 | +* `exists_sidon_binaryRows_of_prime`: in particular one of size `p - 1` for every prime `p` with |
| 22 | + `(p - 1)² ≤ k L`. |
| 23 | +* `binaryRows_two_sided`: with `sidon_card_le_of_binaryRows`, the largest Sidon subset of `A_k` |
| 24 | + has size `s` with `p - 1 ≤ s ≤ √(k L) + √(k s)`. |
| 25 | + |
| 26 | +Status. These statements are Lean-checked. The asymptotic `s(A_k) = (1 + o(1)) √(k L)` for |
| 27 | +`k = o(L)` also needs primes `p ~ √(k L)` (the prime number theorem, not in this repository) and |
| 28 | +the quadratic step of (1) (task t-fbb0199375); it remains a paper proof. Erdős Problem 530 is |
| 29 | +open. |
| 30 | +-/ |
| 31 | + |
| 32 | +namespace ErdosSwarm.Erdos530RowWindows |
| 33 | + |
| 34 | +open Finset |
| 35 | + |
| 36 | +private theorem two_pow_aux {a b c d : ℕ} (hab : a ≤ b) (hcd : c ≤ d) (hac : a ≤ c) |
| 37 | + (h : 2 ^ a + 2 ^ b = 2 ^ c + 2 ^ d) : a = c ∧ b = d := by |
| 38 | + obtain ⟨x, rfl⟩ := Nat.exists_eq_add_of_le hab |
| 39 | + obtain ⟨y, rfl⟩ := Nat.exists_eq_add_of_le hac |
| 40 | + obtain ⟨z, rfl⟩ := Nat.exists_eq_add_of_le hcd |
| 41 | + have h' : 1 + 2 ^ x = 2 ^ y * (1 + 2 ^ z) := by |
| 42 | + have h2 : 2 ^ a * (1 + 2 ^ x) = 2 ^ a * (2 ^ y * (1 + 2 ^ z)) := by |
| 43 | + simp only [pow_add] at h |
| 44 | + linarith |
| 45 | + exact Nat.eq_of_mul_eq_mul_left (by positivity) h2 |
| 46 | + rcases Nat.eq_zero_or_pos y with rfl | hy |
| 47 | + · have hxz : 2 ^ x = 2 ^ z := by |
| 48 | + rw [pow_zero] at h' |
| 49 | + omega |
| 50 | + have := Nat.pow_right_injective (le_refl 2) hxz |
| 51 | + omega |
| 52 | + · exfalso |
| 53 | + obtain ⟨y', rfl⟩ := Nat.exists_eq_succ_of_ne_zero hy.ne' |
| 54 | + have hR : 2 ≤ 2 ^ y' * (1 + 2 ^ z) := by |
| 55 | + have h1 : 1 ≤ 2 ^ y' := Nat.one_le_two_pow |
| 56 | + have h2 : 1 ≤ 2 ^ z := Nat.one_le_two_pow |
| 57 | + nlinarith |
| 58 | + have h'' : 1 + 2 ^ x = 2 * (2 ^ y' * (1 + 2 ^ z)) := by |
| 59 | + rw [h', pow_succ] |
| 60 | + ring |
| 61 | + rcases Nat.eq_zero_or_pos x with rfl | hx |
| 62 | + · rw [pow_zero] at h'' |
| 63 | + omega |
| 64 | + · obtain ⟨x', rfl⟩ := Nat.exists_eq_succ_of_ne_zero hx.ne' |
| 65 | + rw [pow_succ] at h'' |
| 66 | + omega |
| 67 | + |
| 68 | +/-- A sum of two powers of two determines the unordered pair of exponents. -/ |
| 69 | +theorem two_pow_add_two_pow_inj {a b c d : ℕ} (h : 2 ^ a + 2 ^ b = 2 ^ c + 2 ^ d) : |
| 70 | + (a = c ∧ b = d) ∨ (a = d ∧ b = c) := by |
| 71 | + -- order each pair, then put the smallest exponent on the left |
| 72 | + wlog hab : a ≤ b generalizing a b |
| 73 | + · have := this (a := b) (b := a) (by omega) (by omega) |
| 74 | + tauto |
| 75 | + wlog hcd : c ≤ d generalizing c d |
| 76 | + · have := this (c := d) (d := c) (by omega) (by omega) |
| 77 | + tauto |
| 78 | + rcases le_total a c with hac | hca |
| 79 | + · exact Or.inl (two_pow_aux hab hcd hac h) |
| 80 | + · obtain ⟨h1, h2⟩ := two_pow_aux hcd hab hca h.symm |
| 81 | + exact Or.inl ⟨h1.symm, h2.symm⟩ |
| 82 | + |
| 83 | +/-- An equal pair sum in the binary rows `{2 L 2^i + j : j < L}` has equal offset sums and the |
| 84 | +same unordered pair of rows. -/ |
| 85 | +theorem binaryRows_sum_eq {L i₁ i₂ i₃ i₄ j₁ j₂ j₃ j₄ : ℕ} |
| 86 | + (h₁ : j₁ < L) (h₂ : j₂ < L) (h₃ : j₃ < L) (h₄ : j₄ < L) |
| 87 | + (h : 2 * L * 2 ^ i₁ + j₁ + (2 * L * 2 ^ i₂ + j₂) = 2 * L * 2 ^ i₃ + j₃ + (2 * L * 2 ^ i₄ + j₄)) : |
| 88 | + j₁ + j₂ = j₃ + j₄ ∧ ((i₁ = i₃ ∧ i₂ = i₄) ∨ (i₁ = i₄ ∧ i₂ = i₃)) := by |
| 89 | + have hL : 0 < 2 * L := by omega |
| 90 | + have e : (j₁ + j₂) + 2 * L * (2 ^ i₁ + 2 ^ i₂) = (j₃ + j₄) + 2 * L * (2 ^ i₃ + 2 ^ i₄) := by |
| 91 | + linarith |
| 92 | + have hmod := congrArg (· % (2 * L)) e |
| 93 | + simp only [Nat.add_mul_mod_self_left] at hmod |
| 94 | + rw [Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] at hmod |
| 95 | + refine ⟨hmod, two_pow_add_two_pow_inj (Nat.eq_of_mul_eq_mul_left hL ?_)⟩ |
| 96 | + omega |
| 97 | + |
| 98 | +/-- The row point of `t`: row `t / L`, offset `t % L`. -/ |
| 99 | +private def enc (L t : ℕ) : ℕ := 2 * L * 2 ^ (t / L) + t % L |
| 100 | + |
| 101 | +private theorem enc_sum {L t₁ t₂ t₃ t₄ : ℕ} (hL : 0 < L) |
| 102 | + (h : enc L t₁ + enc L t₂ = enc L t₃ + enc L t₄) : t₁ + t₂ = t₃ + t₄ := by |
| 103 | + obtain ⟨hj, hi⟩ := binaryRows_sum_eq (Nat.mod_lt _ hL) (Nat.mod_lt _ hL) (Nat.mod_lt _ hL) |
| 104 | + (Nat.mod_lt _ hL) h |
| 105 | + have e₁ := Nat.div_add_mod t₁ L |
| 106 | + have e₂ := Nat.div_add_mod t₂ L |
| 107 | + have e₃ := Nat.div_add_mod t₃ L |
| 108 | + have e₄ := Nat.div_add_mod t₄ L |
| 109 | + rcases hi with ⟨h1, h2⟩ | ⟨h1, h2⟩ |
| 110 | + · rw [h1] at e₁ |
| 111 | + rw [h2] at e₂ |
| 112 | + omega |
| 113 | + · rw [h1] at e₁ |
| 114 | + rw [h2] at e₂ |
| 115 | + omega |
| 116 | + |
| 117 | +/-- Pullback: a Sidon set of integers in `[0, k L)` gives a Sidon subset of the binary rows |
| 118 | +`{2 L 2^i + j : i < k, j < L}` of the same size. -/ |
| 119 | +theorem exists_sidon_binaryRows {k L : ℕ} (T : Finset ℕ) (hT : IsSidon (T : Set ℕ)) |
| 120 | + (hTsub : ∀ t ∈ T, t < k * L) : |
| 121 | + ∃ S : Finset ℝ, |
| 122 | + (∀ a ∈ S, ∃ i : ℕ, i < k ∧ ∃ j : ℕ, j < L ∧ a = 2 * (L : ℝ) * 2 ^ i + (j : ℝ)) ∧ |
| 123 | + IsSidon (S : Set ℝ) ∧ S.card = T.card := by |
| 124 | + rcases Nat.eq_zero_or_pos L with rfl | hL |
| 125 | + · refine ⟨∅, by simp, by simp [IsSidon], ?_⟩ |
| 126 | + rw [card_empty, eq_comm, card_eq_zero, eq_empty_iff_forall_notMem] |
| 127 | + intro t ht |
| 128 | + have := hTsub t ht |
| 129 | + omega |
| 130 | + have hinj : Set.InjOn (fun t : ℕ => ((enc L t : ℕ) : ℝ)) (T : Set ℕ) := by |
| 131 | + intro t _ t' _ htt |
| 132 | + have h1 : enc L t = enc L t' := Nat.cast_injective (R := ℝ) htt |
| 133 | + have := enc_sum hL (t₁ := t) (t₂ := t) (t₃ := t') (t₄ := t') (by omega) |
| 134 | + omega |
| 135 | + refine ⟨T.image fun t : ℕ => ((enc L t : ℕ) : ℝ), ?_, ?_, card_image_of_injOn hinj⟩ |
| 136 | + · intro a ha |
| 137 | + obtain ⟨t, ht, rfl⟩ := mem_image.mp ha |
| 138 | + refine ⟨t / L, Nat.div_lt_of_lt_mul (by rw [mul_comm]; exact hTsub t ht), t % L, |
| 139 | + Nat.mod_lt _ hL, ?_⟩ |
| 140 | + simp only [enc] |
| 141 | + push_cast |
| 142 | + ring |
| 143 | + · intro a₁ ha₁ a₃ ha₃ a₂ ha₂ a₄ ha₄ hsum |
| 144 | + obtain ⟨t₁, ht₁, rfl⟩ := mem_image.mp (mem_coe.mp ha₁) |
| 145 | + obtain ⟨t₂, ht₂, rfl⟩ := mem_image.mp (mem_coe.mp ha₂) |
| 146 | + obtain ⟨t₃, ht₃, rfl⟩ := mem_image.mp (mem_coe.mp ha₃) |
| 147 | + obtain ⟨t₄, ht₄, rfl⟩ := mem_image.mp (mem_coe.mp ha₄) |
| 148 | + have hnat : enc L t₁ + enc L t₂ = enc L t₃ + enc L t₄ := by exact_mod_cast hsum |
| 149 | + rcases hT t₁ (mem_coe.mpr ht₁) t₃ (mem_coe.mpr ht₃) t₂ (mem_coe.mpr ht₂) t₄ (mem_coe.mpr ht₄) |
| 150 | + (enc_sum hL hnat) with ⟨h1, h2⟩ | ⟨h1, h2⟩ |
| 151 | + · exact Or.inl ⟨by rw [h1], by rw [h2]⟩ |
| 152 | + · exact Or.inr ⟨by rw [h1], by rw [h2]⟩ |
| 153 | + |
| 154 | +/-- The binary rows `{2 L 2^i + j : i < k, j < L}` have a Sidon subset of size `h (k L)`, where |
| 155 | +`h N` is the largest size of a Sidon subset of `{1, …, N}`. -/ |
| 156 | +theorem exists_sidon_binaryRows_card_h (k L : ℕ) : |
| 157 | + ∃ S : Finset ℝ, |
| 158 | + (∀ a ∈ S, ∃ i : ℕ, i < k ∧ ∃ j : ℕ, j < L ∧ a = 2 * (L : ℝ) * 2 ^ i + (j : ℝ)) ∧ |
| 159 | + IsSidon (S : Set ℝ) ∧ S.card = _root_.Erdos30.h (k * L) := by |
| 160 | + obtain ⟨F, hF, hS, hcard⟩ := ErdosSwarm.Erdos30.exists_eq_h (k * L) |
| 161 | + have hinj : Set.InjOn (fun t : ℕ => t - 1) (F : Set ℕ) := by |
| 162 | + intro t ht t' ht' htt |
| 163 | + have h1 := (mem_Icc.mp (hF (mem_coe.mp ht))).1 |
| 164 | + have h2 := (mem_Icc.mp (hF (mem_coe.mp ht'))).1 |
| 165 | + have htt' : t - 1 = t' - 1 := htt |
| 166 | + omega |
| 167 | + have hTS : IsSidon ((F.image fun t : ℕ => t - 1 : Finset ℕ) : Set ℕ) := by |
| 168 | + intro a₁ ha₁ a₃ ha₃ a₂ ha₂ a₄ ha₄ hsum |
| 169 | + obtain ⟨t₁, ht₁, rfl⟩ := mem_image.mp (mem_coe.mp ha₁) |
| 170 | + obtain ⟨t₂, ht₂, rfl⟩ := mem_image.mp (mem_coe.mp ha₂) |
| 171 | + obtain ⟨t₃, ht₃, rfl⟩ := mem_image.mp (mem_coe.mp ha₃) |
| 172 | + obtain ⟨t₄, ht₄, rfl⟩ := mem_image.mp (mem_coe.mp ha₄) |
| 173 | + have h1 := (mem_Icc.mp (hF ht₁)).1 |
| 174 | + have h2 := (mem_Icc.mp (hF ht₂)).1 |
| 175 | + have h3 := (mem_Icc.mp (hF ht₃)).1 |
| 176 | + have h4 := (mem_Icc.mp (hF ht₄)).1 |
| 177 | + rcases hS t₁ (mem_coe.mpr ht₁) t₃ (mem_coe.mpr ht₃) t₂ (mem_coe.mpr ht₂) t₄ (mem_coe.mpr ht₄) |
| 178 | + (by omega) with ⟨e1, e2⟩ | ⟨e1, e2⟩ |
| 179 | + · exact Or.inl ⟨by rw [e1], by rw [e2]⟩ |
| 180 | + · exact Or.inr ⟨by rw [e1], by rw [e2]⟩ |
| 181 | + have hTsub : ∀ a ∈ F.image fun t : ℕ => t - 1, a < k * L := by |
| 182 | + intro a ha |
| 183 | + obtain ⟨t, ht, rfl⟩ := mem_image.mp ha |
| 184 | + have := mem_Icc.mp (hF ht) |
| 185 | + omega |
| 186 | + obtain ⟨S, hcover, hSidon, hScard⟩ := exists_sidon_binaryRows _ hTS hTsub |
| 187 | + exact ⟨S, hcover, hSidon, by rw [hScard, card_image_of_injOn hinj, hcard]⟩ |
| 188 | + |
| 189 | +/-- The binary rows have a Sidon subset of size `p - 1` for every prime `p` with |
| 190 | +`(p - 1)² ≤ k L` (the note's Ruzsa-type lower bound, through the accepted |
| 191 | +`ErdosSwarm.Erdos30.pred_prime_le_h_sq`). -/ |
| 192 | +theorem exists_sidon_binaryRows_of_prime {k L p : ℕ} (hp : p.Prime) (hpk : (p - 1) ^ 2 ≤ k * L) : |
| 193 | + ∃ S : Finset ℝ, |
| 194 | + (∀ a ∈ S, ∃ i : ℕ, i < k ∧ ∃ j : ℕ, j < L ∧ a = 2 * (L : ℝ) * 2 ^ i + (j : ℝ)) ∧ |
| 195 | + IsSidon (S : Set ℝ) ∧ S.card = p - 1 := by |
| 196 | + obtain ⟨S, hcover, hSidon, hScard⟩ := exists_sidon_binaryRows_card_h k L |
| 197 | + have hle : p - 1 ≤ S.card := by |
| 198 | + rw [hScard] |
| 199 | + exact (ErdosSwarm.Erdos30.pred_prime_le_h_sq p hp).trans (ErdosSwarm.Erdos30.h_mono hpk) |
| 200 | + obtain ⟨S', hS'sub, hS'card⟩ := exists_subset_card_eq hle |
| 201 | + exact ⟨S', fun a ha => hcover a (hS'sub ha), |
| 202 | + Set.IsSidon.subset hSidon (coe_subset.mpr hS'sub), hS'card⟩ |
| 203 | + |
| 204 | +/-- Theorem 1 for the binary rows, both sides: for a prime `p` with `(p - 1)² ≤ k L` there is a |
| 205 | +Sidon subset `S` of `{2 L 2^i + j : i < k, j < L}` with `p - 1 ≤ |S|`, and every Sidon subset |
| 206 | +has `|S| ≤ √(k L) + √(k |S|)`. -/ |
| 207 | +theorem binaryRows_two_sided {k L p : ℕ} (hp : p.Prime) (hpk : (p - 1) ^ 2 ≤ k * L) : |
| 208 | + (∃ S : Finset ℝ, |
| 209 | + (∀ a ∈ S, ∃ i : ℕ, i < k ∧ ∃ j : ℕ, j < L ∧ a = 2 * (L : ℝ) * 2 ^ i + (j : ℝ)) ∧ |
| 210 | + IsSidon (S : Set ℝ) ∧ p - 1 ≤ S.card) ∧ |
| 211 | + ∀ S : Finset ℝ, |
| 212 | + (∀ a ∈ S, ∃ i : ℕ, i < k ∧ ∃ j : ℕ, j < L ∧ a = 2 * (L : ℝ) * 2 ^ i + (j : ℝ)) → |
| 213 | + IsSidon (S : Set ℝ) → (S.card : ℝ) ≤ Real.sqrt (k * L) + Real.sqrt (k * S.card) := by |
| 214 | + refine ⟨?_, fun S hsub hS => sidon_card_le_of_binaryRows S hS hsub⟩ |
| 215 | + obtain ⟨S, hcover, hSidon, hScard⟩ := exists_sidon_binaryRows_of_prime hp hpk |
| 216 | + exact ⟨S, hcover, hSidon, hScard.ge⟩ |
| 217 | + |
| 218 | +end ErdosSwarm.Erdos530RowWindows |