Documentation

CslibFrontier.Languages.Probabilistic.Iteration.Chain

Probabilistic loops as chains of distributions #

A bounded loop OracleComp.iterate count step initial that is run with a probabilistic stateful handler, or evaluated as a closed program, has the law of the count-step chain Nat.iterate (fun dist => dist.bind next) count (PMF.pure start). In this form, two loops can be compared one step at a time with Probability.PMF.RepInv.iterate and Probability.PMF.HiddenCoupling.iterate.

Main results #

theorem Cslib.OracleComp.run_interpret_iterate_pmf {ι : Type u} {spec : OracleSpec ι} {State Hidden : Type v} (handler : (q : ι) → StateT Hidden PMF (spec q)) (count : ℕ) (step : State → OracleComp spec State) (initial : State) (hidden : Hidden) :
(interpret handler (iterate count step initial)).run hidden = (fun (dist : PMF (State × Hidden)) => dist.bind fun (pair : State × Hidden) => (interpret handler (step pair.1)).run pair.2)^[count] (PMF.pure (initial, hidden))

Running a loop with a probabilistic stateful handler gives the count-step chain of distributions on the joint program and handler state.

theorem Cslib.ProbComp.eval_iterate {State : Type} (count : ℕ) (step : State → ProbComp State) (initial : State) :
eval (OracleComp.iterate count step initial) = (fun (dist : PMF State) => dist.bind fun (state : State) => (step state).eval)^[count] (PMF.pure initial)

A closed loop evaluates to the count-step chain of its step laws.

theorem Cslib.ProbComp.eval_iterate_congr {State : Type} {step step' : State → ProbComp State} (h : ∀ (state : State), (step state).eval = (step' state).eval) (count : ℕ) (initial : State) :
eval (OracleComp.iterate count step initial) = eval (OracleComp.iterate count step' initial)

Steps with the same law give loops with the same law.