Download data/lean/OAI/Combinatorics/BalancedRyser/Probability/CountingExposureKernel.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.03 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BalancedRyser/Probability/CountingExposureKernel.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/BalancedRyser/Probability/CountingExposureKernel.lean
-
curl -L -o CountingExposureKernel.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/BalancedRyser/Probability/CountingExposureKernel.lean
9.03 kB
| import Mathlib.Basic.ENNReal.BigOperators | |
| import Mathlib.Probability.ProbabilityMassFunction.Constructions | |
| import Mathlib.Tactic | |
| import OAI.Combinatorics.BalancedRyser.Incidence.Affine | |
| import OAI.Combinatorics.BalancedRyser.Incidence.AffineSecondMoment | |
| import OAI.Combinatorics.BalancedRyser.Profiles.MarkedExposure | |
| namespace OAI | |
| open scoped BigOperators | |
| namespace Balanced.CountingExposureKernel | |
| noncomputable section | |
| variable {Ξ± : Type*} [Fintype Ξ±] [DecidableEq Ξ±] | |
| def uniformSetWeight (s : Finset Ξ±) (a : Ξ±) : β := | |
| if a β s then (s.card : β)β»ΒΉ else 0 | |
| omit [Fintype Ξ±] in | |
| theorem uniformSetWeight_nonneg (s : Finset Ξ±) (a : Ξ±) : | |
| 0 β€ uniformSetWeight s a := by | |
| unfold uniformSetWeight | |
| split_ifs <;> positivity | |
| theorem sum_uniformSetWeight (s : Finset Ξ±) (hs : s.Nonempty) : | |
| β a, uniformSetWeight s a = 1 := by | |
| have hc : (s.card : β) β 0 := by exact_mod_cast hs.card_pos.ne' | |
| simp [uniformSetWeight, hc] | |
| omit [Fintype Ξ±] in | |
| theorem uniformSetWeight_le (s : Finset Ξ±) (a : Ξ±) : | |
| uniformSetWeight s a β€ (s.card : β)β»ΒΉ := by | |
| unfold uniformSetWeight | |
| split_ifs | |
| Β· exact le_rfl | |
| Β· positivity | |
| variable {F : Type*} [Fintype F] [DecidableEq F] | |
| def available (used : Finset F) : Finset F := Finset.univ \ used | |
| @[simp] theorem card_available (used : Finset F) : | |
| (available used).card = Fintype.card F - used.card := by | |
| simp only [available, Finset.card_sdiff_of_subset (Finset.subset_univ used), | |
| Finset.card_univ] | |
| def tokenWeight (r : Direction F β β) (used : Direction F β Finset F) | |
| (l : Line F) : β := | |
| (r l.1 : β) / (β d, (r d : β)) * uniformSetWeight (available (used l.1)) l.2 | |
| theorem tokenWeight_nonneg (r : Direction F β β) (used : Direction F β Finset F) | |
| (l : Line F) : 0 β€ tokenWeight r used l := by | |
| exact mul_nonneg (div_nonneg (Nat.cast_nonneg _) (Finset.sum_nonneg (by simp))) | |
| (uniformSetWeight_nonneg _ _) | |
| theorem sum_tokenWeight (r : Direction F β β) (used : Direction F β Finset F) | |
| (hr : 0 < β d, (r d : β)) | |
| (hu : β d, (available (used d)).Nonempty) : | |
| β l : Line F, tokenWeight r used l = 1 := by | |
| simp only [tokenWeight, Fintype.sum_prod_type, β Finset.mul_sum] | |
| simp only [sum_uniformSetWeight _ (hu _), mul_one, β Finset.sum_div] | |
| exact div_self hr.ne' | |
| def tokenPMF (r : Direction F β β) (used : Direction F β Finset F) | |
| (hr : 0 < β d, (r d : β)) | |
| (hu : β d, (available (used d)).Nonempty) : PMF (Line F) := | |
| PMF.ofFintype (fun l => ENNReal.ofReal (tokenWeight r used l)) (by | |
| rw [β ENNReal.ofReal_sum_of_nonneg (fun l _ => tokenWeight_nonneg r used l), | |
| sum_tokenWeight r used hr hu, ENNReal.ofReal_one]) | |
| @[simp] theorem tokenPMF_real (r : Direction F β β) (used : Direction F β Finset F) | |
| (hr : 0 < β d, (r d : β)) | |
| (hu : β d, (available (used d)).Nonempty) (l : Line F) : | |
| (tokenPMF r used hr hu l).toReal = tokenWeight r used l := by | |
| exact ENNReal.toReal_ofReal (tokenWeight_nonneg r used l) | |
| theorem tokenWeight_le_two_div (r : Direction F β β) | |
| (used : Direction F β Finset F) (k : β) (Ξ· : β) | |
| (hk : 0 < k) (hΞ· : 0 < Ξ·) (hqk : 2 * k β€ Fintype.card F) | |
| (hr : β d, r d β€ k) (hu : β d, (used d).card β€ k) | |
| (hremaining : Ξ· * (k : β) * ((Fintype.card F : β) + 1) β€ | |
| β d, (r d : β)) (l : Line F) : | |
| tokenWeight r used l β€ 2 / (Ξ· * (Fintype.card F : β) ^ 2) := by | |
| let q : β := Fintype.card F | |
| have hq : 0 < q := by dsimp [q]; exact_mod_cast (by omega : 0 < Fintype.card F) | |
| have hkR : (0 : β) < k := by exact_mod_cast hk | |
| have hkq : k β€ Fintype.card F := by omega | |
| have htot : 0 < β d, (r d : β) := | |
| lt_of_lt_of_le (mul_pos (mul_pos hΞ· hkR) (by positivity)) hremaining | |
| have hdir : (r l.1 : β) / (β d, (r d : β)) β€ 1 / (Ξ· * q) := by | |
| apply (div_le_div_iffβ htot (mul_pos hΞ· hq)).mpr | |
| have hrR : (r l.1 : β) β€ k := by exact_mod_cast hr l.1 | |
| have hm := mul_le_mul_of_nonneg_right hrR (mul_nonneg hΞ·.le hq.le) | |
| dsimp [q] at hm β’ | |
| nlinarith [mul_nonneg hΞ·.le hkR.le] | |
| have hused : (used l.1).card β€ Fintype.card F := (hu l.1).trans hkq | |
| have hcard : ((available (used l.1)).card : β) = q - (used l.1).card := by | |
| rw [card_available, Nat.cast_sub hused] | |
| have havail : q / 2 β€ ((available (used l.1)).card : β) := by | |
| rw [hcard] | |
| have hx : ((used l.1).card : β) β€ k := by exact_mod_cast hu l.1 | |
| have hy : 2 * (k : β) β€ q := by dsimp [q]; exact_mod_cast hqk | |
| linarith | |
| have hoff : uniformSetWeight (available (used l.1)) l.2 β€ 2 / q := by | |
| calc | |
| uniformSetWeight (available (used l.1)) l.2 β€ | |
| ((available (used l.1)).card : β)β»ΒΉ := uniformSetWeight_le _ _ | |
| _ β€ 1 / (q / 2) := by | |
| simpa only [one_div] using one_div_le_one_div_of_le (by positivity : 0 < q / 2) havail | |
| _ = 2 / q := by ring | |
| calc | |
| tokenWeight r used l β€ (1 / (Ξ· * q)) * (2 / q) := | |
| mul_le_mul hdir hoff (uniformSetWeight_nonneg _ _) (by positivity) | |
| _ = 2 / (Ξ· * (Fintype.card F : β) ^ 2) := by dsimp [q]; ring | |
| def coverWeight (used : Finset (Line F)) (l : Line F) : β := | |
| uniformSetWeight (Finset.univ \ used) l | |
| theorem coverWeight_le_one_div_sq [Nonempty F] | |
| (used : Finset (Line F)) (hu : used.card β€ Fintype.card F) (l : Line F) : | |
| coverWeight used l β€ 1 / (Fintype.card F : β) ^ 2 := by | |
| have hq : (0 : β) < Fintype.card F := by exact_mod_cast Fintype.card_pos | |
| have hc : (Fintype.card F : β) ^ 2 β€ ((Finset.univ \ used).card : β) := by | |
| have h := Finset.card_sdiff_add_card_eq_card (Finset.subset_univ used) | |
| have hcast := congrArg (fun n : β => (n : β)) h | |
| have huR : (used.card : β) β€ Fintype.card F := by exact_mod_cast hu | |
| simp only [Nat.cast_add, Finset.card_univ, Fintype.card_prod, | |
| Fintype.card_option, Nat.cast_mul, Nat.cast_add, Nat.cast_one] at hcast | |
| nlinarith | |
| calc | |
| coverWeight used l β€ ((Finset.univ \ used).card : β)β»ΒΉ := uniformSetWeight_le _ _ | |
| _ β€ 1 / (Fintype.card F : β) ^ 2 := by | |
| simpa only [one_div] using one_div_le_one_div_of_le (by positivity) hc | |
| theorem cover_available_nonempty [Nonempty F] | |
| (used : Finset (Line F)) (hu : used.card β€ Fintype.card F) : | |
| (Finset.univ \ used).Nonempty := by | |
| apply Finset.card_pos.mp | |
| have hc := Finset.card_sdiff_add_card_eq_card (Finset.subset_univ used) | |
| have hq := Fintype.card_pos (Ξ± := F) | |
| simp only [Finset.card_univ, Fintype.card_prod, Fintype.card_option] at hc | |
| nlinarith | |
| theorem sum_coverWeight [Nonempty F] | |
| (used : Finset (Line F)) (hu : used.card β€ Fintype.card F) : | |
| β l : Line F, coverWeight used l = 1 := | |
| sum_uniformSetWeight _ (cover_available_nonempty used hu) | |
| variable [Field F] | |
| def markedLines (U : Finset (Point F)) (Ξ΅ : β) : Finset (Line F) := | |
| Finset.univ.filter fun l => Ξ΅ < | |
| |(affineIntersectionCount U l : β) / Fintype.card F - | |
| (U.card : β) / (Fintype.card F : β) ^ 2| | |
| theorem markedLines_eq (U : Finset (Point F)) (Ξ΅ : β) : | |
| markedLines U Ξ΅ = Finset.univ.filter (fun l => | |
| Ξ΅ * Fintype.card F < |(affineIntersectionCount U l : β) - | |
| (U.card : β) / Fintype.card F|) := by | |
| apply Finset.filter_congr | |
| intro l _ | |
| exact MarkedExposure.normalized_deviation_iff _ _ _ _ | |
| (by exact_mod_cast Fintype.card_pos (Ξ± := F)) | |
| theorem marked_mass_le (U : Finset (Point F)) (Ξ΅ C : β) (w : Line F β β) | |
| (hΞ΅ : 0 < Ξ΅) (hC : 0 β€ C) | |
| (hw : β l, w l β€ C / (Fintype.card F : β) ^ 2) : | |
| (β l β markedLines U Ξ΅, w l) β€ C / (4 * Ξ΅ ^ 2 * Fintype.card F) := by | |
| rw [markedLines_eq] | |
| exact MarkedExposure.mass_large_deviations_le Finset.univ | |
| (fun l => (affineIntersectionCount U l : β)) w | |
| ((U.card : β) / Fintype.card F) (Fintype.card F) Ξ΅ C | |
| (by exact_mod_cast Fintype.card_pos (Ξ± := F)) hΞ΅ hC | |
| (affineSecondMoment_proof (F := F) U).2.2.2.1 (fun l _ => hw l) | |
| theorem token_marked_mass_le (U : Finset (Point F)) (Ξ΅ : β) | |
| (r : Direction F β β) (used : Direction F β Finset F) (k : β) (Ξ· : β) | |
| (hΞ΅ : 0 < Ξ΅) (hk : 0 < k) (hΞ· : 0 < Ξ·) | |
| (hqk : 2 * k β€ Fintype.card F) | |
| (hr : β d, r d β€ k) (hu : β d, (used d).card β€ k) | |
| (hremaining : Ξ· * (k : β) * ((Fintype.card F : β) + 1) β€ | |
| β d, (r d : β)) : | |
| (β l β markedLines U Ξ΅, tokenWeight r used l) β€ | |
| (2 / Ξ·) / (4 * Ξ΅ ^ 2 * Fintype.card F) := by | |
| apply marked_mass_le U Ξ΅ (2 / Ξ·) (tokenWeight r used) hΞ΅ (by positivity) | |
| intro l | |
| simpa only [div_div] using tokenWeight_le_two_div r used k Ξ· hk hΞ· hqk hr hu | |
| hremaining l | |
| theorem cover_marked_mass_le (U : Finset (Point F)) (Ξ΅ : β) | |
| (used : Finset (Line F)) (hΞ΅ : 0 < Ξ΅) (hu : used.card β€ Fintype.card F) : | |
| (β l β markedLines U Ξ΅, coverWeight used l) β€ | |
| 1 / (4 * Ξ΅ ^ 2 * Fintype.card F) := by | |
| exact marked_mass_le U Ξ΅ 1 (coverWeight used) hΞ΅ (by norm_num) | |
| (coverWeight_le_one_div_sq used hu) | |
| end | |
| end Balanced.CountingExposureKernel | |
| end OAI | |