Documentation

CslibFrontier.Computability.Probabilistic.Retry

Strict PPT bounded retries #

Cslib.OracleComp.retry good program fuel runs program at most fuel times and returns the first result satisfying good. It is strict probabilistic polynomial time when program is, good is decided in polynomial time and fuel is computed in unary: the loop is a bounded iteration whose state is the optional result found so far (Cslib.Probability.IsPPTOn.iterateWith_spec), and every reachable state is none or a possible result of one run.

Main definitions #

Main results #

def Cslib.OracleComp.retryStep {ι : Type u} {spec : OracleSpec ι} {α : Type} (good : α → Bool) (program : OracleComp spec α) (o : Option α) :
OracleComp spec (Option α)

One run of the retry loop: keep a result already found, otherwise run program and keep its result when it is good.

theorem Cslib.OracleComp.retryStep_some {ι : Type u} {spec : OracleSpec ι} {α : Type} (good : α → Bool) (program : OracleComp spec α) (a : α) :
retryStep good program (some a) = pure (some a)
theorem Cslib.OracleComp.iterate_retryStep_some {ι : Type u} {spec : OracleSpec ι} {α : Type} (good : α → Bool) (program : OracleComp spec α) (n : ℕ) (a : α) :
iterate n (retryStep good program) (some a) = pure (some a)
theorem Cslib.OracleComp.retry_eq_iterate {ι : Type u} {spec : OracleSpec ι} {α : Type} (good : α → Bool) (program : OracleComp spec α) (fuel : ℕ) :
retry (fun (a : α) => good a = true) program fuel = iterate fuel (retryStep good program) none

The retry loop as an iteration: fuel runs of retryStep from none.

theorem Cslib.Probability.IsPPTOn.retry {α β : Type} {input : α ↪ List Bool} {output : β ↪ List Bool} {program : α → ProbComp β} {good : β → Bool} {fuel : α → ℕ} (hprogram : IsPPTOn input output program) (hgood : Turing.MultiTapeTM.ComputableInPolyTime good output Turing.MultiTapeTM.encBool) (hfuel : Turing.MultiTapeTM.ComputableInPolyTime fuel input Turing.MultiTapeTM.encUnary) :
IsPPTOn input (Turing.MultiTapeTM.encOption output) fun (a : α) => OracleComp.retry (fun (b : β) => good b = true) (program a) (fuel a)

Bounded retries are strict PPT. If program is strict PPT, good is decided in polynomial time and the fuel is computed in unary, then running program at most fuel a times and returning the first good result is strict PPT, with the optional result encoded by encOption.