| | @@ -0,0 +1,203 @@ |
| 1 | +import ErdosSwarm.Erdos530PrimeField |
| 2 | +import Mathlib.Algebra.BigOperators.Expect |
| 3 | +import Mathlib.Algebra.BigOperators.Field |
| 4 | +import Mathlib.Tactic.LinearCombination |
| 5 | + |
| 6 | +/-! |
| 7 | +# The size of a random parabola slice for Erdős problem 530 |
| 8 | + |
| 9 | +For a plane set and any profile `f`, add a uniformly random affine function |
| 10 | +to `f` and count how many points lie on the resulting graph. Its mean and |
| 11 | +variance depend only on the column sizes. At two distinct abscissas, the |
| 12 | +heights are independent and uniform. For the quadratic profile in odd |
| 13 | +characteristic, every slice provides Sidon representatives in the source. |
| 14 | +-/ |
| 15 | + |
| 16 | +namespace ErdosSwarm.Erdos530ParabolaSlice |
| 17 | + |
| 18 | +open Finset |
| 19 | +open scoped BigOperators |
| 20 | + |
| 21 | +variable {F : Type*} [Field F] [DecidableEq F] |
| 22 | + |
| 23 | +/-- Points of `I` on the graph of `f` plus the affine function with |
| 24 | +slope `s.1` and intercept `s.2`. -/ |
| 25 | +def graphSlice (I : Finset (F × F)) (f : F → F) (s : F × F) : Finset (F × F) := |
| 26 | + I.filter fun z => z.2 = f z.1 + s.1 * z.1 + s.2 |
| 27 | + |
| 28 | +section Moments |
| 29 | + |
| 30 | +variable [Fintype F] |
| 31 | + |
| 32 | +/-- The number of points of the plane set above `x`. -/ |
| 33 | +def columnSize (I : Finset (F × F)) (x : F) : ℕ := |
| 34 | + (univ.filter fun y => (x, y) ∈ I).card |
| 35 | + |
| 36 | +private def hit (I : Finset (F × F)) (x y : F) : ℝ := |
| 37 | + if (x, y) ∈ I then 1 else 0 |
| 38 | + |
| 39 | +omit [Field F] in |
| 40 | +private theorem sum_columnSize (I : Finset (F × F)) : |
| 41 | + (∑ x, (columnSize I x : ℝ)) = I.card := by |
| 42 | + calc |
| 43 | + _ = ∑ z : F × F, hit I z.1 z.2 := by |
| 44 | + rw [Fintype.sum_prod_type] |
| 45 | + simp [hit, columnSize] |
| 46 | + _ = _ := by simp [hit] |
| 47 | + |
| 48 | +private theorem card_graphSlice_eq_sum (I : Finset (F × F)) (f : F → F) (s : F × F) : |
| 49 | + ((graphSlice I f s).card : ℝ) = ∑ x, hit I x (f x + s.1 * x + s.2) := by |
| 50 | + let h (x : F) := f x + s.1 * x + s.2 |
| 51 | + have heq : graphSlice I f s = |
| 52 | + (univ.filter fun x => (x, h x) ∈ I).image fun x => (x, h x) := by |
| 53 | + ext ⟨x, y⟩ |
| 54 | + simp only [graphSlice, mem_filter, mem_image, mem_univ, true_and, Prod.mk.injEq] |
| 55 | + constructor |
| 56 | + · rintro ⟨hi, rfl⟩ |
| 57 | + exact ⟨x, hi, rfl, rfl⟩ |
| 58 | + · rintro ⟨_, hi, rfl, rfl⟩ |
| 59 | + exact ⟨hi, rfl⟩ |
| 60 | + rw [heq, card_image_of_injective _ (fun a b e => congrArg Prod.fst e)] |
| 61 | + simp [hit, h] |
| 62 | + |
| 63 | +omit [DecidableEq F] in |
| 64 | +private theorem expect_one_height (f : F → F) (x : F) (g : F → ℝ) : |
| 65 | + (𝔼 s : F × F, g (f x + s.1 * x + s.2)) = 𝔼 y, g y := by |
| 66 | + have shift (m : F) : (𝔼 b : F, g (f x + m * x + b)) = 𝔼 y, g y := |
| 67 | + Fintype.expect_equiv (Equiv.addLeft (f x + m * x)) _ _ (fun _ => rfl) |
| 68 | + rw [← univ_product_univ, expect_product] |
| 69 | + simp only [shift, Fintype.expect_const] |
| 70 | + |
| 71 | +/-- Two heights determine the unique slope and intercept through them. -/ |
| 72 | +private def heightEquiv (f : F → F) (x y : F) (hxy : x ≠ y) : (F × F) ≃ F × F where |
| 73 | + toFun s := (f x + s.1 * x + s.2, f y + s.1 * y + s.2) |
| 74 | + invFun z := |
| 75 | + let m := ((z.1 - f x) - (z.2 - f y)) / (x - y) |
| 76 | + (m, z.1 - f x - m * x) |
| 77 | + left_inv := by |
| 78 | + intro s |
| 79 | + apply Prod.ext <;> dsimp <;> field_simp [sub_ne_zero.mpr hxy] <;> ring |
| 80 | + right_inv := by |
| 81 | + intro z |
| 82 | + apply Prod.ext <;> dsimp <;> field_simp [sub_ne_zero.mpr hxy] <;> ring |
| 83 | + |
| 84 | +omit [DecidableEq F] in |
| 85 | +private theorem expect_two_heights (f : F → F) {x y : F} (hxy : x ≠ y) (g h : F → ℝ) : |
| 86 | + (𝔼 s : F × F, g (f x + s.1 * x + s.2) * h (f y + s.1 * y + s.2)) = |
| 87 | + (𝔼 u, g u) * 𝔼 v, h v := by |
| 88 | + calc |
| 89 | + _ = 𝔼 z : F × F, g z.1 * h z.2 := |
| 90 | + Fintype.expect_equiv (heightEquiv f x y hxy) _ _ (fun _ => rfl) |
| 91 | + _ = _ := by rw [← univ_product_univ, expect_product, expect_mul_expect] |
| 92 | + |
| 93 | +omit [Field F] in |
| 94 | +private theorem expect_hit (I : Finset (F × F)) (x : F) : |
| 95 | + (𝔼 y, hit I x y) = (columnSize I x : ℝ) / Fintype.card F := by |
| 96 | + simp [hit, columnSize, Fintype.expect_eq_sum_div_card] |
| 97 | + |
| 98 | +/-- Mean slice size over all slopes and intercepts, including slope zero. -/ |
| 99 | +theorem expect_card_graphSlice (I : Finset (F × F)) (f : F → F) : |
| 100 | + (𝔼 s, ((graphSlice I f s).card : ℝ)) = (I.card : ℝ) / Fintype.card F := by |
| 101 | + simp_rw [card_graphSlice_eq_sum, expect_sum_comm, expect_one_height, expect_hit] |
| 102 | + rw [← sum_div, sum_columnSize] |
| 103 | + |
| 104 | +/-- The exact variance is the sum of the Bernoulli variances of the columns. -/ |
| 105 | +theorem variance_card_graphSlice (I : Finset (F × F)) (f : F → F) : |
| 106 | + (𝔼 s, (((graphSlice I f s).card : ℝ) - (I.card : ℝ) / Fintype.card F) ^ 2) = |
| 107 | + (∑ x, (columnSize I x : ℝ) * (Fintype.card F - (columnSize I x : ℝ))) / |
| 108 | + (Fintype.card F : ℝ) ^ 2 := by |
| 109 | + let q : ℝ := Fintype.card F |
| 110 | + let μ (x : F) := (columnSize I x : ℝ) / q |
| 111 | + let centered (x y : F) := hit I x y - μ x |
| 112 | + let height (s : F × F) (x : F) := f x + s.1 * x + s.2 |
| 113 | + have hq : q ≠ 0 := by dsimp [q]; exact_mod_cast Fintype.card_ne_zero |
| 114 | + have hzero (x : F) : (𝔼 y, centered x y) = 0 := by |
| 115 | + simp [centered, expect_sub_distrib, expect_hit, μ, q] |
| 116 | + have hdiag (x : F) : |
| 117 | + (𝔼 s : F × F, centered x (height s x) * centered x (height s x)) = μ x * (1 - μ x) := by |
| 118 | + rw [expect_one_height f x (fun y => centered x y * centered x y)] |
| 119 | + have hbernoulli (y : F) : centered x y * centered x y = |
| 120 | + (1 - 2 * μ x) * hit I x y + (μ x) ^ 2 := by |
| 121 | + dsimp only [centered, hit] |
| 122 | + split <;> ring |
| 123 | + simp_rw [hbernoulli] |
| 124 | + rw [expect_add_distrib, ← mul_expect, expect_hit, Fintype.expect_const] |
| 125 | + change (1 - 2 * μ x) * μ x + (μ x) ^ 2 = _ |
| 126 | + ring |
| 127 | + have hoff (x y : F) (hxy : x ≠ y) : |
| 128 | + (𝔼 s : F × F, centered x (height s x) * centered y (height s y)) = 0 := |
| 129 | + (expect_two_heights f hxy (centered x) (centered y)).trans (by rw [hzero, zero_mul]) |
| 130 | + have hsum (s : F × F) : |
| 131 | + ((graphSlice I f s).card : ℝ) - (I.card : ℝ) / q = ∑ x, centered x (height s x) := by |
| 132 | + simp only [centered, μ, height, sum_sub_distrib, ← sum_div, sum_columnSize, |
| 133 | + card_graphSlice_eq_sum] |
| 134 | + change (𝔼 s, (((graphSlice I f s).card : ℝ) - (I.card : ℝ) / q) ^ 2) = _ |
| 135 | + calc |
| 136 | + _ = ∑ x, ∑ y, 𝔼 s : F × F, centered x (height s x) * centered y (height s y) := by |
| 137 | + simp_rw [hsum, sq, sum_mul_sum, expect_sum_comm] |
| 138 | + _ = ∑ x, μ x * (1 - μ x) := by |
| 139 | + apply sum_congr rfl |
| 140 | + intro x _ |
| 141 | + rw [sum_eq_single_of_mem x (mem_univ _) (fun y _ hy => hoff x y hy.symm), hdiag] |
| 142 | + _ = _ := by |
| 143 | + rw [sum_div] |
| 144 | + apply sum_congr rfl |
| 145 | + intro x _ |
| 146 | + change (columnSize I x : ℝ) / q * (1 - (columnSize I x : ℝ) / q) = |
| 147 | + (columnSize I x : ℝ) * (q - (columnSize I x : ℝ)) / q ^ 2 |
| 148 | + field_simp |
| 149 | + |
| 150 | +/-- Each of the `q` columns contributes at most `1/4` to the variance. -/ |
| 151 | +theorem variance_card_graphSlice_le (I : Finset (F × F)) (f : F → F) : |
| 152 | + (𝔼 s, (((graphSlice I f s).card : ℝ) - (I.card : ℝ) / Fintype.card F) ^ 2) ≤ |
| 153 | + (Fintype.card F : ℝ) / 4 := by |
| 154 | + have hq : (0 : ℝ) < Fintype.card F := by exact_mod_cast Fintype.card_pos |
| 155 | + rw [variance_card_graphSlice, sum_div] |
| 156 | + calc |
| 157 | + _ ≤ ∑ _x : F, (1 / 4 : ℝ) := by |
| 158 | + apply sum_le_sum |
| 159 | + intro x _ |
| 160 | + apply (div_le_iff₀ (by positivity)).2 |
| 161 | + nlinarith only [sq_nonneg ((Fintype.card F : ℝ) - 2 * columnSize I x)] |
| 162 | + _ = _ := by simp [div_eq_mul_inv] |
| 163 | + |
| 164 | +end Moments |
| 165 | + |
| 166 | +/-- Adding an affine function to the quadratic profile preserves its Sidon property. -/ |
| 167 | +theorem isSidon_parabolaSlice (h2 : (2 : F) ≠ 0) (I : Finset (F × F)) (s : F × F) : |
| 168 | + IsSidon (graphSlice I (fun x => x ^ 2) s : Set (F × F)) := by |
| 169 | + let T := graphSlice I (fun x => x ^ 2) s |
| 170 | + have hon {z : F × F} (hz : z ∈ T) : z.2 = z.1 ^ 2 + s.1 * z.1 + s.2 := |
| 171 | + (mem_filter.mp hz).2 |
| 172 | + have hext {z w : F × F} (hz : z ∈ T) (hw : w ∈ T) (h : z.1 = w.1) : z = w := |
| 173 | + Prod.ext h (by rw [hon hz, hon hw, h]) |
| 174 | + intro a ha c hc b hb d hd habcd |
| 175 | + have hs : a.1 + b.1 = c.1 + d.1 := congrArg Prod.fst habcd |
| 176 | + have hv : a.2 + b.2 = c.2 + d.2 := congrArg Prod.snd habcd |
| 177 | + rw [hon ha, hon hb, hon hc, hon hd] at hv |
| 178 | + have hsq : a.1 ^ 2 + b.1 ^ 2 = c.1 ^ 2 + d.1 ^ 2 := by linear_combination hv - s.1 * hs |
| 179 | + rcases Erdos530Parabola.parabola_pair h2 hs hsq with ⟨h₁, h₂⟩ | ⟨h₁, h₂⟩ |
| 180 | + · exact Or.inl ⟨hext ha hc h₁, hext hb hd h₂⟩ |
| 181 | + · exact Or.inr ⟨hext ha hd h₁, hext hb hc h₂⟩ |
| 182 | + |
| 183 | +/-- Choose one source representative for each point of this particular slice. -/ |
| 184 | +theorem exists_sidon_representatives_parabolaSlice (h2 : (2 : F) ≠ 0) |
| 185 | + {α : Type*} [AddCommMonoid α] (B : Finset α) (g : α → F × F) |
| 186 | + (hg : ∀ a ∈ B, ∀ b ∈ B, ∀ c ∈ B, ∀ d ∈ B, a + b = c + d → g a + g b = g c + g d) |
| 187 | + (s : F × F) : |
| 188 | + ∃ S ⊆ B, IsSidon (S : Set α) ∧ |
| 189 | + S.image g = graphSlice (B.image g) (fun x => x ^ 2) s ∧ |
| 190 | + Set.InjOn g (S : Set α) ∧ |
| 191 | + S.card = (graphSlice (B.image g) (fun x => x ^ 2) s).card := by |
| 192 | + let T := graphSlice (B.image g) (fun x => x ^ 2) s |
| 193 | + have hT : T ⊆ B.image g := filter_subset _ _ |
| 194 | + obtain ⟨R, hRB, hinj, himg⟩ := exists_subset_injOn_image_eq_of_surjOn (f := g) (B : Set α) T |
| 195 | + (fun y hy => by simpa using hT hy) |
| 196 | + have hc : R.card = T.card := (card_image_of_injOn hinj).symm.trans (congrArg card himg) |
| 197 | + obtain ⟨S, hSR, hsid, hcard⟩ := Erdos530PrimeField.exists_sidon_of_image_sidon R g |
| 198 | + (fun a ha b hb c hc d hd => hg a (hRB ha) b (hRB hb) c (hRB hc) d (hRB hd)) |
| 199 | + T (by rw [himg]) (isSidon_parabolaSlice h2 _ s) |
| 200 | + obtain rfl := eq_of_subset_of_card_le hSR (hc.trans hcard.symm).le |
| 201 | + exact ⟨S, hRB, hsid, himg, hinj, hcard⟩ |
| 202 | + |
| 203 | +end ErdosSwarm.Erdos530ParabolaSlice |