| | @@ -0,0 +1,131 @@ |
| 1 | +import ErdosSwarm.Erdos530ProjectionMoments |
| 2 | +import Mathlib.Data.Nat.Choose.Sum |
| 3 | + |
| 4 | +/-! |
| 5 | +# Bonferroni bounds for the mean size of a linear image |
| 6 | + |
| 7 | +The finite inclusion–exclusion step in §2 of |
| 8 | +`experiments/erdos530/lower-middle-energy2/box-occupancy/POISSON.md`. |
| 9 | +An occupied fibre of size `s` contributes the signed remainder |
| 10 | +`(-1)^h * (s-1).choose h` at order `h`. Summing over the image gives an |
| 11 | +identity for each map. Averaging it gives the even and odd bounds on mean |
| 12 | +occupancy used in equation (4). |
| 13 | +-/ |
| 14 | + |
| 15 | +namespace ErdosSwarm.Erdos530Bonferroni |
| 16 | + |
| 17 | +open Finset Erdos530Monochromatic Erdos530ProjectionMoments |
| 18 | + |
| 19 | +/-- The first `h` terms of inclusion–exclusion, with the term of order one positive. -/ |
| 20 | +def bonferroniSum {R : Type*} [Ring R] (h : ℕ) (C : ℕ → R) : R := |
| 21 | + ∑ k ∈ range h, (-1 : R) ^ k * C (k + 1) |
| 22 | + |
| 23 | +private theorem fibre_remainder {s : ℕ} (hs : 0 < s) (h : ℕ) : |
| 24 | + 1 - bonferroniSum h (fun j => (s.choose j : ℤ)) = |
| 25 | + (-1 : ℤ) ^ h * (s - 1).choose h := by |
| 26 | + obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hs.ne' |
| 27 | + have hid := Int.alternating_sum_range_choose_eq_choose (n := n) (m := h) |
| 28 | + rw [sum_range_succ'] at hid |
| 29 | + simpa only [bonferroniSum, pow_succ, mul_neg_one, neg_mul, sum_neg_distrib, |
| 30 | + pow_zero, Nat.choose_zero_right, Nat.cast_one, one_mul, Nat.succ_sub_one, |
| 31 | + sub_eq_add_neg, add_comm] using hid |
| 32 | + |
| 33 | +section Maps |
| 34 | + |
| 35 | +variable {α β : Type*} [DecidableEq α] [DecidableEq β] |
| 36 | + |
| 37 | +omit [DecidableEq α] in |
| 38 | +private theorem card_fibre_pos {A : Finset α} {f : α → β} {y : β} (hy : y ∈ A.image f) : |
| 39 | + 0 < (fibre A f y).card := by |
| 40 | + obtain ⟨a, ha, rfl⟩ := mem_image.mp hy |
| 41 | + exact card_pos.mpr ⟨a, mem_filter.mpr ⟨ha, rfl⟩⟩ |
| 42 | + |
| 43 | +/-- Exact signed remainder in the image-size formula at every order, including zero. -/ |
| 44 | +theorem card_image_sub_bonferroniSum (A : Finset α) (f : α → β) (h : ℕ) : |
| 45 | + ((A.image f).card : ℤ) - bonferroniSum h (fun j => ((monoSubsets A f j).card : ℤ)) = |
| 46 | + (-1 : ℤ) ^ h * ∑ y ∈ A.image f, (((fibre A f y).card - 1).choose h : ℤ) := by |
| 47 | + calc |
| 48 | + _ = ∑ y ∈ A.image f, |
| 49 | + (1 - bonferroniSum h (fun j => ((fibre A f y).card.choose j : ℤ))) := by |
| 50 | + rw [sum_sub_distrib] |
| 51 | + simp only [sum_const, nsmul_eq_mul, mul_one] |
| 52 | + congr 1 |
| 53 | + unfold bonferroniSum |
| 54 | + simp_rw [card_monoSubsets A f (Nat.succ_pos _), Nat.cast_sum, mul_sum] |
| 55 | + exact sum_comm |
| 56 | + _ = _ := by |
| 57 | + rw [mul_sum] |
| 58 | + exact sum_congr rfl fun y hy => fibre_remainder (card_fibre_pos hy) h |
| 59 | + |
| 60 | +/-- Truncating after at least `A.card` terms already gives the exact image size. -/ |
| 61 | +theorem bonferroniSum_eq_card_image_of_card_le (A : Finset α) (f : α → β) {h : ℕ} |
| 62 | + (hh : A.card ≤ h) : |
| 63 | + bonferroniSum h (fun j => ((monoSubsets A f j).card : ℤ)) = (A.image f).card := by |
| 64 | + have hz (y : β) (hy : y ∈ A.image f) : (((fibre A f y).card - 1).choose h : ℤ) = 0 := by |
| 65 | + have hle : (fibre A f y).card ≤ A.card := card_le_card (filter_subset _ _) |
| 66 | + have hpos := card_fibre_pos hy |
| 67 | + rw [Nat.choose_eq_zero_of_lt (by omega), Nat.cast_zero] |
| 68 | + have hid := card_image_sub_bonferroniSum A f h |
| 69 | + rw [sum_eq_zero hz, mul_zero, sub_eq_zero] at hid |
| 70 | + exact hid.symm |
| 71 | + |
| 72 | +/-- An even truncation gives a lower bound for each map. -/ |
| 73 | +theorem bonferroniSum_even_le_card_image (A : Finset α) (f : α → β) (m : ℕ) : |
| 74 | + bonferroniSum (2 * m) (fun j => ((monoSubsets A f j).card : ℤ)) ≤ (A.image f).card := by |
| 75 | + apply sub_nonneg.mp |
| 76 | + rw [card_image_sub_bonferroniSum, pow_mul, neg_one_sq, one_pow, one_mul] |
| 77 | + exact sum_nonneg fun _ _ => Nat.cast_nonneg _ |
| 78 | + |
| 79 | +/-- An odd truncation gives an upper bound for each map. -/ |
| 80 | +theorem card_image_le_bonferroniSum_odd (A : Finset α) (f : α → β) (m : ℕ) : |
| 81 | + ((A.image f).card : ℤ) ≤ bonferroniSum (2 * m + 1) (fun j => ((monoSubsets A f j).card : ℤ)) := by |
| 82 | + apply sub_nonpos.mp |
| 83 | + rw [card_image_sub_bonferroniSum, pow_succ, pow_mul, neg_one_sq, one_pow, one_mul, |
| 84 | + neg_one_mul, neg_nonpos] |
| 85 | + exact sum_nonneg fun _ _ => Nat.cast_nonneg _ |
| 86 | + |
| 87 | +end Maps |
| 88 | + |
| 89 | +section LinearMaps |
| 90 | + |
| 91 | +variable (F : Type*) {V : Type*} (W : Type*) [Field F] [AddCommGroup V] [Module F V] |
| 92 | + [AddCommGroup W] [Module F W] [Fintype (V →ₗ[F] W)] [DecidableEq W] |
| 93 | + |
| 94 | +/-- Mean image size under the uniform distribution on all linear maps, including zero. -/ |
| 95 | +noncomputable def meanImageSize (A : Finset V) : ℝ := |
| 96 | + (∑ L : V →ₗ[F] W, ((A.image L).card : ℝ)) / Fintype.card (V →ₗ[F] W) |
| 97 | + |
| 98 | +variable [DecidableEq V] |
| 99 | + |
| 100 | +/-- The alternating sum of mean collision counts is the mean of the per-map sums. -/ |
| 101 | +theorem bonferroniSum_meanCollisions (A : Finset V) (h : ℕ) : |
| 102 | + bonferroniSum h (meanCollisions F W A) = |
| 103 | + (∑ L : V →ₗ[F] W, ((bonferroniSum h (fun j => (monoSubsets A L j).card) : ℤ) : ℝ)) / |
| 104 | + Fintype.card (V →ₗ[F] W) := by |
| 105 | + simp only [bonferroniSum, meanCollisions, ← mul_div_assoc, ← sum_div, mul_sum, |
| 106 | + Int.cast_sum, Int.cast_mul, Int.cast_pow, Int.cast_neg, Int.cast_one, Int.cast_natCast] |
| 107 | + rw [sum_comm] |
| 108 | + |
| 109 | +/-- Even Bonferroni lower bound for the uniform mean image size. -/ |
| 110 | +theorem bonferroniSum_even_le_meanImageSize (A : Finset V) (m : ℕ) : |
| 111 | + bonferroniSum (2 * m) (meanCollisions F W A) ≤ meanImageSize F W A := by |
| 112 | + rw [bonferroniSum_meanCollisions, meanImageSize] |
| 113 | + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) |
| 114 | + exact sum_le_sum fun L _ => by exact_mod_cast bonferroniSum_even_le_card_image A L m |
| 115 | + |
| 116 | +/-- Odd Bonferroni upper bound for the uniform mean image size. -/ |
| 117 | +theorem meanImageSize_le_bonferroniSum_odd (A : Finset V) (m : ℕ) : |
| 118 | + meanImageSize F W A ≤ bonferroniSum (2 * m + 1) (meanCollisions F W A) := by |
| 119 | + rw [bonferroniSum_meanCollisions, meanImageSize] |
| 120 | + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) |
| 121 | + exact sum_le_sum fun L _ => by exact_mod_cast card_image_le_bonferroniSum_odd A L m |
| 122 | + |
| 123 | +/-- The averaged identity is exact once the truncation reaches the size of the source set. -/ |
| 124 | +theorem bonferroniSum_eq_meanImageSize_of_card_le (A : Finset V) {h : ℕ} (hh : A.card ≤ h) : |
| 125 | + bonferroniSum h (meanCollisions F W A) = meanImageSize F W A := by |
| 126 | + rw [bonferroniSum_meanCollisions, meanImageSize] |
| 127 | + congr 1 |
| 128 | + exact sum_congr rfl fun L _ => by exact_mod_cast bonferroniSum_eq_card_image_of_card_le A L hh |
| 129 | + |
| 130 | +end LinearMaps |
| 131 | +end ErdosSwarm.Erdos530Bonferroni |