| | @@ -0,0 +1,183 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap78.Data |
| 2 | + |
| 3 | +/-! |
| 4 | +# Charging repeated distances in Erdős #530 |
| 5 | + |
| 6 | +Equation (1) of `experiments/erdos530/upper-smaller-k2/NOTES.md` assigns complementary |
| 7 | +endpoint weights to the two incidences at a repeated distance. Their scores sum to one |
| 8 | +kernel weight. A single incidence costs at most the same weight. |
| 9 | +-/ |
| 10 | + |
| 11 | +namespace ErdosSwarm.Erdos530Gap78 |
| 12 | + |
| 13 | +open Finset ErdosSwarm.Erdos530Gap |
| 14 | +open ErdosSwarm.Erdos530Gap103 (coord iso) |
| 15 | + |
| 16 | +/-- The kernel is nonnegative and attains its maximum at zero. -/ |
| 17 | +theorem kernel_mem_Icc (y : ℝ) : kernel y ∈ Set.Icc 0 (kernel 0) := by |
| 18 | + constructor |
| 19 | + · exact add_nonneg (mul_nonneg (by norm_num) (le_max_left _ _)) |
| 20 | + (mul_nonneg (by norm_num) (le_max_left _ _)) |
| 21 | + · have h₁ : max 0 (1 - |y| / 5) ≤ 1 := max_le zero_le_one (by linarith only [abs_nonneg y]) |
| 22 | + have h₂ : max 0 (1 - 24 * |y|) ≤ 1 := max_le zero_le_one (by linarith only [abs_nonneg y]) |
| 23 | + have h₀ : kernel 0 = 7 / 10 / 5 + 3 / 10 * 24 := by norm_num [kernel] |
| 24 | + rw [h₀] |
| 25 | + unfold kernel |
| 26 | + linarith only [h₁, h₂] |
| 27 | + |
| 28 | +/-- Linear interpolation keeps the endpoint profile between zero and one. -/ |
| 29 | +theorem profile_mem_Icc (y : ℝ) : profile y ∈ Set.Icc 0 1 := by |
| 30 | + have heights (j : ℕ) : profileHeights.getD j 0 ∈ Set.Icc (0 : ℝ) 1000 := by |
| 31 | + rcases j with _ | _ | _ | _ | _ | _ | _ | _ | _ | j <;> norm_num [profileHeights, Set.mem_Icc] |
| 32 | + unfold profile |
| 33 | + split_ifs with h |
| 34 | + · exact ⟨le_rfl, zero_le_one⟩ |
| 35 | + · rw [not_or, not_lt, not_le] at h |
| 36 | + set j := ⌊2 * y⌋₊ |
| 37 | + have h₀ : 0 ≤ 2 * y - (j : ℝ) := sub_nonneg.mpr (Nat.floor_le (by linarith only [h.1])) |
| 38 | + have h₁ : 0 ≤ 1 - (2 * y - (j : ℝ)) := by |
| 39 | + linarith only [show 2 * y < (j : ℝ) + 1 from Nat.lt_floor_add_one _] |
| 40 | + refine ⟨div_nonneg (add_nonneg (mul_nonneg (heights j).1 h₁) |
| 41 | + (mul_nonneg (heights (j + 1)).1 h₀)) (by norm_num), ?_⟩ |
| 42 | + rw [div_le_one (by norm_num)] |
| 43 | + linarith only [mul_le_mul_of_nonneg_right (heights j).2 h₁, |
| 44 | + mul_le_mul_of_nonneg_right (heights (j + 1)).2 h₀] |
| 45 | + |
| 46 | +/-- The left and reflected profiles have disjoint supports. -/ |
| 47 | +theorem psi_mem_Icc (y : ℝ) : psi y ∈ Set.Icc 0 1 := by |
| 48 | + have zero_of_ge {z : ℝ} (hz : 4 ≤ z) : profile z = 0 := if_pos (Or.inr hz) |
| 49 | + unfold psi |
| 50 | + split_ifs |
| 51 | + · rcases le_total 4 y with h | h |
| 52 | + · rw [zero_of_ge h, zero_add] |
| 53 | + exact profile_mem_Icc _ |
| 54 | + · rw [zero_of_ge (show 4 ≤ 32 - y by linarith only [h]), add_zero] |
| 55 | + exact profile_mem_Icc _ |
| 56 | + · exact ⟨le_rfl, zero_le_one⟩ |
| 57 | + |
| 58 | +/-- One incidence costs at most the kernel weight of its distance. -/ |
| 59 | +theorem score_le_kernel (t y gy : ℝ) : score t y gy ≤ kernel (y - t) := by |
| 60 | + unfold score |
| 61 | + split_ifs |
| 62 | + · calc |
| 63 | + _ ≤ kernel (y - t) / 2 * 2 := mul_le_mul_of_nonneg_left |
| 64 | + (by linarith only [(psi_mem_Icc t).2, (psi_mem_Icc gy).1]) |
| 65 | + (div_nonneg (kernel_mem_Icc _).1 (by norm_num)) |
| 66 | + _ = _ := by ring |
| 67 | + · exact le_rfl |
| 68 | + |
| 69 | +/-- At a repeated distance the transported seed points are the two opposite outsiders. |
| 70 | +The profile differences cancel exactly. -/ |
| 71 | +theorem score_add_of_swapped_endpoints {t y t' y' : ℝ} |
| 72 | + (ht : t ∈ Set.Icc 0 32) (ht' : t' ∈ Set.Icc 0 32) |
| 73 | + (hW : kernel (y - t) = kernel (y' - t')) : |
| 74 | + score t y t' + score t' y' t = kernel (y - t) := by |
| 75 | + simp only [score, if_pos (Set.mem_Icc.mp ht), if_pos (Set.mem_Icc.mp ht'), ← hW] |
| 76 | + ring |
| 77 | + |
| 78 | +/-- Each host point has coordinate strictly between the two endpoints. -/ |
| 79 | +theorem coord_mem_Ioo {M x : ℕ} (hx : x ∈ host M) : coord M x ∈ Set.Ioo (0 : ℝ) 32 := by |
| 80 | + obtain ⟨hx₁, hx₂⟩ := mem_Icc.mp hx |
| 81 | + have h₁ : (1 : ℝ) ≤ x := by exact_mod_cast hx₁ |
| 82 | + have h₂ : (x : ℝ) ≤ M := by exact_mod_cast hx₂ |
| 83 | + have hM : (0 : ℝ) < M := by linarith only [h₁, h₂] |
| 84 | + unfold coord |
| 85 | + push_cast |
| 86 | + exact ⟨div_pos (by linarith only [h₁]) hM, (div_lt_iff₀ hM).mpr (by linarith only [h₂])⟩ |
| 87 | + |
| 88 | +private theorem kernel_coord_sub (M a x : ℕ) : |
| 89 | + kernel (coord M a - coord M x) = kernel (32 * (((x : ℤ) - a).natAbs : ℝ) / M) := by |
| 90 | + have e : coord M a - coord M x = 32 * ((a : ℝ) - x) / M := by |
| 91 | + unfold coord |
| 92 | + push_cast |
| 93 | + ring |
| 94 | + have habs : (((x : ℤ) - a).natAbs : ℝ) = |(a : ℝ) - x| := by |
| 95 | + rw [Nat.cast_natAbs, Int.cast_abs, abs_sub_comm] |
| 96 | + push_cast |
| 97 | + rfl |
| 98 | + have h : |32 * ((a : ℝ) - x) / M| = |32 * |(a : ℝ) - x| / M| := by |
| 99 | + rw [abs_div, abs_div, abs_mul, abs_mul, abs_abs] |
| 100 | + unfold kernel |
| 101 | + rw [e, habs, h] |
| 102 | + |
| 103 | +/-- Grouping the retained incidences by distance costs at most the missing weight. |
| 104 | +Each discarded incidence contributes at most `kernel 0`. -/ |
| 105 | +theorem second_occurrence {M : ℕ} {S B : Finset ℕ} {P : Finset (ℕ × ℕ)} {g : ℕ → Bool × ℤ} |
| 106 | + (hS : S ⊆ host M) (hB : B ⊆ host M \ S) (hP : P ⊆ B ×ˢ S) |
| 107 | + (hD : ∀ p ∈ P, ∀ a ∈ S, ∀ a' ∈ S, ((a : ℤ) - a').natAbs ≠ ((p.1 : ℤ) - p.2).natAbs) |
| 108 | + (hg : ∀ p ∈ P, ∀ p' ∈ P, p ≠ p' → |
| 109 | + ((p.1 : ℤ) - p.2).natAbs = ((p'.1 : ℤ) - p'.2).natAbs → |
| 110 | + (p'.1 : ℤ) = Erdos530Gap103.iso (g p.1) p.2 ∧ |
| 111 | + (p'.2 : ℤ) = Erdos530Gap103.iso (g p.1) p.1) : |
| 112 | + ∑ x ∈ B, ∑ a ∈ S, score (Erdos530Gap103.coord M x) (Erdos530Gap103.coord M a) |
| 113 | + (Erdos530Gap103.coord M (Erdos530Gap103.iso (g x) a)) ≤ |
| 114 | + missingWeight M S + kernel 0 * ((B ×ˢ S) \ P).card := by |
| 115 | + classical |
| 116 | + let len (p : ℕ × ℕ) := ((p.1 : ℤ) - p.2).natAbs |
| 117 | + let W (d : ℕ) := kernel (32 * (d : ℝ) / M) |
| 118 | + let cost (p : ℕ × ℕ) := score (coord M p.1) (coord M p.2) (coord M (iso (g p.1) p.2)) |
| 119 | + have hker (p : ℕ × ℕ) : kernel (coord M p.2 - coord M p.1) = W (len p) := |
| 120 | + kernel_coord_sub M p.2 p.1 |
| 121 | + have hone (p : ℕ × ℕ) : cost p ≤ W (len p) := (score_le_kernel _ _ _).trans_eq (hker p) |
| 122 | + have hcoord {p : ℕ × ℕ} (hp : p ∈ P) : coord M p.1 ∈ Set.Icc (0 : ℝ) 32 := |
| 123 | + Set.Ioo_subset_Icc_self (coord_mem_Ioo (mem_sdiff.mp (hB (mem_product.mp (hP hp)).1)).1) |
| 124 | + have hfiber (d : ℕ) (hd : d ∈ P.image len) : |
| 125 | + ∑ p ∈ P.filter (fun p => len p = d), cost p ≤ W d := by |
| 126 | + obtain ⟨p, hp, rfl⟩ := mem_image.mp hd |
| 127 | + let F := P.filter fun r => len r = len p |
| 128 | + change ∑ r ∈ F, cost r ≤ W (len p) |
| 129 | + have hpF : p ∈ F := mem_filter.mpr ⟨hp, rfl⟩ |
| 130 | + by_cases hex : ∃ q ∈ F, q ≠ p |
| 131 | + · obtain ⟨q, hqF, hqp⟩ := hex |
| 132 | + obtain ⟨hq, hlen⟩ := mem_filter.mp hqF |
| 133 | + have partner {r : ℕ × ℕ} (hr : r ∈ F) (hrp : r ≠ p) := |
| 134 | + hg p hp r (mem_filter.mp hr).1 hrp.symm (mem_filter.mp hr).2.symm |
| 135 | + have hq' := partner hqF hqp |
| 136 | + have hp' := hg q hq p hp hqp hlen |
| 137 | + have hF : F = {p, q} := by |
| 138 | + refine Subset.antisymm ?_ (insert_subset hpF (singleton_subset_iff.mpr hqF)) |
| 139 | + intro r hr |
| 140 | + by_cases hrp : r = p |
| 141 | + · simp [hrp] |
| 142 | + · have hr' := partner hr hrp |
| 143 | + have hrq : r = q := Prod.ext (by exact_mod_cast hr'.1.trans hq'.1.symm) |
| 144 | + (by exact_mod_cast hr'.2.trans hq'.2.symm) |
| 145 | + simp [hrq] |
| 146 | + rw [hF, sum_pair hqp.symm] |
| 147 | + apply le_of_eq |
| 148 | + dsimp only [cost] |
| 149 | + rw [← hq'.1, ← hp'.1] |
| 150 | + have hw : kernel (coord M p.2 - coord M p.1) = kernel (coord M q.2 - coord M q.1) := by |
| 151 | + rw [hker p, hker q, hlen] |
| 152 | + exact (score_add_of_swapped_endpoints (hcoord hp) (hcoord hq) hw).trans (hker p) |
| 153 | + · have hF : F = {p} := by |
| 154 | + refine Subset.antisymm ?_ (singleton_subset_iff.mpr hpF) |
| 155 | + intro q hq |
| 156 | + exact mem_singleton.mpr (by by_contra hne; exact hex ⟨q, hq, hne⟩) |
| 157 | + rw [hF, sum_singleton] |
| 158 | + exact hone p |
| 159 | + have hretained : ∑ p ∈ P, cost p ≤ missingWeight M S := by |
| 160 | + calc |
| 161 | + _ = ∑ d ∈ P.image len, ∑ p ∈ P.filter (fun p => len p = d), cost p := |
| 162 | + (sum_fiberwise_of_maps_to (fun p hp => mem_image_of_mem len hp) cost).symm |
| 163 | + _ ≤ ∑ d ∈ P.image len, W d := sum_le_sum hfiber |
| 164 | + _ ≤ missingWeight M S := by |
| 165 | + unfold missingWeight |
| 166 | + refine sum_le_sum_of_subset_of_nonneg ?_ fun d _ _ => (kernel_mem_Icc _).1 |
| 167 | + intro d hd |
| 168 | + obtain ⟨p, hp, rfl⟩ := mem_image.mp hd |
| 169 | + obtain ⟨hx, ha⟩ := mem_product.mp (hP hp) |
| 170 | + obtain ⟨hxM, hxS⟩ := mem_sdiff.mp (hB hx) |
| 171 | + have hne : p.1 ≠ p.2 := fun he => hxS (he ▸ ha) |
| 172 | + have hxI := mem_Icc.mp hxM |
| 173 | + have haI := mem_Icc.mp (hS ha) |
| 174 | + exact mem_filter.mpr ⟨mem_Icc.mpr ⟨by dsimp [len]; omega, by dsimp [len]; omega⟩, hD p hp⟩ |
| 175 | + have hdiscarded : ∑ p ∈ (B ×ˢ S) \ P, cost p ≤ kernel 0 * ((B ×ˢ S) \ P).card := by |
| 176 | + rw [mul_comm, ← nsmul_eq_mul] |
| 177 | + exact sum_le_card_nsmul _ _ _ fun p _ => (hone p).trans (kernel_mem_Icc _).2 |
| 178 | + calc |
| 179 | + _ = ∑ p ∈ B ×ˢ S, cost p := (sum_product _ _ cost).symm |
| 180 | + _ = (∑ p ∈ (B ×ˢ S) \ P, cost p) + ∑ p ∈ P, cost p := (sum_sdiff hP).symm |
| 181 | + _ ≤ _ := by linarith only [hretained, hdiscarded] |
| 182 | + |
| 183 | +end ErdosSwarm.Erdos530Gap78 |