introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.49 kB
import Mathlib
import OAI.Combinatorics.IndependentSets.Repetition.Value
namespace OAI
namespace IndependentSetsGames.Foundations.Games
open scoped BigOperators
noncomputable section
namespace FiniteDistribution
theorem pushforward_eq_of_agree_on_support
{Ξ© Ξ“ : Type*} [Fintype Ξ©] [Fintype Ξ“]
(ΞΌ : FiniteDistribution Ξ©) (f g : Ξ© β†’ Ξ“)
(h : βˆ€ x, ΞΌ.weight x β‰  0 β†’ f x = g x) :
ΞΌ.pushforward f = ΞΌ.pushforward g := by
classical
apply eq_of_weight_eq
intro y
simp only [pushforward]
apply Finset.sum_congr rfl
intro x _
by_cases hx : ΞΌ.weight x = 0
Β· simp [hx]
Β· rw [h x hx]
theorem product_pushforward
{Ξ© Ξ“ A B : Type*} [Fintype Ξ©] [Fintype Ξ“] [Fintype A] [Fintype B]
(ΞΌ : FiniteDistribution Ξ©) (Ξ½ : FiniteDistribution Ξ“)
(f : Ξ© β†’ A) (g : Ξ“ β†’ B) :
(ΞΌ.product Ξ½).pushforward (fun z => (f z.1, g z.2)) =
(ΞΌ.pushforward f).product (Ξ½.pushforward g) := by
classical
apply eq_of_weight_eq
rintro ⟨a, b⟩
simp only [pushforward, product]
rw [Fintype.sum_prod_type, Finset.sum_mul_sum]
apply Finset.sum_congr rfl
intro x _
apply Finset.sum_congr rfl
intro y _
by_cases hx : f x = a <;> by_cases hy : g y = b <;> simp [hx, hy]
theorem table_row_weight_ne_zero
{Q A : Type*} [Fintype Q] [Fintype A] [DecidableEq Q]
(responses : Q β†’ FiniteDistribution A) (answers : Q β†’ A)
(h : (table responses).weight answers β‰  0) (q : Q) :
(responses q).weight (answers q) β‰  0 := by
intro hq
apply h
change (∏ r, (responses r).weight (answers r)) = 0
exact Finset.prod_eq_zero (Finset.mem_univ q) hq
theorem table_repair_pushforward
{Q A : Type*} [Fintype Q] [Fintype A] [DecidableEq Q]
(responses : Q β†’ FiniteDistribution A) (repair : Q β†’ A β†’ A)
(hrepair : βˆ€ q a, (responses q).weight a β‰  0 β†’ repair q a = a) (q : Q) :
(table responses).pushforward (fun answers => repair q (answers q)) =
responses q := by
calc
_ = (table responses).pushforward (fun answers => answers q) := by
apply pushforward_eq_of_agree_on_support
intro answers h
exact hrepair q (answers q) (table_row_weight_ne_zero responses answers h q)
_ = responses q := table_eval_pushforward responses q
end FiniteDistribution
namespace KernelSampling
abbrev Seed (Q₁ Qβ‚‚ A B : Type*) := (Q₁ β†’ A) Γ— (Qβ‚‚ β†’ B)
def readLeft {Q₁ Qβ‚‚ A B : Type*} (seed : Seed Q₁ Qβ‚‚ A B) (q : Q₁) : A := seed.1 q
def readRight {Q₁ Qβ‚‚ A B : Type*} (seed : Seed Q₁ Qβ‚‚ A B) (q : Qβ‚‚) : B := seed.2 q
def seedLaw {Q₁ Qβ‚‚ A B : Type*}
[Fintype Q₁] [Fintype Qβ‚‚] [Fintype A] [Fintype B]
[DecidableEq Q₁] [DecidableEq Qβ‚‚]
(left : Q₁ β†’ FiniteDistribution A) (right : Qβ‚‚ β†’ FiniteDistribution B) :
FiniteDistribution (Seed Q₁ Qβ‚‚ A B) :=
(FiniteDistribution.table left).product (FiniteDistribution.table right)
theorem read_joint_pushforward {Q₁ Qβ‚‚ A B : Type*}
[Fintype Q₁] [Fintype Qβ‚‚] [Fintype A] [Fintype B]
[DecidableEq Q₁] [DecidableEq Qβ‚‚]
(left : Q₁ β†’ FiniteDistribution A) (right : Qβ‚‚ β†’ FiniteDistribution B)
(x : Q₁) (y : Qβ‚‚) :
(seedLaw left right).pushforward (fun seed => (readLeft seed x, readRight seed y)) =
(left x).product (right y) := by
unfold seedLaw readLeft readRight
rw [FiniteDistribution.product_pushforward
(FiniteDistribution.table left) (FiniteDistribution.table right)
(fun answers => answers x) (fun answers => answers y),
FiniteDistribution.table_eval_pushforward, FiniteDistribution.table_eval_pushforward]
theorem repaired_joint_pushforward {Q₁ Qβ‚‚ A B : Type*}
[Fintype Q₁] [Fintype Qβ‚‚] [Fintype A] [Fintype B]
[DecidableEq Q₁] [DecidableEq Qβ‚‚]
(left : Q₁ β†’ FiniteDistribution A) (right : Qβ‚‚ β†’ FiniteDistribution B)
(repairLeft : Q₁ β†’ A β†’ A) (repairRight : Qβ‚‚ β†’ B β†’ B)
(hleft : βˆ€ x a, (left x).weight a β‰  0 β†’ repairLeft x a = a)
(hright : βˆ€ y b, (right y).weight b β‰  0 β†’ repairRight y b = b)
(x : Q₁) (y : Qβ‚‚) :
(seedLaw left right).pushforward (fun seed =>
(repairLeft x (readLeft seed x), repairRight y (readRight seed y))) =
(left x).product (right y) := by
unfold seedLaw readLeft readRight
rw [FiniteDistribution.product_pushforward
(FiniteDistribution.table left) (FiniteDistribution.table right)
(fun answers => repairLeft x (answers x)) (fun answers => repairRight y (answers y)),
FiniteDistribution.table_repair_pushforward left repairLeft hleft,
FiniteDistribution.table_repair_pushforward right repairRight hright]
variable {I A B S : Type*} [DecidableEq I]
def completedLeft (j : I)
(seed : Seed (A Γ— S) (B Γ— S) (I β†’ A) (I β†’ B)) (q : A Γ— S) : I β†’ A :=
Function.update (readLeft seed q) j q.1
def completedRight (j : I)
(seed : Seed (A Γ— S) (B Γ— S) (I β†’ A) (I β†’ B)) (q : B Γ— S) : I β†’ B :=
Function.update (readRight seed q) j q.1
@[simp] theorem completedLeft_coordinate (j : I)
(seed : Seed (A Γ— S) (B Γ— S) (I β†’ A) (I β†’ B)) (q : A Γ— S) :
completedLeft j seed q j = q.1 := by simp [completedLeft]
@[simp] theorem completedRight_coordinate (j : I)
(seed : Seed (A Γ— S) (B Γ— S) (I β†’ A) (I β†’ B)) (q : B Γ— S) :
completedRight j seed q j = q.1 := by simp [completedRight]
private theorem update_eq_of_coordinate (xs : I β†’ A) (j : I) (a : A)
(h : xs j = a) : Function.update xs j a = xs := by
funext i
by_cases hi : i = j <;> simp [Function.update, hi, h]
theorem completed_joint_pushforward
[Fintype I] [Fintype A] [Fintype B] [Fintype S]
[DecidableEq A] [DecidableEq B] [DecidableEq S]
(left : (A Γ— S) β†’ FiniteDistribution (I β†’ A))
(right : (B Γ— S) β†’ FiniteDistribution (I β†’ B)) (j : I)
(hleft : βˆ€ q xs, (left q).weight xs β‰  0 β†’ xs j = q.1)
(hright : βˆ€ q ys, (right q).weight ys β‰  0 β†’ ys j = q.1)
(x : A Γ— S) (y : B Γ— S) :
(seedLaw left right).pushforward
(fun seed => (completedLeft j seed x, completedRight j seed y)) =
(left x).product (right y) := by
apply repaired_joint_pushforward left right
(fun q xs => Function.update xs j q.1) (fun q ys => Function.update ys j q.1)
Β· intro q xs h
exact update_eq_of_coordinate xs j q.1 (hleft q xs h)
Β· intro q ys h
exact update_eq_of_coordinate ys j q.1 (hright q ys h)
end KernelSampling
end
end IndependentSetsGames.Foundations.Games
end OAI