math / data /lean /OAI /Computability /PerfectCompleteness /Sampling /CutSamplerLocality.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
7.15 kB
import OAI.Computability.PerfectCompleteness.Construction.FactoredFunctionsLemmas
import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerRefinement
namespace OAI
section
namespace PerfectCompleteness.CutSamplerLocality
open scoped BigOperators Classical
open RecursiveSpaces DescendantSpaces RecursiveSampler PointwiseSpaces
open CutSamplerRefinement
noncomputable section
universe u w
variable {branch : Nat β†’ Nat} {n m : Nat}
def View : {n m : Nat} β†’ (p : Path branch n (m + 1)) β†’
(A : Slots branch n β†’ Type u) β†’ (clean : Fin (branch m) β†’ Prop) β†’ Type u
| _, m, .refl _, A, clean =>
(i : {i : Fin (branch m) // Β¬ clean i}) β†’ Assignment (childFamily A i.val)
| _, _, .step i p, A, clean =>
((j : OffPath i) β†’ Assignment (childFamily A j.val)) Γ—
View p (childFamily A i) clean
def view : {n m : Nat} β†’ (p : Path branch n (m + 1)) β†’
(A : Slots branch n β†’ Type u) β†’ (clean : Fin (branch m) β†’ Prop) β†’
Assignment A β†’ View p A clean
| _, _, .refl _, A, _, x => fun i => childRestriction A i.val x
| _, _, .step i p, A, clean, x =>
(fun j => childRestriction A j.val x,
view p (childFamily A i) clean (childRestriction A i x))
def subTape (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat)
(i : Fin (branch n)) (p : Path branch n m)
(A : Slots branch (n + 1) β†’ Type u)
(tape : CutSamplerRefinement.Tape π•œ repeats (.step i p) A)
(h : Fin (repeats (n + 1))) (b : Bool) :
CutSamplerRefinement.Tape π•œ repeats p (childFamily A i) :=
fun j => tape (Sum.inr ((h, b), j))
def ZeroAtClean (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) :
{n m : Nat} β†’ (p : Path branch n (m + 1)) β†’ (A : Slots branch n β†’ Type u) β†’
(clean : Fin (branch m) β†’ Prop) β†’ CutSamplerRefinement.Tape π•œ repeats p A β†’ Prop
| _, _, .refl _, _, clean, tape => βˆ€ i, clean i β†’ tape () i = 0
| _ + 1, _, .step i p, A, clean, tape =>
βˆ€ h b, ZeroAtClean π•œ repeats p (childFamily A i) clean
(subTape π•œ repeats i p A tape h b)
theorem evaluate_refl (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat)
(A : Slots branch (m + 1) β†’ Type u)
(tape : CutSamplerRefinement.Tape π•œ repeats (.refl (m + 1)) A) :
CutSamplerRefinement.evaluate π•œ repeats (.refl (m + 1)) A tape =
UniformChildSum.recursiveSum A (tape ()) := rfl
theorem evaluate_step (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat)
(i : Fin (branch n)) (p : Path branch n m)
(A : Slots branch (n + 1) β†’ Type u)
(tape : CutSamplerRefinement.Tape π•œ repeats (.step i p) A) :
CutSamplerRefinement.evaluate π•œ repeats (.step i p) A tape =
RecursiveSampler.combine π•œ A i (repeats (n + 1))
(fun j => tape (Sum.inl j))
(fun h => CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h false))
(fun h => CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h true)) := rfl
theorem evaluate_eq_of_view_eq (π•œ : Type w) [Field π•œ]
(repeats : Nat β†’ Nat) (p : Path branch n (m + 1)) :
βˆ€ (A : Slots branch n β†’ Type u) (clean : Fin (branch m) β†’ Prop)
(tape : CutSamplerRefinement.Tape π•œ repeats p A),
ZeroAtClean π•œ repeats p A clean tape β†’
βˆ€ x y : Assignment A, view p A clean x = view p A clean y β†’
(CutSamplerRefinement.evaluate π•œ repeats p A tape).val x =
(CutSamplerRefinement.evaluate π•œ repeats p A tape).val y := by
induction n generalizing m with
| zero =>
have h := p.height_le
omega
| succ n ih =>
cases p with
| refl =>
intro A clean tape hzero x y hview
have heval (z : Assignment A) :
(UniformChildSum.recursiveSum (π•œ := π•œ) A (tape ())).val z =
βˆ‘ i : Fin (branch n), (tape () i).val (childRestriction A i z) := by
have hsum := congrFun
(UniformChildSum.childSum_apply (π•œ := π•œ) (childRestriction A)
(fun i => space π•œ branch n (childFamily A i)) (tape ())) z
simp only [Finset.sum_apply, PointwiseSpaces.pullback_apply] at hsum
refine hsum.trans ?_
refine Finset.sum_congr (ΞΉ := Fin (branch n)) ?_ ?_
Β· ext i
simp only [Finset.mem_univ]
Β· intro i _
rfl
rw [evaluate_refl, heval x, heval y]
apply Finset.sum_congr rfl
intro i _
by_cases hi : clean i
Β· rw [hzero i hi]
rfl
· exact congrArg (tape () i).val (congrFun hview ⟨i, hi⟩)
| step i p =>
intro A clean tape hzero x y hview
have hout : βˆ€ j : OffPath i, childRestriction A j.val x = childRestriction A j.val y :=
congrFun (congrArg Prod.fst hview)
have hin : view p (childFamily A i) clean (childRestriction A i x) =
view p (childFamily A i) clean (childRestriction A i y) :=
congrArg Prod.snd hview
rw [evaluate_step]
simp only [RecursiveSampler.combine, RecursiveSampler.combineFunction,
Finset.sum_apply, Pi.add_apply, Pi.mul_apply, PointwiseSpaces.pullback_apply]
change
(βˆ‘ j : OffPath i, (tape (Sum.inl j)).val (childRestriction A j.val x)) +
(βˆ‘ h, (CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h false)).val (childRestriction A i x) *
(CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h true)).val (childRestriction A i x)) =
(βˆ‘ j : OffPath i, (tape (Sum.inl j)).val (childRestriction A j.val y)) +
(βˆ‘ h, (CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h false)).val (childRestriction A i y) *
(CutSamplerRefinement.evaluate π•œ repeats p (childFamily A i)
(subTape π•œ repeats i p A tape h true)).val (childRestriction A i y))
congr 1
Β· exact Finset.sum_congr rfl (fun j _ => congrArg (tape (Sum.inl j)).val (hout j))
Β· apply Finset.sum_congr rfl
intro h _
rw [ih p (childFamily A i) clean (subTape π•œ repeats i p A tape h false)
(hzero h false) _ _ hin,
ih p (childFamily A i) clean (subTape π•œ repeats i p A tape h true)
(hzero h true) _ _ hin]
theorem evaluate_factors (π•œ : Type w) [Field π•œ]
(repeats : Nat β†’ Nat) (p : Path branch n (m + 1))
(A : Slots branch n β†’ Type u) (clean : Fin (branch m) β†’ Prop)
(tape : CutSamplerRefinement.Tape π•œ repeats p A)
(hzero : ZeroAtClean π•œ repeats p A clean tape) :
(CutSamplerRefinement.evaluate π•œ repeats p A tape).val ∈
FactoredFunctions.factoringSpace (view p A clean) :=
evaluate_eq_of_view_eq π•œ repeats p A clean tape hzero
end
end PerfectCompleteness.CutSamplerLocality
end
end OAI