Documentation

CslibFrontier.Languages.Probabilistic.Oracle.Norm

Priority-ordered normalization of stateful and stateless oracle runs #

Tags the lemmas of the simp set runWith_norm. Combined with pmf_norm, simp only [runWith_norm, pmf_norm] reduces concrete ProbOracleComp and OracleComp do-blocks to PMF.bind, PMF.pure, and PMF.map in one pass, while stopping cleanly at ProbOracleComp.runWith oracle (adversary n pk) s or OracleComp.evalWith handler (adversary n pk) when adversary is a black-box parameter:

OracleComp.interpret_bind, ProbOracleComp.run_bind, ProbOracleComp.simulate_bind, and StateT.run_bind are deliberately excluded: bottom-up simp would otherwise rewrite inside ((OracleComp.interpret …).run s), (program.run oracle), or (ProbOracleComp.simulate …) before the enclosing priority-1200 run-folding or handler-composition rules match.

The set is priority-ordered and is not claimed to be confluent: when several rules match the same term, the run-folding and handler-composition rules (priority 1200) and the memoryless-oracle and embedded-sampling rules (priority 1100) take precedence over the default-priority syntax-stepping rules.

Main results #

theorem Cslib.ProbOracleComp.eval_interpret_eq_evalWith {Query α : Type} {spec : Query → Type} (oracle : (q : Query) → ProbComp (spec q)) (program : ProbOracleComp spec α) :

Evaluating a ProbOracleComp against a stateless ProbComp oracle is OracleComp.evalWith with ProbComp.unifOracle and the evaluated oracle.

theorem Cslib.ProbOracleComp.eval_run_eq_evalWith {Query α : Type} {spec : Query → Type} (oracle : (q : Query) → ProbComp (spec q)) (program : ProbOracleComp spec α) :
(program.run oracle).eval = OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle fun (q : Query) => (oracle q).eval) program

Evaluating program.run oracle is OracleComp.evalWith with ProbComp.unifOracle and the evaluated oracle.

theorem Cslib.ProbOracleComp.evalWith_run_interpret {Query Query' State α : Type} {spec : Query → Type} {spec' : Query' → Type} (oracle : (q : Query) → PMF (spec q)) (handler : (q : Query') → StateT State (ProbOracleComp spec) (spec' q)) (program : ProbOracleComp spec' α) (s : State) :
OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle oracle) ((OracleComp.interpret (OracleComp.sumHandler (fun (n : ℕ) => StateT.lift (sample (ProbComp.unifFin n))) handler) program).run s) = runWith (fun (q : Query') (state : State) => OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle oracle) ((handler q).run state)) program s

Evaluating a stateful ProbOracleComp handler run under a stateless PMF external oracle is ProbOracleComp.runWith against the evaluated handler.

theorem Cslib.ProbOracleComp.runWith_interpret_sumHandler_eta {Query Query' State α : Type} {spec : Query → Type} {spec' : Query' → Type} (oracle : (q : Query) → StateT State PMF (spec q)) (handler : (q : Query') → ProbOracleComp spec (spec' q)) (program : ProbOracleComp spec' α) (s : State) :
runWith oracle (OracleComp.interpret (OracleComp.sumHandler (fun (n : ℕ) => sample (ProbComp.unifFin n)) handler) program) s = runWith (fun (q : Query') (state : State) => runWith oracle (handler q) state) program s

Eta-expanded form of ProbOracleComp.runWith_interpret_sumHandler supplying the state argument to the inner ProbOracleComp.runWith, so runWith_norm normalizes concrete handler programs even when program is an opaque adversary.

theorem Cslib.ProbOracleComp.runWith_simulate_eta {Query : Type u} {Query' : Type v} {State : Type} {α : Type w} {spec : Query → Type} {spec' : Query' → Type} (oracle : (q : Query) → StateT State PMF (spec q)) (handler : (q : Query') → ProbOracleComp spec (spec' q)) (program : ProbOracleComp spec' α) (s : State) :
runWith oracle (simulate handler program) s = runWith (fun (q : Query') (state : State) => runWith oracle (handler q) state) program s

Eta-expanded form of ProbOracleComp.runWith_simulate supplying the state argument to the inner ProbOracleComp.runWith, so runWith_norm normalizes concrete handler programs even when program is an opaque adversary.

theorem Cslib.ProbOracleComp.evalWith_sumHandler_simulate {Query : Type u} {Query' : Type v} {α : Type w} {spec : Query → Type} {spec' : Query' → Type} (oracle : (q : Query) → PMF (spec q)) (handler : (q : Query') → ProbOracleComp spec (spec' q)) (program : ProbOracleComp spec' α) :

Evaluating ProbOracleComp.simulate handler program under a stateless sum handler evaluates program against the evaluated handler programs while preserving uniform private sampling.

theorem Cslib.ProbOracleComp.evalWith_interpret_sumHandler {Query Query' α : Type} {spec : Query → Type} {spec' : Query' → Type} (oracle : (q : Query) → PMF (spec q)) (handler : (q : Query') → ProbOracleComp spec (spec' q)) (program : ProbOracleComp spec' α) :

Spelled-out OracleComp.interpret counterpart of ProbOracleComp.evalWith_sumHandler_simulate, folding a stateless handler substitution under OracleComp.evalWith while preserving ProbComp.unifOracle on private samples.

theorem Cslib.ProbOracleComp.runWith_pure_state {Query : Type u} {spec : Query → Type} {State : Type s} {α : Type w} (f : (q : Query) → spec q) (program : ProbOracleComp spec α) (s : State) :
runWith (fun (q : Query) (state : State) => PMF.pure (f q, state)) program s = PMF.map (fun (x : α) => (x, s)) (OracleComp.evalWith (OracleComp.sumHandler ProbComp.unifOracle fun (q : Query) => PMF.pure (f q)) program)

Against a deterministic memoryless raw oracle returning (f q, state), ProbOracleComp.runWith evaluates program against fun q => PMF.pure (f q) and leaves s unchanged. Unlike ProbOracleComp.runWith_memoryless, this matches after PMF.pure_map simplifies (PMF.pure (f q)).map (·, state) inside simp only [runWith_norm, pmf_norm].

theorem Cslib.ProbOracleComp.evalWith_sumHandler_sample {Query α : Type} {spec : Query → Type} (random : (n : ℕ) → PMF (Fin (n + 1))) (oracle : (q : Query) → PMF (spec q)) (program : ProbComp α) :
OracleComp.evalWith (OracleComp.sumHandler random oracle) (sample program) = OracleComp.evalWith random program

Evaluating an embedded private sample under a sum handler uses only the sampling handler.

theorem Cslib.ProbOracleComp.evalWith_sumHandler_query {Query : Type} {spec : Query → Type} (random : (n : ℕ) → PMF (Fin (n + 1))) (oracle : (q : Query) → PMF (spec q)) (q : Query) :
OracleComp.evalWith (OracleComp.sumHandler random oracle) (query q) = oracle q

Evaluating a single external query under a sum handler invokes the external handler.

theorem Cslib.ProbOracleComp.evalWith_sumHandler_unifOracle_sample {Query α : Type} {spec : Query → Type} (oracle : (q : Query) → PMF (spec q)) (program : ProbComp α) :

Evaluating an embedded private sample under ProbComp.unifOracle and an external handler gives ProbComp.eval.

theorem Cslib.ProbOracleComp.runWith_liftLeft {Query State α : Type} {spec : Query → Type} (oracle : (q : Query) → StateT State PMF (spec q)) (program : ProbComp α) (s : State) :
runWith oracle (OracleComp.liftLeft program) s = PMF.map (fun (x : α) => (x, s)) program.eval

Running an embedded left (ProbComp) program under ProbOracleComp.runWith evaluates the program and leaves the oracle state unchanged.

theorem Cslib.ProbOracleComp.runWith_liftRight {Query State α : Type} {spec : Query → Type} (oracle : (q : Query) → StateT State PMF (spec q)) (program : OracleComp spec α) (s : State) :
runWith oracle program.liftRight s = OracleComp.runWith oracle program s

Running an embedded right (OracleComp spec) program under ProbOracleComp.runWith runs it directly against oracle via OracleComp.runWith.

theorem Cslib.Probability.PMF.map_id' {α : Type u_1} (p : PMF α) :
PMF.map (fun (x : α) => x) p = p

Eta-expanded form of PMF.map_id, matching p.map (fun x => x) after PMF.map_comp and Function.comp_def unfold (p.map (·, s)).map Prod.fst.