| | @@ -0,0 +1,214 @@ |
| 1 | +import ErdosSwarm.Erdos530DigitRank |
| 2 | + |
| 3 | +/-! |
| 4 | +# Fixed-order collision moments of dense eight-digit samples |
| 5 | + |
| 6 | +For a sample of size `n` and a plane of size `q = p²`, the normalized |
| 7 | +mean number of colliding unordered `j`-subsets approaches `(n/q)^j / j!` |
| 8 | +uniformly while `n/q` stays bounded. This is the fixed-order estimate |
| 9 | +of §2 of `experiments/erdos530/lower-middle-energy2/box-occupancy/POISSON.md`. |
| 10 | +-/ |
| 11 | + |
| 12 | +namespace ErdosSwarm.Erdos530DigitMoments |
| 13 | + |
| 14 | +open Finset Filter Erdos530DigitTuple Erdos530DigitRank Erdos530ProjectionMoments |
| 15 | + Erdos530RankMoments |
| 16 | + |
| 17 | +/-- Among the tuples of length `k + 1` from `n` points, repeated pairs |
| 18 | +account for at most `(k + 1).choose 2 * n ^ k` tuples. -/ |
| 19 | +theorem pow_succ_le_descFactorial_add (n k : ℕ) : |
| 20 | + n ^ (k + 1) ≤ n.descFactorial (k + 1) + (k + 1).choose 2 * n ^ k := by |
| 21 | + induction k with |
| 22 | + | zero => simp |
| 23 | + | succ k ih => |
| 24 | + have h₁ := Nat.mul_le_mul_right (n.descFactorial (k + 1)) |
| 25 | + (show n ≤ n - (k + 1) + (k + 1) by omega) |
| 26 | + have h₂ := Nat.mul_le_mul_left (k + 1) (n.descFactorial_le_pow (k + 1)) |
| 27 | + have h₃ := Nat.mul_le_mul_left n ih |
| 28 | + rw [Nat.descFactorial_succ n (k + 1), Nat.choose_succ_succ (k + 1) 1, Nat.choose_one_right] |
| 29 | + simp only [pow_succ] at h₂ h₃ ⊢ |
| 30 | + nlinarith only [h₁, h₂, h₃] |
| 31 | + |
| 32 | +/-- Error from giving each unordered subset the full-rank weight. |
| 33 | +The inequality also applies when `j > n`. -/ |
| 34 | +theorem choose_div_pow_error (n j : ℕ) (hj : 0 < j) {q : ℝ} (hq : 0 < q) : |
| 35 | + |(n.choose j : ℝ) / q ^ j - ((n : ℝ) / q) ^ j / j.factorial| ≤ |
| 36 | + ((j.choose 2 : ℝ) / j.factorial) * ((n : ℝ) / q) ^ (j - 1) / q := by |
| 37 | + obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hj.ne' |
| 38 | + let f : ℝ := (k + 1).factorial |
| 39 | + have hf : 0 < f := by dsimp [f]; positivity |
| 40 | + have hlow : f * (n.choose (k + 1) : ℝ) ≤ (n : ℝ) ^ (k + 1) := by |
| 41 | + dsimp [f] |
| 42 | + exact_mod_cast (Nat.descFactorial_eq_factorial_mul_choose n (k + 1)) ▸ |
| 43 | + n.descFactorial_le_pow (k + 1) |
| 44 | + have hhigh : (n : ℝ) ^ (k + 1) ≤ |
| 45 | + f * (n.choose (k + 1) : ℝ) + ((k + 1).choose 2 : ℝ) * (n : ℝ) ^ k := by |
| 46 | + dsimp [f] |
| 47 | + exact_mod_cast (Nat.descFactorial_eq_factorial_mul_choose n (k + 1)) ▸ |
| 48 | + pow_succ_le_descFactorial_add n k |
| 49 | + change |(n.choose (k + 1) : ℝ) / q ^ (k + 1) - ((n : ℝ) / q) ^ (k + 1) / f| ≤ |
| 50 | + ((k + 1).choose 2 : ℝ) / f * ((n : ℝ) / q) ^ k / q |
| 51 | + have heq : (n.choose (k + 1) : ℝ) / q ^ (k + 1) - ((n : ℝ) / q) ^ (k + 1) / f = |
| 52 | + -(((n : ℝ) ^ (k + 1) - f * n.choose (k + 1)) / (f * q ^ (k + 1))) := by |
| 53 | + rw [div_pow] |
| 54 | + field_simp |
| 55 | + ring |
| 56 | + rw [heq, abs_neg, abs_of_nonneg (div_nonneg (sub_nonneg.mpr hlow) (by positivity))] |
| 57 | + calc |
| 58 | + _ ≤ (((k + 1).choose 2 : ℝ) * (n : ℝ) ^ k) / (f * q ^ (k + 1)) := |
| 59 | + div_le_div_of_nonneg_right (by linarith only [hhigh]) (by positivity) |
| 60 | + _ = _ := by rw [div_pow, pow_succ]; ring |
| 61 | + |
| 62 | +/-- Reduction preserves every row of the digit box once the prime exceeds 7. -/ |
| 63 | +theorem modRow_injective {p r : ℕ} [Fact p.Prime] (hp : 7 < p) : |
| 64 | + Function.Injective (modRow (r := r) p) := by |
| 65 | + intro x y h |
| 66 | + funext i |
| 67 | + apply Fin.ext |
| 68 | + have hx : (x i).val < p := lt_of_lt_of_le (x i).isLt hp |
| 69 | + have hy : (y i).val < p := lt_of_lt_of_le (y i).isLt hp |
| 70 | + simpa only [modRow, ZMod.val_natCast_of_lt hx, ZMod.val_natCast_of_lt hy] using |
| 71 | + congrArg ZMod.val (congrFun h i) |
| 72 | + |
| 73 | +private theorem eventually_large_card (M : ℝ) : |
| 74 | + ∀ᶠ r : ℕ in atTop, ∀ n : ℕ, 8 ^ r ≤ (49 * r + 1) * n → M < (n : ℝ) := by |
| 75 | + have hpoly (r : ℕ) (hr : 4 ≤ r) : (49 * r + 1) * r ≤ 8 ^ r := by |
| 76 | + induction r, hr using Nat.le_induction with |
| 77 | + | base => decide |
| 78 | + | succ r hr ih => |
| 79 | + calc |
| 80 | + (49 * (r + 1) + 1) * (r + 1) ≤ (2 * (49 * r + 1)) * (2 * r) := |
| 81 | + Nat.mul_le_mul (by omega) (by omega) |
| 82 | + _ ≤ 8 ^ r * 8 := by nlinarith only [ih] |
| 83 | + _ = _ := (pow_succ _ _).symm |
| 84 | + obtain ⟨N, hN⟩ := exists_nat_gt M |
| 85 | + filter_upwards [eventually_ge_atTop N, eventually_ge_atTop 4] with r hNr hr n hn |
| 86 | + have hrn : r ≤ n := Nat.le_of_mul_le_mul_left ((hpoly r hr).trans hn) (by positivity) |
| 87 | + exact hN.trans_le (by exact_mod_cast hNr.trans hrn) |
| 88 | + |
| 89 | +/-- The density and the upper bound on `n/p²` force the plane cardinality to |
| 90 | +grow uniformly. This will supply the prime-size condition in the rank bound. -/ |
| 91 | +theorem eventually_lt_plane_card (M : ℝ) {b : ℝ} (hb : 0 < b) : |
| 92 | + ∀ᶠ r : ℕ in atTop, ∀ (p : ℕ) [Fact p.Prime] (X : Finset (Fin r → Fin 8)), |
| 93 | + 8 ^ r ≤ (49 * r + 1) * X.card → (X.card : ℝ) / (p : ℝ) ^ 2 ≤ b → |
| 94 | + M < (p : ℝ) ^ 2 := by |
| 95 | + filter_upwards [eventually_large_card (b * M)] with r hr p hp X hX hρ |
| 96 | + have hp' : 0 < (p : ℝ) := by exact_mod_cast hp.out.pos |
| 97 | + have hn := (div_le_iff₀ (sq_pos_of_pos hp')).mp hρ |
| 98 | + exact (mul_lt_mul_iff_right₀ hb).mp ((hr X.card hX).trans_le hn) |
| 99 | + |
| 100 | +/-- Every fixed lower threshold on the prime eventually holds uniformly under the same hypotheses. -/ |
| 101 | +theorem eventually_lt_prime (k : ℕ) {b : ℝ} (hb : 0 < b) : |
| 102 | + ∀ᶠ r : ℕ in atTop, ∀ (p : ℕ) [Fact p.Prime] (X : Finset (Fin r → Fin 8)), |
| 103 | + 8 ^ r ≤ (49 * r + 1) * X.card → (X.card : ℝ) / (p : ℝ) ^ 2 ≤ b → k < p := by |
| 104 | + filter_upwards [eventually_lt_plane_card ((k : ℝ) ^ 2) hb] with r hr p _ X hX hρ |
| 105 | + by_contra! hsmall |
| 106 | + exact (hr p X hX hρ).not_ge (pow_le_pow_left₀ (Nat.cast_nonneg p) (by exact_mod_cast hsmall) 2) |
| 107 | + |
| 108 | +private noncomputable local instance planeMapsFintype (r p : ℕ) [Fact p.Prime] : |
| 109 | + Fintype ((Fin r → ZMod p) →ₗ[ZMod p] ZMod p × ZMod p) := by |
| 110 | + have : Finite ((Fin r → ZMod p) →ₗ[ZMod p] ZMod p × ZMod p) := Module.finite_of_finite (ZMod p) |
| 111 | + exact Fintype.ofFinite _ |
| 112 | + |
| 113 | +/-- Mean number of colliding unordered `j`-subsets per cell, averaged over |
| 114 | +all linear maps from the reduced sample to the prime-field plane. -/ |
| 115 | +noncomputable def normalizedMoment {r : ℕ} (p : ℕ) [Fact p.Prime] |
| 116 | + (X : Finset (Fin r → Fin 8)) (j : ℕ) : ℝ := |
| 117 | + meanCollisions (ZMod p) (ZMod p × ZMod p) (X.image (modRow p)) j / (p : ℝ) ^ 2 |
| 118 | + |
| 119 | +/-- Expression using the mean in any enumeration of the finite type of linear maps. -/ |
| 120 | +theorem normalizedMoment_eq_meanCollisions {r p : ℕ} [Fact p.Prime] |
| 121 | + [maps : Fintype ((Fin r → ZMod p) →ₗ[ZMod p] ZMod p × ZMod p)] |
| 122 | + (X : Finset (Fin r → Fin 8)) (j : ℕ) : |
| 123 | + normalizedMoment p X j = |
| 124 | + meanCollisions (ZMod p) (ZMod p × ZMod p) (X.image (modRow p)) j / (p : ℝ) ^ 2 := by |
| 125 | + unfold normalizedMoment |
| 126 | + rw [Subsingleton.elim (planeMapsFintype r p) maps] |
| 127 | + |
| 128 | +/-- Finite error bound. The first term counts tuples with a repeated pair. |
| 129 | +Each remaining term bounds the excess collision probability at one dependent rank. -/ |
| 130 | +theorem normalizedMoment_error_le {r p j : ℕ} [Fact p.Prime] (hp : 7 < p) (hj : 0 < j) |
| 131 | + (X : Finset (Fin r → Fin 8)) : |
| 132 | + |normalizedMoment p X j - ((X.card : ℝ) / (p : ℝ) ^ 2) ^ j / j.factorial| ≤ |
| 133 | + ((j.choose 2 : ℝ) / j.factorial) * ((X.card : ℝ) / (p : ℝ) ^ 2) ^ (j - 1) / (p : ℝ) ^ 2 + |
| 134 | + ∑ d ∈ range (j - 1), (rankCount (ZMod p) (X.image (modRow p)) j d : ℝ) / |
| 135 | + ((p : ℝ) ^ 2) ^ (d + 1) := by |
| 136 | + let q := (p : ℝ) ^ 2 |
| 137 | + let A := X.image (modRow p) |
| 138 | + have hq : 1 ≤ q := one_le_pow₀ (by exact_mod_cast (show 1 ≤ p by omega)) |
| 139 | + have hq' : 0 < q := zero_lt_one.trans_le hq |
| 140 | + have hcard : (Fintype.card (ZMod p × ZMod p) : ℝ) = q := by simp [q, Fintype.card_prod, ZMod.card, sq] |
| 141 | + have hA : A.card = X.card := card_image_of_injective _ (modRow_injective hp) |
| 142 | + have hid := meanCollisions_div_card_eq_correction (ZMod p) (ZMod p × ZMod p) A hj |
| 143 | + rw [hcard, hA] at hid |
| 144 | + let B (d : ℕ) : ℝ := rankCount (ZMod p) A j d |
| 145 | + let excess (d : ℕ) := B d * (1 / q ^ (d + 1) - 1 / q ^ j) |
| 146 | + have hnonneg (d : ℕ) (hd : d ∈ range (j - 1)) : 0 ≤ excess d := by |
| 147 | + have hd' := mem_range.mp hd |
| 148 | + exact mul_nonneg (Nat.cast_nonneg _) (sub_nonneg.mpr (one_div_le_one_div_of_le (pow_pos hq' _) |
| 149 | + (pow_le_pow_right₀ hq (by omega)))) |
| 150 | + have hexcess : |∑ d ∈ range (j - 1), excess d| ≤ ∑ d ∈ range (j - 1), B d / q ^ (d + 1) := by |
| 151 | + rw [abs_of_nonneg (sum_nonneg hnonneg)] |
| 152 | + apply sum_le_sum |
| 153 | + intro d _ |
| 154 | + calc |
| 155 | + excess d ≤ B d * (1 / q ^ (d + 1)) := |
| 156 | + mul_le_mul_of_nonneg_left (sub_le_self _ (by positivity)) (Nat.cast_nonneg _) |
| 157 | + _ = _ := by ring |
| 158 | + have heq : normalizedMoment p X j = (X.card.choose j : ℝ) / q ^ j + ∑ d ∈ range (j - 1), excess d := hid |
| 159 | + rw [heq, add_sub_right_comm] |
| 160 | + exact (abs_add_le _ _).trans (add_le_add (choose_div_pow_error X.card j hj hq') hexcess) |
| 161 | + |
| 162 | +private theorem eventually_rank_contribution {j d : ℕ} (hd : d + 1 < j) |
| 163 | + {b δ : ℝ} (hb : 0 < b) (hδ : 0 < δ) : |
| 164 | + ∀ᶠ r : ℕ in atTop, ∀ (p : ℕ) [Fact p.Prime], max 49 j < p → |
| 165 | + ∀ X : Finset (Fin r → Fin 8), 8 ^ r ≤ (49 * r + 1) * X.card → |
| 166 | + (X.card : ℝ) / (p : ℝ) ^ 2 ≤ b → |
| 167 | + (rankCount (ZMod p) (X.image (modRow p)) j d : ℝ) / ((p : ℝ) ^ 2) ^ (d + 1) ≤ δ := by |
| 168 | + filter_upwards [eventually_rankCount_lt j d hd (div_pos hδ (pow_pos hb (d + 1)))] with |
| 169 | + r hr p hp hlarge X hX hρ |
| 170 | + let q := (p : ℝ) ^ 2 |
| 171 | + have hρ₀ : 0 ≤ (X.card : ℝ) / q := by dsimp [q]; positivity |
| 172 | + calc |
| 173 | + _ ≤ (δ / b ^ (d + 1) * (X.card : ℝ) ^ (d + 1)) / q ^ (d + 1) := |
| 174 | + div_le_div_of_nonneg_right (hr p hlarge X hX).le (by dsimp [q]; positivity) |
| 175 | + _ = δ / b ^ (d + 1) * ((X.card : ℝ) / q) ^ (d + 1) := by rw [div_pow]; ring |
| 176 | + _ ≤ δ / b ^ (d + 1) * b ^ (d + 1) := |
| 177 | + mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hρ₀ hρ _) (by positivity) |
| 178 | + _ = δ := div_mul_cancel₀ _ (pow_ne_zero _ hb.ne') |
| 179 | + |
| 180 | +/-- For each fixed positive order, the dimension threshold is simultaneous for every |
| 181 | +prime and every sufficiently dense sample with bounded ratio of points to plane cells. -/ |
| 182 | +theorem eventually_normalizedMoment_close {j : ℕ} (hj : 0 < j) {b ε : ℝ} |
| 183 | + (hb : 0 < b) (hε : 0 < ε) : |
| 184 | + ∀ᶠ r : ℕ in atTop, ∀ (p : ℕ) [Fact p.Prime] (X : Finset (Fin r → Fin 8)), |
| 185 | + 8 ^ r ≤ (49 * r + 1) * X.card → (X.card : ℝ) / (p : ℝ) ^ 2 ≤ b → |
| 186 | + |normalizedMoment p X j - ((X.card : ℝ) / (p : ℝ) ^ 2) ^ j / j.factorial| < ε := by |
| 187 | + let δ := ε / ((j : ℝ) + 1) |
| 188 | + have hδ : 0 < δ := by dsimp [δ]; positivity |
| 189 | + let C := ((j.choose 2 : ℝ) / j.factorial) * b ^ (j - 1) |
| 190 | + have hstrata := (eventually_all_finset (range (j - 1))).2 |
| 191 | + (fun d hd => eventually_rank_contribution (show d + 1 < j by have := mem_range.mp hd; omega) hb hδ) |
| 192 | + filter_upwards [eventually_lt_prime (max 49 j) hb, |
| 193 | + eventually_lt_plane_card (C / δ) hb, hstrata] with r hprime hcells hr p hp X hX hρ |
| 194 | + let q := (p : ℝ) ^ 2 |
| 195 | + have hp' : 0 < (p : ℝ) := by exact_mod_cast hp.out.pos |
| 196 | + have hq : 0 < q := sq_pos_of_pos hp' |
| 197 | + have hlarge := hprime p X hX hρ |
| 198 | + have hmain : ((j.choose 2 : ℝ) / j.factorial) * ((X.card : ℝ) / q) ^ (j - 1) / q < δ := by |
| 199 | + calc |
| 200 | + _ ≤ C / q := by dsimp [C]; gcongr |
| 201 | + _ < δ := (div_lt_iff₀ hq).mpr (by |
| 202 | + have h := (div_lt_iff₀ hδ).mp (hcells p X hX hρ) |
| 203 | + simpa only [mul_comm] using h) |
| 204 | + have hsum : (∑ d ∈ range (j - 1), (rankCount (ZMod p) (X.image (modRow p)) j d : ℝ) / |
| 205 | + q ^ (d + 1)) ≤ (j : ℝ) * δ := calc |
| 206 | + _ ≤ ∑ _d ∈ range (j - 1), δ := sum_le_sum fun d hd => hr d hd p hlarge X hX hρ |
| 207 | + _ = ((j - 1 : ℕ) : ℝ) * δ := by simp |
| 208 | + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.sub_le j 1) hδ.le |
| 209 | + calc |
| 210 | + _ ≤ _ := normalizedMoment_error_le (by omega) hj X |
| 211 | + _ < δ + (j : ℝ) * δ := add_lt_add_of_lt_of_le hmain hsum |
| 212 | + _ = ε := by dsimp [δ]; field_simp; ring |
| 213 | + |
| 214 | +end ErdosSwarm.Erdos530DigitMoments |