Documentation

CslibFrontier.Languages.Probabilistic.Clocked.Subst

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 #

Main results #

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).

def Cslib.ClockedComp.substRun {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} (P : ClockedComp spec α) (h : (q : ι) → ClockedComp spec' (spec q)) (k j : ℕ) :
OptionT (OracleComp spec') α

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.

def Cslib.ClockedComp.substFrom {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} (P : ClockedComp spec α) (h : (q : ι) → ClockedComp spec' (spec q)) (j : ℕ) :
ℕ → ℕ → OptionT (OracleComp spec') α

The tries substRun P h i j for i = k, …, k + r - 1, returning the first result.

def Cslib.ClockedComp.subst {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} (P : ClockedComp spec α) (h : (q : ι) → ClockedComp spec' (spec q)) :
ClockedComp spec' α

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.

def Cslib.ClockedComp.Implements {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} (h : (q : ι) → ClockedComp spec' (spec q)) (o : (q : κ) → Part (spec' q)) (o' : (q : ι) → Part (spec q)) :

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 #

theorem Cslib.ClockedComp.Stable.subst {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} {o : (q : κ) → Part (spec' q)} {P : ClockedComp spec α} {h : (q : ι) → ClockedComp spec' (spec q)} (hh : ∀ (q : ι), Stable o (h q)) (hP : Stable (fun (q : ι) => eval o (h q)) P) :
Stable o (P.subst h)

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.

theorem Cslib.ClockedComp.eval_subst {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} {o : (q : κ) → Part (spec' q)} {P : ClockedComp spec α} {h : (q : ι) → ClockedComp spec' (spec q)} (hh : ∀ (q : ι), Stable o (h q)) (hP : Stable (fun (q : ι) => eval o (h q)) P) :
eval o (P.subst h) = eval (fun (q : ι) => eval o (h q)) P

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 #

theorem Cslib.ClockedComp.Implements.eval_subst {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} {o : (q : κ) → Part (spec' q)} {o' : (q : ι) → Part (spec q)} {h : (q : ι) → ClockedComp spec' (spec q)} (hh : Implements h o o') {P : ClockedComp spec α} (hP : Stable o' P) :
eval o (P.subst h) = eval o' P

Run against an implementation, the substituted program computes what the program computes against the implemented handler.

theorem Cslib.ClockedComp.Implements.stable_subst {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {α : Type} {o : (q : κ) → Part (spec' q)} {o' : (q : ι) → Part (spec q)} {h : (q : ι) → ClockedComp spec' (spec q)} (hh : Implements h o o') {P : ClockedComp spec α} (hP : Stable o' P) :
Stable o (P.subst h)
theorem Cslib.ClockedComp.Implements.query {ι : Type u} {spec : OracleSpec ι} (o : (q : ι) → Part (spec q)) :
Implements (fun (q : ι) => ClockedComp.query q) o o

Each handler implements itself by its queries.

theorem Cslib.ClockedComp.Implements.trans {ι : Type u} {κ : Type u'} {spec : OracleSpec ι} {spec' : OracleSpec κ} {o : (q : κ) → Part (spec' q)} {o' : (q : ι) → Part (spec q)} {h : (q : ι) → ClockedComp spec' (spec q)} {ι'' : Type u''} {spec'' : OracleSpec ι''} {o'' : (q : ι'') → Part (spec'' q)} {h' : (q : ι'') → ClockedComp spec (spec'' q)} (hh' : Implements h' o' o'') (hh : Implements h o o') :
Implements (fun (q : ι'') => (h' q).subst h) o o''

Implementations compose by substitution.

theorem Cslib.ClockedComp.Implements.sumHandler {κ : Type u'} {spec' : OracleSpec κ} {o : (q : κ) → Part (spec' q)} {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} {o₁ : (q : ι₁) → Part (spec₁ q)} {o₂ : (q : ι₂) → Part (spec₂ q)} {h₁ : (q : ι₁) → ClockedComp spec' (spec₁ q)} {h₂ : (q : ι₂) → ClockedComp spec' (spec₂ q)} (hh₁ : Implements h₁ o o₁) (hh₂ : Implements h₂ o o₂) :

Implementations of two interfaces over the same interface implement their sum.