introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.77 kB
import OAI.Computability.UniqueGames.Foundations.FiniteTrialsLemmas
namespace OAI
section
/-! An actual finite probability rectangle implementing all thresholds from a
fixed finite list. The seed distribution is shared; each local acceptance test
depends only on its own density. -/
namespace UniqueGamesTheorem.Foundations.CorrelatedSampling
noncomputable section
variable {Ξ± : Type*} [Fintype Ξ±]
private theorem sum_div_const {ΞΉ : Type*} [Fintype ΞΉ] (f : ΞΉ β†’ ℝ) (c : ℝ) :
(βˆ‘ i, f i) / c = βˆ‘ i, f i / c := by
simp only [div_eq_mul_inv, Finset.sum_mul]
abbrev RectangleSeed (thresholds : List ℝ) (Ξ± : Type*) :=
Ξ± Γ— Fin (thresholdPartition thresholds).length
def rectangleWeight (thresholds : List ℝ) (seed : RectangleSeed thresholds Ξ±) : ℝ :=
((thresholdPartition thresholds)[seed.2].hi - (thresholdPartition thresholds)[seed.2].lo) /
(Fintype.card Ξ± : ℝ)
def rectangleAccept (thresholds : List ℝ) (density : Ξ± β†’ ℝ)
(seed : RectangleSeed thresholds Ξ±) : Bool :=
decide ((thresholdPartition thresholds)[seed.2].lo < density seed.1)
theorem rectangleWeight_nonnegative (thresholds : List ℝ) (seed : RectangleSeed thresholds Ξ±) :
0 ≀ rectangleWeight thresholds seed :=
div_nonneg (sub_nonneg.mpr ((thresholdPartition thresholds)[seed.2].valid)) (by positivity)
theorem rectangleWeight_normalized [Nonempty Ξ±] (thresholds : List ℝ) :
βˆ‘ seed : RectangleSeed thresholds Ξ±, rectangleWeight thresholds seed = 1 := by
rw [Fintype.sum_prod_type]
have hrow (a : Ξ±) : (βˆ‘ i, rectangleWeight thresholds (a, i)) =
1 / (Fintype.card Ξ± : ℝ) := by
unfold rectangleWeight
rw [← sum_div_const, sum_interval_get (fun I => I.hi - I.lo), partition_total_mass]
simp_rw [hrow]
have hc : (Fintype.card Ξ± : ℝ) β‰  0 := by exact_mod_cast Fintype.card_ne_zero
simp [hc]
def rectangleDistribution [Nonempty Ξ±] (thresholds : List ℝ) :
Games.FiniteDistribution (RectangleSeed thresholds Ξ±) where
weight := rectangleWeight thresholds
nonnegative := rectangleWeight_nonnegative thresholds
normalized := rectangleWeight_normalized thresholds
theorem rectangle_row_mass (thresholds : List ℝ) (density : Ξ± β†’ ℝ) (a : Ξ±)
(hm : density a ∈ thresholds) (h0 : 0 ≀ density a) (h1 : density a ≀ 1) :
(βˆ‘ i, if rectangleAccept thresholds density (a, i) then
rectangleWeight thresholds (a, i) else 0) = density a / (Fintype.card Ξ± : ℝ) := by
calc
_ = (βˆ‘ i : Fin (thresholdPartition thresholds).length,
if (thresholdPartition thresholds)[i].lo < density a then
(thresholdPartition thresholds)[i].hi - (thresholdPartition thresholds)[i].lo else 0) /
(Fintype.card Ξ± : ℝ) := by
rw [sum_div_const]
apply Finset.sum_congr rfl
intro i _
simp [rectangleAccept, rectangleWeight, ite_div]
_ = density a / (Fintype.card Ξ± : ℝ) := by
rw [sum_interval_get (fun I => if I.lo < density a then I.hi - I.lo else 0),
partition_acceptance_mass thresholds (density a) hm h0 h1]
theorem rectangle_acceptance_mass (thresholds : List ℝ) (density : Ξ± β†’ ℝ)
(hm : βˆ€ a, density a ∈ thresholds) (h0 : βˆ€ a, 0 ≀ density a)
(h1 : βˆ€ a, density a ≀ 1) :
eventMass (rectangleWeight thresholds) (rectangleAccept thresholds density) =
(βˆ‘ a, density a) / (Fintype.card Ξ± : ℝ) := by
unfold eventMass
rw [Fintype.sum_prod_type]
simp_rw [rectangle_row_mass thresholds density _ (hm _) (h0 _) (h1 _)]
rw [sum_div_const]
theorem rectangle_label_mass [DecidableEq Ξ±] (thresholds : List ℝ) (density : Ξ± β†’ ℝ) (a : Ξ±)
(hm : βˆ€ x, density x ∈ thresholds) (h0 : βˆ€ x, 0 ≀ density x)
(h1 : βˆ€ x, density x ≀ 1) :
eventMass (rectangleWeight thresholds)
(fun seed => rectangleAccept thresholds density seed && decide (seed.1 = a)) =
density a / (Fintype.card Ξ± : ℝ) := by
unfold eventMass
rw [Fintype.sum_prod_type]
calc
_ = βˆ‘ x : Ξ±, if x = a then density x / (Fintype.card Ξ± : ℝ) else 0 := by
apply Finset.sum_congr rfl
intro x _
by_cases hx : x = a
Β· simpa [hx] using rectangle_row_mass thresholds density x (hm x) (h0 x) (h1 x)
Β· simp [hx]
_ = density a / (Fintype.card Ξ± : ℝ) := by simp
omit [Fintype Ξ±] in theorem rectangle_and (thresholds : List ℝ) (p q : Ξ± β†’ ℝ) :
(fun seed => rectangleAccept thresholds p seed && rectangleAccept thresholds q seed) =
rectangleAccept thresholds (fun a => min (p a) (q a)) := by
funext seed
simp [rectangleAccept]
omit [Fintype Ξ±] in theorem rectangle_or (thresholds : List ℝ) (p q : Ξ± β†’ ℝ) :
(fun seed => rectangleAccept thresholds p seed || rectangleAccept thresholds q seed) =
rectangleAccept thresholds (fun a => max (p a) (q a)) := by
funext seed
simp [rectangleAccept]
theorem min_mem_thresholds (thresholds : List ℝ) {x y : ℝ} (hx : x ∈ thresholds)
(hy : y ∈ thresholds) : min x y ∈ thresholds := by
by_cases h : x ≀ y <;> simp [min_def, h, hx, hy]
theorem max_mem_thresholds (thresholds : List ℝ) {x y : ℝ} (hx : x ∈ thresholds)
(hy : y ∈ thresholds) : max x y ∈ thresholds := by
by_cases h : x ≀ y <;> simp [max_def, h, hx, hy]
theorem rectangle_union_mass (thresholds : List ℝ) (p q : Ξ± β†’ ℝ)
(hpm : βˆ€ a, p a ∈ thresholds) (hqm : βˆ€ a, q a ∈ thresholds)
(hp0 : βˆ€ a, 0 ≀ p a) (_hq0 : βˆ€ a, 0 ≀ q a)
(hp1 : βˆ€ a, p a ≀ 1) (hq1 : βˆ€ a, q a ≀ 1) :
eventMass (rectangleWeight thresholds)
(fun seed => rectangleAccept thresholds p seed || rectangleAccept thresholds q seed) =
unionMass p q / (Fintype.card Ξ± : ℝ) := by
rw [rectangle_or]
exact rectangle_acceptance_mass thresholds _
(fun a => max_mem_thresholds thresholds (hpm a) (hqm a))
(fun a => (hp0 a).trans (le_max_left _ _)) (fun a => max_le (hp1 a) (hq1 a))
theorem rectangle_common_label_mass [DecidableEq Ξ±] (thresholds : List ℝ)
(p q : Ξ± β†’ ℝ) (a : Ξ±)
(hpm : βˆ€ x, p x ∈ thresholds) (hqm : βˆ€ x, q x ∈ thresholds)
(hp0 : βˆ€ x, 0 ≀ p x) (hq0 : βˆ€ x, 0 ≀ q x)
(hp1 : βˆ€ x, p x ≀ 1) (_hq1 : βˆ€ x, q x ≀ 1) :
eventMass (rectangleWeight thresholds)
(fun seed => (rectangleAccept thresholds p seed && rectangleAccept thresholds q seed) &&
decide (seed.1 = a)) = min (p a) (q a) / (Fintype.card Ξ± : ℝ) := by
have hand := congrFun (rectangle_and thresholds p q)
simp_rw [hand]
exact rectangle_label_mass thresholds _ a
(fun x => min_mem_thresholds thresholds (hpm x) (hqm x))
(fun x => le_min (hp0 x) (hq0 x)) (fun x => (min_le_left _ _).trans (hp1 x))
end
end UniqueGamesTheorem.Foundations.CorrelatedSampling
end
end OAI