| | @@ -0,0 +1,232 @@ |
| 1 | +import ErdosSwarm.Erdos530ConditionalProjection |
| 2 | +import Mathlib.Algebra.BigOperators.Field |
| 3 | +import Mathlib.Data.Finset.CastCard |
| 4 | +import Mathlib.Data.Real.Basic |
| 5 | +import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional |
| 6 | + |
| 7 | +/-! |
| 8 | +# Mean collision counts for Erdős problem 530 |
| 9 | + |
| 10 | +Equations (3) and (4) of §1 of |
| 11 | +`experiments/erdos530/lower-middle-energy2/box-occupancy/NOTES.md` count |
| 12 | +unordered subsets under a uniform linear map, including the zero map. The |
| 13 | +target cardinality `q` is `p²` for a plane over a field of order `p`. The pair term |
| 14 | +recovers the projection count in [Proposition 7.2 of the October 2026 |
| 15 | +report](https://github.com/xinjiegit/sidon-palomar/blob/7a3e0ae77/docs/research-report.tex#L763-L794). |
| 16 | +-/ |
| 17 | + |
| 18 | +namespace ErdosSwarm.Erdos530ProjectionMoments |
| 19 | + |
| 20 | +open Finset Erdos530Monochromatic Erdos530ConditionalProjection |
| 21 | +open scoped Classical |
| 22 | + |
| 23 | +variable (F : Type*) {V : Type*} (W : Type*) [Field F] [AddCommGroup V] [Module F V] |
| 24 | + [AddCommGroup W] [Module F W] [Fintype (V →ₗ[F] W)] [DecidableEq W] |
| 25 | + |
| 26 | +/-- Fraction of linear maps that take a single value on `T`. -/ |
| 27 | +noncomputable def collisionWeight (T : Finset V) : ℝ := |
| 28 | + ((univ.filter fun L : V →ₗ[F] W => (T.image L).card = 1).card : ℝ) / |
| 29 | + Fintype.card (V →ₗ[F] W) |
| 30 | + |
| 31 | +/-- Mean number of monochromatic `k`-subsets of `A` over all linear maps. -/ |
| 32 | +noncomputable def meanCollisions [DecidableEq V] (A : Finset V) (k : ℕ) : ℝ := |
| 33 | + (∑ L : V →ₗ[F] W, ((monoSubsets A L k).card : ℝ)) / Fintype.card (V →ₗ[F] W) |
| 34 | + |
| 35 | +/-- Number of points of `A` in the affine span of `T`. -/ |
| 36 | +noncomputable def spanCount (A T : Finset V) : ℕ := |
| 37 | + (A.filter fun x => x ∈ affineSpan F (T : Set V)).card |
| 38 | + |
| 39 | +theorem collisionWeight_nonneg (T : Finset V) : 0 ≤ collisionWeight F W T := |
| 40 | + div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _) |
| 41 | + |
| 42 | +variable [DecidableEq V] |
| 43 | + |
| 44 | +/-- On the `k`-subsets of `A`, the weight counts the maps appearing in the |
| 45 | +accepted definition of `monoSubsets`. -/ |
| 46 | +theorem collisionWeight_eq_monoSubsets {A T : Finset V} {k : ℕ} (hT : T ∈ A.powersetCard k) : |
| 47 | + collisionWeight F W T = |
| 48 | + ((univ.filter fun L : V →ₗ[F] W => T ∈ monoSubsets A L k).card : ℝ) / |
| 49 | + Fintype.card (V →ₗ[F] W) := by |
| 50 | + obtain ⟨hTA, hcard⟩ := mem_powersetCard.mp hT |
| 51 | + simp only [collisionWeight, mem_monoSubsets, hTA, hcard, eq_self, true_and] |
| 52 | + |
| 53 | +/-- Double count incidences of linear maps with their monochromatic subsets. -/ |
| 54 | +theorem meanCollisions_eq_sum (A : Finset V) (k : ℕ) : |
| 55 | + meanCollisions F W A k = ∑ T ∈ A.powersetCard k, collisionWeight F W T := by |
| 56 | + unfold meanCollisions collisionWeight monoSubsets |
| 57 | + simp only [← sum_div, card_filter, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero] |
| 58 | + rw [sum_comm] |
| 59 | + |
| 60 | +theorem collisionWeight_insert_of_mem {T : Finset V} (hT : T.Nonempty) {x : V} |
| 61 | + (hx : x ∈ affineSpan F (T : Set V)) : |
| 62 | + collisionWeight F W (insert x T) = collisionWeight F W T := by |
| 63 | + simp only [collisionWeight, filter_insert_collision_of_mem hT hx] |
| 64 | + |
| 65 | +variable [Fintype W] |
| 66 | + |
| 67 | +theorem collisionWeight_insert_of_notMem {T : Finset V} (hT : T.Nonempty) {x : V} |
| 68 | + (hx : x ∉ affineSpan F (T : Set V)) : |
| 69 | + collisionWeight F W (insert x T) = collisionWeight F W T / Fintype.card W := by |
| 70 | + have h := card_insert_collision_of_notMem (W := W) hT hx |
| 71 | + have h' : (Fintype.card W : ℝ) * |
| 72 | + ((univ.filter fun L : V →ₗ[F] W => ((insert x T).image L).card = 1).card : ℝ) = |
| 73 | + (univ.filter fun L : V →ₗ[F] W => (T.image L).card = 1).card := by exact_mod_cast h |
| 74 | + unfold collisionWeight |
| 75 | + rw [← h'] |
| 76 | + field_simp |
| 77 | + |
| 78 | +/-- Every two-point subset collides with probability `1 / q`. -/ |
| 79 | +theorem collisionWeight_pair {T : Finset V} (hT : T.card = 2) : |
| 80 | + collisionWeight F W T = 1 / Fintype.card W := by |
| 81 | + obtain ⟨a, b, hab, rfl⟩ := card_eq_two.mp hT |
| 82 | + have hx : a ∉ affineSpan F (({b} : Finset V) : Set V) := by |
| 83 | + simpa only [coe_singleton, AffineSubspace.mem_affineSpan_singleton] using hab |
| 84 | + rw [collisionWeight_insert_of_notMem F W (singleton_nonempty b) hx] |
| 85 | + simp [collisionWeight, Fintype.card_ne_zero] |
| 86 | + |
| 87 | +/-- The expected number of colliding pairs is the pair term in equation (3). -/ |
| 88 | +theorem meanCollisions_two (A : Finset V) : |
| 89 | + meanCollisions F W A 2 = (A.card.choose 2 : ℝ) / Fintype.card W := by |
| 90 | + rw [meanCollisions_eq_sum] |
| 91 | + calc |
| 92 | + _ = ∑ _T ∈ A.powersetCard 2, (1 : ℝ) / Fintype.card W := |
| 93 | + sum_congr rfl fun _ h => collisionWeight_pair F W (mem_powersetCard.mp h).2 |
| 94 | + _ = _ := by simp [div_eq_mul_inv] |
| 95 | + |
| 96 | +/-- The weight of an unordered triple is determined by collinearity, independently |
| 97 | +of the choice or ordering of its three points. -/ |
| 98 | +theorem collisionWeight_three {T : Finset V} (hT : T.card = 3) : |
| 99 | + collisionWeight F W T = |
| 100 | + if Collinear F (T : Set V) then (1 : ℝ) / Fintype.card W else 1 / (Fintype.card W : ℝ) ^ 2 := by |
| 101 | + obtain ⟨a, b, c, -, -, hbc, rfl⟩ := card_eq_three.mp hT |
| 102 | + have hpair : ({b, c} : Finset V).card = 2 := by simp [hbc] |
| 103 | + have hline : Collinear F (({a, b, c} : Finset V) : Set V) ↔ |
| 104 | + a ∈ affineSpan F (({b, c} : Finset V) : Set V) := by |
| 105 | + simp only [coe_insert, coe_singleton] |
| 106 | + exact ⟨fun h => h.mem_affineSpan_of_mem_of_ne (by simp) (by simp) (by simp) hbc, |
| 107 | + collinear_insert_of_mem_affineSpan_pair⟩ |
| 108 | + split_ifs with h |
| 109 | + · rw [collisionWeight_insert_of_mem F W (insert_nonempty b {c}) (hline.mp h), |
| 110 | + collisionWeight_pair F W hpair] |
| 111 | + · rw [collisionWeight_insert_of_notMem F W (insert_nonempty b {c}) (mt hline.mpr h), |
| 112 | + collisionWeight_pair F W hpair, div_div, sq] |
| 113 | + |
| 114 | +/-- For a triple the weight is at least `1 / q²`, including the collinear case. -/ |
| 115 | +theorem collisionWeight_three_ge {T : Finset V} (hT : T.card = 3) : |
| 116 | + 1 / (Fintype.card W : ℝ) ^ 2 ≤ collisionWeight F W T := by |
| 117 | + rw [collisionWeight_three F W hT] |
| 118 | + split_ifs |
| 119 | + · have hq : 1 ≤ (Fintype.card W : ℝ) := by exact_mod_cast Fintype.card_pos (α := W) |
| 120 | + exact one_div_le_one_div_of_le (by positivity) (by nlinarith) |
| 121 | + · exact le_rfl |
| 122 | + |
| 123 | +/-- Equation (3), with the triple lower bound valid even when there are no triples. -/ |
| 124 | +theorem meanCollisions_three_ge (A : Finset V) : |
| 125 | + (A.card.choose 3 : ℝ) / (Fintype.card W : ℝ) ^ 2 ≤ meanCollisions F W A 3 := by |
| 126 | + rw [meanCollisions_eq_sum] |
| 127 | + calc |
| 128 | + _ = ∑ _T ∈ A.powersetCard 3, (1 : ℝ) / (Fintype.card W : ℝ) ^ 2 := by simp [div_eq_mul_inv] |
| 129 | + _ ≤ _ := sum_le_sum fun _ h => collisionWeight_three_ge F W (mem_powersetCard.mp h).2 |
| 130 | + |
| 131 | +theorem meanCollisions_three_pos {A : Finset V} (hA : 3 ≤ A.card) : |
| 132 | + 0 < meanCollisions F W A 3 := |
| 133 | + lt_of_lt_of_le (div_pos (Nat.cast_pos.mpr (Nat.choose_pos hA)) |
| 134 | + (sq_pos_of_pos (Nat.cast_pos.mpr (Fintype.card_pos (α := W))))) |
| 135 | + (meanCollisions_three_ge F W A) |
| 136 | + |
| 137 | +private theorem insert_collision_iff {α β : Type*} [DecidableEq α] [DecidableEq β] |
| 138 | + (f : α → β) {T : Finset α} (hT : T.Nonempty) (x : α) : |
| 139 | + ((insert x T).image f).card = 1 ↔ (T.image f).card = 1 ∧ f x ∈ T.image f := by |
| 140 | + rw [image_insert] |
| 141 | + by_cases h : f x ∈ T.image f |
| 142 | + · simp [h] |
| 143 | + · have hpos := (hT.image f).card_pos |
| 144 | + rw [card_insert_of_notMem h] |
| 145 | + simp only [h, and_false, iff_false] |
| 146 | + omega |
| 147 | + |
| 148 | +/-- Rewrite the accepted marked-subset count as a sum over all possible insertions. -/ |
| 149 | +private theorem marked_sum {α β : Type*} [DecidableEq α] [DecidableEq β] |
| 150 | + (A : Finset α) (f : α → β) {k : ℕ} (hk : 0 < k) : |
| 151 | + (k + 1) * (monoSubsets A f (k + 1)).card = |
| 152 | + ∑ T ∈ A.powersetCard k, ∑ x ∈ A \ T, if ((insert x T).image f).card = 1 then 1 else 0 := by |
| 153 | + rw [succ_mul_card_monoSubsets_succ A f hk, monoSubsets, sum_filter] |
| 154 | + refine sum_congr rfl fun T hTA => ?_ |
| 155 | + have hT : T.Nonempty := card_pos.mp ((mem_powersetCard.mp hTA).2.symm ▸ hk) |
| 156 | + simp_rw [insert_collision_iff f hT] |
| 157 | + by_cases h : (T.image f).card = 1 |
| 158 | + · simp only [h, if_true, true_and, extensions, card_filter] |
| 159 | + · simp [h] |
| 160 | + |
| 161 | +omit [Fintype W] in |
| 162 | +/-- Count each monochromatic `(k+1)`-subset once for each of its marked points. -/ |
| 163 | +theorem succ_mul_meanCollisions (A : Finset V) {k : ℕ} (hk : 0 < k) : |
| 164 | + ((k + 1 : ℕ) : ℝ) * meanCollisions F W A (k + 1) = |
| 165 | + ∑ T ∈ A.powersetCard k, ∑ x ∈ A \ T, collisionWeight F W (insert x T) := by |
| 166 | + have h : (k + 1) * ∑ L : V →ₗ[F] W, (monoSubsets A L (k + 1)).card = |
| 167 | + ∑ T ∈ A.powersetCard k, ∑ x ∈ A \ T, |
| 168 | + (univ.filter fun L : V →ₗ[F] W => ((insert x T).image L).card = 1).card := by |
| 169 | + rw [mul_sum] |
| 170 | + simp_rw [marked_sum A _ hk] |
| 171 | + rw [sum_comm] |
| 172 | + refine sum_congr rfl fun T _ => ?_ |
| 173 | + rw [sum_comm] |
| 174 | + simp only [card_filter] |
| 175 | + unfold meanCollisions collisionWeight |
| 176 | + simp only [← sum_div, ← mul_div_assoc] |
| 177 | + congr 1 |
| 178 | + exact_mod_cast h |
| 179 | + |
| 180 | +/-- Conditional on a collision of `T`, each of the other points in its span joins |
| 181 | +the fibre, and each point outside joins with probability `1 / q`. -/ |
| 182 | +theorem sum_collisionWeight_insert (A T : Finset V) (hT : T.Nonempty) (hTA : T ⊆ A) : |
| 183 | + ∑ x ∈ A \ T, collisionWeight F W (insert x T) = |
| 184 | + collisionWeight F W T * ((spanCount F A T : ℝ) - T.card + |
| 185 | + ((A.card : ℝ) - spanCount F A T) / Fintype.card W) := by |
| 186 | + let B := A.filter fun x => x ∈ affineSpan F (T : Set V) |
| 187 | + have hBA : B ⊆ A := filter_subset _ _ |
| 188 | + have hTB : T ⊆ B := fun x hx => mem_filter.mpr ⟨hTA hx, mem_affineSpan F hx⟩ |
| 189 | + have hdis : Disjoint (A \ B) (B \ T) := disjoint_sdiff_self_left.mono_right sdiff_subset |
| 190 | + rw [← sdiff_union_sdiff_cancel hBA hTB, sum_union hdis] |
| 191 | + have hin : ∀ x ∈ B \ T, collisionWeight F W (insert x T) = collisionWeight F W T := by |
| 192 | + intro x hx |
| 193 | + exact collisionWeight_insert_of_mem F W hT (mem_filter.mp (mem_sdiff.mp hx).1).2 |
| 194 | + have hout : ∀ x ∈ A \ B, collisionWeight F W (insert x T) = |
| 195 | + collisionWeight F W T / Fintype.card W := by |
| 196 | + intro x hx |
| 197 | + obtain ⟨ha, hb⟩ := mem_sdiff.mp hx |
| 198 | + exact collisionWeight_insert_of_notMem F W hT (fun h => hb (mem_filter.mpr ⟨ha, h⟩)) |
| 199 | + rw [sum_congr rfl hin, sum_congr rfl hout] |
| 200 | + simp only [sum_const, nsmul_eq_mul, cast_card_sdiff hTB, cast_card_sdiff hBA] |
| 201 | + change ((A.card : ℝ) - B.card) * _ + ((B.card : ℝ) - T.card) * _ = |
| 202 | + _ * ((B.card : ℝ) - T.card + ((A.card : ℝ) - B.card) / _) |
| 203 | + ring |
| 204 | + |
| 205 | +/-- The exact fourth-moment identity (4). The weights are marginal probabilities, |
| 206 | +so the formula allows arbitrary dependence between different fourth points. -/ |
| 207 | +theorem four_mul_meanCollisions_four (A : Finset V) : |
| 208 | + 4 * meanCollisions F W A 4 = ∑ T ∈ A.powersetCard 3, |
| 209 | + collisionWeight F W T * ((spanCount F A T : ℝ) - 3 + |
| 210 | + ((A.card : ℝ) - spanCount F A T) / Fintype.card W) := by |
| 211 | + rw [show (4 : ℝ) = ((3 + 1 : ℕ) : ℝ) by norm_num, succ_mul_meanCollisions F W A (by decide : 0 < 3)] |
| 212 | + refine sum_congr rfl fun T h => ?_ |
| 213 | + obtain ⟨hTA, hcard⟩ := mem_powersetCard.mp h |
| 214 | + have hT : T.Nonempty := card_pos.mp (by omega) |
| 215 | + simpa only [hcard, Nat.cast_ofNat] using sum_collisionWeight_insert F W A T hT hTA |
| 216 | + |
| 217 | +/-- A uniform cap on the triple spans gives the upper bound in (4). -/ |
| 218 | +theorem four_mul_meanCollisions_four_le (A : Finset V) (M : ℝ) |
| 219 | + (hM : ∀ T ∈ A.powersetCard 3, (spanCount F A T : ℝ) ≤ M) : |
| 220 | + 4 * meanCollisions F W A 4 ≤ meanCollisions F W A 3 * |
| 221 | + (M - 3 + ((A.card : ℝ) - 3) / Fintype.card W) := by |
| 222 | + rw [four_mul_meanCollisions_four, meanCollisions_eq_sum, sum_mul] |
| 223 | + refine sum_le_sum fun T h => mul_le_mul_of_nonneg_left ?_ (collisionWeight_nonneg F W T) |
| 224 | + obtain ⟨hTA, hcard⟩ := mem_powersetCard.mp h |
| 225 | + have hmin : 3 ≤ spanCount F A T := by |
| 226 | + rw [← hcard] |
| 227 | + exact card_le_card fun x hx => mem_filter.mpr ⟨hTA hx, mem_affineSpan F hx⟩ |
| 228 | + have hmin' : 3 ≤ (spanCount F A T : ℝ) := by exact_mod_cast hmin |
| 229 | + exact add_le_add (sub_le_sub_right (hM T h) _) |
| 230 | + (div_le_div_of_nonneg_right (sub_le_sub_left hmin' _) (Nat.cast_nonneg _)) |
| 231 | + |
| 232 | +end ErdosSwarm.Erdos530ProjectionMoments |