Sum handlers of lifted oracles #
A program with private coins often runs in a state monad whose oracle never changes the state:
both handlers of OracleComp.sumHandler are StateT.lifts, or the coins are lifted and the right
handler answers from the current state and returns it unchanged. The lemmas here pull the state
out of the combined handler, so such a run reduces to a stateless interpretation in one rewrite.
Main results #
Cslib.OracleComp.sumHandler_lift: the sum of lifted handlers is the lift of their sum.Cslib.OracleComp.run_interpret_sumHandler_readOnly: a run with lifted coins and a right handler that only reads the state is the interpretation against the handlers at the initial state.
theorem Cslib.OracleComp.sumHandler_lift {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} {σ : Type v} {m : Type v → Type w} [Monad m] (left : (q : ι₁) → m (spec₁ q)) (right : (q : ι₂) → m (spec₂ q)) :
(sumHandler (fun (q : ι₁) => StateT.lift (left q)) fun (q : ι₂) => StateT.lift (right q)) = fun (q : ι₁ ⊕ ι₂) =>
StateT.lift (sumHandler left right q)
The sum of two lifted handlers is the lift of their sum.
theorem Cslib.OracleComp.run_interpret_sumHandler_readOnly {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} {α σ : Type v} {m : Type v → Type w} [Monad m] [LawfulMonad m] (left : (q : ι₁) → m (spec₁ q)) (right : (q : ι₂) → σ → m (spec₂ q)) (program : OracleComp (spec₁.sum spec₂) α) (s : σ) :
(interpret
(sumHandler (fun (q : ι₁) => StateT.lift (left q)) fun (q : ι₂) (s : σ) =>
(fun (a : spec₂ q) => (a, s)) <$> right q s)
program).run
s = (fun (a : α) => (a, s)) <$> interpret (sumHandler left fun (q : ι₂) => right q s) program
A run with lifted coins whose right handler reads the state without changing it is the interpretation against the handlers at the initial state.