| | @@ -0,0 +1,207 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap78.Data |
| 2 | + |
| 3 | +/-! |
| 4 | +# The missing energy for the 77/78 kernel (brief A2 of `Erdos530Gap78/PLAN.md`) |
| 5 | + |
| 6 | +`upper-smaller-k2/NOTES.md` §1, the display before (2): for a Sidon set `S ⊆ [1, M]`, |
| 7 | + |
| 8 | +`2 Q + ∑_{a, a' ∈ S} W(u_a − u_{a'}) ≤ M/32 + |S| W(0)`. |
| 9 | + |
| 10 | +The proof of `Erdos530Gap103.missing_energy` is generalised here over the kernel |
| 11 | +(`missing_energy_of_kernel`): it uses only that `W` is even and that the right-endpoint sum |
| 12 | +`∑_{d=1}^{M} W(32 d/M)` is at most `M/64`. By Sidon uniqueness the double sum is `|S| W(0)` |
| 13 | +plus twice the kernel weight of the differences of `S`, and together with the weight `Q` of |
| 14 | +the non-differences this is twice the right-endpoint sum. For the new kernel (two tents, |
| 15 | +`7/10` of width `5` and `3/10` of width `1/24`) the right-endpoint sums of the tents are at |
| 16 | +most their integrals, `(M/32)(7/20 + 3/20) = M/64` (`kernel_sum_le`). |
| 17 | +-/ |
| 18 | + |
| 19 | +namespace ErdosSwarm.Erdos530Gap78 |
| 20 | + |
| 21 | +open Finset ErdosSwarm.Erdos530Gap |
| 22 | + |
| 23 | +/-- The right-endpoint sum of a tent while its last term is nonnegative. -/ |
| 24 | +theorem tent_sum_closed (t : ℝ) (ht : 0 ≤ t) (n : ℕ) (hn : (n : ℝ) * t ≤ 1) : |
| 25 | + ∑ d ∈ Icc 1 n, max 0 (1 - (d : ℝ) * t) = n - t * (n * (n + 1) / 2) := by |
| 26 | + induction n with |
| 27 | + | zero => simp |
| 28 | + | succ n ih => |
| 29 | + push_cast at hn |
| 30 | + have hn' : (n : ℝ) * t ≤ 1 := by nlinarith |
| 31 | + rw [sum_Icc_succ_top (by omega), ih hn', max_eq_right (by push_cast; linarith)] |
| 32 | + push_cast |
| 33 | + ring |
| 34 | + |
| 35 | +/-- The right-endpoint sum of the tent `max(0, 1 − y t)` is at most its integral `1/(2t)` |
| 36 | +over the positive axis. -/ |
| 37 | +theorem tent_sum_le (t : ℝ) (ht : 0 < t) (n : ℕ) : |
| 38 | + ∑ d ∈ Icc 1 n, max 0 (1 - (d : ℝ) * t) ≤ 1 / (2 * t) := by |
| 39 | + induction n with |
| 40 | + | zero => simpa using ht.le |
| 41 | + | succ n ih => |
| 42 | + by_cases h : ((n + 1 : ℕ) : ℝ) * t ≤ 1 |
| 43 | + · rw [tent_sum_closed t ht.le (n + 1) h, le_div_iff₀ (by positivity)] |
| 44 | + push_cast |
| 45 | + have h0 : (0 : ℝ) ≤ n + 1 := by positivity |
| 46 | + nlinarith [sq_nonneg (1 - ((n : ℝ) + 1) * t), mul_nonneg h0 (sq_nonneg t)] |
| 47 | + · rw [sum_Icc_succ_top (by omega), max_eq_left (by linarith), add_zero] |
| 48 | + exact ih |
| 49 | + |
| 50 | +/-- The missing energy for any even kernel `W` whose right-endpoint sum at step `32/M` is at |
| 51 | +most `M/64`: the proof of `Erdos530Gap103.missing_energy`, with the weight `Q` of the |
| 52 | +non-differences written out. -/ |
| 53 | +theorem missing_energy_of_kernel (W : ℝ → ℝ) (hW : ∀ y, W (-y) = W y) {M : ℕ} |
| 54 | + {S : Finset ℕ} (hS : S ⊆ host M) (hsid : IsSidon (S : Set ℕ)) |
| 55 | + (hsum : ∑ d ∈ Icc 1 M, W (32 * (d : ℝ) / M) ≤ (M : ℝ) / 64) : |
| 56 | + 2 * ∑ d ∈ (Icc 1 M).filter (fun d => ∀ a ∈ S, ∀ a' ∈ S, ((a : ℤ) - a').natAbs ≠ d), |
| 57 | + W (32 * (d : ℝ) / M) + |
| 58 | + ∑ a ∈ S, ∑ a' ∈ S, W (Erdos530Gap103.coord M a - Erdos530Gap103.coord M a') ≤ |
| 59 | + (M : ℝ) / 32 + S.card * W 0 := by |
| 60 | + set g : ℕ → ℝ := fun d => W (32 * (d : ℝ) / M) with hg |
| 61 | + set f : ℕ × ℕ → ℝ := |
| 62 | + fun p => W (Erdos530Gap103.coord M p.1 - Erdos530Gap103.coord M p.2) with hf |
| 63 | + -- the kernel at a coordinate difference, in either order |
| 64 | + have hval : ∀ a a' : ℕ, a' ≤ a → |
| 65 | + W (Erdos530Gap103.coord M a - Erdos530Gap103.coord M a') = g (a - a') ∧ |
| 66 | + W (Erdos530Gap103.coord M a' - Erdos530Gap103.coord M a) = g (a - a') := by |
| 67 | + intro a a' h |
| 68 | + have e : Erdos530Gap103.coord M (a : ℤ) - Erdos530Gap103.coord M (a' : ℤ) = |
| 69 | + 32 * ((a - a' : ℕ) : ℝ) / M := by |
| 70 | + unfold Erdos530Gap103.coord |
| 71 | + push_cast [Nat.cast_sub h] |
| 72 | + ring |
| 73 | + have e' : Erdos530Gap103.coord M (a' : ℤ) - Erdos530Gap103.coord M (a : ℤ) = |
| 74 | + -(32 * ((a - a' : ℕ) : ℝ) / M) := by |
| 75 | + rw [← e] |
| 76 | + ring |
| 77 | + exact ⟨by rw [e], by rw [e', hW]⟩ |
| 78 | + set Q := ∑ d ∈ (Icc 1 M).filter |
| 79 | + (fun d => ∀ a ∈ S, ∀ a' ∈ S, ((a : ℤ) - a').natAbs ≠ d), g d with hQd |
| 80 | + -- the differences of `S` and the ordered pairs `a' < a` |
| 81 | + have hpairs : ∑ p ∈ (S ×ˢ S).filter (fun p => p.2 < p.1), g (p.1 - p.2) = |
| 82 | + ∑ d ∈ (Icc 1 M).filter |
| 83 | + (fun d => ¬ ∀ a ∈ S, ∀ a' ∈ S, ((a : ℤ) - a').natAbs ≠ d), g d := by |
| 84 | + refine sum_nbij (fun p => p.1 - p.2) ?_ ?_ ?_ (fun _ _ => rfl) |
| 85 | + · intro p hp |
| 86 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 87 | + obtain ⟨h1, h2⟩ := mem_product.mp hp |
| 88 | + have hle := (mem_Icc.mp (hS h1)).2 |
| 89 | + refine mem_filter.mpr ⟨mem_Icc.mpr ⟨by omega, by omega⟩, fun h => ?_⟩ |
| 90 | + exact h p.1 h1 p.2 h2 (by omega) |
| 91 | + · intro p hp q hq hpq |
| 92 | + rw [mem_coe] at hp hq |
| 93 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 94 | + obtain ⟨hq, hlt'⟩ := mem_filter.mp hq |
| 95 | + obtain ⟨hp1, hp2⟩ := mem_product.mp hp |
| 96 | + obtain ⟨hq1, hq2⟩ := mem_product.mp hq |
| 97 | + have hpq' : p.1 - p.2 = q.1 - q.2 := hpq |
| 98 | + rcases hsid p.1 (mem_coe.mpr hp1) q.1 (mem_coe.mpr hq1) q.2 (mem_coe.mpr hq2) |
| 99 | + p.2 (mem_coe.mpr hp2) (by omega) with ⟨h1, h2⟩ | ⟨h1, h2⟩ |
| 100 | + · exact Prod.ext h1 h2.symm |
| 101 | + · omega |
| 102 | + · intro d hd |
| 103 | + rw [mem_coe] at hd |
| 104 | + obtain ⟨hd, hne⟩ := mem_filter.mp hd |
| 105 | + have hd1 := (mem_Icc.mp hd).1 |
| 106 | + push Not at hne |
| 107 | + obtain ⟨a, ha, a', ha', hdiff⟩ := hne |
| 108 | + rcases lt_or_ge a' a with h | h |
| 109 | + · exact ⟨(a, a'), mem_coe.mpr (mem_filter.mpr ⟨mem_product.mpr ⟨ha, ha'⟩, h⟩), |
| 110 | + by simp only; omega⟩ |
| 111 | + · exact ⟨(a', a), mem_coe.mpr (mem_filter.mpr ⟨mem_product.mpr ⟨ha', ha⟩, by omega⟩), |
| 112 | + by simp only; omega⟩ |
| 113 | + have hQ : Q + ∑ d ∈ (Icc 1 M).filter |
| 114 | + (fun d => ¬ ∀ a ∈ S, ∀ a' ∈ S, ((a : ℤ) - a').natAbs ≠ d), g d = |
| 115 | + ∑ d ∈ Icc 1 M, g d := by |
| 116 | + exact sum_filter_add_sum_filter_not _ _ _ |
| 117 | + -- split the double sum into `a' < a`, `a < a'` and the diagonal |
| 118 | + have h1 := sum_filter_add_sum_filter_not (S ×ˢ S) (fun p : ℕ × ℕ => p.2 < p.1) f |
| 119 | + have h2 := sum_filter_add_sum_filter_not ((S ×ˢ S).filter (fun p : ℕ × ℕ => ¬ p.2 < p.1)) |
| 120 | + (fun p : ℕ × ℕ => p.1 < p.2) f |
| 121 | + have hA : ∑ p ∈ (S ×ˢ S).filter (fun p => p.2 < p.1), f p = |
| 122 | + ∑ p ∈ (S ×ˢ S).filter (fun p => p.2 < p.1), g (p.1 - p.2) := |
| 123 | + sum_congr rfl fun p hp => (hval p.1 p.2 (mem_filter.mp hp).2.le).1 |
| 124 | + have hB : ∑ p ∈ ((S ×ˢ S).filter (fun p : ℕ × ℕ => ¬ p.2 < p.1)).filter |
| 125 | + (fun p : ℕ × ℕ => p.1 < p.2), f p = |
| 126 | + ∑ p ∈ (S ×ˢ S).filter (fun p => p.2 < p.1), g (p.1 - p.2) := by |
| 127 | + refine sum_nbij' Prod.swap Prod.swap ?_ ?_ (fun _ _ => rfl) (fun _ _ => rfl) ?_ |
| 128 | + · intro p hp |
| 129 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 130 | + obtain ⟨h1, h2⟩ := mem_product.mp (mem_filter.mp hp).1 |
| 131 | + exact mem_filter.mpr ⟨mem_product.mpr ⟨h2, h1⟩, hlt⟩ |
| 132 | + · intro p hp |
| 133 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 134 | + obtain ⟨h1, h2⟩ := mem_product.mp hp |
| 135 | + exact mem_filter.mpr ⟨mem_filter.mpr ⟨mem_product.mpr ⟨h2, h1⟩, |
| 136 | + by simp only [Prod.fst_swap, Prod.snd_swap]; omega⟩, hlt⟩ |
| 137 | + · intro p hp |
| 138 | + exact (hval p.2 p.1 (mem_filter.mp hp).2.le).2 |
| 139 | + have hC : ∑ p ∈ ((S ×ˢ S).filter (fun p : ℕ × ℕ => ¬ p.2 < p.1)).filter |
| 140 | + (fun p : ℕ × ℕ => ¬ p.1 < p.2), f p = S.card * W 0 := by |
| 141 | + rw [← nsmul_eq_mul, ← sum_const] |
| 142 | + refine sum_nbij' (fun p => p.1) (fun a => (a, a)) ?_ ?_ ?_ (fun _ _ => rfl) ?_ |
| 143 | + · intro p hp |
| 144 | + exact (mem_product.mp (mem_filter.mp (mem_filter.mp hp).1).1).1 |
| 145 | + · intro a ha |
| 146 | + exact mem_filter.mpr ⟨mem_filter.mpr ⟨mem_product.mpr ⟨ha, ha⟩, lt_irrefl a⟩, |
| 147 | + lt_irrefl a⟩ |
| 148 | + · intro p hp |
| 149 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 150 | + have hlt' := (mem_filter.mp hp).2 |
| 151 | + exact Prod.ext rfl (by simp only; omega) |
| 152 | + · intro p hp |
| 153 | + obtain ⟨hp, hlt⟩ := mem_filter.mp hp |
| 154 | + have hlt' := (mem_filter.mp hp).2 |
| 155 | + have heq : p.1 = p.2 := by omega |
| 156 | + simp only [hf, heq, sub_self] |
| 157 | + rw [← sum_product' S S fun a a' => W (Erdos530Gap103.coord M a - Erdos530Gap103.coord M a')] |
| 158 | + change 2 * Q + ∑ p ∈ S ×ˢ S, f p ≤ _ |
| 159 | + linarith |
| 160 | + |
| 161 | +/-- The even kernel. -/ |
| 162 | +theorem kernel_neg (y : ℝ) : kernel (-y) = kernel y := by |
| 163 | + unfold kernel |
| 164 | + rw [abs_neg] |
| 165 | + |
| 166 | +/-- The right-endpoint sum of the new kernel at step `32/M` is at most |
| 167 | +`(M/32)·∫₀^∞ W = (M/32)(7/20 + 3/20) = M/64`. -/ |
| 168 | +theorem kernel_sum_le {M : ℕ} (hM : 0 < M) : |
| 169 | + ∑ d ∈ Icc 1 M, kernel (32 * (d : ℝ) / M) ≤ (M : ℝ) / 64 := by |
| 170 | + have hM' : (0 : ℝ) < M := by exact_mod_cast hM |
| 171 | + have h1 := tent_sum_le (32 / (5 * M)) (by positivity) M |
| 172 | + have h2 := tent_sum_le (768 / M) (by positivity) M |
| 173 | + have key : ∀ d ∈ Icc 1 M, kernel (32 * (d : ℝ) / M) = |
| 174 | + 7 / 50 * max 0 (1 - (d : ℝ) * (32 / (5 * M))) + |
| 175 | + 36 / 5 * max 0 (1 - (d : ℝ) * (768 / M)) := by |
| 176 | + intro d _ |
| 177 | + have habs : |32 * (d : ℝ) / M| = 32 * (d : ℝ) / M := abs_of_nonneg (by positivity) |
| 178 | + have e1 : 32 * (d : ℝ) / M / 5 = (d : ℝ) * (32 / (5 * M)) := by |
| 179 | + field_simp |
| 180 | + have e2 : 24 * (32 * (d : ℝ) / M) = (d : ℝ) * (768 / M) := by |
| 181 | + field_simp |
| 182 | + ring |
| 183 | + unfold kernel |
| 184 | + rw [habs, e1, e2] |
| 185 | + ring |
| 186 | + rw [sum_congr rfl key, sum_add_distrib, ← mul_sum, ← mul_sum] |
| 187 | + have e1 : 1 / (2 * (32 / (5 * (M : ℝ)))) = 5 * M / 64 := by |
| 188 | + field_simp |
| 189 | + ring |
| 190 | + have e2 : 1 / (2 * (768 / (M : ℝ))) = M / 1536 := by |
| 191 | + field_simp |
| 192 | + ring |
| 193 | + rw [e1] at h1 |
| 194 | + rw [e2] at h2 |
| 195 | + linarith |
| 196 | + |
| 197 | +/-- **Brief A2** (`Plan.lean`, the statement unchanged). `upper-smaller-k2/NOTES.md` §1, the |
| 198 | +display before (2): each positive difference of the Sidon set occurs once, and the |
| 199 | +right-endpoint sum of the decreasing kernel over the positive integers is at most `M/64`. -/ |
| 200 | +theorem missing_energy {M : ℕ} {S : Finset ℕ} (hM : 0 < M) (hS : S ⊆ host M) |
| 201 | + (hsid : IsSidon (S : Set ℕ)) : |
| 202 | + 2 * missingWeight M S + |
| 203 | + ∑ a ∈ S, ∑ a' ∈ S, kernel (Erdos530Gap103.coord M a - Erdos530Gap103.coord M a') ≤ |
| 204 | + (M : ℝ) / 32 + S.card * kernel 0 := |
| 205 | + missing_energy_of_kernel kernel kernel_neg hS hsid (kernel_sum_le hM) |
| 206 | + |
| 207 | +end ErdosSwarm.Erdos530Gap78 |