math / data /lean /OAI /Combinatorics /BalancedRyser /Probability /CountingExposureKernel.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
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