Documentation

CslibFrontier.Computability.Program.Randomized

Randomized structured programs #

The structured control flow of Code can interpret machine operations as probabilistic computations. ExecRand describes successful executions on every path and pairs each resulting data state with its exact instruction count. The operation interpretation returns none when an operation faults and some computation for an operation that always returns a data state. Deterministic successful operations can return pure computations. Sampling costs one instruction when the flat machine implements the sampling operation as a primitive instruction.

Main definitions #

Main results #

The structured semantics and assembly proof generalize those in CslibFrontier.Computability.WordRAM.Randomized.Structured.

inductive Cslib.Program.ExecRand {I : InstructionSet} (evalRand : I.Op → I.Data → Option (ProbComp I.Data)) :
Code I.Op I.Test → I.Data → ProbComp (I.Data × ℕ) → Prop

Exact randomized execution of structured code, with every branch of the computation terminating successfully. Each primitive operation costs one flat instruction.

structure Cslib.Program.RandomizedFlatMachine {I : InstructionSet} (evalRand : I.Op → I.Data → Option (ProbComp I.Data)) (F : FlatMachine I) :
Type (max i (u + 1))

A randomized interpretation of a flat machine. The running configurations use the flat program counter and data. A machine may also have halted or faulted configurations.

def Cslib.Program.RandomizedFlatMachine.run {I : InstructionSet} {evalRand : I.Op → I.Data → Option (ProbComp I.Data)} {F : FlatMachine I} (R : RandomizedFlatMachine evalRand F) (p : List F.Instr) :

Run the flat program for the given instruction budget.

theorem Cslib.Program.RandomizedFlatMachine.run_zero {I : InstructionSet} {evalRand : I.Op → I.Data → Option (ProbComp I.Data)} {F : FlatMachine I} (R : RandomizedFlatMachine evalRand F) (p : List F.Instr) (cfg : R.Config) :
R.run p 0 cfg = pure cfg

A zero budget returns the initial configuration.

theorem Cslib.Program.RandomizedFlatMachine.run_succ {I : InstructionSet} {evalRand : I.Op → I.Data → Option (ProbComp I.Data)} {F : FlatMachine I} (R : RandomizedFlatMachine evalRand F) (p : List F.Instr) (n : ℕ) (cfg : R.Config) :
R.run p (n + 1) cfg = R.step p cfg >>= R.run p n

A positive budget takes one step and runs the remaining budget.

theorem Cslib.Program.ExecRand.runRand_assemble {I : InstructionSet} {evalRand : I.Op → I.Data → Option (ProbComp I.Data)} {F : FlatMachine I} (R : RandomizedFlatMachine evalRand F) {p : List F.Instr} {c : Code I.Op I.Test} {x : I.Data} {m : ProbComp (I.Data × ℕ)} {pc T : ℕ} (h : ExecRand evalRand c x m) (hp : Contains p pc (Code.assemble F c pc)) (hT : ∀ z ∈ OracleComp.support m, z.2 ≤ T) :
R.run p T (R.running pc x) = do let z ← m R.run p (T - z.2) (R.running (pc + c.size) z.1)

Running a contained compiled program agrees with performing the structured computation and then continuing after its block for the remaining budget on each path.