With-High-Probability Word-RAM State-Transition Implementations #
This module defines a reusable Word-RAM subroutine certificate
(Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl) for data structures whose
individual operations execute within a deterministic worst-case instruction budget
worstCaseTime : ℕ with probability at least 1 - failureProb (for instance, O(1) worst-case
instructions with probability at least 1 - n_max ^ (-c) in fixed-capacity hash tables; see
Bender, Farach-Colton, J. Kuszmaul, and W. Kuszmaul, SOSA 2024, Sections 2.1 and
5).
Design #
Exact operational coupling via
ExecRandand clockedevalRand:- First,
Cslib.WordRAM.ExecRand.tsum_le_eval_runRand_assembleandCslib.WordRAM.ExecRand.toOuterMeasure_le_evalRand_programprove that for any fault-free structured randomized executionExecRand w c x m(even when rare fallback branches take more thanBinstructions), every execution path(y, n)withn ≤ Balready halts cleanly atRandCfg.halted (y.regs out) yin the clocked flat-machine distributionevalRand w (c.program out) (B + 1) ⟨0, x⟩. - In
HighProbStateTransitionImpl, each stepo : D.Opfrom a coupled distributionν : PMF (CoupledState Seed D.State r_ds)produces a transition kernelμ_step : CoupledState Seed D.State r_ds → PMF (CoupledState Seed D.State r_ds × ℕ)coupled withExecRand w P.code t.data (m_step t)via(μ_step t).map (fun p => (p.1.data, p.2)) = (m_step t).eval, realizingD.step,decode,rep, andModifies (Block.mk base space).footprinton every supported branch while bounding the slow-path probability(ν.bind μ_step).toOuterMeasure {p | worstCaseTime < p.2}byfailureProb(averaged overν, so both static-seed hash tables and per-operation randomized algorithms are covered uniformly).
- First,
Both per-operation (
step_whp) and whole-sequence (seq_whp) worst-case bounds:step_whpandstep_whp_ofFncertify that from any reachable coupled distributionν(after an oblivious prefix of any length), runningP.code.program outRegat deterministic horizonworstCaseTime + 1is fault-free across all horizons and halts withinworstCaseTime + 1instructions in a valid successor state with probability at least1 - failureProb.ExecWhpSteps,steps_whp,seq_whp, andseq_whp_ofFntrack the trajectory recordWhpSeqOutcome(recording the current coupled state, the accumulated transcriptList (Sigma D.Result), andmaxSteps : ℕ, the maximum body instruction count across all operations inops), proving via a union bound thatτ_final.toOuterMeasure {tr | worstCaseTime < tr.maxSteps} ≤ ops.length * failureProband hence every operation inopsruns in at mostworstCaseTimeworst-case body instructions with probability at least1 - ops.length * failureProb.
Basis transport and embeddings:
mapSimulatesandtoStandardlift anyHighProbStateTransitionImplfromBasis.exacttoBasis.standardpreserving exact instruction bounds and failure probabilities.Cslib.DataStructure.WordRAM.StateTransitionImpl.toHighProbembeds any unamortized (potential = 0) deterministicStateTransitionImplwith uniform step boundworstCaseTimeatfailureProb = 0.
Main definitions #
Cslib.DataStructure.WordRAM.Randomized.WhpSeqOutcome: trajectory outcome bundling currentCoupledState, accumulated input-outputtranscript, and maximum per-operation instruction countmaxSteps.Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl: reusable with-high-probability Word-RAM subroutine implementation certificate.Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ofFn: constructor for functional specifications[D.HasStepFn stepFn].Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ExecWhpSteps: operational multi-step trajectory execution relation acrossops : List D.Op.
Main results #
Cslib.WordRAM.ExecRand.tsum_le_eval_runRand_assemble,Cslib.WordRAM.ExecRand.toOuterMeasure_le_evalRand_program,Cslib.WordRAM.ExecRand.one_sub_le_evalRand_program: partial-horizon halting probability bridges fromExecRandto clockedevalRandat horizonB + 1.Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initFresh_exec,initClear_exec,initFresh_program: worst-case randomized initialization bounds.Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.step_whp,step_whp_ofFn: per-operation worst-case halting bounds at horizonworstCaseTime + 1.Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.steps_whp,seq_whp,seq_whp_ofFn,reachable_step_whp_ofFn,poly_seq_failureProb_le: whole-sequence worst-case execution bounds across arbitrary and polynomial-length sequences.
References #
Complementary lower bound for discrete PMF outer measure: if p.toOuterMeasure s ≤ δ, then
1 - δ ≤ p.toOuterMeasure sᶜ.
Partial-horizon assembly lower bound (tsum_le_eval_runRand_assemble).
For any structured execution ExecRand w c x m assembled at pc inside p (even when m has
branches taking more than T steps), the probability mass reaching cfg₀ at step T is bounded
below by the sum over all fast branches z = (y, n) with n ≤ T of continuing from
⟨pc + c.size, y⟩ for the remaining T - n steps.
Partial-horizon flat-program halting lower bound (toOuterMeasure_le_evalRand_program).
For any ExecRand w c x m, every fast branch z = (y, n) with n ≤ B halts at
RandCfg.halted (y.regs out) y in evalRand w (c.program out) (B + 1) ⟨0, x⟩.
Event-level partial-horizon flat-program halting bound (one_sub_le_evalRand_program).
If m satisfies postcondition Q z.1 on every supported branch and exceeds B_hor steps with
probability at most δ, then evalRand w (c.program out) (B_hor + 1) ⟨0, x⟩ halts in a state
satisfying Q with probability at least 1 - δ.
Trajectory outcome across an oblivious operation sequence ops : List D.Op, bundling the
current coupled (seed, state, data) triple, the accumulated input-output transcript, and the
maximum single-operation body instruction count maxSteps observed across all executed steps.
- current : CoupledState Seed D.State r
Current coupled
(seed, state, data)configuration. Accumulated input-output transcript of operations executed so far.
- maxSteps : ℕ
Maximum single-operation executed instruction count across all steps so far.
Initialize a WhpSeqOutcome from a CoupledState with empty transcript and maxSteps = 0.
Append one operation outcome (q, a, n) to tr : WhpSeqOutcome.
Reusable Word-RAM subroutine implementation certificate for a randomized data structure P
realizing a relational specification D at word width w, base address base, runtime parameters
params, and initial abstract state s₀, where every operation executes fault-free within a
deterministic worst-case body instruction budget worstCaseTime : ℕ with probability at least
1 - failureProb.
- Seed : Type
Latent random seed type (
Unitwhen no persistent seed is needed). Reference distribution over latent seeds.
- seedSlack : ENNReal
Marginal density slack factor (
1when the seed distribution is exact). The marginal density slack factor is finite.
- space : ℕ
Contiguous memory footprint length
[base, base + space). - spanTime : ℕ
Worst-case instruction bound for
P.allocSpan. - setupTime : ℕ
Worst-case instruction bound for
P.initSetup. - setupRandCalls : ℕ
Worst-case
rand-call bound forP.initSetup. - worstCaseTime : ℕ
Deterministic worst-case body instruction bound per operation on the high-probability event.
- failureProb : ENNReal
Upper bound on the probability that a single admissible operation exceeds
worstCaseTimeexecuted body instructions. - Ghost : Type
Deterministic oblivious ghost state type (
Unitwhen unused). - ghostInit : self.Ghost
Initial deterministic ghost state at initialization (
s₀). Deterministic ghost-state update on operation
o.Standalone register encoding for argument delivery.
Partial argument-matching predicate for inline callers (refined by
encode).Output decoder reading typed operation observations from final registers.
- bounded {g : self.Ghost} {θ : self.Seed} {s : D.State} {x : WordRAM.Data r_ds} : self.ghostRep g θ s x → WordRAM.Data.Bounded w x
Represented configurations are word-bounded.
- arguments_fit {s : D.State} (o : D.Op) : D.valid s o → ∀ (i : Fin r_ds), P.input i = true → WordRAM.Fits w (self.encode o i)
Standalone encoded arguments fit in
w-bit words on admissible calls. - encode_matches (o : D.Op) (regs : Fin r_ds → ℕ) : self.argMatch o fun (i : Fin r_ds) => if P.input i = true then self.encode o i else regs i
Full standalone argument delivery satisfies
argMatch. - rep_supported {g : self.Ghost} {θ : self.Seed} {s : D.State} {x x' : WordRAM.Data r_ds} : (∀ (i : Fin r_ds), P.input i = false → x'.regs i = x.regs i) → (∀ a ∈ { base := base, length := self.space }.footprint, x'.mem a = x.mem a) → WordRAM.Data.Bounded w x' → self.ghostRep g θ s x → self.ghostRep g θ s x'
ghostRepdepends only on persistent registers (P.input i = false) and[base, base + space). Distinctness of registers used by
zeroFillCoderelative tobaseRegandfrontierReg.Initialization parameter registers are not overwritten by
zeroFillCode.- incCur_eval {x : WordRAM.Data r_ds} : x.regs P.oneReg = 1 → WordRAM.Fits w (x.regs P.curReg + 1) → WordRAM.Op.eval w P.incCur x = some (x.set P.curReg (x.regs P.curReg + 1))
P.incCurincrementsP.curRegby1whenP.oneReg = 1and the sum fits inwbits. - span_exec {x : WordRAM.Data r_ds} : WordRAM.Data.Bounded w x → x.regs P.frontierReg = base → (∀ (j : Fin k_init), x.regs (P.initParams j) = params j) → ∃ (x₁ : WordRAM.Data r_ds), WordRAM.ExecWithin w P.allocSpan x x₁ self.spanTime ∧ x₁.mem = x.mem ∧ x₁.regs P.baseReg = base ∧ x₁.regs P.frontierReg = base + self.space ∧ ∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j
Execution of
P.allocSpan: recordsbaseReg = baseand advancesfrontierReg. - setup_exec {x₁ : WordRAM.Data r_ds} : WordRAM.Data.Bounded w x₁ → x₁.regs P.baseReg = base → x₁.regs P.frontierReg = base + self.space → (∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j) → (∀ a ∈ { base := base, length := self.space }.footprint, x₁.mem a = 0) → ∃ (m₀ : ProbComp (WordRAM.Data r_ds × ℕ)) (ν₀ : PMF (self.Seed × WordRAM.Data r_ds)), WordRAM.ExecRand w P.initSetup x₁ m₀ ∧ OracleComp.IsQueryBounded m₀ self.setupRandCalls ∧ (∀ z ∈ OracleComp.support m₀, z.2 ≤ self.setupTime) ∧ PMF.map Prod.snd ν₀ = (Prod.fst <$> m₀).eval ∧ (∀ (θ : self.Seed), (PMF.map Prod.fst ν₀) θ ≤ self.seedSlack * self.seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + self.space ∧ self.ghostRep self.ghostInit p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := self.space }.footprint x₁.mem p.2.mem
Worst-case bounded randomized execution of
P.initSetuponce[base, base + space)holds zeros, producing a coupled distributionν₀ : PMF (Seed × Data r_ds)withinsetupTimedeterministic worst-case instructions andsetupRandCallsrandcalls. - singleState : Prop
- step_exec (g : self.Ghost) (o : D.Op) (ν : PMF (CoupledState self.Seed D.State r_ds)) : (self.singleState → ∃ (s : D.State), ∀ t ∈ ν.support, t.state = s) → (∀ (θ : self.Seed), (PMF.map CoupledState.seed ν) θ ≤ self.seedSlack * self.seedLaw θ) → (∀ t ∈ ν.support, D.valid t.state o ∧ self.ghostRep g t.seed t.state t.data ∧ self.argMatch o t.data.regs) → ∃ (m_step : CoupledState self.Seed D.State r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_step : CoupledState self.Seed D.State r_ds → PMF (CoupledState self.Seed D.State r_ds × ℕ)), (∀ t ∈ ν.support, WordRAM.ExecRand w P.code t.data (m_step t) ∧ PMF.map (fun (p : CoupledState self.Seed D.State r_ds × ℕ) => (p.1.data, p.2)) (μ_step t) = (m_step t).eval ∧ ∀ p ∈ (μ_step t).support, ∃ (a : D.Result o), D.step t.state o p.1.state a ∧ self.decode o p.1.data.regs = some a ∧ self.ghostRep (self.ghostStep g o) p.1.seed p.1.state p.1.data ∧ WordRAM.Modifies { base := base, length := self.space }.footprint t.data.mem p.1.data.mem) ∧ (∀ (θ' : self.Seed), (PMF.map CoupledState.seed (PMF.map Prod.fst (ν.bind μ_step))) θ' ≤ self.seedSlack * self.seedLaw θ') ∧ (self.singleState → ∃ (s' : D.State), ∀ p ∈ (ν.bind μ_step).support, p.1.state = s') ∧ (ν.bind μ_step).toOuterMeasure {p : CoupledState self.Seed D.State r_ds × ℕ | self.worstCaseTime < p.2} ≤ self.failureProb
Coupled one-step execution of
P.codefor any admissible operationofrom a coupled distributionν : PMF (CoupledState Seed D.State r_ds)with seed marginal bounded byseedSlack * seedLaw: produces a structured executionExecRand w P.code t.data (m_step t)and coupled step-count kernelμ_stepmatching(m_step t).eval, realizingD.step,decode,ghostRep (ghostStep g o), andModifieson every branch, preserving the seed marginal and single-state invariant, and bounding(ν.bind μ_step).toOuterMeasure {p | worstCaseTime < p.2}byfailureProb.
Existentially projected representation invariant ∃ g, C.ghostRep g θ s x.
Deterministic ghost state reached after oblivious operation prefix ops.
Canonical embedding of an unamortized deterministic StateTransitionImpl (potential = 0 and
uniform per-operation step bound worstCaseTime) into HighProbStateTransitionImpl with
failureProb = 0.
Deterministic worst-case body instruction bound for P.initFresh (spanTime + setupTime).
Deterministic worst-case body instruction bound for P.initClear
(initTime + (4 * space + 6)).
Extract next data structure state from a step outcome pair ((seed, data), steps).
Extract next seed from a step outcome pair ((seed, data), steps).
Construct a HighProbStateTransitionImpl certificate with deterministic oblivious ghost state
Ghost for a functional specification [D.HasStepFn stepFn].
Construct a HighProbStateTransitionImpl certificate for a functional specification
[D.HasStepFn stepFn] without auxiliary ghost state (Ghost = Unit).
Single-state specialization of step_exec when [D.HasStepFn stepFn].
Lift a HighProbStateTransitionImpl certificate along any defined-evaluation basis simulation
φ : B.Simulates B'.
Lift an exact-basis HighProbStateTransitionImpl certificate to Basis.standard.
Deliver externally encoded arguments, preserving maintained memory and persistent registers. This mathematical register replacement is not a charged native instruction sequence.
Execute P.initFresh on zeroed [base, base + C.space) within C.initTime deterministic
worst-case instructions and C.setupRandCalls rand calls.
Flat-program corollary for P.initFresh.program out: halts fault-free within C.initTime + 1
instructions on every path.
Execute P.initClear on arbitrary dirty memory within C.initClearTime deterministic
worst-case instructions and C.setupRandCalls rand calls.
Per-operation with-high-probability worst-case bounds (step_whp, step_whp_ofFn) #
Per-operation with-high-probability worst-case halting bound (step_whp).
From any reachable coupled state distribution ν : PMF (CoupledState C.Seed D.State r_ds) at
deterministic ghost state g : C.Ghost, preparing arguments for any admissible operation o and
running P.code.program out is fault-free across all horizons, transitions to a valid coupled
distribution ν_next preserving the seed marginal and ghostRep (C.ghostStep g o), and halts
within deterministic horizon C.worstCaseTime + 1 in evalRand with probability at least
1 - C.failureProb.
Per-operation with-high-probability worst-case bound for functional specifications
(step_whp_ofFn).
Multi-operation whole-sequence worst-case execution (ExecWhpSteps, steps_whp, seq_whp, #
seq_whp_ofFn, reachable_step_whp_ofFn, poly_seq_failureProb_le)
Extract coupled state from an operational step outcome ((coupledState, res), steps).
Extract operation result from an operational step outcome ((coupledState, res), steps).
Operational multi-step trajectory execution relation for C : HighProbStateTransitionImpl.
At each operation o :: ops, from every supported trajectory prefix tr ∈ τ.support, running
P.code on C.prepare o tr.current.data executes via ExecRand (m_op),
matches (μ_op tr.current) in (data, steps) distribution (hence reaches .halted in evalRand
within C.worstCaseTime + 1 steps on every branch with n ≤ C.worstCaseTime), witnesses a valid
transition D.step tr.current.state o q.state a with decode o q.data.regs = some a, rep,
Bounded w, and Modifies, and records (q, a, max tr.maxSteps n) in the trajectory.
- nil {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : WordRAM.SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {C : HighProbStateTransitionImpl P D w base params s₀} {out : Fin r_ds} (τ : PMF (WhpSeqOutcome C.Seed D r_ds)) : C.ExecWhpSteps out [] τ τ
- cons {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : WordRAM.SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {C : HighProbStateTransitionImpl P D w base params s₀} {out : Fin r_ds} {o : D.Op} {ops : List D.Op} {τ τ_final : PMF (WhpSeqOutcome C.Seed D r_ds)} (m_op : CoupledState C.Seed D.State r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_step : CoupledState C.Seed D.State r_ds → PMF ((CoupledState C.Seed D.State r_ds × D.Result o) × ℕ)) (hstep : ∀ t ∈ (PMF.map WhpSeqOutcome.current τ).support, let x_in := C.prepare o t.data; WordRAM.RandFaultFree w (P.code.program out) { pc := 0, data := x_in } ∧ WordRAM.ExecRand w P.code x_in (m_op t) ∧ PMF.map (fun (p : (CoupledState C.Seed D.State r_ds × D.Result o) × ℕ) => ((whpState p).data, p.2)) (μ_step t) = (m_op t).eval ∧ (∀ (y : WordRAM.Data r_ds), (m_op t).eval.toOuterMeasure {z : WordRAM.Data r_ds × ℕ | z.1 = y ∧ z.2 ≤ C.worstCaseTime} ≤ (WordRAM.evalRand w (P.code.program out) (C.worstCaseTime + 1) { pc := 0, data := x_in }) (WordRAM.RandCfg.halted (y.regs out) y)) ∧ ∀ p ∈ (μ_step t).support, D.step t.state o (whpState p).state (whpRes p) ∧ C.decode o (whpState p).data.regs = some (whpRes p) ∧ C.rep (whpState p).seed (whpState p).state (whpState p).data ∧ WordRAM.Data.Bounded w (whpState p).data ∧ WordRAM.Modifies { base := base, length := C.space }.footprint t.data.mem (whpState p).data.mem) (hrest : C.ExecWhpSteps out ops (τ.bind fun (tr : WhpSeqOutcome C.Seed D r_ds) => PMF.map (fun (p : (CoupledState C.Seed D.State r_ds × D.Result o) × ℕ) => tr.appendStep o (whpState p) (whpRes p) p.2) (μ_step tr.current)) τ_final) : C.ExecWhpSteps out (o :: ops) τ τ_final
Whole-sequence trajectory execution and union bound (steps_whp).
Across any admissible sequence ops : List D.Op, starting from trajectory distribution τ whose
current-state marginal satisfies the seed bound and rep, P.code executes all operations in ops
under C.ExecWhpSteps out ops τ τ_final such that the probability of any operation in ops
exceeding C.worstCaseTime executed instructions increases by at most ops.length * C.failureProb.
End-to-end whole-sequence with-high-probability theorem from fresh initialization
(seq_whp).
Starting from zeroed [base, base + C.space), P.initFresh halts within C.initTime deterministic
worst-case instructions, and across any admissible sequence ops : List D.Op, every single
operation in ops executes within C.worstCaseTime body instructions with probability at least
1 - ops.length * C.failureProb.
Deterministic-specification transcript exactness for ExecWhpSteps: when [D.HasStepFn stepFn]
and the initial trajectory distribution has tr.current.state = s and tr.transcript = acc on its
support, every supported final trajectory tr ∈ τ_final.support reaches abstract state
(D.run s ops).1 with exact output transcript acc ++ (D.run s ops).2.
End-to-end whole-sequence with-high-probability theorem for functional specifications
(seq_whp_ofFn).
Across any admissible history ops : List D.Op, every branch produces the exact specification
transcript (D.run s₀ ops).2 and maintains C.rep _ (D.run s₀ ops).1 _, while with probability at
least 1 - ops.length * C.failureProb, every single operation in ops executes within
C.worstCaseTime deterministic worst-case body instructions.
Per-operation w.h.p. bound after an arbitrary-length oblivious prefix
(reachable_step_whp_ofFn).
After executing any admissible oblivious prefix ops (regardless of ops.length), preparing the
next admissible operation o and running P.code.program out halts within C.worstCaseTime + 1
instructions in evalRand with probability at least 1 - C.failureProb.
Polynomial-length sequence helper: when ops.length ≤ max n_max 1 ^ c₀ and
C.failureProb ≤ (max n_max 1 : ℝ≥0∞)⁻¹ ^ (c + c₀), the whole-sequence failure probability
(ops.length : ℝ≥0∞) * C.failureProb is at most (max n_max 1 : ℝ≥0∞)⁻¹ ^ c.