Download data/lean/OAI/Computability/PerfectCompleteness/Sampling/BucketSampler.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.57 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BucketSampler.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BucketSampler.lean
-
curl -L -o BucketSampler.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/PerfectCompleteness/Sampling/BucketSampler.lean
8.57 kB
| import Mathlib.Algebra.Field.ZMod | |
| import OAI.Computability.PerfectCompleteness.Algebra.EvaluationMatrix | |
| import OAI.Computability.PerfectCompleteness.Sampling.RecordSeedSamplingLemmas | |
| namespace OAI | |
| namespace PerfectCompleteness.BucketSampler | |
| open UniqueGamesTheorem.Foundations.Games | |
| open scoped BigOperators Classical | |
| noncomputable section | |
| abbrev F2 := ZMod 2 | |
| abbrev Direction (β : Nat) := {v : Fin β β F2 // v β 0} | |
| abbrev Tape (β : Nat) (Ξ© : Type*) := Direction β β Ξ© | |
| variable {Ξ© H : Type*} [AddCommGroup H] [Module F2 H] | |
| def rankOne {β : Nat} (v : Fin β β F2) (h : H) : Fin β β H := | |
| fun i => v i β’ h | |
| def evaluate (β : Nat) (eval : Ξ© β H) (t : Tape β Ξ©) : Fin β β H := | |
| fun i => β v : Direction β, v.val i β’ eval (t v) | |
| theorem evaluate_eq_sum (β : Nat) (eval : Ξ© β H) (t : Tape β Ξ©) : | |
| evaluate β eval t = β v : Direction β, rankOne v.val (eval (t v)) := by | |
| funext i | |
| simp only [evaluate, Finset.sum_apply, rankOne] | |
| theorem evaluate_update (β : Nat) (eval : Ξ© β H) (t : Tape β Ξ©) | |
| (a : Direction β) (new : Ξ©) : | |
| evaluate β eval (Function.update t a new) = | |
| evaluate β eval t + rankOne a.val (eval new - eval (t a)) := by | |
| funext i | |
| let S : H := β v : Direction β, v.val i β’ eval (t v) | |
| let S' : H := β v : Direction β, v.val i β’ eval (Function.update t a new v) | |
| have hd : S' - S = a.val i β’ (eval new - eval (t a)) := by | |
| dsimp only [S', S] | |
| rw [β Finset.sum_sub_distrib, Finset.sum_eq_single a] | |
| Β· rw [Function.update_self, smul_sub] | |
| Β· intro b _ hba | |
| simp only [Function.update_of_ne hba, sub_self] | |
| Β· intro ha | |
| exact (ha (Finset.mem_univ a)).elim | |
| change S' = S + a.val i β’ (eval new - eval (t a)) | |
| simpa only [sub_add_cancel] using | |
| (congrArg (fun z : H => z + S) hd).trans (add_comm _ _) | |
| theorem linearMap_evaluate (β : Nat) (eval : Ξ© β H) (t : Tape β Ξ©) | |
| (q : H ββ[F2] F2) (i : Fin β) : | |
| q (evaluate β eval t i) = β v : Direction β, v.val i * q (eval (t v)) := by | |
| simp only [evaluate, map_sum, map_smul, smul_eq_mul] | |
| theorem evaluate_apply {X : Type*} (β : Nat) (V : Submodule F2 (X β F2)) | |
| (eval : Ξ© β V) (t : Tape β Ξ©) (i : Fin β) (x : X) : | |
| (evaluate β eval t i).val x = | |
| β v : Direction β, v.val i * (eval (t v)).val x := | |
| linearMap_evaluate β eval t (EvaluationMatrix.evaluation V x) i | |
| instance directionZero_isEmpty : IsEmpty (Direction 0) where | |
| false v := v.property (funext fun i => Fin.elim0 i) | |
| @[simp] theorem evaluate_zero_width (eval : Ξ© β H) (t : Tape 0 Ξ©) : | |
| evaluate 0 eval t = 0 := by | |
| funext i | |
| exact Fin.elim0 i | |
| section Laws | |
| variable [Fintype Ξ©] | |
| def tapeLaw (β : Nat) (ΞΌ : FiniteDistribution Ξ©) : FiniteDistribution (Tape β Ξ©) := | |
| FiniteProduct.law (fun _ : Direction β => ΞΌ) | |
| @[simp] theorem tapeLaw_weight (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (t : Tape β Ξ©) : | |
| (tapeLaw β ΞΌ).weight t = β v : Direction β, ΞΌ.weight (t v) := rfl | |
| theorem tapeLaw_marginal (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (v : Direction β) : | |
| (tapeLaw β ΞΌ).pushforward (fun t => t v) = ΞΌ := | |
| FiniteProduct.eval_pushforward (fun _ : Direction β => ΞΌ) v | |
| theorem expectation_product (β : Nat) (ΞΌ : FiniteDistribution Ξ©) | |
| (f : Direction β β Ξ© β β) : | |
| (tapeLaw β ΞΌ).expectation (fun t => β v, f v (t v)) = | |
| β v, ΞΌ.expectation (f v) := | |
| FiniteProduct.expectation_product (fun _ : Direction β => ΞΌ) f | |
| omit [AddCommGroup H] [Module F2 H] in | |
| theorem expectation_bucket_mul (β : Nat) (ΞΌ : FiniteDistribution Ξ©) | |
| (eval : Ξ© β H) (v w : Direction β) (hvw : v β w) (f g : H β β) : | |
| (tapeLaw β ΞΌ).expectation (fun t => f (eval (t v)) * g (eval (t w))) = | |
| ΞΌ.expectation (fun t => f (eval t)) * ΞΌ.expectation (fun t => g (eval t)) := | |
| FiniteProduct.expectation_eval_mul (fun _ : Direction β => ΞΌ) v w hvw | |
| (fun t => f (eval t)) (fun t => g (eval t)) | |
| @[simp] theorem tapeLaw_zero_width_weight (ΞΌ : FiniteDistribution Ξ©) (t : Tape 0 Ξ©) : | |
| (tapeLaw 0 ΞΌ).weight t = 1 := by | |
| simp [tapeLaw, FiniteProduct.law] | |
| variable [Fintype H] | |
| omit [AddCommGroup H] [Module F2 H] in | |
| theorem bucket_marginal (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (eval : Ξ© β H) | |
| (v : Direction β) : | |
| (tapeLaw β ΞΌ).pushforward (fun t => eval (t v)) = ΞΌ.pushforward eval := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro h | |
| calc | |
| _ = (tapeLaw β ΞΌ).expectation (fun t => if eval (t v) = h then 1 else 0) := by | |
| simp [FiniteDistribution.pushforward, FiniteDistribution.expectation, mul_ite] | |
| _ = ΞΌ.expectation (fun t => if eval t = h then 1 else 0) := | |
| FiniteProduct.expectation_eval (fun _ : Direction β => ΞΌ) v | |
| (fun t : Ξ© => if eval t = h then (1 : β) else 0) | |
| _ = _ := by | |
| simp [FiniteDistribution.pushforward, FiniteDistribution.expectation, mul_ite] | |
| def law (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (eval : Ξ© β H) : | |
| FiniteDistribution (Fin β β H) := | |
| (tapeLaw β ΞΌ).pushforward (evaluate β eval) | |
| theorem probability_law (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (eval : Ξ© β H) | |
| (event : (Fin β β H) β Bool) : | |
| (law β ΞΌ eval).probability event = | |
| (tapeLaw β ΞΌ).probability (fun t => event (evaluate β eval t)) := | |
| FiniteDistribution.probability_pushforward _ _ _ | |
| end Laws | |
| section FreshArrays | |
| variable {J : Type*} [Fintype J] [DecidableEq J] [Fintype Ξ©] | |
| abbrev FreshTape (J : Type*) (β : Nat) (Ξ© : Type*) := J β Tape β Ξ© | |
| def freshTapeLaw (J : Type*) [Fintype J] [DecidableEq J] (β : Nat) | |
| (ΞΌ : FiniteDistribution Ξ©) : FiniteDistribution (FreshTape J β Ξ©) := | |
| FiniteProduct.law (fun _ : J => tapeLaw β ΞΌ) | |
| theorem freshTapeLaw_marginal (β : Nat) (ΞΌ : FiniteDistribution Ξ©) (j : J) : | |
| (freshTapeLaw J β ΞΌ).pushforward (fun t => t j) = tapeLaw β ΞΌ := | |
| FiniteProduct.eval_pushforward (fun _ : J => tapeLaw β ΞΌ) j | |
| theorem freshArrays_expectation_product (β : Nat) (ΞΌ : FiniteDistribution Ξ©) | |
| (eval : Ξ© β H) (f : J β (Fin β β H) β β) : | |
| (freshTapeLaw J β ΞΌ).expectation | |
| (fun t => β j, f j (evaluate β eval (t j))) = | |
| β j, (tapeLaw β ΞΌ).expectation (fun t => f j (evaluate β eval t)) := | |
| FiniteProduct.expectation_product (fun _ : J => tapeLaw β ΞΌ) | |
| (fun j t => f j (evaluate β eval t)) | |
| end FreshArrays | |
| open PointwiseSpaces RecursiveSpaces DescendantSpaces | |
| universe u | |
| variable {branch : Nat β Nat} {n m : Nat} | |
| abbrev RecursiveTape (β : Nat) (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) := | |
| Tape β (RecursiveSampler.Tape F2 repeats p A) | |
| def recursiveEvaluate (β : Nat) (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) (t : RecursiveTape β repeats p A) : | |
| Fin β β space F2 branch n A := | |
| evaluate β (RecursiveSampler.evaluate F2 repeats p A) t | |
| def recursiveTapeLaw (β : Nat) (repeats : Nat β Nat) (p : Path branch n m) | |
| (A : Slots branch n β Type u) [β s, Finite (A s)] : | |
| FiniteDistribution (RecursiveTape β repeats p A) := | |
| tapeLaw β (RecursiveSampler.tapeLaw F2 repeats p A) | |
| theorem recursiveTapeLaw_marginal (β : Nat) (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) [β s, Finite (A s)] | |
| (v : Direction β) : | |
| (recursiveTapeLaw β repeats p A).pushforward (fun t => t v) = | |
| RecursiveSampler.tapeLaw F2 repeats p A := | |
| tapeLaw_marginal β (RecursiveSampler.tapeLaw F2 repeats p A) v | |
| theorem recursiveBucket_marginal (β : Nat) (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) [β s, Finite (A s)] | |
| [Fintype (space F2 branch n A)] (v : Direction β) : | |
| (recursiveTapeLaw β repeats p A).pushforward | |
| (fun t => RecursiveSampler.evaluate F2 repeats p A (t v)) = | |
| RecursiveSampler.law F2 repeats p A := | |
| bucket_marginal β (RecursiveSampler.tapeLaw F2 repeats p A) | |
| (RecursiveSampler.evaluate F2 repeats p A) v | |
| theorem recursiveEvaluate_apply (β : Nat) (repeats : Nat β Nat) | |
| (p : Path branch n m) (A : Slots branch n β Type u) | |
| (t : RecursiveTape β repeats p A) (i : Fin β) (x : Assignment A) : | |
| (recursiveEvaluate β repeats p A t i).val x = | |
| β v : Direction β, v.val i * | |
| (RecursiveSampler.evaluate F2 repeats p A (t v)).val x := | |
| evaluate_apply β (space F2 branch n A) (RecursiveSampler.evaluate F2 repeats p A) t i x | |
| end | |
| end PerfectCompleteness.BucketSampler | |
| end OAI | |