| | @@ -0,0 +1,165 @@ |
| 1 | +import ErdosSwarm.Erdos30FactorialPrimeInterval |
| 2 | +import ErdosSwarm.Erdos530BoxSpan |
| 3 | +import ErdosSwarm.Erdos530SymbolSpace |
| 4 | +import ErdosSwarm.Erdos530TripleSpan |
| 5 | + |
| 6 | +/-! |
| 7 | +# A uniform Sidon bound for eight-digit boxes |
| 8 | + |
| 9 | +Sections 2–3 of `experiments/erdos530/lower-middle-energy2/box-occupancy/NOTES.md`. |
| 10 | +The finite triple-span estimate retains the endpoint coefficient at finite |
| 11 | +cardinality. The prime interval from Erdős #30 supplies a threshold depending |
| 12 | +only on the cardinality of the input. |
| 13 | +-/ |
| 14 | + |
| 15 | +namespace ErdosSwarm.Erdos530BoxOccupancy |
| 16 | + |
| 17 | +open Filter Finset |
| 18 | + |
| 19 | +/-- The coefficient in (5) for a triple-span cap `M` and prime ratio `x = p / √n`. -/ |
| 20 | +noncomputable def spanCoefficient (M x : ℝ) : ℝ := |
| 21 | + (M * x ^ 2 + 1 - M / 2) / (x * (M * x ^ 2 + 1)) |
| 22 | + |
| 23 | +/-- Dropping the finite-cardinality corrections from (1) gives a lower bound |
| 24 | +when `M z ≥ 2n`, where `z = p²`. -/ |
| 25 | +private theorem finite_correction {n z M : ℝ} (hn : 3 ≤ n) (hz : 0 < z) |
| 26 | + (hM : 2 * n ≤ M * z) : |
| 27 | + n - M * n ^ 2 / (2 * (M * z + n)) ≤ |
| 28 | + n - n * (n - 1) / 2 / z + n * (n - 1) / 2 * (n - 2) / (z * (M * z + n - 3)) := by |
| 29 | + have hden : 0 < M * z + n - 3 := by linarith |
| 30 | + have hnpos : 0 < n := by linarith |
| 31 | + have hMpos : 0 < M := pos_of_mul_pos_left (by linarith : 0 < M * z) hz.le |
| 32 | + calc |
| 33 | + _ ≤ n - n * (n - 1) / 2 / z + n * (n - 1) / 2 * (n - 2) / (z * (M * z + n)) := by |
| 34 | + apply sub_nonneg.mp |
| 35 | + have hid : n - n * (n - 1) / 2 / z + n * (n - 1) / 2 * (n - 2) / (z * (M * z + n)) |
| 36 | + - (n - M * n ^ 2 / (2 * (M * z + n))) = |
| 37 | + n * (M * z - 2 * n + 2) / (2 * z * (M * z + n)) := by |
| 38 | + field_simp |
| 39 | + ring |
| 40 | + rw [hid] |
| 41 | + exact div_nonneg (mul_nonneg (by linarith) (by linarith)) (by positivity) |
| 42 | + _ ≤ _ := by |
| 43 | + apply add_le_add_right |
| 44 | + have hnum : 0 ≤ n * (n - 1) / 2 * (n - 2) := |
| 45 | + mul_nonneg (div_nonneg (mul_nonneg (by linarith) (by linarith)) (by norm_num)) (by linarith) |
| 46 | + apply div_le_div_of_nonneg_left hnum (mul_pos hz hden) |
| 47 | + exact mul_le_mul_of_nonneg_left (by linarith) hz.le |
| 48 | + |
| 49 | +/-- The finite inequality (1) implies (5) with its exact coefficient for every |
| 50 | +`n ≥ 3` and `M x² ≥ 2`. -/ |
| 51 | +theorem spanCoefficient_mul_sqrt_le_of_finite_bound {n : ℕ} (hn : 3 ≤ n) {M p x s : ℝ} |
| 52 | + (hx : 0 < x) (hpx : p = x * Real.sqrt n) (hM : 2 ≤ M * x ^ 2) |
| 53 | + (hbound : (n : ℝ) - (n.choose 2 : ℝ) / p ^ 2 + |
| 54 | + 3 * (n.choose 3 : ℝ) / (p ^ 4 * (M + ((n : ℝ) - 3) / p ^ 2)) ≤ p * s) : |
| 55 | + spanCoefficient M x * Real.sqrt n ≤ s := by |
| 56 | + have hn' : 3 ≤ (n : ℝ) := by exact_mod_cast hn |
| 57 | + have hnpos : 0 < (n : ℝ) := by linarith |
| 58 | + have hp : 0 < p := hpx ▸ mul_pos hx (Real.sqrt_pos.2 hnpos) |
| 59 | + have hp2 : p ^ 2 = x ^ 2 * n := by rw [hpx, mul_pow, Real.sq_sqrt hnpos.le] |
| 60 | + have hcap : 2 * (n : ℝ) ≤ M * p ^ 2 := by |
| 61 | + rw [hp2, ← mul_assoc] |
| 62 | + exact mul_le_mul_of_nonneg_right hM hnpos.le |
| 63 | + have hMpos : 0 < M := pos_of_mul_pos_left (by linarith : 0 < M * x ^ 2) (sq_nonneg x) |
| 64 | + have hchoose : 3 * (n.choose 3 : ℝ) = (n.choose 2 : ℝ) * ((n : ℝ) - 2) := by |
| 65 | + rw [mul_comm, ← Nat.cast_ofNat (R := ℝ) (n := 2), ← Nat.cast_sub (by omega : 2 ≤ n)] |
| 66 | + exact_mod_cast Nat.choose_succ_right_eq n 2 |
| 67 | + have hden : p ^ 4 * (M + ((n : ℝ) - 3) / p ^ 2) = p ^ 2 * (M * p ^ 2 + n - 3) := by |
| 68 | + field_simp |
| 69 | + ring |
| 70 | + rw [hchoose, Nat.cast_choose_two, hden] at hbound |
| 71 | + apply (mul_le_mul_iff_right₀ hp).mp |
| 72 | + calc |
| 73 | + p * (spanCoefficient M x * Real.sqrt n) = |
| 74 | + (x * spanCoefficient M x) * (Real.sqrt n) ^ 2 := by rw [hpx]; ring |
| 75 | + _ = n - M * (n : ℝ) ^ 2 / (2 * (M * p ^ 2 + n)) := by |
| 76 | + rw [Real.sq_sqrt hnpos.le, hp2, |
| 77 | + show M * (x ^ 2 * (n : ℝ)) + n = (M * x ^ 2 + 1) * n by ring] |
| 78 | + unfold spanCoefficient |
| 79 | + field_simp |
| 80 | + _ ≤ _ := (finite_correction hn' (sq_pos_of_pos hp) hcap).trans hbound |
| 81 | + |
| 82 | +/-- On the whole closed prime interval, the right endpoint gives the smallest |
| 83 | +coefficient for a cap of 64 points. -/ |
| 84 | +theorem le_spanCoefficient_64 {x : ℝ} (hlo : 7 / 6 ≤ x) (hhi : x ≤ 9 / 7) : |
| 85 | + 25655 / 47097 ≤ spanCoefficient 64 x := by |
| 86 | + have hx : 0 < x := by linarith |
| 87 | + -- After clearing denominators, the difference factors as (9 - 7x) times this quadratic. |
| 88 | + have hquad : 0 < 234560 * x ^ 2 - 129024 * x - 162223 := by |
| 89 | + nlinarith only [sq_nonneg (x - 7 / 6), hlo] |
| 90 | + have hprod := mul_nonneg (by linarith : 0 ≤ 9 - 7 * x) hquad.le |
| 91 | + unfold spanCoefficient |
| 92 | + apply (le_div_iff₀ (by positivity)).2 |
| 93 | + nlinarith only [hprod] |
| 94 | + |
| 95 | +/-- The prime and its threshold depend only on `n`. -/ |
| 96 | +private theorem eventually_box_prime : |
| 97 | + ∀ᶠ n : ℕ in atTop, ∃ p : ℕ, p.Prime ∧ 7 < p ∧ |
| 98 | + 7 / 6 ≤ (p : ℝ) / Real.sqrt n ∧ (p : ℝ) / Real.sqrt n ≤ 9 / 7 := by |
| 99 | + have hs : Tendsto (fun n : ℕ => Real.sqrt n) atTop atTop := |
| 100 | + Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop |
| 101 | + have hy := hs.const_mul_atTop (by norm_num : (0 : ℝ) < 9 / 7) |
| 102 | + filter_upwards [hy.eventually Erdos30.eventually_exists_prime_457_div_500, |
| 103 | + hs.eventually_ge_atTop 8] with n ⟨p, hp, hlo, hhi⟩ hs8 |
| 104 | + change 457 / 500 * (9 / 7 * Real.sqrt n) < (p : ℝ) at hlo |
| 105 | + change (p : ℝ) ≤ 9 / 7 * Real.sqrt n at hhi |
| 106 | + change 8 ≤ Real.sqrt n at hs8 |
| 107 | + have hspos : 0 < Real.sqrt n := by linarith |
| 108 | + refine ⟨p, hp, ?_, (le_div_iff₀ hspos).2 (by linarith), (div_le_iff₀ hspos).2 hhi⟩ |
| 109 | + exact_mod_cast (by linarith : (7 : ℝ) < p) |
| 110 | + |
| 111 | +universe u |
| 112 | + |
| 113 | +/-- Every sufficiently large eight-digit box model contains a Sidon subset |
| 114 | +of size at least `(25655/47097) √n`. One threshold works for all ambient |
| 115 | +additive commutative monoids, dimensions, point sets, and coordinate maps. -/ |
| 116 | +theorem exists_threshold_sidon_subset_of_eight_digit_box : |
| 117 | + ∃ n₀ : ℕ, ∀ n ≥ n₀, ∀ {α : Type u} [AddCommMonoid α] {r : ℕ} |
| 118 | + (A : Finset α), A.card = n → ∀ f : A → Fin r → ℤ, Function.Injective f → |
| 119 | + (∀ a i, 0 ≤ f a i ∧ f a i ≤ 7) → Erdos530SymbolSpace.PreservesSums A f → |
| 120 | + ∃ S ⊆ A, IsSidon (S : Set α) ∧ (25655 / 47097 : ℝ) * Real.sqrt n ≤ S.card := by |
| 121 | + classical |
| 122 | + obtain ⟨n₀, h₀⟩ := eventually_atTop.mp (eventually_box_prime.and (eventually_ge_atTop 3)) |
| 123 | + refine ⟨n₀, ?_⟩ |
| 124 | + intro n hn α _ r A hA f hinj hbox hsums |
| 125 | + obtain ⟨⟨p, hp, hp7, hlo, hhi⟩, hn3⟩ := h₀ n hn |
| 126 | + let : Fact p.Prime := ⟨hp⟩ |
| 127 | + let g (a : α) (i : Fin r) : ZMod p := if ha : a ∈ A then (f ⟨a, ha⟩ i : ZMod p) else 0 |
| 128 | + have hg (a : A) (i : Fin r) : g a i = (f a i : ZMod p) := dif_pos a.property |
| 129 | + have hval (a : A) (i : Fin r) : ((g a i).val : ℤ) = f a i := by |
| 130 | + rw [hg, ZMod.val_intCast, Int.emod_eq_of_lt (hbox a i).1 (by have := (hbox a i).2; omega)] |
| 131 | + have hginj : Set.InjOn g (A : Set α) := by |
| 132 | + intro a ha b hb hab |
| 133 | + have heq : f ⟨a, ha⟩ = f ⟨b, hb⟩ := by |
| 134 | + funext i |
| 135 | + rw [← hval ⟨a, ha⟩ i, ← hval ⟨b, hb⟩ i] |
| 136 | + exact congrArg (fun z : ZMod p => (z.val : ℤ)) (congrFun hab i) |
| 137 | + exact congrArg Subtype.val (hinj heq) |
| 138 | + have hboxg : ∀ x ∈ A.image g, ∀ i, (x i).val < 8 := by |
| 139 | + intro x hx i |
| 140 | + obtain ⟨a, ha, rfl⟩ := mem_image.mp hx |
| 141 | + have hv : ((g a i).val : ℤ) = f ⟨a, ha⟩ i := hval ⟨a, ha⟩ i |
| 142 | + exact_mod_cast hv.trans_lt ((hbox ⟨a, ha⟩ i).2.trans_lt (by decide : (7 : ℤ) < 8)) |
| 143 | + obtain ⟨S, hSA, hS, hbound⟩ := |
| 144 | + Erdos530TripleSpan.exists_sidon_subset_of_triple_span_bound (p := p) (by omega) |
| 145 | + A (hA ▸ hn3) g hginj (by |
| 146 | + intro a ha b hb c hc d hd habcd |
| 147 | + funext i |
| 148 | + have h := congrFun (hsums ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩ ⟨d, hd⟩ habcd) i |
| 149 | + simpa only [Pi.add_apply, g, dif_pos ha, dif_pos hb, dif_pos hc, dif_pos hd, Int.cast_add] |
| 150 | + using congrArg (fun z : ℤ => (z : ZMod p)) h) 64 (by |
| 151 | + intro T hT |
| 152 | + exact_mod_cast Erdos530BoxSpan.spanCount_le_64_of_digit_box hboxg hT) |
| 153 | + rw [hA] at hbound |
| 154 | + let x := (p : ℝ) / Real.sqrt n |
| 155 | + have hxlo : 7 / 6 ≤ x := hlo |
| 156 | + have hs : 0 < Real.sqrt n := Real.sqrt_pos.2 (by exact_mod_cast (by omega : 0 < n)) |
| 157 | + have hpx : (p : ℝ) = x * Real.sqrt n := (div_mul_cancel₀ _ hs.ne').symm |
| 158 | + refine ⟨S, hSA, hS, ?_⟩ |
| 159 | + calc |
| 160 | + (25655 / 47097 : ℝ) * Real.sqrt n ≤ spanCoefficient 64 x * Real.sqrt n := |
| 161 | + mul_le_mul_of_nonneg_right (le_spanCoefficient_64 hlo hhi) hs.le |
| 162 | + _ ≤ S.card := spanCoefficient_mul_sqrt_le_of_finite_bound hn3 (by linarith) hpx |
| 163 | + (by nlinarith only [hxlo, sq_nonneg (x - 1)]) hbound |
| 164 | + |
| 165 | +end ErdosSwarm.Erdos530BoxOccupancy |