Download data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerRefinement.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerRefinement.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerRefinement.lean
-
curl -L -o CutSamplerRefinement.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/CutSamplerRefinement.lean
9 kB
| import OAI.Computability.PerfectCompleteness.Repetition.CleanConditioning | |
| import OAI.Computability.PerfectCompleteness.Sampling.RecordSeedSamplingLemmas | |
| import OAI.Computability.PerfectCompleteness.Sampling.UniformChildSum | |
| import OAI.Computability.UniqueGames.Foundations.SamplingLemmas | |
| namespace OAI | |
| section | |
| namespace PerfectCompleteness.CutSamplerRefinement | |
| open PointwiseSpaces RecursiveSpaces DescendantSpaces RecursiveSampler | |
| open UniqueGamesTheorem.Foundations.Games | |
| open scoped Classical | |
| noncomputable section | |
| universe u w | |
| variable {branch : Nat β Nat} {n m : Nat} | |
| def RefinedSpace (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n m) β (A : Slots branch n β Type u) β | |
| DrawIndex repeats p β Type (max u w) | |
| | 0, _, .refl _, A, _ => space π branch 0 A | |
| | n + 1, _, .refl _, A, _ => | |
| (i : Fin (branch n)) β squareSpace (space π branch n (childFamily A i)) | |
| | n + 1, _, .step i p, A, j => | |
| match j with | |
| | Sum.inl j => squareSpace (space π branch n (childFamily A j.val)) | |
| | Sum.inr j => RefinedSpace π repeats p (childFamily A i) j.2 | |
| def zeroFactor (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n m) β (A : Slots branch n β Type u) β | |
| (j : DrawIndex repeats p) β RefinedSpace π repeats p A j | |
| | 0, _, .refl _, A, _ => (0 : space π branch 0 A) | |
| | n + 1, _, .refl _, A, _ => | |
| fun i => (0 : squareSpace (space π branch n (childFamily A i))) | |
| | n + 1, _, .step i p, A, j => | |
| match j with | |
| | Sum.inl j => (0 : squareSpace (space π branch n (childFamily A j.val))) | |
| | Sum.inr j => zeroFactor π repeats p (childFamily A i) j.2 | |
| instance refinedNonempty (π : Type w) [Field π] (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) (j : DrawIndex repeats p) : | |
| Nonempty (RefinedSpace π repeats p A j) := β¨zeroFactor π repeats p A jβ© | |
| theorem refined_finite (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) : | |
| β (A : Slots branch n β Type u), (β s, Finite (A s)) β | |
| β j : DrawIndex repeats p, Finite (RefinedSpace π repeats p A j) := by | |
| induction p with | |
| | refl n => | |
| intro A hA j | |
| let : β s, Finite (A s) := hA | |
| cases n with | |
| | zero => | |
| change Finite (space π branch 0 A) | |
| infer_instance | |
| | succ n => | |
| change Finite ((i : Fin (branch n)) β | |
| squareSpace (space π branch n (childFamily A i))) | |
| let : β i : Fin (branch n), | |
| Finite (squareSpace (space π branch n (childFamily A i))) := fun i => by | |
| let : β s, Finite ((childFamily A i) s) := fun s => hA (i, s) | |
| infer_instance | |
| infer_instance | |
| | @step n m i p ih => | |
| intro A hA j | |
| cases j with | |
| | inl j => | |
| let : β s, Finite ((childFamily A j.val) s) := fun s => hA (j.val, s) | |
| change Finite (squareSpace (space π branch n (childFamily A j.val))) | |
| infer_instance | |
| | inr j => | |
| exact ih (childFamily A i) (fun s => hA (i, s)) j.2 | |
| instance refinedFinite (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) [β s, Finite (A s)] (j : DrawIndex repeats p) : | |
| Finite (RefinedSpace π repeats p A j) := | |
| refined_finite π repeats p A (fun _ => inferInstance) j | |
| instance refinedFintype (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) [β s, Finite (A s)] (j : DrawIndex repeats p) : | |
| Fintype (RefinedSpace π repeats p A j) := Fintype.ofFinite _ | |
| def collapseFactor (π : Type w) [Field π] (repeats : Nat β Nat) : | |
| {n m : Nat} β (p : Path branch n m) β (A : Slots branch n β Type u) β | |
| (j : DrawIndex repeats p) β RefinedSpace π repeats p A j β DrawSpace π repeats p A j | |
| | 0, _, .refl _, _, _, x => x | |
| | _ + 1, _, .refl _, A, _, x => UniformChildSum.recursiveSum A x | |
| | _ + 1, _, .step i p, A, j, x => | |
| match j with | |
| | Sum.inl _ => x | |
| | Sum.inr j => collapseFactor π repeats p (childFamily A i) j.2 x | |
| abbrev Tape (π : Type w) [Field π] (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) := | |
| (j : DrawIndex repeats p) β RefinedSpace π repeats p A j | |
| def collapse (π : Type w) [Field π] (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) : | |
| Tape π repeats p A β RecursiveSampler.Tape π repeats p A := | |
| fun x j => collapseFactor π repeats p A j (x j) | |
| def tapeLaw (π : Type w) [Field π] [Finite π] (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) [β s, Finite (A s)] : | |
| FiniteDistribution (Tape π repeats p A) := | |
| FiniteProduct.law (fun j => FiniteDistribution.uniform (RefinedSpace π repeats p A j)) | |
| private theorem pushforward_identity {Ξ© : Type*} [Fintype Ξ©] (ΞΌ : FiniteDistribution Ξ©) : | |
| ΞΌ.pushforward (fun x => x) = ΞΌ := by | |
| change ΞΌ.pushforward (Equiv.refl Ξ©) = ΞΌ | |
| rw [FiniteDistribution.pushforward_equiv] | |
| exact FiniteDistribution.eq_of_weight_eq (fun _ => rfl) | |
| theorem collapseFactor_uniform (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) : | |
| β (A : Slots branch n β Type u) [β s, Finite (A s)] (j : DrawIndex repeats p), | |
| (FiniteDistribution.uniform (RefinedSpace π repeats p A j)).pushforward | |
| (collapseFactor π repeats p A j) = | |
| FiniteDistribution.uniform (DrawSpace π repeats p A j) := by | |
| induction p with | |
| | refl n => | |
| intro A hA j | |
| cases n with | |
| | zero => | |
| let : β s, Finite (A s) := hA | |
| let : Fintype (space π branch 0 A) := Fintype.ofFinite _ | |
| change (FiniteDistribution.uniform (space π branch 0 A)).pushforward | |
| (fun x => x) = FiniteDistribution.uniform (space π branch 0 A) | |
| exact pushforward_identity _ | |
| | succ n => | |
| let : Fintype ((i : Fin (branch n)) β | |
| squareSpace (space π branch n (childFamily A i))) := | |
| refinedFintype π repeats (.refl (n + 1)) A j | |
| let : Fintype (space π branch (n + 1) A) := | |
| RecursiveSampler.drawSpaceFintype π repeats (.refl (n + 1)) A j | |
| exact UniformLinearImage.uniform_pushforward_linearMap | |
| (UniformChildSum.recursiveSum (π := π) A) | |
| (UniformChildSum.recursiveSum_surjective (π := π) A) | |
| | @step n m i p ih => | |
| intro A hA j | |
| cases j with | |
| | inl j => | |
| let : β s, Finite ((childFamily A j.val) s) := fun s => hA (j.val, s) | |
| let : Fintype (squareSpace (space π branch n (childFamily A j.val))) := | |
| Fintype.ofFinite _ | |
| change (FiniteDistribution.uniform | |
| (squareSpace (space π branch n (childFamily A j.val)))).pushforward | |
| (fun x => x) = FiniteDistribution.uniform | |
| (squareSpace (space π branch n (childFamily A j.val))) | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro x | |
| simp [FiniteDistribution.pushforward] | |
| | inr j => | |
| let : β s, Finite ((childFamily A i) s) := fun s => hA (i, s) | |
| exact ih (childFamily A i) j.2 | |
| theorem collapse_tapeLaw (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) [β s, Finite (A s)] : | |
| (tapeLaw π repeats p A).pushforward (collapse π repeats p A) = | |
| RecursiveSampler.tapeLaw π repeats p A := by | |
| unfold tapeLaw collapse | |
| rw [CleanConditioning.pushforward_law] | |
| simp_rw [collapseFactor_uniform] | |
| rfl | |
| def evaluate (π : Type w) [Field π] (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) (x : Tape π repeats p A) : | |
| space π branch n A := | |
| RecursiveSampler.evaluate π repeats p A (collapse π repeats p A x) | |
| theorem evaluate_law (π : Type w) [Field π] [Finite π] | |
| (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) [β s, Finite (A s)] [Fintype (space π branch n A)] : | |
| (tapeLaw π repeats p A).pushforward (evaluate π repeats p A) = | |
| RecursiveSampler.law π repeats p A := by | |
| change (tapeLaw π repeats p A).pushforward | |
| ((RecursiveSampler.evaluate π repeats p A) β collapse π repeats p A) = _ | |
| calc | |
| _ = ((tapeLaw π repeats p A).pushforward (collapse π repeats p A)).pushforward | |
| (RecursiveSampler.evaluate π repeats p A) := | |
| (FiniteDistribution.pushforward_comp (tapeLaw π repeats p A) | |
| (collapse π repeats p A) (RecursiveSampler.evaluate π repeats p A)).symm | |
| _ = _ := by | |
| rw [collapse_tapeLaw] | |
| rfl | |
| end | |
| end PerfectCompleteness.CutSamplerRefinement | |
| end | |
| end OAI | |