Download data/lean/OAI/Computability/UniqueGames/Foundations/KernelSampling.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.83 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/UniqueGames/Foundations/KernelSampling.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/UniqueGames/Foundations/KernelSampling.lean
-
curl -L -o KernelSampling.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/UniqueGames/Foundations/KernelSampling.lean
7.83 kB
| import OAI.Computability.UniqueGames.Foundations.ValueLemmas | |
| namespace OAI | |
| section | |
| /-! | |
| Exact sampling of two conditional kernels from one finite weighted shared seed. | |
| The seed consists of independent full response tables and is independent of the | |
| questions. Supported-coordinate repairs preserve the sampled laws and enforce | |
| the designated coordinate even on seeds of weight zero. The seed is not claimed | |
| to be uniform: the kernel weights may be arbitrary real numbers. | |
| -/ | |
| namespace UniqueGamesTheorem.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] | |
| /-- Applying separate maps to independent samples preserves their independence. -/ | |
| 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] | |
| /-- A full response table of nonzero weight uses a supported answer in every row. -/ | |
| 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 | |
| /-- Repairing table entries only off each row's support leaves its exact law intact. -/ | |
| 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 | |
| /-- A single seed supplies a full local table to each side. -/ | |
| 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 | |
| /-- The fixed weighted seed law; it does not depend on the sampled questions. -/ | |
| 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) | |
| /-- The two reads have exactly the product of the requested conditional laws. -/ | |
| 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] | |
| /-- Separate supported repairs retain the exact joint product law. -/ | |
| 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] | |
| section Completion | |
| variable {I A B S : Type*} [DecidableEq I] | |
| /-- Restore the designated coordinate on every left table read. -/ | |
| 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 | |
| /-- Restore the designated coordinate on every right table read. -/ | |
| 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] | |
| /-- Exact conditional completion from a finite weighted shared seed. The reads | |
| always restore the specified coordinates, including on seeds of weight zero; | |
| the support hypotheses ensure that this repair preserves the requested laws. -/ | |
| 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 Completion | |
| end KernelSampling | |
| end | |
| end UniqueGamesTheorem.Foundations.Games | |
| end | |
| end OAI | |