import OAI.Computability.PerfectCompleteness.Sampling.CutSamplerKeyLocalityLemmas namespace OAI section namespace PerfectCompleteness.LowerCutScalar open RecursiveSpaces DescendantSpaces RecursiveSampler TerminalCalls noncomputable section universe u w variable {branch : Nat β†’ Nat} {n m : Nat} abbrev Values (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) (p : Path branch n (m + 1)) (A : Slots branch n β†’ Type u) := TerminalIndex repeats p β†’ space π•œ branch (m + 1) (p.family A) def reconstruct (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) : {n m : Nat} β†’ (p : Path branch n (m + 1)) β†’ (A : Slots branch n β†’ Type u) β†’ Values π•œ repeats p A β†’ CutTerminalSplit.ExteriorTape π•œ repeats p A β†’ space π•œ branch n A | _, _, .refl _, _, values, _ => values () | n + 1, _, .step i p, A, values, exterior => RecursiveSampler.combine π•œ A i (repeats (n + 1)) (fun j => exterior ⟨.inl j, not_isTerminal_ordinary repeats i p j⟩) (fun h => reconstruct π•œ repeats p (childFamily A i) (fun terminal => values ((h, false), terminal)) (CutSamplerReplayGrouping.subExterior π•œ repeats i p A (h, false) exterior)) (fun h => reconstruct π•œ repeats p (childFamily A i) (fun terminal => values ((h, true), terminal)) (CutSamplerReplayGrouping.subExterior π•œ repeats i p A (h, true) exterior)) @[simp] theorem reconstruct_refl (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) (A : Slots branch (m + 1) β†’ Type u) (values : Values π•œ repeats (.refl (m + 1)) A) (exterior : CutTerminalSplit.ExteriorTape π•œ repeats (.refl (m + 1)) A) : reconstruct π•œ repeats (.refl (m + 1)) A values exterior = values () := rfl theorem reconstruct_step (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) (i : Fin (branch n)) (p : Path branch n (m + 1)) (A : Slots branch (n + 1) β†’ Type u) (values : Values π•œ repeats (.step i p) A) (exterior : CutTerminalSplit.ExteriorTape π•œ repeats (.step i p) A) : reconstruct π•œ repeats (.step i p) A values exterior = RecursiveSampler.combine π•œ A i (repeats (n + 1)) (fun j => exterior ⟨.inl j, not_isTerminal_ordinary repeats i p j⟩) (fun h => reconstruct π•œ repeats p (childFamily A i) (fun terminal => values ((h, false), terminal)) (CutSamplerReplayGrouping.subExterior π•œ repeats i p A (h, false) exterior)) (fun h => reconstruct π•œ repeats p (childFamily A i) (fun terminal => values ((h, true), terminal)) (CutSamplerReplayGrouping.subExterior π•œ repeats i p A (h, true) exterior)) := rfl theorem reconstruct_splitTape (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) (p : Path branch n (m + 1)) : βˆ€ (A : Slots branch n β†’ Type u) (tape : CutSamplerRefinement.Tape π•œ repeats p A), reconstruct π•œ repeats p A (fun terminal => UniformChildSum.recursiveSum (p.family A) ((CutTerminalSplit.splitTape π•œ repeats p A tape).1 terminal)) (CutTerminalSplit.splitTape π•œ repeats p A tape).2 = CutSamplerRefinement.evaluate π•œ repeats p A tape := by induction n generalizing m with | zero => have h := p.height_le omega | succ n ih => cases p with | refl => intro A tape rfl | step i p => intro A tape rw [reconstruct_step, CutSamplerLocality.evaluate_step] apply congrArgβ‚‚ (RecursiveSampler.combine π•œ A i (repeats (n + 1)) (fun j => tape (.inl j))) Β· funext h rw [CutSamplerReplayGrouping.subExterior_splitTape] simp_rw [CutTerminalZero.splitTape_terminal_step] exact ih p (childFamily A i) (CutSamplerLocality.subTape π•œ repeats i p A tape h false) Β· funext h rw [CutSamplerReplayGrouping.subExterior_splitTape] simp_rw [CutTerminalZero.splitTape_terminal_step] exact ih p (childFamily A i) (CutSamplerLocality.subTape π•œ repeats i p A tape h true) theorem reconstruct_join (π•œ : Type w) [Field π•œ] (repeats : Nat β†’ Nat) (p : Path branch n (m + 1)) (A : Slots branch n β†’ Type u) (terminal : CutTerminalSplit.TerminalTape π•œ repeats p A) (exterior : CutTerminalSplit.ExteriorTape π•œ repeats p A) : reconstruct π•œ repeats p A (fun call => UniformChildSum.recursiveSum (p.family A) (terminal call)) exterior = CutSamplerRefinement.evaluate π•œ repeats p A ((CutTerminalSplit.splitTape π•œ repeats p A).symm (terminal, exterior)) := by simpa only [Equiv.apply_symm_apply] using reconstruct_splitTape π•œ repeats p A ((CutTerminalSplit.splitTape π•œ repeats p A).symm (terminal, exterior)) end end PerfectCompleteness.LowerCutScalar end end OAI