Reductions between oracle interfaces as handlers #
A handler h : (q : ι) → ClockedComp spec' (spec q) answers each query of the interface spec
by a clocked program over another interface spec'. Substituting it into a clocked program P
over spec gives a clocked program P.subst h over spec'. Against a partial handler o for
spec' it computes what P computes against the handler fun q => eval o (h q)
(ClockedComp.eval_subst), and it is stable when P and the handler programs are
(ClockedComp.Stable.subst).
ClockedComp.Implements h o o' says that h computes the partial handler o' from o by stable
programs. Queries implement every handler (Implements.query), substitution composes
implementations (Implements.trans), and implementations of two interfaces combine on their sum
(Implements.sumHandler).
Main definitions #
Cslib.ClockedComp.subst: substitute a handler into a clocked program.Cslib.ClockedComp.Implements: a handler computes one partial handler from another.
Main results #
Cslib.ClockedComp.eval_subst:eval o (P.subst h) = eval (fun q => eval o (h q)) P.Cslib.ClockedComp.Stable.subst: substitution preserves stability.Cslib.ClockedComp.Implements.query,.trans,.sumHandler,.eval_subst.
Implementation notes #
The run of P.subst h with fuel j cannot simply run P and the handler programs with the same
fuel j: a stable program may make more queries as its fuel grows, each needing more fuel from
the handler, so that no single fuel suffices. Instead, the run with fuel j tries P with fuel
0, …, j - 1 in turn, answering its queries by the handler programs run with fuel j
(ClockedComp.substRun), and returns the first result. Each try is the ordinary interpretation
OracleComp.interpret of the fuel-k program in OptionT (OracleComp spec'), so a handler that
runs out of fuel ends the try.
Implements asks for nothing beyond stability: every partial handler is implemented by constant
and diverging programs, so it is a reducibility only together with a restriction on the programs,
such as a computable dialogue over natOracleSpec (Cslib.ClockedComp.dialogue), under which it
is transitive through codes (Nat.RecursiveIn.Code.exists_clockedComp_trans).
The run of P with fuel k, its queries answered by the handler programs run with fuel j.
It runs out of fuel if P or one of the handler programs does.
The tries substRun P h i j for i = k, …, k + r - 1, returning the first result.
Substitute the handler h into P: answer each query q of P by the program h q. With
fuel j it tries P with fuel 0, …, j - 1, each with the handler programs run with fuel j,
and returns the first result.
The handler h implements the partial handler o' for spec against the partial handler
o for spec': each h q is stable against o and computes o' q.
Runs answered by partial runs #
The runs of a substituted program #
Substitution preserves stability: if P is stable against the composed handler and every
handler program is stable against o, then P.subst h is stable against o.
Substitution of a handler. If P is stable against the composed handler and every
handler program is stable against o, then P.subst h computes against o what P computes
when each query q is answered by eval o (h q).
Implementations #
Run against an implementation, the substituted program computes what the program computes against the implemented handler.
Each handler implements itself by its queries.
Implementations compose by substitution.
Implementations of two interfaces over the same interface implement their sum.