Documentation

CslibFrontier.Languages.Probabilistic.Oracle.Substitution

Oracle substitution preserving private randomness #

ProbOracleComp.simulate handler program replaces the external calls of program with handler, forwarding private sampling unchanged. Both the handler and the resulting reduction remain free-monadic programs. A later OracleComp.interpret supplies the random sampler and any shared oracle state; reductions need only describe their external-oracle simulation.

Main definitions #

Main results #

References #

This API follows the separation of untouched effects from simulated oracles in Devon Tuma, Quang Dao, and collaborators' VCVio, in particular OracleSpec.passthrough and simulateQ (revision 87bc1892fff1982e97cfd8c7303c9d1f2bfdc2f9), in the OracleComp.SimSemantics.Append.Core and OracleComp.SimSemantics.SimulateQ modules. The implementation uses the heterogeneous OracleComp.substitute fold and its composition law.

def Cslib.ProbOracleComp.simulate {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {α : Type w} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (program : ProbOracleComp spec α) :

Replace external oracle calls by programs over another interface, preserving every private sample. Randomness is interpreted only when the resulting program is run.

@[simp]
theorem Cslib.ProbOracleComp.simulate_pure {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {α : Type w} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (a : α) :
simulate handler (pure a) = pure a

Substitution leaves a returned value unchanged.

@[simp]
theorem Cslib.ProbOracleComp.simulate_bind {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {α β : Type w} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (program : ProbOracleComp spec α) (next : α → ProbOracleComp spec β) :
simulate handler (program >>= next) = do let a ← simulate handler program simulate handler (next a)

Substitution preserves ordinary same-universe sequential composition.

@[simp]
theorem Cslib.ProbOracleComp.simulate_map {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {α β : Type w} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (f : α → β) (program : ProbOracleComp spec α) :
simulate handler (f <$> program) = f <$> simulate handler program

Substitution preserves ordinary same-universe deterministic postprocessing.

@[simp]
theorem Cslib.ProbOracleComp.simulate_query {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (q : Query) :
simulate handler (query q) = handler q

An external call is replaced by its handler program.

@[simp]
theorem Cslib.ProbOracleComp.simulate_sample {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {α : Type w} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (program : ProbComp α) :
simulate handler (sample program) = sample program

Substitution forwards private samples without consulting the external handler.

theorem Cslib.ProbOracleComp.interpret_simulate {Query : Type u} {Query' : Type u'} {spec : Query → Type} {spec' : Query' → Type} {m : Type → Type v} [Monad m] [LawfulMonad m] (random : (n : ℕ) → m (Fin (n + 1))) (oracle : (q : Query') → m (spec' q)) (handler : (q : Query) → ProbOracleComp spec' (spec q)) {α : Type} (program : ProbOracleComp spec α) :
OracleComp.interpret (OracleComp.sumHandler random oracle) (simulate handler program) = OracleComp.interpret (OracleComp.sumHandler random fun (q : Query) => OracleComp.interpret (OracleComp.sumHandler random oracle) (handler q)) program

Running a substituted program runs each handler under the same outer interpreter. In particular, a stateful interpreter shares its state across all calls and private samples.

theorem Cslib.ProbOracleComp.simulate_simulate {Query : Type u} {Query' : Type u'} {Query'' : Type u''} {spec : Query → Type} {spec' : Query' → Type} {spec'' : Query'' → Type} (handler : (q : Query) → ProbOracleComp spec' (spec q)) (handler' : (q : Query') → ProbOracleComp spec'' (spec' q)) {α : Type w} (program : ProbOracleComp spec α) :
simulate handler' (simulate handler program) = simulate (fun (q : Query) => simulate handler' (handler q)) program

Two successive substitutions compose at the external handler, preserving private samples.