| | @@ -0,0 +1,215 @@ |
| 1 | +import ErdosSwarm.Erdos530DigitLevel |
| 2 | +import Mathlib.Combinatorics.Additive.Energy |
| 3 | + |
| 4 | +/-! |
| 5 | +# The energy of the base-16 digit box for Erdős problem 530 |
| 6 | + |
| 7 | +The digit box `D_r = Erdos530DigitLevel.digitBox r` consists of the numbers with `r` base-16 |
| 8 | +digits in `{0, …, 7}`. Its |
| 9 | +additive energy (Mathlib's `Finset.addEnergy`, the number of ordered quadruples |
| 10 | +`(a₁, a₂, b₁, b₂)` with `a₁ + b₁ = a₂ + b₂`) is exactly `344 ^ r`: no sum of two digits |
| 11 | +carries, so an equality of pair sums holds digit by digit, and one digit contributes |
| 12 | +`1² + 2² + ⋯ + 8² + ⋯ + 2² + 1² = 344`. Every subset of `D_r` therefore has energy at most |
| 13 | +`344 ^ r`. Adjoining a finite set `G` to any finite `B` adds at most `4 |G| |B ∪ G|²` ordered |
| 14 | +equalities: choose the slot of a point of `G` and two other entries; the last is determined. |
| 15 | + |
| 16 | +These are the finite energy estimates in §6 of |
| 17 | +`experiments/erdos530/lower-middle-energy/NOTES.md`. Nothing here bears on the structural |
| 18 | +implication for arbitrary sets in the middle energy range, which remains open. |
| 19 | +-/ |
| 20 | + |
| 21 | +namespace ErdosSwarm.Erdos530DigitEnergy |
| 22 | + |
| 23 | +open Finset Erdos530DigitLevel |
| 24 | + |
| 25 | +section General |
| 26 | + |
| 27 | +variable {α β : Type*} [DecidableEq α] [DecidableEq β] |
| 28 | + |
| 29 | +/-- A map that is injective on `s` and preserves and reflects equality of pair sums on `s` |
| 30 | +preserves the additive energy of `s`. -/ |
| 31 | +theorem addEnergy_image_of_sum_iff [Add α] [Add β] (f : α → β) (s : Finset α) |
| 32 | + (hinj : Set.InjOn f s) |
| 33 | + (hf : ∀ a ∈ s, ∀ b ∈ s, ∀ c ∈ s, ∀ d ∈ s, f a + f b = f c + f d ↔ a + b = c + d) : |
| 34 | + (s.image f).addEnergy (s.image f) = s.addEnergy s := by |
| 35 | + unfold Finset.addEnergy |
| 36 | + symm |
| 37 | + refine card_bij (fun x _ => ((f x.1.1, f x.1.2), (f x.2.1, f x.2.2))) ?_ ?_ ?_ |
| 38 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ hx |
| 39 | + simp only [mem_filter, mem_product] at hx |
| 40 | + obtain ⟨⟨⟨ha₁, ha₂⟩, hb₁, hb₂⟩, h⟩ := hx |
| 41 | + simp only [mem_filter, mem_product] |
| 42 | + exact ⟨⟨⟨mem_image_of_mem f ha₁, mem_image_of_mem f ha₂⟩, mem_image_of_mem f hb₁, |
| 43 | + mem_image_of_mem f hb₂⟩, (hf a₁ ha₁ b₁ hb₁ a₂ ha₂ b₂ hb₂).2 h⟩ |
| 44 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ hx ⟨⟨c₁, c₂⟩, d₁, d₂⟩ hy h |
| 45 | + simp only [mem_filter, mem_product] at hx hy |
| 46 | + obtain ⟨⟨⟨ha₁, ha₂⟩, hb₁, hb₂⟩, -⟩ := hx |
| 47 | + obtain ⟨⟨⟨hc₁, hc₂⟩, hd₁, hd₂⟩, -⟩ := hy |
| 48 | + simp only [Prod.mk.injEq] at h |
| 49 | + obtain ⟨⟨h₁, h₂⟩, h₃, h₄⟩ := h |
| 50 | + rw [hinj ha₁ hc₁ h₁, hinj ha₂ hc₂ h₂, hinj hb₁ hd₁ h₃, hinj hb₂ hd₂ h₄] |
| 51 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ hx |
| 52 | + simp only [mem_filter, mem_product, mem_image] at hx |
| 53 | + obtain ⟨⟨⟨⟨a₁, ha₁, rfl⟩, a₂, ha₂, rfl⟩, ⟨b₁, hb₁, rfl⟩, b₂, hb₂, rfl⟩, h⟩ := hx |
| 54 | + refine ⟨((a₁, a₂), (b₁, b₂)), ?_, rfl⟩ |
| 55 | + simp only [mem_filter, mem_product] |
| 56 | + exact ⟨⟨⟨ha₁, ha₂⟩, hb₁, hb₂⟩, (hf a₁ ha₁ b₁ hb₁ a₂ ha₂ b₂ hb₂).1 h⟩ |
| 57 | + |
| 58 | +/-- The additive energy of a product set is the product of the energies. -/ |
| 59 | +theorem addEnergy_product [Add α] [Add β] (s : Finset α) (t : Finset β) : |
| 60 | + (s ×ˢ t).addEnergy (s ×ˢ t) = s.addEnergy s * t.addEnergy t := by |
| 61 | + unfold Finset.addEnergy |
| 62 | + rw [← card_product] |
| 63 | + refine card_nbij' (fun x => (((x.1.1.1, x.1.2.1), (x.2.1.1, x.2.2.1)), |
| 64 | + ((x.1.1.2, x.1.2.2), (x.2.1.2, x.2.2.2)))) |
| 65 | + (fun y => (((y.1.1.1, y.2.1.1), (y.1.1.2, y.2.1.2)), |
| 66 | + ((y.1.2.1, y.2.2.1), (y.1.2.2, y.2.2.2)))) ?_ ?_ ?_ ?_ |
| 67 | + · rintro ⟨⟨⟨a₁, a₁'⟩, a₂, a₂'⟩, ⟨b₁, b₁'⟩, b₂, b₂'⟩ hx |
| 68 | + simp only [coe_filter, mem_product, Set.mem_ofPred_eq, Prod.mk_add_mk, Prod.mk.injEq, |
| 69 | + coe_product, Set.mem_prod] at hx ⊢ |
| 70 | + tauto |
| 71 | + · rintro ⟨⟨⟨a₁, a₂⟩, b₁, b₂⟩, ⟨a₁', a₂'⟩, b₁', b₂'⟩ hy |
| 72 | + simp only [coe_filter, mem_product, Set.mem_ofPred_eq, Prod.mk_add_mk, Prod.mk.injEq, |
| 73 | + coe_product, Set.mem_prod] at hy ⊢ |
| 74 | + tauto |
| 75 | + · rintro ⟨⟨⟨a₁, a₁'⟩, a₂, a₂'⟩, ⟨b₁, b₁'⟩, b₂, b₂'⟩ - |
| 76 | + rfl |
| 77 | + · rintro ⟨⟨⟨a₁, a₂⟩, b₁, b₂⟩, ⟨a₁', a₂'⟩, b₁', b₂'⟩ - |
| 78 | + rfl |
| 79 | + |
| 80 | +/-- Adjoining `G` to `B` creates at most `4 |G| |B ∪ G|²` new ordered equalities of pair |
| 81 | +sums: fix the slot of an element of `G` and two of the other three entries. The sets may |
| 82 | +overlap, and summands may repeat. -/ |
| 83 | +theorem addEnergy_union_le [AddCommMonoid α] [IsCancelAdd α] (B G : Finset α) : |
| 84 | + (B ∪ G).addEnergy (B ∪ G) ≤ B.addEnergy B + 4 * G.card * (B ∪ G).card ^ 2 := by |
| 85 | + set A := B ∪ G with hA |
| 86 | + have key : ∀ g : (α × α) × α × α → α × α × α, |
| 87 | + (∀ x y : (α × α) × α × α, x.1.1 + x.2.1 = x.1.2 + x.2.2 → y.1.1 + y.2.1 = y.1.2 + y.2.2 → |
| 88 | + g x = g y → x = y) → |
| 89 | + ∀ P : Finset ((α × α) × α × α), (∀ x ∈ P, x.1.1 + x.2.1 = x.1.2 + x.2.2) → |
| 90 | + (∀ x ∈ P, g x ∈ G ×ˢ A ×ˢ A) → P.card ≤ G.card * A.card ^ 2 := by |
| 91 | + intro g hg P hP hmem |
| 92 | + calc P.card ≤ (G ×ˢ A ×ˢ A).card := |
| 93 | + card_le_card_of_injOn g hmem fun x hx y hy h => hg x y (hP x hx) (hP y hy) h |
| 94 | + _ = G.card * A.card ^ 2 := by rw [card_product, card_product, sq] |
| 95 | + set Q := {x ∈ (A ×ˢ A) ×ˢ A ×ˢ A | x.1.1 + x.2.1 = x.1.2 + x.2.2} with hQ |
| 96 | + have hQeq : ∀ P : Finset ((α × α) × α × α), P ⊆ Q → ∀ x ∈ P, x.1.1 + x.2.1 = x.1.2 + x.2.2 := |
| 97 | + fun P hPQ x hx => (mem_filter.mp (hPQ hx)).2 |
| 98 | + have hQmem : ∀ x ∈ Q, x.1.1 ∈ A ∧ x.1.2 ∈ A ∧ x.2.1 ∈ A ∧ x.2.2 ∈ A := by |
| 99 | + intro x hx |
| 100 | + simp only [hQ, mem_filter, mem_product] at hx |
| 101 | + tauto |
| 102 | + have h₁ : (Q.filter fun x => x.1.1 ∈ G).card ≤ G.card * A.card ^ 2 := by |
| 103 | + refine key (fun x => (x.1.1, x.1.2, x.2.1)) ?_ _ (hQeq _ (filter_subset _ _)) ?_ |
| 104 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ ⟨⟨c₁, c₂⟩, d₁, d₂⟩ hx hy h |
| 105 | + simp only [Prod.mk.injEq] at h hx hy ⊢ |
| 106 | + obtain ⟨rfl, rfl, rfl⟩ := h |
| 107 | + exact ⟨⟨rfl, rfl⟩, rfl, add_left_cancel (hx.symm.trans hy)⟩ |
| 108 | + · intro x hx |
| 109 | + have := hQmem x (mem_of_mem_filter x hx) |
| 110 | + simp only [mem_product] |
| 111 | + exact ⟨(mem_filter.mp hx).2, this.2.1, this.2.2.1⟩ |
| 112 | + have h₂ : (Q.filter fun x => x.1.2 ∈ G).card ≤ G.card * A.card ^ 2 := by |
| 113 | + refine key (fun x => (x.1.2, x.1.1, x.2.2)) ?_ _ (hQeq _ (filter_subset _ _)) ?_ |
| 114 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ ⟨⟨c₁, c₂⟩, d₁, d₂⟩ hx hy h |
| 115 | + simp only [Prod.mk.injEq] at h hx hy ⊢ |
| 116 | + obtain ⟨rfl, rfl, rfl⟩ := h |
| 117 | + exact ⟨⟨rfl, rfl⟩, add_left_cancel (hx.trans hy.symm), rfl⟩ |
| 118 | + · intro x hx |
| 119 | + have := hQmem x (mem_of_mem_filter x hx) |
| 120 | + simp only [mem_product] |
| 121 | + exact ⟨(mem_filter.mp hx).2, this.1, this.2.2.2⟩ |
| 122 | + have h₃ : (Q.filter fun x => x.2.1 ∈ G).card ≤ G.card * A.card ^ 2 := by |
| 123 | + refine key (fun x => (x.2.1, x.1.1, x.2.2)) ?_ _ (hQeq _ (filter_subset _ _)) ?_ |
| 124 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ ⟨⟨c₁, c₂⟩, d₁, d₂⟩ hx hy h |
| 125 | + simp only [Prod.mk.injEq] at h hx hy ⊢ |
| 126 | + obtain ⟨rfl, rfl, rfl⟩ := h |
| 127 | + exact ⟨⟨rfl, add_right_cancel (hx.symm.trans hy)⟩, rfl, rfl⟩ |
| 128 | + · intro x hx |
| 129 | + have := hQmem x (mem_of_mem_filter x hx) |
| 130 | + simp only [mem_product] |
| 131 | + exact ⟨(mem_filter.mp hx).2, this.1, this.2.2.2⟩ |
| 132 | + have h₄ : (Q.filter fun x => x.2.2 ∈ G).card ≤ G.card * A.card ^ 2 := by |
| 133 | + refine key (fun x => (x.2.2, x.1.2, x.2.1)) ?_ _ (hQeq _ (filter_subset _ _)) ?_ |
| 134 | + · rintro ⟨⟨a₁, a₂⟩, b₁, b₂⟩ ⟨⟨c₁, c₂⟩, d₁, d₂⟩ hx hy h |
| 135 | + simp only [Prod.mk.injEq] at h hx hy ⊢ |
| 136 | + obtain ⟨rfl, rfl, rfl⟩ := h |
| 137 | + exact ⟨⟨add_right_cancel (hx.trans hy.symm), rfl⟩, rfl, rfl⟩ |
| 138 | + · intro x hx |
| 139 | + have := hQmem x (mem_of_mem_filter x hx) |
| 140 | + simp only [mem_product] |
| 141 | + exact ⟨(mem_filter.mp hx).2, this.2.1, this.2.2.1⟩ |
| 142 | + have hcover : Q ⊆ {x ∈ (B ×ˢ B) ×ˢ B ×ˢ B | x.1.1 + x.2.1 = x.1.2 + x.2.2} ∪ |
| 143 | + ((Q.filter fun x => x.1.1 ∈ G) ∪ ((Q.filter fun x => x.1.2 ∈ G) ∪ |
| 144 | + ((Q.filter fun x => x.2.1 ∈ G) ∪ (Q.filter fun x => x.2.2 ∈ G)))) := by |
| 145 | + intro x hx |
| 146 | + have hm := hQmem x hx |
| 147 | + have he := (mem_filter.mp hx).2 |
| 148 | + simp only [hA, mem_union] at hm |
| 149 | + simp only [mem_union, mem_filter, mem_product] |
| 150 | + tauto |
| 151 | + calc A.addEnergy A = Q.card := rfl |
| 152 | + _ ≤ _ := card_le_card hcover |
| 153 | + _ ≤ B.addEnergy B + ((Q.filter fun x => x.1.1 ∈ G).card + ((Q.filter fun x => x.1.2 ∈ G).card + |
| 154 | + ((Q.filter fun x => x.2.1 ∈ G).card + (Q.filter fun x => x.2.2 ∈ G).card))) := by |
| 155 | + refine (card_union_le _ _).trans (Nat.add_le_add_left ?_ _) |
| 156 | + refine (card_union_le _ _).trans (Nat.add_le_add_left ?_ _) |
| 157 | + refine (card_union_le _ _).trans (Nat.add_le_add_left ?_ _) |
| 158 | + exact card_union_le _ _ |
| 159 | + _ ≤ B.addEnergy B + 4 * G.card * A.card ^ 2 := by |
| 160 | + have : 4 * G.card * A.card ^ 2 = G.card * A.card ^ 2 + (G.card * A.card ^ 2 + |
| 161 | + (G.card * A.card ^ 2 + G.card * A.card ^ 2)) := by ring |
| 162 | + rw [this] |
| 163 | + gcongr |
| 164 | + |
| 165 | +end General |
| 166 | + |
| 167 | +/-- Appending a leading digit: `D_{r+1} = {x + 16 y : x < 8, y ∈ D_r}`. -/ |
| 168 | +theorem digitBox_succ (r : ℕ) : |
| 169 | + digitBox (r + 1) = (range 8 ×ˢ digitBox r).image fun p => p.1 + 16 * p.2 := by |
| 170 | + ext n |
| 171 | + simp only [digitBox, mem_image, Behrend.mem_box, mem_product, mem_range, Prod.exists] |
| 172 | + constructor |
| 173 | + · rintro ⟨a, ha, rfl⟩ |
| 174 | + exact ⟨a 0, Behrend.map 16 (a ∘ Fin.succ), ⟨ha 0, a ∘ Fin.succ, fun i => ha i.succ, rfl⟩, |
| 175 | + by rw [Behrend.map_succ', mul_comm]⟩ |
| 176 | + · rintro ⟨x, y, ⟨hx, b, hb, rfl⟩, rfl⟩ |
| 177 | + refine ⟨Fin.cons x b, fun i => ?_, ?_⟩ |
| 178 | + · refine Fin.cases ?_ (fun j => ?_) i |
| 179 | + · simpa using hx |
| 180 | + · simpa using hb j |
| 181 | + · rw [Behrend.map_succ', mul_comm] |
| 182 | + rfl |
| 183 | + |
| 184 | +theorem addEnergy_range_eight : (range 8).addEnergy (range 8) = 344 := by |
| 185 | + decide +kernel |
| 186 | + |
| 187 | +/-- The energy of the digit box: `E(D_r) = 344 ^ r`. -/ |
| 188 | +theorem addEnergy_digitBox (r : ℕ) : (digitBox r).addEnergy (digitBox r) = 344 ^ r := by |
| 189 | + induction r with |
| 190 | + | zero => decide |
| 191 | + | succ r ih => |
| 192 | + rw [digitBox_succ, addEnergy_image_of_sum_iff, addEnergy_product, addEnergy_range_eight, ih, |
| 193 | + pow_succ, mul_comm] |
| 194 | + · rintro ⟨x, y⟩ hx ⟨x', y'⟩ hx' h |
| 195 | + simp only [coe_product, Set.mem_prod, mem_coe, mem_range] at hx hx' |
| 196 | + simp only [Prod.mk.injEq] |
| 197 | + dsimp only at h |
| 198 | + omega |
| 199 | + · rintro ⟨x₁, y₁⟩ h₁ ⟨x₂, y₂⟩ h₂ ⟨x₃, y₃⟩ h₃ ⟨x₄, y₄⟩ h₄ |
| 200 | + simp only [mem_product, mem_range] at h₁ h₂ h₃ h₄ |
| 201 | + simp only [Prod.mk_add_mk, Prod.mk.injEq] |
| 202 | + omega |
| 203 | + |
| 204 | +/-- Every set of numbers with `r` base-16 digits in `{0, …, 7}` has energy at most `344 ^ r`. -/ |
| 205 | +theorem addEnergy_le_of_subset_digitBox {r : ℕ} {B : Finset ℕ} (hB : B ⊆ digitBox r) : |
| 206 | + B.addEnergy B ≤ 344 ^ r := |
| 207 | + (addEnergy_mono hB hB).trans_eq (addEnergy_digitBox r) |
| 208 | + |
| 209 | +/-- The energy of a subset of the digit box together with an arbitrary finite scaffold. -/ |
| 210 | +theorem addEnergy_union_le_of_subset_digitBox {r : ℕ} {B : Finset ℕ} (hB : B ⊆ digitBox r) |
| 211 | + (G : Finset ℕ) : |
| 212 | + (B ∪ G).addEnergy (B ∪ G) ≤ 344 ^ r + 4 * G.card * (B ∪ G).card ^ 2 := |
| 213 | + (addEnergy_union_le B G).trans (Nat.add_le_add_right (addEnergy_le_of_subset_digitBox hB) _) |
| 214 | + |
| 215 | +end ErdosSwarm.Erdos530DigitEnergy |