Randomized word RAMs #
A randomized word RAM executes a Cslib.WordRAM.Program B r at word size w, interpreting
Instr.rand dst src as drawing a uniform integer in [0, regs src] (ProbComp.unifFin) when
regs src < 2 ^ w (Fits w (regs src)), writing the sample to dst, advancing pc by 1, and
charging one instruction and one rand call. When regs src ≥ 2 ^ w on an unbounded raw state,
Instr.rand faults; on any word-bounded state (Data.Bounded w), regs src < 2 ^ w holds
automatically and Instr.rand preserves Data.Bounded w. Note that rand(0) succeeds without
faulting, writes 0, and still charges one instruction and one rand call (unifBitCost 0 = 0
entropy bits).
Following Cslib.OracleComp, clocked T-step execution runRand is defined as a terminating
program in ProbComp (RandCfg r) (= OracleComp unifSpec (RandCfg r)), and its configuration
distribution evalRand in PMF (RandCfg r) is obtained via the monad morphism ProbComp.eval.
Unlike deterministic Outcome.halt (which carries only the scalar output), the absorbing
randomized configuration RandCfg r records the final Data r alongside the scalar output
(RandCfg.halted v data) so flat-program theorems can assert in-place memory postconditions
directly.
On rand-free programs (Program.IsRandFree), runRand makes zero oracle calls and agrees in
both directions with deterministic Runs/Executes (runRand_eq_pure_halted_iff_of_isRandFree,
exists_data_runRand_eq_pure_halted_iff_executes_of_isRandFree). Conversely, any deterministic
halting run lifts unconditionally to runRand without IsRandFree because a deterministic run
never executes Instr.rand (runRand_eq_pure_halted_of_runs_halt).
Main definitions #
Cslib.WordRAM.RandCfg,Cslib.WordRAM.RandCfg.ofOutcome: absorbing randomized machine configuration (running,halted v data,faulted) and lifting from deterministicOutcome.Cslib.WordRAM.stepRand,Cslib.WordRAM.runRand,Cslib.WordRAM.evalRand: single-step and clockedT-step randomized execution inProbCompandPMF.Cslib.WordRAM.RandFaultFree,Cslib.WordRAM.RandHaltsWithin: zero-fault invariant and worst-case step bound.Cslib.WordRAM.RandCallsBounded,Cslib.WordRAM.unifBitCost,Cslib.WordRAM.RandBitsBounded: worst-caserand-call and entropy-bit budgets viaOracleComp.IsQueryBoundedandOracleComp.IsCostBounded.
Main results #
Cslib.WordRAM.runRand_add: clocked runs compose additively inProbComp.Cslib.WordRAM.runRand_bounded_init: from an input that fitsw, every supported configuration remains word-bounded.Cslib.WordRAM.runRand_eq_pure_halted_of_runs_halt: deterministic halting runs lift unconditionally torunRandwith the halting state'sData r.Cslib.WordRAM.runRand_isQueryBounded_zero_of_isRandFree:rand-free programs issue zero queries.Cslib.WordRAM.runRand_eq_pure_halted_iff_of_isRandFree,Cslib.WordRAM.exists_data_runRand_eq_pure_halted_iff_executes_of_isRandFree: two-way agreement with deterministic semantics onrand-free programs.Cslib.WordRAM.RandCallsBounded.randBitsBounded:Rrandcalls at word sizewuse at mostR * wentropy bits.
References #
Randomized configurations and single step #
Absorbing machine configuration for clocked randomized execution.
Retains the halting Data r alongside the scalar output v so flat-program specifications can
inspect final memory without changing deterministic Outcome.halt.
- running {r : ℕ} (s : State r) : RandCfg r
Active execution at machine state
s. - halted {r : ℕ} (v : ℕ) (data : Data r) : RandCfg r
Halted with output word
vand final machine datadata. - faulted {r : ℕ} : RandCfg r
Faulted on an invalid operation, out-of-range constant/sample, or out-of-bounds
pc.
Instances For
One step of randomized execution at word size w. Halted and faulted configurations are
absorbing (pure, issuing zero queries), and every non-rand instruction delegates to
deterministic step. Left unmarked by @[simp] because unfolding the program lookup and
instruction dispatch at symbolic program counters blows up step-level goals; rewrite via the
instruction-specific stepRand_* lemmas instead.
Instances For
A deterministic step (any non-faulting outcome of WordRAM.step) agrees unconditionally with
stepRand.
A deterministic halt step agrees unconditionally with stepRand, retaining s.data.
Clocked randomized runs and output distribution #
Translation along basis homomorphisms #
Word-bound preservation #
One randomized step preserves RandCfg.Bounded w.
Clocked randomized execution preserves RandCfg.Bounded w.
Every configuration reachable under runRand from an input that fits w holds only w-bit
words.
Agreement with deterministic semantics #
On a rand-free program, stepRand agrees with deterministic WordRAM.step.
Unconditional lifting (no IsRandFree needed): a deterministic Runs followed by halt gives
pure (.halted v t.data) at every fuel T ≥ m + 1.
On a rand-free program, a single step makes zero oracle calls.
On a rand-free program, clocked execution makes zero oracle calls.
Full state-and-memory agreement on IsRandFree programs, matching Executes.
Scalar projection corollary matching Executes on IsRandFree programs.
Worst-case safety, step bounds, and randomness budgets #
Under RandFaultFree, the fault probability vanishes at every horizon T.
Once RandHaltsWithin w p s T holds, increasing the step budget T' ≥ T leaves the ProbComp
computation identically unchanged (and charges zero additional oracle queries).
Increasing fuel preserves the output distribution once RandHaltsWithin holds.
RandHaltsWithin is monotone in the step bound.
Any program whose randomized runs halt within T steps is fault-free at all horizons.
RandCallsBounded is monotone in the call budget R.
Once RandHaltsWithin w p s T holds, running for T' ≥ T steps charges zero additional rand
calls.
Nominal bit cost of a single ProbComp.unifFin n draw: ⌈log₂(n + 1)⌉ (0 bits for
rand(0), w bits for rand(2 ^ w - 1)). Charging ⌈log₂(n + 1)⌉ bits per draw is an
information-theoretic accounting convention, not the number of fair coins an exact rejection
sampler consumes, which has no finite worst-case bound when n + 1 is not a power of two.
Instances For
At word size w, R rand calls cost at most R * w entropy bits.