Clocked oracle programs with unbounded search #
An OracleComp always halts, so it cannot express unbounded search. A clocked oracle program
ClockedComp spec α is an OracleComp indexed by a fuel bound: run with fuel k, it either
finishes with some a or gives up with none. It is the transformer stack
ReaderT ℕ (OptionT (OracleComp spec)), so pure, bind, do notation and the monad laws come
from the transformers. ClockedComp.query makes an oracle call and ClockedComp.rfind is
unbounded search: with fuel k it tries the first k arguments, each with fuel k.
The partial semantics ClockedComp.eval o P answers queries with a partial handler
o : (q : ι) → Part (spec q) and returns the result of the least fuel for which the run finishes;
it diverges when an oracle answer on the way is undefined or when no fuel suffices. A run with
fuel k is ClockedComp.attempt o P k, the ordinary interpretation OracleComp.interpret of
the fuel-k program in Mathlib's Part monad.
The semantics is compositional for stable programs (ClockedComp.Stable): once a run with some
fuel finishes, every run with more fuel finishes with the same result, and every run with less
fuel is defined and either finishes with that result or runs out. Pure values, queries, bind,
map and rfind preserve stability, and on stable programs eval sends them to Part.some, the
handler, Part bind and map, and Nat.rfind.
Main definitions #
Cslib.ClockedComp: oracle programs indexed by fuel.Cslib.ClockedComp.query,Cslib.ClockedComp.rfind: an oracle call and unbounded search.Cslib.ClockedComp.attempt: the run with a given fuel under a partial handler.Cslib.ClockedComp.eval: the partial result.Cslib.ClockedComp.Stable: runs with different fuel agree.
Main results #
Cslib.ClockedComp.mem_eval_iff: a stable program returnsaiff some run finishes witha.Cslib.ClockedComp.eval_pure,.eval_bind,.eval_map,.eval_query,.eval_rfind: the semantics of the program constructors.Cslib.ClockedComp.Stable.pure,.bind,.map,.query,.rfind: they are stable.
Oracle programs indexed by a fuel bound. Run with fuel k, a program is a terminating
OracleComp that returns some a when it finishes and none when it runs out of fuel.
Make one oracle call, whatever the fuel.
The trials i, i + 1, …, i + r - 1 of an unbounded search, each with fuel k.
Unbounded search: the least n for which p n returns true, provided p m returns false
for every m < n. With fuel k it tries p 0, …, p (k - 1), each with fuel k.
The run of P with fuel k, answering each query with the partial handler o.
The partial result of P, answering each query with the partial handler o: the result of
the run with the least fuel that finishes. It diverges if no run finishes, or if a run with less
fuel diverges because the handler is undefined on one of its queries.
Runs of P against the handler o with different fuel agree: once the run with fuel k
finishes with a, the run with any fuel j is defined, and finishes with a unless j < k and
it runs out of fuel.
A finished run of a stable program stays finished with more fuel.
A stable program returns a exactly when one of its runs finishes with a.