Documentation

CslibFrontier.Computability.Probabilistic.Oracle.Codec

Computational oracle codecs and typed-to-word simulation #

Cslib.OracleCodec (CslibFrontier.Languages.Probabilistic.Oracle.Codec) adapts word-oracle programs WordOracleComp Op α to typed oracles via OracleCodec.adapt and OracleCodec.wordOracle. This module supplies the dual typed-to-word direction and strict IsOraclePPTOn composition rules, with explicit reply caps, reply decoders, and fallback queries (no hidden encoding typeclasses):

  1. Fixed-width bit-string codecs (OracleCodec.bitStrings): n-bit queries with w-bit replies on the single word channel, specializing at w = n to OracleCodec.bitString n.
  2. Typed-to-word lifting (OracleCodec.queryWord, OracleCodec.toWord): translates a typed program ProbOracleComp (fun _ : Q => R) α into WordOracleComp Op α by charging a prefix List.take (replyCap q) of each word reply and applying decodeReply q. Under c.wordOracle, runWith_wordOracle_toWord and run_wordOracle_toWord establish exact joint-state and output bisimulation whenever supported replies fit in replyCap q; adapt_toWord gives the syntactic round-trip when the cap holds for all replies; and isCostBounded_toWord / isQueryBounded_toWord preserve query budgets.
  3. Strict IsOraclePPTOn composition (IsOraclePPTOn.queryWord, IsOraclePPTOn.wordOracle_state, IsOraclePPTOn.run_wordOracle_open): certifies typed-to-word calls across multi-channel Op via IsOraclePPTOn.finite_cases, lifts typed stateful handlers to word handlers via c.wordOracle, and substitutes them into strict oracle-PPT word programs via IsOraclePPTOn.run_interpret_preprocess_open while restricting invariant obligations to valid typed queries.

Main definitions #

Main results #

n-bit queries with w-bit replies on the single word channel Unit: a request carries a query if and only if its payload has n bits.

@[simp]

At equal input and output widths, bitStrings n n is bitString n.

def Cslib.OracleCodec.queryWord {Op Q R : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (q : Q) :

Perform one typed query q : Q on the word channel Op: send c.encodeQuery q, read at most replyCap q bits of the word reply, and decode them with decodeReply q.

def Cslib.OracleCodec.toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (program : ProbOracleComp (fun (x : Q) => R) α) :

Translate a typed oracle program ProbOracleComp (fun _ : Q => R) α into a WordOracleComp Op α program using c.queryWord replyCap decodeReply, forwarding private coin draws unchanged.

@[simp]
theorem Cslib.OracleCodec.toWord_pure {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (a : α) :
c.toWord replyCap decodeReply (pure a) = pure a
@[simp]
theorem Cslib.OracleCodec.toWord_bind {Op Q R α β : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (program : ProbOracleComp (fun (x : Q) => R) α) (next : α → ProbOracleComp (fun (x : Q) => R) β) :
c.toWord replyCap decodeReply (program >>= next) = do let a ← c.toWord replyCap decodeReply program c.toWord replyCap decodeReply (next a)
@[simp]
theorem Cslib.OracleCodec.toWord_map {Op Q R α β : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (f : α → β) (program : ProbOracleComp (fun (x : Q) => R) α) :
c.toWord replyCap decodeReply (f <$> program) = f <$> c.toWord replyCap decodeReply program
@[simp]
theorem Cslib.OracleCodec.toWord_sample {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (program : ProbComp α) :
c.toWord replyCap decodeReply (ProbOracleComp.sample program) = ProbOracleComp.sample program
@[simp]
theorem Cslib.OracleCodec.toWord_query {Op Q R : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (q : Q) :
c.toWord replyCap decodeReply (ProbOracleComp.query q) = c.queryWord replyCap decodeReply q
theorem Cslib.OracleCodec.adapt_toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) {replyCap : Q → ℕ} {decodeReply : Q → List Bool → R} (hcap : ∀ (q : Q) (r : R), ((c.encodeReply q) r).length ≤ replyCap q) (hdec : ∀ (q : Q) (r : R), decodeReply q ((c.encodeReply q) r) = r) (program : ProbOracleComp (fun (x : Q) => R) α) :
c.adapt (c.toWord replyCap decodeReply program) = program

Syntactic round-trip (adapt ∘ toWord = id): when every encoded reply fits within replyCap q and decodeReply q left-inverts c.encodeReply q, adapting c.toWord back to the typed interface recovers program identically.

theorem Cslib.OracleCodec.runWith_wordOracle_toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) {State : Type} (oracle : Q → StateT State PMF R) {replyCap : Q → ℕ} {decodeReply : Q → List Bool → R} (hcap : ∀ (q : Q) (s : State) (r : R) (s' : State), (r, s') ∈ (oracle q s).support → ((c.encodeReply q) r).length ≤ replyCap q) (hdec : ∀ (q : Q) (r : R), decodeReply q ((c.encodeReply q) r) = r) (program : ProbOracleComp (fun (x : Q) => R) α) (s : State) :
ProbOracleComp.runWith (c.wordOracle oracle) (c.toWord replyCap decodeReply program) s = ProbOracleComp.runWith oracle program s

Stateful runWith bisimulation: running c.toWord replyCap decodeReply program against c.wordOracle oracle has the exact same joint (α × State) distribution as running program directly against oracle, provided every supported reply of oracle has encoded length at most replyCap q and decodeReply q left-inverts c.encodeReply q.

theorem Cslib.OracleCodec.run_wordOracle_toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) (oracle : Q → ProbComp R) {replyCap : Q → ℕ} {decodeReply : Q → List Bool → R} (hcap : ∀ (q : Q), ∀ r ∈ (oracle q).eval.support, ((c.encodeReply q) r).length ≤ replyCap q) (hdec : ∀ (q : Q) (r : R), decodeReply q ((c.encodeReply q) r) = r) (program : ProbOracleComp (fun (x : Q) => R) α) :
(ProbOracleComp.run (c.toWord replyCap decodeReply program) (c.wordOracle oracle)).eval = (program.run oracle).eval

Stateless ProbComp bisimulation: evaluating (c.toWord replyCap decodeReply program).run (c.wordOracle oracle) matches program.run oracle whenever every supported reply of oracle fits in replyCap q.

theorem Cslib.OracleCodec.isCostBounded_toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) {cost : Q → ℕ} {wordCost : Op × List Bool → ℕ} (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) (hcost : ∀ (q : Q), wordCost (c.encodeQuery q) ≤ cost q) {program : ProbOracleComp (fun (x : Q) => R) α} {n : ℕ} (h : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) cost) program n) :
OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) wordCost) (c.toWord replyCap decodeReply program) n

toWord preserves cost budgets whenever each encoded word request costs at most the typed query's cost.

theorem Cslib.OracleCodec.isQueryBounded_toWord {Op Q R α : Type} (c : OracleCodec Op Q fun (x : Q) => R) (replyCap : Q → ℕ) (decodeReply : Q → List Bool → R) {program : ProbOracleComp (fun (x : Q) => R) α} {n : ℕ} (h : program.IsQueryBounded n) :
ProbOracleComp.IsQueryBounded (c.toWord replyCap decodeReply program) n

toWord preserves external query budgets (IsQueryBounded).

theorem Cslib.Probability.IsOraclePPTOn.queryWord {Op Q R α : Type} [DecidableEq Op] [Finite Op] (c : OracleCodec Op Q fun (x : Q) => R) {input : α ↪ List Bool} {opEncoding : Op ↪ List Bool} {replyEncoding : R ↪ List Bool} {replyCap : α → Q → ℕ} {decodeReply : Q → List Bool → R} {q : α → Q} (henc : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => c.encodeQuery (q a)) input (Turing.MultiTapeTM.encPair opEncoding Turing.MultiTapeTM.encBits)) (hcap : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => replyCap a (q a)) input Turing.MultiTapeTM.encUnary) (hdec : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : α × List Bool) => decodeReply (q p.1) p.2) (Turing.MultiTapeTM.encPair input Turing.MultiTapeTM.encBits) replyEncoding) :
IsOraclePPTOn input replyEncoding fun (a : α) => c.queryWord (replyCap a) decodeReply (q a)

Performing a single typed query c.queryWord over a finite multi-channel word interface Op is strict oracle PPT whenever c.encodeQuery, replyCap, and decodeReply are computable in plain polynomial time.

theorem Cslib.Probability.IsOraclePPTOn.wordOracle_state {Op External Q R Caller State : Type} [DecidableEq External] (c : OracleCodec Op Q fun (x : Q) => R) (defaultQuery : Q) {input : Caller ↪ List Bool} {opEncoding : Op ↪ List Bool} {queryEncoding : Q ↪ List Bool} {replyEncoding : R ↪ List Bool} {stateEncoding : State ↪ List Bool} {typed : Caller → Q → StateT State (WordOracleComp External) R} (hdecode : Turing.MultiTapeTM.ComputableInPolyTime c.decodeQuery (Turing.MultiTapeTM.encPair opEncoding Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encOption queryEncoding)) (hencodeReply : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : Q × R) => (c.encodeReply p.1) p.2) (Turing.MultiTapeTM.encPair queryEncoding replyEncoding) Turing.MultiTapeTM.encBits) (htyped : IsOraclePPTOn (Turing.MultiTapeTM.encPair input (Turing.MultiTapeTM.encPair queryEncoding stateEncoding)) (Turing.MultiTapeTM.encPair replyEncoding stateEncoding) fun (p : Caller × Q × State) => typed p.1 p.2.1 p.2.2) :
IsOraclePPTOn (encHandlerCall input opEncoding stateEncoding) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encBits stateEncoding) fun (x : Caller × (Op × List Bool) × State) => match x with | (caller, request, state) => c.wordOracle (typed caller) request state

Lifting a strict oracle-PPT typed stateful handler typed : Caller → Q → StateT State (WordOracleComp External) R through c.wordOracle produces a strict oracle-PPT word handler on encHandlerCall. The explicit defaultQuery : Q is used only as the dead fallback of Option.getD after testing (c.decodeQuery request).isSome.

theorem Cslib.Probability.IsOraclePPTOn.run_wordOracle_open {Op External Q R α β Caller State : Type} [DecidableEq Op] [DecidableEq External] (c : OracleCodec Op Q fun (x : Q) => R) (defaultQuery : Q) {source : α ↪ List Bool} {input : Caller ↪ List Bool} {output : β ↪ List Bool} {opEncoding : Op ↪ List Bool} {queryEncoding : Q ↪ List Bool} {replyEncoding : R ↪ List Bool} {stateEncoding : State ↪ List Bool} {program : α → WordOracleComp Op β} {typed : Caller → Q → StateT State (WordOracleComp External) R} {prepare : Caller → α} {initial : Caller → State} {resources : Caller → List Bool → ℕ} (hprogram : IsOraclePPTOn source output program) (hprepare : Turing.MultiTapeTM.ComputableInPolyTime prepare input source) (hdecode : Turing.MultiTapeTM.ComputableInPolyTime c.decodeQuery (Turing.MultiTapeTM.encPair opEncoding Turing.MultiTapeTM.encBits) (Turing.MultiTapeTM.encOption queryEncoding)) (hencodeReply : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : Q × R) => (c.encodeReply p.1) p.2) (Turing.MultiTapeTM.encPair queryEncoding replyEncoding) Turing.MultiTapeTM.encBits) (htyped : IsOraclePPTOn (Turing.MultiTapeTM.encPair input (Turing.MultiTapeTM.encPair queryEncoding stateEncoding)) (Turing.MultiTapeTM.encPair replyEncoding stateEncoding) fun (p : Caller × Q × State) => typed p.1 p.2.1 p.2.2) (hinitial : Turing.MultiTapeTM.ComputableInPolyTime initial input stateEncoding) (invariant : Caller → State → Prop) (hinit : ∀ (a : Caller), invariant a (initial a)) (hresources : Turing.MultiTapeTM.ComputableInPolyTime (fun (pair : Caller × List Bool) => resources pair.1 pair.2) (Turing.MultiTapeTM.encPair input Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encUnary) (hpreserve : ∀ (a : Caller) (q : Q) (state : State), invariant a state → ∀ result ∈ OracleComp.support (typed a q state), invariant a result.2 ∧ ((c.encodeReply q) result.1).length ≤ resources a (c.encodeQuery q).2 ∧ (stateEncoding result.2).length ≤ (stateEncoding state).length + resources a (c.encodeQuery q).2) :
IsOraclePPTOn input (Turing.MultiTapeTM.encPair output stateEncoding) fun (a : Caller) => (OracleComp.interpret (OracleComp.sumHandler (fun (n : ℕ) => StateT.lift (ProbOracleComp.sample (ProbComp.unifFin n))) (c.wordOracle (typed a))) (program (prepare a))).run (initial a)

Open stateful substitution through c.wordOracle: certify running an IsOraclePPTOn word program against c.wordOracle (typed a) from initial a, checking invariant preservation and reply/state size bounds only on valid typed queries q : Q (with request = c.encodeQuery q).