math / data /lean /OAI /Computability /PerfectCompleteness /Sampling /CutSamplerReplayTransportLemmas.lean
Download data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerReplayTransportLemmas.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerReplayTransportLemmas.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerReplayTransportLemmas.lean
-
curl -L -o CutSamplerReplayTransportLemmas.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerReplayTransportLemmas.lean
13.7 kB
| import OAI.Computability.PerfectCompleteness.Construction.LocalReconstruction | |
| import OAI.Computability.PerfectCompleteness.Foundations.RecursiveSpaceEquivLemmas | |
| import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerKeyLocalityLemmas | |
| import OAI.Computability.PerfectCompleteness.Sampling.RecordSeedSamplingLemmas | |
| import OAI.Computability.UniqueGames.Foundations.Conditioning | |
| import OAI.Computability.UniqueGames.Foundations.SamplingLemmas | |
| namespace OAI | |
| namespace PerfectCompleteness.CutSamplerReplayTransport | |
| open PointwiseSpaces RecursiveSpaces DescendantSpaces RecursiveSampler | |
| open CutSamplerKeyLocality | |
| open scoped BigOperators Classical | |
| noncomputable section | |
| universe u v w | |
| variable {branch : Nat β Nat} {n m : Nat} | |
| (π : Type w) [Field π] (repeats : Nat β Nat) | |
| theorem squareEquiv_symm_apply | |
| {A : Slots branch n β Type u} {B : Slots branch n β Type v} | |
| (e : β s, A s β B s) (f : squareSpace (space π branch n A)) | |
| (y : Assignment B) : | |
| ((RecursiveSpaceEquiv.squareEquiv (π := π) e).symm f).val y = | |
| f.val (project (fun s => (e s).symm) y) := rfl | |
| theorem squareEquiv_symm_eval_of_agree | |
| {A : Slots branch n β Type u} {B : Slots branch n β Type v} | |
| (e : β s, A s β B s) (f : squareSpace (space π branch n A)) | |
| (x : Assignment A) (y : Assignment B) | |
| (hagree : β s, e s (x s) = y s) : | |
| ((RecursiveSpaceEquiv.squareEquiv (π := π) e).symm f).val y = f.val x := by | |
| rw [squareEquiv_symm_apply] | |
| apply congrArg f.val | |
| funext s | |
| exact (congrArg (e s).symm (hagree s)).symm.trans ((e s).symm_apply_apply (x s)) | |
| def transport (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n (m + 1)) β | |
| (A : Slots branch n β Type u) β (B : Slots branch n β Type v) β | |
| (clean : Fin (branch m) β Prop) β | |
| (β s, keptLeaf p clean s β A s β B s) β | |
| CutSamplerReplay.Tape π repeats p A clean β | |
| CutSamplerReplay.Tape π repeats p B clean | |
| | _, _, .refl _, _, _, _, e, tape => | |
| fun i => (RecursiveSpaceEquiv.squareEquiv (π := π) | |
| (fun s => e (i.val, s) i.property)).symm (tape i) | |
| | _, _, .step i p, A, B, clean, e, tape => | |
| (fun j => (RecursiveSpaceEquiv.squareEquiv (π := π) | |
| (fun s => e (j.val, s) (Or.inl j.property))).symm (tape.1 j), | |
| fun call => transport π repeats p (childFamily A i) (childFamily B i) clean | |
| (fun s hs => e (i, s) (Or.inr hs)) (tape.2 call)) | |
| theorem evaluate_transport (p : Path branch n (m + 1)) : | |
| β (A : Slots branch n β Type u) (B : Slots branch n β Type v) | |
| (clean : Fin (branch m) β Prop) | |
| (e : β s, keptLeaf p clean s β A s β B s) | |
| (tape : CutSamplerReplay.Tape π repeats p A clean) | |
| (x : Assignment A) (y : Assignment B), | |
| (β s hs, e s hs (x s) = y s) β | |
| CutSamplerReplay.evaluate π repeats p B clean | |
| (transport π repeats p A B clean e tape) y = | |
| CutSamplerReplay.evaluate π repeats p A clean tape x := by | |
| induction n generalizing m with | |
| | zero => | |
| have h := p.height_le | |
| omega | |
| | succ n ih => | |
| cases p with | |
| | refl => | |
| intro A B clean e tape x y hagree | |
| simp only [CutSamplerReplay.evaluate_refl] | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| exact squareEquiv_symm_eval_of_agree π | |
| (fun s => e (i.val, s) i.property) (tape i) | |
| (childRestriction A i.val x) (childRestriction B i.val y) | |
| (fun s => hagree (i.val, s) i.property) | |
| | step i p => | |
| intro A B clean e tape x y hagree | |
| simp only [CutSamplerReplay.evaluate_step] | |
| apply congrArgβ (fun a b : π => a + b) | |
| Β· apply Finset.sum_congr rfl | |
| intro j _ | |
| exact squareEquiv_symm_eval_of_agree π | |
| (fun s => e (j.val, s) (Or.inl j.property)) (tape.1 j) | |
| (childRestriction A j.val x) (childRestriction B j.val y) | |
| (fun s => hagree (j.val, s) (Or.inl j.property)) | |
| Β· apply Finset.sum_congr rfl | |
| intro h _ | |
| apply congrArgβ (fun a b : π => a * b) | |
| Β· exact ih p (childFamily A i) (childFamily B i) clean | |
| (fun s hs => e (i, s) (Or.inr hs)) (tape.2 (h, false)) | |
| (childRestriction A i x) (childRestriction B i y) | |
| (fun s hs => hagree (i, s) (Or.inr hs)) | |
| Β· exact ih p (childFamily A i) (childFamily B i) clean | |
| (fun s hs => e (i, s) (Or.inr hs)) (tape.2 (h, true)) | |
| (childRestriction A i x) (childRestriction B i y) | |
| (fun s hs => hagree (i, s) (Or.inr hs)) | |
| end | |
| end PerfectCompleteness.CutSamplerReplayTransport | |
| section | |
| namespace PerfectCompleteness.LocalReconstruction.Recipe | |
| open scoped BigOperators | |
| variable {π Atom Atom' X J : Type*} [Field π] | |
| def map (f : Atom β Atom') : Recipe π Atom β Recipe π Atom' | |
| | .constant c => .constant c | |
| | .atom a => .atom (f a) | |
| | .add r s => .add (map f r) (map f s) | |
| | .mul r s => .mul (map f r) (map f s) | |
| theorem evaluate_map (f : Atom β Atom') (atoms : Atom' β X β π) | |
| (r : Recipe π Atom) : | |
| (r.map f).evaluate atoms = r.evaluate (fun a => atoms (f a)) := by | |
| induction r with | |
| | constant c => rfl | |
| | atom a => rfl | |
| | add r s hr hs => simp only [map, evaluate, hr, hs] | |
| | mul r s hr hs => simp only [map, evaluate, hr, hs] | |
| def sumList (f : J β Recipe π Atom) : List J β Recipe π Atom | |
| | [] => .constant 0 | |
| | j :: js => .add (f j) (sumList f js) | |
| theorem evaluate_sumList (f : J β Recipe π Atom) (js : List J) | |
| (atoms : Atom β X β π) : | |
| (sumList f js).evaluate atoms = (js.map fun j => (f j).evaluate atoms).sum := by | |
| induction js with | |
| | nil => rfl | |
| | cons j js ih => simp only [sumList, evaluate, List.map_cons, List.sum_cons, ih] | |
| noncomputable def sumIndexed [Fintype J] (f : J β Recipe π Atom) : Recipe π Atom := | |
| sumList f Finset.univ.toList | |
| theorem evaluate_sumIndexed [Fintype J] (f : J β Recipe π Atom) | |
| (atoms : Atom β X β π) : | |
| (sumIndexed f).evaluate atoms = β j, (f j).evaluate atoms := by | |
| rw [sumIndexed, evaluate_sumList, Finset.sum_map_toList] | |
| end PerfectCompleteness.LocalReconstruction.Recipe | |
| namespace PerfectCompleteness.StoppedSamplerRecipe | |
| open scoped BigOperators | |
| open PointwiseSpaces RecursiveSpaces DescendantSpaces RecursiveSampler | |
| open LocalReconstruction | |
| noncomputable section | |
| universe u w | |
| variable {branch : Nat β Nat} {n m : Nat} | |
| def ordinaryTag (repeats : Nat β Nat) (i : Fin (branch n)) (p : Path branch n m) | |
| (j : OffPath i) : DrawIndex repeats (.step i p) := Sum.inl j | |
| def factorTag (repeats : Nat β Nat) (i : Fin (branch n)) (p : Path branch n m) | |
| (h : Fin (repeats (n + 1))) (b : Bool) (j : DrawIndex repeats p) : | |
| DrawIndex repeats (.step i p) := Sum.inr ((h, b), j) | |
| def recipe (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n m) β Recipe π (DrawIndex repeats p) | |
| | _, _, .refl _ => .atom () | |
| | n + 1, _, .step i p => | |
| .add | |
| (Recipe.sumIndexed (fun j : OffPath i => .atom (ordinaryTag repeats i p j))) | |
| (Recipe.sumIndexed (fun h : Fin (repeats (n + 1)) => | |
| .mul | |
| ((recipe π repeats p).map (factorTag repeats i p h false)) | |
| ((recipe π repeats p).map (factorTag repeats i p h true)))) | |
| def atoms (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n m) β (A : Slots branch n β Type u) β | |
| Tape π repeats p A β DrawIndex repeats p β Assignment A β π | |
| | _, _, .refl _, _, t, j => (t j).val | |
| | _, _, .step i p, A, t, j => | |
| match j with | |
| | Sum.inl j => pullback π (childRestriction A j.val) (t (Sum.inl j)).val | |
| | Sum.inr j => | |
| pullback π (childRestriction A i) | |
| (atoms π repeats p (childFamily A i) | |
| (subTape π repeats i p A t j.1.1 j.1.2) j.2) | |
| variable (π : Type w) [Field π] | |
| theorem evaluate_recipe (repeats : Nat β Nat) (p : Path branch n m) : | |
| β (A : Slots branch n β Type u) (t : Tape π repeats p A), | |
| (recipe π repeats p).evaluate (atoms π repeats p A t) = | |
| (RecursiveSampler.evaluate π repeats p A t).val := by | |
| induction p with | |
| | refl n => | |
| intro A t | |
| rfl | |
| | @step n m i p ih => | |
| intro A t | |
| have child (h : Fin (repeats (n + 1))) (b : Bool) : | |
| ((recipe π repeats p).map (factorTag repeats i p h b)).evaluate | |
| (atoms π repeats (.step i p) A t) = | |
| (RecursiveSampler.evaluate π repeats p (childFamily A i) | |
| (subTape π repeats i p A t h b)).val β childRestriction A i := by | |
| rw [Recipe.evaluate_map] | |
| change (recipe π repeats p).evaluate (fun j => | |
| atoms π repeats p (childFamily A i) (subTape π repeats i p A t h b) j β | |
| childRestriction A i) = _ | |
| rw [Recipe.evaluate_pullback, ih] | |
| simp only [recipe, Recipe.evaluate, Recipe.evaluate_sumIndexed, child] | |
| funext x | |
| simp only [RecursiveSampler.evaluate, combine, combineFunction, | |
| Finset.sum_apply, Pi.add_apply, Pi.mul_apply, Function.comp_apply, | |
| atoms, ordinaryTag, PointwiseSpaces.pullback_apply] | |
| theorem evaluate_factors {Z : Type*} (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) (t : Tape π repeats p A) (other : Assignment A β Z) | |
| (known : β j, atoms π repeats p A t j β FactoredFunctions.factoringSpace other) : | |
| (RecursiveSampler.evaluate π repeats p A t).val β | |
| FactoredFunctions.factoringSpace other := by | |
| rw [β evaluate_recipe π repeats p A t] | |
| exact Recipe.evaluate_factors other (atoms π repeats p A t) known (recipe π repeats p) | |
| end | |
| end PerfectCompleteness.StoppedSamplerRecipe | |
| end | |
| namespace PerfectCompleteness.UniformConditioning | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open UniqueGamesTheorem.Foundations.Games | |
| variable {Ξ© Ξ : Type*} [Fintype Ξ©] [Fintype Ξ] [Nonempty Ξ©] [Nonempty Ξ] | |
| theorem uniform_transport (e : Ξ© β Ξ) : | |
| (FiniteDistribution.uniform Ξ©).transport e = FiniteDistribution.uniform Ξ := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro y | |
| change 1 / (Fintype.card Ξ© : β) = 1 / (Fintype.card Ξ : β) | |
| rw [Fintype.card_congr e] | |
| theorem uniform_probability_equiv (e : Ξ© β Ξ) (event : Ξ β Bool) : | |
| (FiniteDistribution.uniform Ξ©).probability (fun x => event (e x)) = | |
| (FiniteDistribution.uniform Ξ).probability event := by | |
| rw [β uniform_transport e, FiniteDistribution.probability_transport] | |
| theorem uniform_probability (T : Ξ© β Prop) : | |
| (FiniteDistribution.uniform Ξ©).probability (fun x => decide (T x)) = | |
| (Fintype.card {x : Ξ© // T x} : β) / (Fintype.card Ξ© : β) := by | |
| calc | |
| _ = (β x : Ξ©, if T x then (1 : β) else 0) / (Fintype.card Ξ© : β) := by | |
| change (β x : Ξ©, if decide (T x) then 1 / (Fintype.card Ξ© : β) else 0) = _ | |
| simp only [div_eq_mul_inv, Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| by_cases hx : T x <;> simp [hx] | |
| _ = _ := by simp only [Fintype.card_subtype, Finset.sum_boole] | |
| theorem uniform_probability_pos (T : Ξ© β Prop) [Nonempty {x : Ξ© // T x}] : | |
| 0 < (FiniteDistribution.uniform Ξ©).probability (fun x => decide (T x)) := by | |
| rw [uniform_probability] | |
| exact div_pos (Nat.cast_pos.mpr Fintype.card_pos) (Nat.cast_pos.mpr Fintype.card_pos) | |
| omit [Nonempty Ξ©] in | |
| theorem uniform_subtype_pushforward_weight (T : Ξ© β Prop) | |
| [Nonempty {x : Ξ© // T x}] (x : Ξ©) : | |
| ((FiniteDistribution.uniform {x : Ξ© // T x}).pushforward Subtype.val).weight x = | |
| if T x then 1 / (Fintype.card {x : Ξ© // T x} : β) else 0 := by | |
| change (β y : {x : Ξ© // T x}, | |
| if y.val = x then 1 / (Fintype.card {x : Ξ© // T x} : β) else 0) = _ | |
| by_cases hx : T x | |
| Β· rw [ite_eq_left hx] | |
| rw [Finset.sum_eq_single (β¨x, hxβ© : {x : Ξ© // T x})] | |
| Β· simp | |
| Β· intro y _ hy | |
| have hne : y.val β x := fun heq => hy (Subtype.ext heq) | |
| simp [hne] | |
| Β· simp | |
| Β· rw [ite_eq_right hx] | |
| apply Finset.sum_eq_zero | |
| intro y _ | |
| have hne : y.val β x := fun heq => hx (heq βΈ y.property) | |
| simp [hne] | |
| theorem condition_uniform (T : Ξ© β Prop) [Nonempty {x : Ξ© // T x}] | |
| (positive : 0 < (FiniteDistribution.uniform Ξ©).probability (fun x => decide (T x))) : | |
| (FiniteDistribution.uniform Ξ©).condition (fun x => decide (T x)) positive = | |
| (FiniteDistribution.uniform {x : Ξ© // T x}).pushforward Subtype.val := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro x | |
| rw [uniform_subtype_pushforward_weight] | |
| change (if decide (T x) then | |
| (1 / (Fintype.card Ξ© : β)) / | |
| (FiniteDistribution.uniform Ξ©).probability (fun x => decide (T x)) else 0) = _ | |
| rw [uniform_probability] | |
| have hcard : (Fintype.card Ξ© : β) β 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero | |
| by_cases hx : T x | |
| Β· simpa [hx] using | |
| div_div_div_cancel_rightβ hcard (1 : β) (Fintype.card {x : Ξ© // T x} : β) | |
| Β· simp [hx] | |
| theorem probability_condition_uniform (T : Ξ© β Prop) [Nonempty {x : Ξ© // T x}] | |
| (positive : 0 < (FiniteDistribution.uniform Ξ©).probability (fun x => decide (T x))) | |
| (event : Ξ© β Bool) : | |
| ((FiniteDistribution.uniform Ξ©).condition (fun x => decide (T x)) positive).probability | |
| event = | |
| (FiniteDistribution.uniform {x : Ξ© // T x}).probability (fun x => event x.val) := by | |
| rw [condition_uniform, FiniteDistribution.probability_pushforward] | |
| end | |
| end PerfectCompleteness.UniformConditioning | |
| end OAI | |