| | @@ -1,5 +1,6 @@ |
| 1 | 1 | import FormalConjectures.ErdosProblems.«30» |
| 2 | 2 | import ErdosSwarm.Erdos329 |
| 3 | +import ErdosSwarm.Erdos30Energy |
| 3 | 4 | |
| 4 | 5 | /-! |
| 5 | 6 | # Erdős Problem 30: bounds about `h N`, the largest Sidon subset size of `[1, N]` |
| | @@ -128,4 +129,55 @@ theorem h_ge_sqrt : ∃ c : ℝ, 0 < c ∧ ∀ᶠ N : ℕ in Filter.atTop, c * R |
| 128 | 129 | nlinarith [sq_nonneg (h N : ℝ)] |
| 129 | 130 | linarith |
| 130 | 131 | |
| 132 | +/-- Erdős–Turán window inequality: for a Sidon `A ⊆ [1, N]` and `u ≥ 1`, |
| 133 | +`|A|² u ≤ (N + u - 1)(|A| + u - 1)`. -/ |
| 134 | +theorem window_bound {A : Finset ℕ} {N u : ℕ} (hS : IsSidon (A : Set ℕ)) |
| 135 | + (hA : A ⊆ Finset.Icc 1 N) (hu : 1 ≤ u) : |
| 136 | + A.card ^ 2 * u ≤ (N + u - 1) * (A.card + u - 1) := by |
| 137 | + rcases A.eq_empty_or_nonempty with rfl | hne |
| 138 | + · simp |
| 139 | + set M := A.sup id with hM |
| 140 | + have hMN : M ≤ N := Finset.sup_le fun a ha => (Finset.mem_Icc.mp (hA ha)).2 |
| 141 | + have hM1 : 1 ≤ M := by |
| 142 | + obtain ⟨a, ha⟩ := hne |
| 143 | + exact le_trans (Finset.mem_Icc.mp (hA ha)).1 (Finset.le_sup (f := id) ha) |
| 144 | + set c : ℤ → ℤ := fun x => ((A.filter fun a : ℕ => x < a ∧ (a : ℤ) ≤ x + u).card : ℤ) with hc |
| 145 | + set W := Finset.Icc (-(u : ℤ)) (M : ℤ) with hW |
| 146 | + set S := Finset.Icc (1 - (u : ℤ)) ((M : ℤ) - 1) with hSdef |
| 147 | + have hSW : S ⊆ W := by |
| 148 | + intro x hx; simp only [hSdef, hW, Finset.mem_Icc] at hx ⊢; omega |
| 149 | + have hzero : ∀ x ∈ W, x ∉ S → c x = 0 := by |
| 150 | + intro x hx hxS |
| 151 | + simp only [hSdef, hW, Finset.mem_Icc] at hx hxS |
| 152 | + simp only [hc, Nat.cast_eq_zero, Finset.card_eq_zero, Finset.filter_eq_empty_iff] |
| 153 | + intro a ha |
| 154 | + have h1 := (Finset.mem_Icc.mp (hA ha)).1 |
| 155 | + have h2 : a ≤ M := Finset.le_sup (f := id) ha |
| 156 | + omega |
| 157 | + have hsum : ∑ x ∈ S, c x = A.card * u := by |
| 158 | + rw [Finset.sum_subset hSW hzero]; exact sum_window_card A u |
| 159 | + have hen : ∑ x ∈ S, c x ^ 2 ≤ A.card * u + u * (u - 1) := by |
| 160 | + refine le_trans (Finset.sum_le_sum_of_subset_of_nonneg hSW (fun _ _ _ => sq_nonneg _)) ?_ |
| 161 | + exact window_energy_le A hS u hu |
| 162 | + have hcs := sq_sum_le_card_mul_sum_sq (s := S) (f := c) |
| 163 | + rw [hsum, hSdef, Int.card_Icc] at hcs |
| 164 | + have hcard : (((M : ℤ) - 1 + 1 - (1 - (u : ℤ))).toNat : ℤ) = M + u - 1 := by omega |
| 165 | + rw [hcard] at hcs |
| 166 | + have hk : (0:ℤ) ≤ A.card := by positivity |
| 167 | + have hmul : ((M:ℤ) + u - 1) * (∑ x ∈ S, c x ^ 2) ≤ ((N:ℤ) + u - 1) * (A.card * u + u * (u - 1)) := by |
| 168 | + have h1 : (0:ℤ) ≤ (M:ℤ) + u - 1 := by omega |
| 169 | + have h2 : (0:ℤ) ≤ A.card * u + u * (u - 1) := by |
| 170 | + have : (1:ℤ) ≤ u := by exact_mod_cast hu |
| 171 | + nlinarith |
| 172 | + calc _ ≤ ((M:ℤ) + u - 1) * (A.card * u + u * (u - 1)) := mul_le_mul_of_nonneg_left hen h1 |
| 173 | + _ ≤ _ := mul_le_mul_of_nonneg_right (by omega) h2 |
| 174 | + have key : ((A.card : ℤ) ^ 2 * u) * u ≤ (((N:ℤ) + u - 1) * (A.card + u - 1)) * u := by |
| 175 | + nlinarith |
| 176 | + have hu0 : (0:ℤ) < u := by exact_mod_cast hu |
| 177 | + have := le_of_mul_le_mul_right key hu0 |
| 178 | + have e1 : ((N + u - 1 : ℕ) : ℤ) = N + u - 1 := by omega |
| 179 | + have e2 : ((A.card + u - 1 : ℕ) : ℤ) = A.card + u - 1 := by omega |
| 180 | + zify [e1, e2] |
| 181 | + · exact this |
| 182 | + |
| 131 | 183 | end ErdosSwarm.Erdos30 |