import OAI.Computability.PerfectCompleteness.Foundations.CutTerminalSplit import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerLocality namespace OAI section namespace PerfectCompleteness.CutTerminalZero open RecursiveSpaces DescendantSpaces RecursiveSampler TerminalCalls open scoped Classical noncomputable section universe u w variable {branch : Nat β†’ Nat} {n m : Nat} (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) theorem terminalFactorEquiv_refl (A : Slots branch (m + 1) β†’ Type u) (terminal : TerminalIndex repeats (.refl (m + 1))) (x : CutSamplerRefinement.RefinedSpace π•œ repeats (.refl (m + 1)) A (drawIndex repeats (.refl (m + 1)) terminal)) : CutTerminalSplit.terminalFactorEquiv π•œ repeats (.refl (m + 1)) A terminal x = x := rfl theorem terminalFactorEquiv_step (i : Fin (branch n)) (p : Path branch n (m + 1)) (A : Slots branch (n + 1) β†’ Type u) (call : Fin (repeats (n + 1)) Γ— Bool) (terminal : TerminalIndex repeats p) (x : CutSamplerRefinement.RefinedSpace π•œ repeats p (childFamily A i) (drawIndex repeats p terminal)) : CutTerminalSplit.terminalFactorEquiv π•œ repeats (.step i p) A (call, terminal) x = CutTerminalSplit.terminalFactorEquiv π•œ repeats p (childFamily A i) terminal x := rfl theorem splitTape_terminal_step (i : Fin (branch n)) (p : Path branch n (m + 1)) (A : Slots branch (n + 1) β†’ Type u) (tape : CutSamplerRefinement.Tape π•œ repeats (.step i p) A) (h : Fin (repeats (n + 1))) (b : Bool) (terminal : TerminalIndex repeats p) : (CutTerminalSplit.splitTape π•œ repeats (.step i p) A tape).1 ((h, b), terminal) = (CutTerminalSplit.splitTape π•œ repeats p (childFamily A i) (CutSamplerLocality.subTape π•œ repeats i p A tape h b)).1 terminal := by simp only [CutTerminalSplit.splitTape_terminal_apply] rfl theorem zeroAtClean_iff (p : Path branch n (m + 1)) : βˆ€ (A : Slots branch n β†’ Type u) (clean : Fin (branch m) β†’ Prop) (tape : CutSamplerRefinement.Tape π•œ repeats p A), (βˆ€ terminal i, clean i β†’ (CutTerminalSplit.splitTape π•œ repeats p A tape).1 terminal i = 0) ↔ CutSamplerLocality.ZeroAtClean π•œ repeats p A clean tape := by induction n generalizing m with | zero => have h := p.height_le omega | succ n ih => cases p with | refl => intro A clean tape constructor Β· intro hzero i hi exact hzero () i hi Β· intro hzero terminal i hi cases terminal exact hzero i hi | step i p => intro A clean tape constructor Β· intro hzero h b apply (ih p (childFamily A i) clean (CutSamplerLocality.subTape π•œ repeats i p A tape h b)).mp intro terminal j hj apply Subtype.ext have hread := congrArg (fun f : CutTerminalSplit.TerminalFactor π•œ (.step i p) A => (f j).val) (splitTape_terminal_step π•œ repeats i p A tape h b terminal) exact hread.symm.trans (congrArg Subtype.val (hzero ((h, b), terminal) j hj)) Β· intro hzero terminal j hj rcases terminal with ⟨⟨h, b⟩, terminal⟩ have hsub := (ih p (childFamily A i) clean (CutSamplerLocality.subTape π•œ repeats i p A tape h b)).mpr (hzero h b) apply Subtype.ext have hread := congrArg (fun f : CutTerminalSplit.TerminalFactor π•œ (.step i p) A => (f j).val) (splitTape_terminal_step π•œ repeats i p A tape h b terminal) exact hread.trans (congrArg Subtype.val (hsub terminal j hj)) theorem evaluate_factors_of_split_zero (p : Path branch n (m + 1)) (A : Slots branch n β†’ Type u) (clean : Fin (branch m) β†’ Prop) (tape : CutSamplerRefinement.Tape π•œ repeats p A) (hzero : βˆ€ terminal i, clean i β†’ (CutTerminalSplit.splitTape π•œ repeats p A tape).1 terminal i = 0) : (CutSamplerRefinement.evaluate π•œ repeats p A tape).val ∈ FactoredFunctions.factoringSpace (CutSamplerLocality.view p A clean) := CutSamplerLocality.evaluate_factors π•œ repeats p A clean tape ((zeroAtClean_iff π•œ repeats p A clean tape).mp hzero) end end PerfectCompleteness.CutTerminalZero end end OAI