| | @@ -0,0 +1,272 @@ |
| 1 | +import Mathlib.Algebra.BigOperators.Ring.Finset |
| 2 | +import Mathlib.Algebra.Order.BigOperators.Group.Finset |
| 3 | +import Mathlib.Algebra.Order.Ring.Abs |
| 4 | +import Mathlib.Data.Fin.VecNotation |
| 5 | +import Mathlib.Data.Finset.Powerset |
| 6 | +import Mathlib.Data.Fintype.BigOperators |
| 7 | +import Mathlib.Data.Nat.Choose.Basic |
| 8 | +import Mathlib.Tactic.Linarith |
| 9 | +import Mathlib.Tactic.LinearCombination |
| 10 | +import Mathlib.Tactic.Ring |
| 11 | + |
| 12 | +/-! |
| 13 | +# Erdős problem 530: one integer label vector from a separating family |
| 14 | + |
| 15 | +Second paragraph of "An integer model for arbitrary row labels" in |
| 16 | +`experiments/erdos530/lower-middle-energy/NOTES.md`, §2. There the real row labels |
| 17 | +`x_1, …, x_k` satisfy the integer relations `x_i + x_j = x_s + x_t`, the integer vectors |
| 18 | +`v_b` (obtained by Cramer's rule) span the kernel of those relations, and "at every pair of |
| 19 | +indices some basis vector distinguishes them". The note then forms an integer combination |
| 20 | +`y = Σ_b c_b v_b` with coefficients in `{0, …, C(k,2)}` that distinguishes every pair, of |
| 21 | +coordinate size at most `(number of vectors) · C(k,2) · max |v_b i|`. |
| 22 | + |
| 23 | +Lean-checked here, for any finite family of integer vectors (no hypothesis that they come from |
| 24 | +Cramer's rule or span anything): |
| 25 | + |
| 26 | +* `exists_coeff_separating`: one step — for `y v : ι → ℤ` some `c ≤ C(k,2)` keeps every pair |
| 27 | + that `y` or `v` distinguishes distinguished by `y + c v`. |
| 28 | +* `exists_separating_combination`: coefficients `c b ≤ C(k,2)` such that `Σ_b c_b v_b` |
| 29 | + distinguishes every pair distinguished by some `v_b`, `b ∈ s`. |
| 30 | +* `exists_int_labels_of_family`: the resulting labels, with the size bound |
| 31 | + `|y i| ≤ |s| · C(k,2) · M` and every relation `v_b i + v_b j = v_b k + v_b l` (all `b ∈ s`) |
| 32 | + inherited by `y`. |
| 33 | +* `exists_int_model_of_family_abs`, `exists_int_model_of_family`: the same for labels |
| 34 | + `x : ι → R` in any type with an addition (the reals in the note): if the family separates the |
| 35 | + pairs that `x` separates and each `v_b` preserves the equal pair sums of `x`, then so does one |
| 36 | + integer vector `y`, with `|y i| ≤ |s| C(k,2) M`, hence of diameter at most `2 |s| C(k,2) M`. |
| 37 | + |
| 38 | +Not here: that such a family exists for real labels (the note's first paragraph, Cramer's rule |
| 39 | +and Hadamard's inequality); that is still a paper proof. |
| 40 | + |
| 41 | +The proof is deterministic: where the note takes random coefficients and a union bound, the |
| 42 | +coefficients are chosen here one vector at a time (each of the `C(k,2)` pairs excludes at most |
| 43 | +one of the `C(k,2) + 1` values of the new coefficient). |
| 44 | + |
| 45 | +Status. Only this combination step is Lean-checked. The existence of the family for real |
| 46 | +labels with `M ≤ 4^k` (Cramer's rule and Hadamard's inequality, first paragraph of the note's |
| 47 | +argument) remains a paper proof, and so does the integer model for real labels as a whole. |
| 48 | +-/ |
| 49 | + |
| 50 | +namespace ErdosSwarm.Erdos530IntegerModel |
| 51 | + |
| 52 | +open Finset |
| 53 | + |
| 54 | +/-- **One coefficient.** For integer vectors `y v : ι → ℤ` on `k = Fintype.card ι` indices |
| 55 | +there is a coefficient `0 ≤ c ≤ C(k,2)` such that `y + c v` distinguishes every pair of indices |
| 56 | +distinguished by `y` or by `v`. |
| 57 | + |
| 58 | +Proof: if every `c` in `{0, …, C(k,2)}` failed at some pair `{i, j}`, two different `c, c'` |
| 59 | +would fail at the same pair; subtracting, `(c - c') (v i - v j) = 0`, so `v i = v j` and then |
| 60 | +`y i = y j`. -/ |
| 61 | +theorem exists_coeff_separating {ι : Type*} [Fintype ι] (y v : ι → ℤ) : |
| 62 | + ∃ c : ℕ, c ≤ (Fintype.card ι).choose 2 ∧ |
| 63 | + ∀ i j, (y i ≠ y j ∨ v i ≠ v j) → y i + c * v i ≠ y j + c * v j := by |
| 64 | + classical |
| 65 | + rcases isEmpty_or_nonempty ι with hι | hι |
| 66 | + · exact ⟨0, Nat.zero_le _, fun i => isEmptyElim i⟩ |
| 67 | + by_contra hcon |
| 68 | + push Not at hcon |
| 69 | + choose! I J hIJ using hcon |
| 70 | + have hne : ∀ c, c ≤ (Fintype.card ι).choose 2 → I c ≠ J c := by |
| 71 | + intro c hc h |
| 72 | + have h1 := (hIJ c hc).1 |
| 73 | + rw [h] at h1 |
| 74 | + simp at h1 |
| 75 | + obtain ⟨c, hc, c', hc', hcc, hf⟩ := Finset.exists_ne_map_eq_of_card_lt_of_maps_to |
| 76 | + (s := Finset.range ((Fintype.card ι).choose 2 + 1)) |
| 77 | + (t := (Finset.univ : Finset ι).powersetCard 2) |
| 78 | + (f := fun c => ({I c, J c} : Finset ι)) |
| 79 | + (by rw [Finset.card_powersetCard, Finset.card_range, Finset.card_univ]; exact Nat.lt_succ_self _) |
| 80 | + (by |
| 81 | + intro c hc |
| 82 | + have hc' : c ≤ (Fintype.card ι).choose 2 := Nat.lt_succ_iff.mp (Finset.mem_range.mp hc) |
| 83 | + exact Finset.mem_coe.mpr (Finset.mem_powersetCard.mpr |
| 84 | + ⟨Finset.subset_univ _, Finset.card_pair (hne c hc')⟩)) |
| 85 | + have hc := Nat.lt_succ_iff.mp (Finset.mem_range.mp hc) |
| 86 | + have hc' := Nat.lt_succ_iff.mp (Finset.mem_range.mp hc') |
| 87 | + have hf' : ({I c, J c} : Finset ι) = {I c', J c'} := hf |
| 88 | + have key : ∀ a b : ι, (y a ≠ y b ∨ v a ≠ v b) → y a + c * v a = y b + c * v b → |
| 89 | + y a + c' * v a = y b + c' * v b → False := by |
| 90 | + intro a b hab e1 e2 |
| 91 | + have e3 : ((c : ℤ) - c') * (v a - v b) = 0 := by linear_combination e1 - e2 |
| 92 | + rcases mul_eq_zero.mp e3 with h | h |
| 93 | + · exact hcc (by exact_mod_cast sub_eq_zero.mp h) |
| 94 | + · have hv : v a = v b := sub_eq_zero.mp h |
| 95 | + rw [hv] at e1 |
| 96 | + have hy : y a = y b := by linarith |
| 97 | + rcases hab with h' | h' |
| 98 | + · exact h' hy |
| 99 | + · exact h' hv |
| 100 | + have h1 : I c ∈ ({I c', J c'} : Finset ι) := by rw [← hf']; simp |
| 101 | + have h2 : J c ∈ ({I c', J c'} : Finset ι) := by rw [← hf']; simp |
| 102 | + simp only [Finset.mem_insert, Finset.mem_singleton] at h1 h2 |
| 103 | + obtain ⟨hab, e1⟩ := hIJ c hc |
| 104 | + obtain ⟨-, e2⟩ := hIJ c' hc' |
| 105 | + rcases h1 with h1 | h1 <;> rcases h2 with h2 | h2 |
| 106 | + · exact hne c hc (h1.trans h2.symm) |
| 107 | + · rw [← h1, ← h2] at e2 |
| 108 | + exact key _ _ hab e1 e2 |
| 109 | + · rw [← h1, ← h2] at e2 |
| 110 | + exact key _ _ hab e1 e2.symm |
| 111 | + · exact hne c hc (h1.trans h2.symm) |
| 112 | + |
| 113 | +/-- **A separating combination.** For a finite family `v b : ι → ℤ`, `b ∈ s`, of integer |
| 114 | +vectors on `k = Fintype.card ι` indices there are coefficients `0 ≤ c b ≤ C(k,2)` such that |
| 115 | +`Σ_{b ∈ s} c b • v b` distinguishes every pair of indices distinguished by some `v b`, `b ∈ s`. |
| 116 | +(Induction on `s` with `exists_coeff_separating`.) -/ |
| 117 | +theorem exists_separating_combination {ι β : Type*} [Fintype ι] (s : Finset β) |
| 118 | + (v : β → ι → ℤ) : |
| 119 | + ∃ c : β → ℕ, (∀ b, c b ≤ (Fintype.card ι).choose 2) ∧ |
| 120 | + ∀ i j, (∃ b ∈ s, v b i ≠ v b j) → |
| 121 | + ∑ b ∈ s, (c b : ℤ) * v b i ≠ ∑ b ∈ s, (c b : ℤ) * v b j := by |
| 122 | + classical |
| 123 | + induction s using Finset.induction_on with |
| 124 | + | empty => exact ⟨fun _ => 0, fun _ => Nat.zero_le _, by simp⟩ |
| 125 | + | insert a s ha ih => |
| 126 | + obtain ⟨c, hc, hsep⟩ := ih |
| 127 | + obtain ⟨c₀, hc₀, h₀⟩ := exists_coeff_separating |
| 128 | + (fun i => ∑ b ∈ s, (c b : ℤ) * v b i) (v a) |
| 129 | + refine ⟨Function.update c a c₀, ?_, ?_⟩ |
| 130 | + · intro b |
| 131 | + by_cases hb : b = a |
| 132 | + · rw [hb, Function.update_self] |
| 133 | + exact hc₀ |
| 134 | + · rw [Function.update_of_ne hb] |
| 135 | + exact hc b |
| 136 | + · intro i j hij |
| 137 | + have hsum : ∀ l, ∑ b ∈ insert a s, (Function.update c a c₀ b : ℤ) * v b l |
| 138 | + = ∑ b ∈ s, (c b : ℤ) * v b l + c₀ * v a l := by |
| 139 | + intro l |
| 140 | + rw [Finset.sum_insert ha, Function.update_self, add_comm] |
| 141 | + congr 1 |
| 142 | + refine Finset.sum_congr rfl fun b hb => ?_ |
| 143 | + rw [Function.update_of_ne (ne_of_mem_of_not_mem hb ha)] |
| 144 | + rw [hsum, hsum] |
| 145 | + apply h₀ |
| 146 | + obtain ⟨b, hb, hbv⟩ := hij |
| 147 | + rcases Finset.mem_insert.mp hb with hba | hb' |
| 148 | + · rw [hba] at hbv |
| 149 | + exact Or.inr hbv |
| 150 | + · exact Or.inl (hsep i j ⟨b, hb', hbv⟩) |
| 151 | + |
| 152 | +/-- **Integer labels from a family.** For a finite family `v b : ι → ℤ`, `b ∈ s`, with |
| 153 | +entries of absolute value at most `M`, there is one integer vector `y` that distinguishes every |
| 154 | +pair distinguished by some `v b`, has `|y i| ≤ |s| · C(k,2) · M` (`k = Fintype.card ι`), and |
| 155 | +satisfies every relation `y i + y j = y k + y l` satisfied by all the `v b`. -/ |
| 156 | +theorem exists_int_labels_of_family {ι β : Type*} [Fintype ι] (s : Finset β) (v : β → ι → ℤ) |
| 157 | + (M : ℕ) (hM : ∀ b ∈ s, ∀ i, |v b i| ≤ M) : |
| 158 | + ∃ y : ι → ℤ, |
| 159 | + (∀ i j, (∃ b ∈ s, v b i ≠ v b j) → y i ≠ y j) ∧ |
| 160 | + (∀ i, |y i| ≤ s.card * (Fintype.card ι).choose 2 * M) ∧ |
| 161 | + (∀ i j k l, (∀ b ∈ s, v b i + v b j = v b k + v b l) → y i + y j = y k + y l) := by |
| 162 | + obtain ⟨c, hc, hsep⟩ := exists_separating_combination s v |
| 163 | + refine ⟨fun i => ∑ b ∈ s, (c b : ℤ) * v b i, hsep, ?_, ?_⟩ |
| 164 | + · intro i |
| 165 | + calc |∑ b ∈ s, (c b : ℤ) * v b i| ≤ ∑ b ∈ s, |(c b : ℤ) * v b i| := |
| 166 | + Finset.abs_sum_le_sum_abs _ _ |
| 167 | + _ ≤ ∑ _b ∈ s, (((Fintype.card ι).choose 2 : ℕ) : ℤ) * M := by |
| 168 | + refine Finset.sum_le_sum fun b hb => ?_ |
| 169 | + rw [abs_mul, Nat.abs_cast] |
| 170 | + exact mul_le_mul (by exact_mod_cast hc b) (hM b hb i) (abs_nonneg _) |
| 171 | + (Int.natCast_nonneg _) |
| 172 | + _ = s.card * (Fintype.card ι).choose 2 * M := by |
| 173 | + rw [Finset.sum_const, nsmul_eq_mul] |
| 174 | + ring |
| 175 | + · intro i j k l h |
| 176 | + show ∑ b ∈ s, (c b : ℤ) * v b i + ∑ b ∈ s, (c b : ℤ) * v b j |
| 177 | + = ∑ b ∈ s, (c b : ℤ) * v b k + ∑ b ∈ s, (c b : ℤ) * v b l |
| 178 | + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] |
| 179 | + refine Finset.sum_congr rfl fun b hb => ?_ |
| 180 | + rw [← mul_add, ← mul_add, h b hb] |
| 181 | + |
| 182 | +/-- **An integer model from a separating family, with bounded entries.** Let `x : ι → R` be |
| 183 | +labels in a type with an addition (the real row labels of the note) and `v b : ι → ℤ`, `b ∈ s`, |
| 184 | +integer vectors with entries of absolute value at most `M` such that every pair separated by `x` |
| 185 | +is separated by some `v b`, and every `v b` preserves the equal pair sums of `x`. Then one |
| 186 | +integer vector `y` separates every pair that `x` separates, preserves the equal pair sums of |
| 187 | +`x`, and has `|y i| ≤ |s| C(k,2) M` for all `i` (`k = Fintype.card ι`). -/ |
| 188 | +theorem exists_int_model_of_family_abs {ι β R : Type*} [Fintype ι] [Add R] (x : ι → R) |
| 189 | + (s : Finset β) (v : β → ι → ℤ) (M : ℕ) (hM : ∀ b ∈ s, ∀ i, |v b i| ≤ M) |
| 190 | + (hsep : ∀ i j, x i ≠ x j → ∃ b ∈ s, v b i ≠ v b j) |
| 191 | + (hrel : ∀ b ∈ s, ∀ i j k l, x i + x j = x k + x l → v b i + v b j = v b k + v b l) : |
| 192 | + ∃ y : ι → ℤ, |
| 193 | + (∀ i j, x i ≠ x j → y i ≠ y j) ∧ |
| 194 | + (∀ i j k l, x i + x j = x k + x l → y i + y j = y k + y l) ∧ |
| 195 | + (∀ i, |y i| ≤ ((s.card * (Fintype.card ι).choose 2 * M : ℕ) : ℤ)) := by |
| 196 | + obtain ⟨y, hy, hbound, hsum⟩ := exists_int_labels_of_family s v M hM |
| 197 | + refine ⟨y, fun i j hij => hy i j (hsep i j hij), |
| 198 | + fun i j k l h => hsum i j k l fun b hb => hrel b hb i j k l h, fun i => ?_⟩ |
| 199 | + have h := hbound i |
| 200 | + push_cast |
| 201 | + exact h |
| 202 | + |
| 203 | +/-- **An integer model from a separating family.** In the setting of |
| 204 | +`exists_int_model_of_family_abs`, one integer vector `y` separates every pair that `x` |
| 205 | +separates, preserves the equal pair sums of `x`, and has `y j - y i ≤ 2 |s| C(k,2) M` for all |
| 206 | +`i, j` (`k = Fintype.card ι`). For `s = ∅` the hypothesis `hsep` says that `x` is constant, and |
| 207 | +the bound is `0`: the vector `y` is constant. -/ |
| 208 | +theorem exists_int_model_of_family {ι β R : Type*} [Fintype ι] [Add R] (x : ι → R) |
| 209 | + (s : Finset β) (v : β → ι → ℤ) (M : ℕ) (hM : ∀ b ∈ s, ∀ i, |v b i| ≤ M) |
| 210 | + (hsep : ∀ i j, x i ≠ x j → ∃ b ∈ s, v b i ≠ v b j) |
| 211 | + (hrel : ∀ b ∈ s, ∀ i j k l, x i + x j = x k + x l → v b i + v b j = v b k + v b l) : |
| 212 | + ∃ y : ι → ℤ, |
| 213 | + (∀ i j, x i ≠ x j → y i ≠ y j) ∧ |
| 214 | + (∀ i j k l, x i + x j = x k + x l → y i + y j = y k + y l) ∧ |
| 215 | + (∀ i j, y j - y i ≤ ((2 * s.card * (Fintype.card ι).choose 2 * M : ℕ) : ℤ)) := by |
| 216 | + obtain ⟨y, hy, hsum, hbound⟩ := exists_int_model_of_family_abs x s v M hM hsep hrel |
| 217 | + refine ⟨y, hy, hsum, fun i j => ?_⟩ |
| 218 | + have hi := abs_le.mp (hbound i) |
| 219 | + have hj := abs_le.mp (hbound j) |
| 220 | + push_cast at hi hj ⊢ |
| 221 | + linarith |
| 222 | + |
| 223 | +/-- An instance: the two vectors `(0,0,1,1)` and `(0,1,0,1)` on four indices (the integer |
| 224 | +coordinates of the real labels `0, 1, √2, 1 + √2`) give four distinct integers of absolute value |
| 225 | +at most `2 · C(4,2) · 1 = 12` with `y 0 + y 3 = y 1 + y 2`. -/ |
| 226 | +theorem exists_four_labels : |
| 227 | + ∃ y : Fin 4 → ℤ, Function.Injective y ∧ y 0 + y 3 = y 1 + y 2 ∧ ∀ i, |y i| ≤ 12 := by |
| 228 | + have hsep : ∀ i j : Fin 4, i ≠ j → ∃ b ∈ (Finset.univ : Finset (Fin 2)), |
| 229 | + (if b = 0 then (![0, 0, 1, 1] : Fin 4 → ℤ) else ![0, 1, 0, 1]) i |
| 230 | + ≠ (if b = 0 then (![0, 0, 1, 1] : Fin 4 → ℤ) else ![0, 1, 0, 1]) j := by decide |
| 231 | + obtain ⟨y, hy, hbound, hsum⟩ := exists_int_labels_of_family (Finset.univ : Finset (Fin 2)) |
| 232 | + (fun b => if b = 0 then ![0, 0, 1, 1] else ![0, 1, 0, 1]) 1 (by decide) |
| 233 | + refine ⟨y, ?_, hsum 0 3 1 2 (by decide), fun i => ?_⟩ |
| 234 | + · intro i j hij |
| 235 | + by_contra hne |
| 236 | + exact hy i j (hsep i j hne) hij |
| 237 | + · have h := hbound i |
| 238 | + have h4 : Nat.choose 4 2 = 6 := by decide |
| 239 | + simpa [h4] using h |
| 240 | + |
| 241 | +/-- The same instance through `exists_int_model_of_family_abs` itself: the labels are |
| 242 | +`x i = (v₀ i, v₁ i)` in `ℤ × ℤ` (used only through its addition), `s` is the whole of `Fin 2` |
| 243 | +and `M = 1`, so the stated bounds are `|y i| ≤ 2 · C(4,2) · 1 = 12` and `y j - y i ≤ 24`. -/ |
| 244 | +theorem exists_four_labels_of_model : |
| 245 | + ∃ y : Fin 4 → ℤ, Function.Injective y ∧ y 0 + y 3 = y 1 + y 2 ∧ |
| 246 | + (∀ i, |y i| ≤ 12) ∧ ∀ i j, y j - y i ≤ 24 := by |
| 247 | + let v : Fin 2 → Fin 4 → ℤ := fun b => if b = 0 then ![0, 0, 1, 1] else ![0, 1, 0, 1] |
| 248 | + let x : Fin 4 → ℤ × ℤ := fun i => (v 0 i, v 1 i) |
| 249 | + have hM : ∀ b ∈ (Finset.univ : Finset (Fin 2)), ∀ i, |v b i| ≤ ((1 : ℕ) : ℤ) := by decide |
| 250 | + have hsep : ∀ i j, x i ≠ x j → ∃ b ∈ (Finset.univ : Finset (Fin 2)), v b i ≠ v b j := by |
| 251 | + decide |
| 252 | + have hrel : ∀ b ∈ (Finset.univ : Finset (Fin 2)), ∀ i j k l, |
| 253 | + x i + x j = x k + x l → v b i + v b j = v b k + v b l := by decide |
| 254 | + have hx : Function.Injective x := by decide |
| 255 | + have h4 : Nat.choose 4 2 = 6 := by decide |
| 256 | + obtain ⟨y, h1, h2, h3⟩ := exists_int_model_of_family_abs x Finset.univ v 1 hM hsep hrel |
| 257 | + have h3' : ∀ i, |y i| ≤ 12 := fun i => by simpa [h4] using h3 i |
| 258 | + refine ⟨y, fun i j hij => ?_, h2 0 3 1 2 (by decide), h3', fun i j => ?_⟩ |
| 259 | + · by_contra hne |
| 260 | + exact h1 i j (fun h => hne (hx h)) hij |
| 261 | + · have hi := abs_le.mp (h3' i) |
| 262 | + have hj := abs_le.mp (h3' j) |
| 263 | + linarith |
| 264 | + |
| 265 | +/-- The empty family (`s = ∅`, constant labels, `M = 0`): the model is a constant vector. -/ |
| 266 | +theorem exists_int_model_of_empty_family {ι R : Type*} [Fintype ι] [Add R] (a : R) : |
| 267 | + ∃ y : ι → ℤ, ∀ i j, y j - y i ≤ 0 := by |
| 268 | + obtain ⟨y, -, -, h⟩ := exists_int_model_of_family (β := Empty) (fun _ : ι => a) ∅ |
| 269 | + (fun b => b.elim) 0 (by simp) (by simp) (by simp) |
| 270 | + exact ⟨y, by simpa using h⟩ |
| 271 | + |
| 272 | +end ErdosSwarm.Erdos530IntegerModel |