| | @@ -0,0 +1,350 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap78.Rounding |
| 2 | +import Mathlib.LinearAlgebra.Matrix.ToLin |
| 3 | + |
| 4 | +/-! |
| 5 | +# Box witnesses for the 77/78 grid |
| 6 | + |
| 7 | +On the grid of mesh 1/24, the broad tent counts the overlap of two length-120 |
| 8 | +windows. In the units of the integer certificate, 6000 times the grid matrix |
| 9 | +is therefore seven times the Gram matrix of the windows, plus 43200 times the |
| 10 | +identity. The box witness gives a supporting inequality by completing one |
| 11 | +square for each window and one for each diagonal entry. |
| 12 | + |
| 13 | +The integer normalization and the box certificate are equations (1)–(3) of |
| 14 | +`experiments/erdos530/grid-certificate-78/NOTES.md`. The cover refines the |
| 15 | +one-step container argument of Phal and Gemini, §4. |
| 16 | +-/ |
| 17 | + |
| 18 | +namespace ErdosSwarm.Erdos530Gap78 |
| 19 | + |
| 20 | +open Finset |
| 21 | + |
| 22 | +noncomputable section |
| 23 | + |
| 24 | +theorem cast_box_sub78 (a b : ℕ) : ((a - b : ℕ) : ℝ) = max 0 ((a : ℝ) - b) := by |
| 25 | + rcases le_total b a with h | h |
| 26 | + · rw [Nat.cast_sub h, max_eq_right (sub_nonneg.mpr (by exact_mod_cast h))] |
| 27 | + · rw [Nat.sub_eq_zero_of_le h, Nat.cast_zero, max_eq_left (sub_nonpos.mpr (by exact_mod_cast h))] |
| 28 | + |
| 29 | +/-- The entries of the length-120 box matrix. -/ |
| 30 | +def boxEntry78 (v j : ℕ) : ℝ := if v ∈ Ico j (j + 120) then 1 else 0 |
| 31 | + |
| 32 | +/-- A window of 8n rows beginning partway through a constant block. The |
| 33 | +overlapping part of each of two consecutive blocks gives the interpolation |
| 34 | +between the tabulated knot sums. -/ |
| 35 | +theorem sum_box_blocks78 (H : ℕ → ℕ) (j n : ℕ) : |
| 36 | + ∑ r ∈ range (8 * n), H ((j + r) / 8) = |
| 37 | + (8 - j % 8) * (∑ k ∈ range n, H (j / 8 + k)) + |
| 38 | + j % 8 * (∑ k ∈ range n, H (j / 8 + k + 1)) := by |
| 39 | + induction n with |
| 40 | + | zero => simp |
| 41 | + | succ n ih => |
| 42 | + rw [Nat.mul_succ, sum_range_add, ih] |
| 43 | + have hpiece : ∑ r ∈ range 8, H ((j + (8 * n + r)) / 8) = |
| 44 | + (8 - j % 8) * H (j / 8 + n) + (j % 8) * H (j / 8 + n + 1) := by |
| 45 | + let f r := H ((j + (8 * n + r)) / 8) |
| 46 | + have he : 8 - j % 8 + j % 8 = 8 := by omega |
| 47 | + have h₁ : ∑ r ∈ range (8 - j % 8), f r = (8 - j % 8) * H (j / 8 + n) := by |
| 48 | + calc _ = ∑ _r ∈ range (8 - j % 8), H (j / 8 + n) := by |
| 49 | + refine sum_congr rfl fun r hr => congrArg H ?_ |
| 50 | + have := mem_range.mp hr |
| 51 | + omega |
| 52 | + _ = _ := by simp |
| 53 | + have h₂ : ∑ r ∈ range (j % 8), f (8 - j % 8 + r) = (j % 8) * H (j / 8 + n + 1) := by |
| 54 | + calc _ = ∑ _r ∈ range (j % 8), H (j / 8 + n + 1) := by |
| 55 | + refine sum_congr rfl fun r hr => congrArg H ?_ |
| 56 | + have := mem_range.mp hr |
| 57 | + omega |
| 58 | + _ = _ := by simp |
| 59 | + change ∑ r ∈ range 8, f r = _ |
| 60 | + conv_lhs => rw [← he, sum_range_add] |
| 61 | + rw [h₁, h₂] |
| 62 | + rw [hpiece, sum_range_succ _ n, sum_range_succ _ n] |
| 63 | + ring |
| 64 | + |
| 65 | +/-- The checked interpolation at j = 8q + r equals the full 120-row sum. -/ |
| 66 | +theorem window_box_blocks78 (H : ℕ → ℕ) (j : ℕ) : |
| 67 | + ∑ v ∈ Ico j (j + 120), H (v / 8) = |
| 68 | + (8 - j % 8) * (∑ k ∈ range 15, H (j / 8 + k)) + |
| 69 | + j % 8 * (∑ k ∈ range 15, H (j / 8 + k + 1)) := by |
| 70 | + rw [sum_Ico_eq_sum_range, Nat.add_sub_cancel_left] |
| 71 | + exact sum_box_blocks78 H j 15 |
| 72 | + |
| 73 | +/-- The 111 box heights each occupy eight rows. -/ |
| 74 | +theorem norm_box_blocks78 (H : ℕ → ℕ) : |
| 75 | + ∑ v ∈ range 888, H (v / 8) ^ 2 = 8 * ∑ k ∈ range 111, H k ^ 2 := by |
| 76 | + simpa using sum_box_blocks78 (fun k => H k ^ 2) 0 111 |
| 77 | + |
| 78 | +/-- A column of the box matrix selects exactly the window starting at its node. -/ |
| 79 | +theorem sum_boxEntry78 {j : ℕ} (hj : j < 769) (h : ℕ → ℝ) : |
| 80 | + ∑ v ∈ range 888, boxEntry78 v j * h v = ∑ v ∈ Ico j (j + 120), h v := by |
| 81 | + simp only [boxEntry78, ite_mul, one_mul, zero_mul, sum_ite_mem] |
| 82 | + have hsub : Ico j (j + 120) ⊆ range 888 := by |
| 83 | + intro v hv |
| 84 | + exact mem_range.mpr (by have := (mem_Ico.mp hv).2; omega) |
| 85 | + rw [inter_eq_right.mpr hsub] |
| 86 | + |
| 87 | +/-- The grid kernel in the integer units of the certificate. -/ |
| 88 | +theorem gridWeight_scaled78 (t : ℤ) : |
| 89 | + 6000 * gridWeight t = 7 * max 0 (120 - |(t : ℝ)|) + (if t = 0 then 43200 else 0) := by |
| 90 | + unfold gridWeight kernel |
| 91 | + rw [abs_div, abs_of_pos (by norm_num : (0 : ℝ) < 24)] |
| 92 | + by_cases ht : t = 0 |
| 93 | + · subst t |
| 94 | + norm_num |
| 95 | + · have hgap : 1 ≤ |(t : ℝ)| := by exact_mod_cast Int.one_le_abs ht |
| 96 | + rw [if_neg ht, max_eq_left (show 1 - 24 * (|(t : ℝ)| / 24) ≤ 0 by linarith)] |
| 97 | + by_cases hd : |(t : ℝ)| ≤ 120 |
| 98 | + · rw [max_eq_right (by linarith : 0 ≤ 1 - |(t : ℝ)| / 24 / 5), |
| 99 | + max_eq_right (by linarith : 0 ≤ 120 - |(t : ℝ)|)] |
| 100 | + ring |
| 101 | + · rw [max_eq_left (by linarith : 1 - |(t : ℝ)| / 24 / 5 ≤ 0), |
| 102 | + max_eq_left (by linarith : 120 - |(t : ℝ)| ≤ 0)] |
| 103 | + ring |
| 104 | + |
| 105 | +theorem gridWeight_nat78 (t : ℤ) : |
| 106 | + ((7 * (120 - t.natAbs) + if t = 0 then 43200 else 0 : ℕ) : ℝ) = 6000 * gridWeight t := by |
| 107 | + rw [gridWeight_scaled78, Nat.cast_add, Nat.cast_mul, cast_box_sub78, Nat.cast_natAbs, Int.cast_abs] |
| 108 | + split_ifs <;> norm_num |
| 109 | + |
| 110 | +/-- The wide tent counts overlapping rows, and the narrow tent is diagonal. -/ |
| 111 | +theorem gridWeight_box78 {j k : ℕ} (hj : j < 769) : |
| 112 | + 6000 * gridWeight ((j : ℤ) - k) = |
| 113 | + 7 * ∑ v ∈ range 888, boxEntry78 v j * boxEntry78 v k + |
| 114 | + (if j = k then 43200 else 0) := by |
| 115 | + have hoverlap : ∑ v ∈ range 888, boxEntry78 v j * boxEntry78 v k = |
| 116 | + ((min j k + 120 - max j k : ℕ) : ℝ) := by |
| 117 | + rw [sum_boxEntry78 hj] |
| 118 | + simp only [boxEntry78, sum_ite_mem, sum_const, nsmul_eq_mul, mul_one] |
| 119 | + have hi : Ico j (j + 120) ∩ Ico k (k + 120) = Ico (max j k) (min j k + 120) := by |
| 120 | + ext v |
| 121 | + simp only [mem_inter, mem_Ico] |
| 122 | + omega |
| 123 | + rw [hi, Nat.card_Ico] |
| 124 | + have hcast : ((min j k + 120 - max j k : ℕ) : ℝ) = max 0 (120 - |(j : ℝ) - k|) := by |
| 125 | + have h : ((min j k + 120 - max j k : ℕ) : ℤ) = max 0 (120 - |(j : ℤ) - k|) := by |
| 126 | + rcases le_total (j : ℤ) k with h | h |
| 127 | + · rw [abs_of_nonpos (by omega)] |
| 128 | + omega |
| 129 | + · rw [abs_of_nonneg (by omega)] |
| 130 | + omega |
| 131 | + exact_mod_cast h |
| 132 | + simp [gridWeight_scaled78, hoverlap, hcast, sub_eq_zero] |
| 133 | + |
| 134 | +/-- The grid energy as a sum of window squares and diagonal squares. -/ |
| 135 | +theorem gridEnergy_box78 (u : ℕ → ℝ) : |
| 136 | + 6000 * ∑ j ∈ range 769, ∑ k ∈ range 769, u j * u k * gridWeight ((j : ℤ) - k) = |
| 137 | + 7 * ∑ v ∈ range 888, (∑ j ∈ range 769, boxEntry78 v j * u j) ^ 2 + |
| 138 | + 43200 * ∑ j ∈ range 769, u j ^ 2 := by |
| 139 | + have hgram : ∑ v ∈ range 888, (∑ j ∈ range 769, boxEntry78 v j * u j) ^ 2 = |
| 140 | + ∑ j ∈ range 769, ∑ k ∈ range 769, |
| 141 | + u j * u k * ∑ v ∈ range 888, boxEntry78 v j * boxEntry78 v k := by |
| 142 | + simp_rw [sq, sum_mul_sum, mul_sum] |
| 143 | + rw [sum_comm] |
| 144 | + refine sum_congr rfl fun j _ => ?_ |
| 145 | + rw [sum_comm] |
| 146 | + exact sum_congr rfl fun k _ => sum_congr rfl fun v _ => by ring |
| 147 | + have hdiag : ∑ j ∈ range 769, ∑ k ∈ range 769, u j * u k * (if j = k then 43200 else 0) = |
| 148 | + 43200 * ∑ j ∈ range 769, u j ^ 2 := by |
| 149 | + rw [mul_sum] |
| 150 | + refine sum_congr rfl fun j hj => ?_ |
| 151 | + simp only [mul_ite, mul_zero, sum_ite_eq, if_pos hj] |
| 152 | + ring |
| 153 | + rw [hgram, ← hdiag] |
| 154 | + simp only [mul_sum, ← sum_add_distrib] |
| 155 | + refine sum_congr rfl fun j hj => sum_congr rfl fun k _ => ?_ |
| 156 | + have h := gridWeight_box78 (k := k) (mem_range.mp hj) |
| 157 | + simp only [← mul_sum] |
| 158 | + linear_combination u j * u k * h |
| 159 | + |
| 160 | +/-- Completing both the window squares and the diagonal squares. The identity |
| 161 | +also applies to signed vectors, including an ordinary supporting-plane charge. -/ |
| 162 | +theorem box_square_identity78 (u H R : ℕ → ℝ) : |
| 163 | + 43200 * (6000 * ∑ j ∈ range 769, ∑ k ∈ range 769, |
| 164 | + u j * u k * gridWeight ((j : ℤ) - k)) + |
| 165 | + 7 * 43200 * (∑ v ∈ range 888, H v ^ 2) + (∑ j ∈ range 769, R j ^ 2) - |
| 166 | + 2 * 43200 * (∑ j ∈ range 769, u j * (7 * (∑ v ∈ Ico j (j + 120), H v) + R j)) = |
| 167 | + 7 * 43200 * (∑ v ∈ range 888, ((∑ j ∈ range 769, boxEntry78 v j * u j) - H v) ^ 2) + |
| 168 | + ∑ j ∈ range 769, (43200 * u j - R j) ^ 2 := by |
| 169 | + let b v := ∑ j ∈ range 769, boxEntry78 v j * u j |
| 170 | + let h j := ∑ v ∈ Ico j (j + 120), H v |
| 171 | + have hdot : ∑ j ∈ range 769, u j * h j = ∑ v ∈ range 888, b v * H v := by |
| 172 | + calc ∑ j ∈ range 769, u j * h j = |
| 173 | + ∑ j ∈ range 769, ∑ v ∈ range 888, boxEntry78 v j * u j * H v := by |
| 174 | + refine sum_congr rfl fun j hj => ?_ |
| 175 | + rw [show h j = _ from (sum_boxEntry78 (mem_range.mp hj) H).symm, mul_sum] |
| 176 | + exact sum_congr rfl fun v _ => by ring |
| 177 | + _ = _ := by simp only [b, sum_mul]; rw [sum_comm] |
| 178 | + have hb : ∑ v ∈ range 888, (b v - H v) ^ 2 = |
| 179 | + (∑ v ∈ range 888, b v ^ 2) - 2 * (∑ v ∈ range 888, b v * H v) + ∑ v ∈ range 888, H v ^ 2 := by |
| 180 | + simp only [mul_sum, ← sum_sub_distrib, ← sum_add_distrib] |
| 181 | + exact sum_congr rfl fun _ _ => by ring |
| 182 | + have hd : ∑ j ∈ range 769, (43200 * u j - R j) ^ 2 = |
| 183 | + 43200 ^ 2 * (∑ j ∈ range 769, u j ^ 2) - 2 * 43200 * (∑ j ∈ range 769, u j * R j) + |
| 184 | + ∑ j ∈ range 769, R j ^ 2 := by |
| 185 | + simp only [mul_sum, ← sum_sub_distrib, ← sum_add_distrib] |
| 186 | + exact sum_congr rfl fun _ _ => by ring |
| 187 | + have hc : (∑ j ∈ range 769, u j * (7 * h j + R j)) = |
| 188 | + 7 * (∑ j ∈ range 769, u j * h j) + ∑ j ∈ range 769, u j * R j := by |
| 189 | + simp only [mul_sum, ← sum_add_distrib] |
| 190 | + exact sum_congr rfl fun _ _ => by ring |
| 191 | + rw [gridEnergy_box78, hd] |
| 192 | + change _ + _ + _ - 2 * 43200 * (∑ j ∈ range 769, u j * (7 * h j + R j)) = |
| 193 | + 7 * 43200 * (∑ v ∈ range 888, (b v - H v) ^ 2) + _ |
| 194 | + rw [hb, hc, hdot] |
| 195 | + dsimp only [b] |
| 196 | + ring |
| 197 | + |
| 198 | +/-- The two completed squares give the lower bound in the units of the integer |
| 199 | +certificate. Here the input mass is scaled by 1024 and the scores by 6000 · 1024. |
| 200 | +An upper bound on the sum of squared residuals thus suffices for every such mass. -/ |
| 201 | +theorem box_witness_lower78 (u H Z : ℕ → ℝ) (L : ℝ) |
| 202 | + (hu : ∀ j ∈ range 769, 0 ≤ u j) : |
| 203 | + 2 * 43200 * L * (∑ j ∈ range 769, u j) ≤ |
| 204 | + 7 * 43200 * (∑ v ∈ range 888, H v ^ 2) + |
| 205 | + (∑ j ∈ range 769, |
| 206 | + max 0 (L - 7 * (∑ v ∈ Ico j (j + 120), H v) - Z j) ^ 2) + |
| 207 | + 43200 * (6000 * (∑ j ∈ range 769, ∑ k ∈ range 769, |
| 208 | + u j * u k * gridWeight ((j : ℤ) - k)) + 2 * ∑ j ∈ range 769, u j * Z j) := by |
| 209 | + let R j := max 0 (L - 7 * (∑ v ∈ Ico j (j + 120), H v) - Z j) |
| 210 | + have hid := box_square_identity78 u H R |
| 211 | + have hlev : L * (∑ j ∈ range 769, u j) ≤ |
| 212 | + (∑ j ∈ range 769, u j * (7 * (∑ v ∈ Ico j (j + 120), H v) + R j)) + |
| 213 | + ∑ j ∈ range 769, u j * Z j := by |
| 214 | + rw [mul_sum, ← sum_add_distrib] |
| 215 | + refine sum_le_sum fun j hj => ?_ |
| 216 | + have h := mul_le_mul_of_nonneg_left |
| 217 | + (le_max_right 0 (L - 7 * (∑ v ∈ Ico j (j + 120), H v) - Z j)) (hu j hj) |
| 218 | + dsimp only [R] |
| 219 | + linarith only [h] |
| 220 | + have hw := sum_nonneg (s := range 888) fun v _ => |
| 221 | + sq_nonneg ((∑ j ∈ range 769, boxEntry78 v j * u j) - H v) |
| 222 | + have hd := sum_nonneg (s := range 769) fun j _ => sq_nonneg (43200 * u j - R j) |
| 223 | + change _ ≤ _ + (∑ j ∈ range 769, R j ^ 2) + _ |
| 224 | + linarith only [hlev, hid, hw, hd] |
| 225 | + |
| 226 | +private theorem matrix_apply_range78 {n : ℕ} (g : ℕ → ℕ → ℝ) (x : Fin n → ℝ) (j : Fin n) : |
| 227 | + Matrix.mulVecLin (m := Fin n) (n := Fin n) (fun a b => g a.val b.val) x j = |
| 228 | + ∑ k ∈ range n, g j.val k * (if h : k < n then x ⟨k, h⟩ else 0) := by |
| 229 | + rw [← Fin.sum_univ_eq_sum_range] |
| 230 | + change (∑ k : Fin n, g j.val k.val * x k) = _ |
| 231 | + exact sum_congr rfl fun k _ => by simp [k.isLt] |
| 232 | + |
| 233 | +/-- The diagonal spike makes the grid matrix invertible on the host nodes. -/ |
| 234 | +private theorem grid_solve78 (v : ℕ → ℝ) : |
| 235 | + ∃ a : ℕ → ℝ, ∀ j ∈ range 769, |
| 236 | + 6000 * (∑ k ∈ range 769, gridWeight ((j : ℤ) - k) * a k) = v j := by |
| 237 | + let G : Matrix (Fin 769) (Fin 769) ℝ := |
| 238 | + fun j k => 6000 * gridWeight ((j.val : ℤ) - k.val) |
| 239 | + let extend (x : Fin 769 → ℝ) (j : ℕ) := if h : j < 769 then x ⟨j, h⟩ else 0 |
| 240 | + have happly (x : Fin 769 → ℝ) (j : Fin 769) : G.mulVecLin x j = |
| 241 | + 6000 * ∑ k ∈ range 769, gridWeight ((j.val : ℤ) - k) * extend x k := by |
| 242 | + have h := matrix_apply_range78 (fun a b => 6000 * gridWeight ((a : ℤ) - b)) x j |
| 243 | + change _ = ∑ k ∈ range 769, (6000 * gridWeight ((j.val : ℤ) - k)) * extend x k at h |
| 244 | + rw [h, mul_sum] |
| 245 | + exact sum_congr rfl fun _ _ => mul_assoc _ _ _ |
| 246 | + have hinj : Function.Injective G.mulVecLin := by |
| 247 | + rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] |
| 248 | + intro x hx |
| 249 | + have hzero : 6000 * ∑ j ∈ range 769, ∑ k ∈ range 769, |
| 250 | + extend x j * extend x k * gridWeight ((j : ℤ) - k) = 0 := by |
| 251 | + rw [mul_sum] |
| 252 | + refine sum_eq_zero fun j hj => ?_ |
| 253 | + have hj' := mem_range.mp hj |
| 254 | + have h := (happly x ⟨j, hj'⟩).symm.trans (congrFun hx ⟨j, hj'⟩) |
| 255 | + calc _ = extend x j * (6000 * ∑ k ∈ range 769, gridWeight ((j : ℤ) - k) * extend x k) := by |
| 256 | + simp only [mul_sum] |
| 257 | + exact sum_congr rfl fun _ _ => by ring |
| 258 | + _ = 0 := by rw [h]; simp |
| 259 | + have hG := gridEnergy_box78 (extend x) |
| 260 | + have hb := sum_nonneg (s := range 888) fun v _ => |
| 261 | + sq_nonneg (∑ j ∈ range 769, boxEntry78 v j * extend x j) |
| 262 | + funext j |
| 263 | + have hsq : extend x j ^ 2 ≤ ∑ k ∈ range 769, extend x k ^ 2 := |
| 264 | + single_le_sum (fun k _ => sq_nonneg (extend x k)) (mem_range.mpr j.isLt) |
| 265 | + have h : extend x j = 0 := by nlinarith only [hzero, hG, hb, hsq, sq_nonneg (extend x j)] |
| 266 | + simpa [extend, j.isLt] using h |
| 267 | + obtain ⟨a, ha⟩ := LinearMap.injective_iff_surjective.mp hinj (fun j : Fin 769 => v j) |
| 268 | + exact ⟨extend a, fun j hj => (happly a ⟨j, mem_range.mp hj⟩).symm.trans (congrFun ha _)⟩ |
| 269 | + |
| 270 | +/-- The same witness gives an ordinary charge vector a. In the scaled units |
| 271 | +of the checker its potential plus Z is at least L, and its energy costs at |
| 272 | +most the certified window and diagonal squares. -/ |
| 273 | +theorem exists_box_supporting_plane78 (H Z : ℕ → ℝ) (L : ℝ) : |
| 274 | + ∃ a : ℕ → ℝ, |
| 275 | + (∀ j ∈ range 769, L ≤ Z j + 6000 * ∑ k ∈ range 769, gridWeight ((j : ℤ) - k) * a k) ∧ |
| 276 | + 43200 * (6000 * ∑ j ∈ range 769, ∑ k ∈ range 769, |
| 277 | + a j * a k * gridWeight ((j : ℤ) - k)) ≤ |
| 278 | + 7 * 43200 * (∑ v ∈ range 888, H v ^ 2) + |
| 279 | + ∑ j ∈ range 769, max 0 (L - 7 * (∑ v ∈ Ico j (j + 120), H v) - Z j) ^ 2 := by |
| 280 | + let h j := ∑ v ∈ Ico j (j + 120), H v |
| 281 | + let R j := max 0 (L - 7 * h j - Z j) |
| 282 | + obtain ⟨a, ha⟩ := grid_solve78 (fun j => 7 * h j + R j) |
| 283 | + refine ⟨a, fun j hj => ?_, ?_⟩ |
| 284 | + · rw [ha j hj] |
| 285 | + dsimp only [R] |
| 286 | + linarith only [le_max_right 0 (L - 7 * h j - Z j)] |
| 287 | + · have henergy : ∑ j ∈ range 769, a j * (7 * h j + R j) = |
| 288 | + 6000 * ∑ j ∈ range 769, ∑ k ∈ range 769, a j * a k * gridWeight ((j : ℤ) - k) := by |
| 289 | + rw [mul_sum] |
| 290 | + refine sum_congr rfl fun j hj => ?_ |
| 291 | + rw [← ha j hj] |
| 292 | + simp only [mul_sum] |
| 293 | + exact sum_congr rfl fun k _ => by ring |
| 294 | + have hid := box_square_identity78 a H R |
| 295 | + have hw := sum_nonneg (s := range 888) fun v _ => |
| 296 | + sq_nonneg ((∑ j ∈ range 769, boxEntry78 v j * a j) - H v) |
| 297 | + have hd := sum_nonneg (s := range 769) fun j _ => sq_nonneg (43200 * a j - R j) |
| 298 | + change _ ≤ _ + ∑ j ∈ range 769, R j ^ 2 |
| 299 | + dsimp only [h] at henergy |
| 300 | + rw [henergy] at hid |
| 301 | + linarith only [hid, hw, hd] |
| 302 | + |
| 303 | +/-- The decrease in the squared residual is increasing both in its original |
| 304 | +size and in the amount of score available at the node. -/ |
| 305 | +theorem box_saving_mono78 {y x a b : ℝ} (hy : 0 ≤ y) (hyx : y ≤ x) |
| 306 | + (ha : 0 ≤ a) (hab : a ≤ b) : |
| 307 | + y ^ 2 - max 0 (y - a) ^ 2 ≤ x ^ 2 - max 0 (x - b) ^ 2 := by |
| 308 | + calc y ^ 2 - max 0 (y - a) ^ 2 ≤ x ^ 2 - max 0 (x - a) ^ 2 := by |
| 309 | + rcases le_total x a with h | h |
| 310 | + · simp only [max_eq_left (sub_nonpos.mpr h), max_eq_left (sub_nonpos.mpr (hyx.trans h))] |
| 311 | + gcongr |
| 312 | + · rw [max_eq_right (sub_nonneg.mpr h)] |
| 313 | + rcases le_total y a with h' | h' |
| 314 | + · rw [max_eq_left (sub_nonpos.mpr h')] |
| 315 | + have := pow_le_pow_left₀ hy h' 2 |
| 316 | + nlinarith only [this, mul_nonneg ha (sub_nonneg.mpr h)] |
| 317 | + · rw [max_eq_right (sub_nonneg.mpr h')] |
| 318 | + nlinarith only [mul_nonneg ha (sub_nonneg.mpr hyx)] |
| 319 | + _ ≤ _ := by |
| 320 | + have h : max 0 (x - b) ≤ max 0 (x - a) := max_le_max_left 0 (sub_le_sub_left hab x) |
| 321 | + linarith only [pow_le_pow_left₀ (le_max_left 0 _) h 2] |
| 322 | + |
| 323 | +/-- Saving at the common offsets of a centre interval gives a bound for the |
| 324 | +whole grid. Nodes outside the image may simply be dropped from the saving. -/ |
| 325 | +theorem box_residual_le78 {ι : Type*} (offsets : Finset ι) (node : ι → ℕ) |
| 326 | + (hinj : Set.InjOn node ↑offsets) (hmem : ∀ t ∈ offsets, node t ∈ range 769) |
| 327 | + (X Z : ℕ → ℝ) (Y z : ι → ℝ) (hX : ∀ j ∈ range 769, 0 ≤ X j) |
| 328 | + (hZ : ∀ j ∈ range 769, 0 ≤ Z j) |
| 329 | + (hY : ∀ t ∈ offsets, 0 ≤ Y t ∧ Y t ≤ X (node t)) |
| 330 | + (hz : ∀ t ∈ offsets, 0 ≤ z t ∧ z t ≤ Z (node t)) : |
| 331 | + (∑ j ∈ range 769, max 0 (X j - Z j) ^ 2) + (∑ t ∈ offsets, Y t ^ 2) ≤ |
| 332 | + (∑ j ∈ range 769, X j ^ 2) + ∑ t ∈ offsets, max 0 (Y t - z t) ^ 2 := by |
| 333 | + classical |
| 334 | + let saving j := X j ^ 2 - max 0 (X j - Z j) ^ 2 |
| 335 | + have h : ∑ t ∈ offsets, (Y t ^ 2 - max 0 (Y t - z t) ^ 2) ≤ ∑ j ∈ range 769, saving j := by |
| 336 | + calc _ ≤ ∑ t ∈ offsets, saving (node t) := sum_le_sum fun t ht => |
| 337 | + box_saving_mono78 (hY t ht).1 (hY t ht).2 (hz t ht).1 (hz t ht).2 |
| 338 | + _ = ∑ j ∈ offsets.image node, saving j := (sum_image hinj).symm |
| 339 | + _ ≤ _ := by |
| 340 | + apply sum_le_sum_of_subset_of_nonneg |
| 341 | + · simpa only [image_subset_iff] using hmem |
| 342 | + · intro j hj _ |
| 343 | + have hle : max 0 (X j - Z j) ≤ X j := max_le (hX j hj) (by linarith only [hZ j hj]) |
| 344 | + exact sub_nonneg.mpr (pow_le_pow_left₀ (le_max_left 0 _) hle 2) |
| 345 | + simp only [saving, sum_sub_distrib] at h |
| 346 | + linarith only [h] |
| 347 | + |
| 348 | +end |
| 349 | + |
| 350 | +end ErdosSwarm.Erdos530Gap78 |