Composable Randomized Word-RAM State-Transition Implementations #
This file extends the relational Cslib.DataStructure.WordRAM.StateTransitionImpl interface to
randomized data structures and Las Vegas subroutines on the Word-RAM — covering both structures
initialized from a random seed (such as universal hash tables, 2-choice hash tables, and cuckoo
hash tables) and structures whose operations make random choices via Instr.rand (such as treaps,
skip lists, reservoir samplers, or randomized rehashing); see [MU17], Sections 2.1,
2.3, and 2.4.
Core design #
A Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl P D w base params s₀ couples machine
execution with a latent seed type Seed : Type, the relational abstract state D.State, and a
reference distribution seedLaw : PMF Seed up to a bounded density factor seedSlack : ℝ≥0∞:
Seed-coupled representation (
rep θ s x) and potential (potential θ x):- Data structures without a persistent random seed set
Seed := Unit,seedLaw := PMF.pure (), andseedSlack := 1(in particular,Cslib.DataStructure.WordRAM.StateTransitionImpl.toRandomizedembeds every relationalCslib.DataStructure.WordRAM.StateTransitionImpldirectly). - Hash tables that resample their hash family on rare table-full events maintain a joint
distribution whose marginal on
Seedsatisfies(ν.map Prod.fst) θ ≤ seedSlack * seedLaw θ.
- Data structures without a persistent random seed set
Distributional execution (
ExecCodeDist):setup_execandstep_execuseExecCodeDistfromCslibFrontier.Computability.WordRAM.Randomized.Expected, which supports both bounded randomized code (ExecRand) and unbounded almost-surely terminating Las Vegaswhileloops (ExecCodeDist.loop_geometric).
Addition-only
ℝ≥0∞amortized-in-expectation bound:- Every operation
o : D.Opfrom a coupled state distributionν : PMF (CoupledState Seed D.State r_ds)whose support states satisfyD.valid t.state o(and are concentrated on a single abstract state whenC.singleStateholds) produces a transition kernelμ_step : CoupledState Seed D.State r_ds → PMF (CoupledState Seed D.State r_ds)and expected step countT_step : CoupledState Seed D.State r_ds → ℝ≥0∞angelically realizingD.step t.state o q.state aon every branch, preserving single-state support (whenC.singleStateholds) and the seed-marginal bound, and satisfying (forΦ(t) := potential t.seed t.data)∑' t, ν t * (T_step t + ∑' q, μ_step t q * Φ(q)) ≤ ∑' t, ν t * (charge t.state o + Φ(t)). - General relational certificates (
singleState := False, the default, includingCslib.DataStructure.WordRAM.StateTransitionImpl.toRandomized) apply to arbitrary branch-dependent state distributionsν : PMF (CoupledState Seed D.State r_ds), whetherDis deterministic or nondeterministic. - For functional specifications (
[D.HasStepFn f]),StateTransitionImpl.ofFn(singleState := True),step_exec_ofFn,frame_caller_dist_ofFn,code_rename_ofFn,call_rename_ofFn,ExecStepsOfFn,steps_expected_amortized_ofFn, andseq_expected_amortized_ofFnspecialize the interface to a single deterministic abstract states : D.Stateand distributionν : PMF (Seed × Data r_ds)(preventing adaptive correlation betweensand the latent seedθin oblivious-adversary structures).
- Every operation
The sequence theorems charge initialization and subroutine bodies for a fixed operation list.
prepare delivers each operation's arguments by a semantic register replacement; its encoding
and delivery, caller dispatch and a whole-client driver are not charged. Callers requiring native
argument preparation can use call_rename / call_rename_ofFn, whose B_prep explicitly charges
the preparation code. Compiling a standalone body adds the final halt separately via
ExecCodeDist.program_halts.
Main definitions #
Cslib.DataStructure.WordRAM.Randomized.CoupledState: coupled latent seed, abstract specification state, and concrete Word-RAM state for relational randomized subroutine analysis.Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl: reusable randomized Word-RAM subroutine certificate for a relational specificationD : StateTransitionSpec.Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.ofFn: constructor for functional specifications[D.HasStepFn f].Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.ExecSteps,ExecStepsOfFn: multi-operation distributional execution traces acrossops : List D.Op.Cslib.DataStructure.WordRAM.StateTransitionImpl.toRandomized: canonical embedding of any relationalCslib.DataStructure.WordRAM.StateTransitionImplintoCslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.mapSimulates,toStandard: basis transport fromBasis.exacttoBasis.standard.
Main results #
Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.initFresh_exec,initFresh_rename: expected-time initialization on fresh zeroed memory.Cslib.WordRAM.SubroutineCode.zeroFillCode_exec,Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.initClear_exec,initClear_rename: expected-time initialization on arbitrary dirty memory.Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.code_rename,call_rename,code_rename_ofFn,call_rename_ofFn: inline subroutine invocation on caller state spaceData r_callervia register injectionf : Fin r_ds → Fin r_caller.Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.frame_caller,frame_caller_dist,frame_caller_dist_ofFn: preservation ofrep,potential, and the coupled caller distribution across arbitrary deterministic or randomized caller steps that do not modify persistent DS registers (P.input i = false) or[base, base + space).Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl.steps_expected_amortized,seq_expected_amortized,steps_expected_amortized_ofFn,seq_expected_amortized_ofFn: telescope theorems bounding initialization and expected body time across any admissible operation sequenceops : List D.Op.
References #
Coupled latent seed, abstract specification state, and concrete Word-RAM state for relational randomized subroutine analysis.
- seed : Seed
Latent random seed.
- state : State
Abstract specification state.
- data : WordRAM.Data r
Concrete Word-RAM register and memory state.
Instances For
Unified standalone and inline subroutine specification/resource certificate for a randomized
Word-RAM data structure P realizing a relational specification D at word width w, base
address base, runtime parameters params, and initial abstract state s₀.
- Seed : Type
Latent random seed type (use
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 : ENNReal
Expected instruction bound for
P.initSetup. - initPotential : ℕ
Upper bound on initial concrete potential after initialization.
Amortized instruction charge per operation.
- rep : self.Seed → D.State → WordRAM.Data r_ds → Prop
Seed-indexed representation invariant linking
Seed,D.State, andData r_ds. - potential : self.Seed → WordRAM.Data r_ds → ℕ
Seed-indexed nonnegative integer potential.
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 {θ : self.Seed} {s : D.State} {x : WordRAM.Data r_ds} : self.rep θ 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 {θ : 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.rep θ s x → self.rep θ s x'
repdepends 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) → ∃ (ν₀ : PMF (self.Seed × WordRAM.Data r_ds)), WordRAM.ExecCodeDist w P.initSetup x₁ (PMF.map Prod.snd ν₀) self.setupTime ∧ (∀ (θ : self.Seed), (PMF.map Prod.fst ν₀) θ ≤ self.seedSlack * self.seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + self.space ∧ self.rep p.1 s₀ p.2 ∧ self.potential p.1 p.2 ≤ self.initPotential ∧ WordRAM.Modifies { base := base, length := self.space }.footprint x₁.mem p.2.mem
- singleState : Prop
Whether
step_execrequires the pre-state distributionνto be concentrated on a single abstract states : D.State(Falseby default for general relational certificates, allowing branch-dependent state distributions even whenDis deterministic;Truefor single-state functional certificates constructed viaStateTransitionImpl.ofFn, where the oblivious adversary fixes a single abstract statesindependent of the latent seedθand every branch transitions to(D.stepFn s o).1). - step_exec (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.rep t.seed t.state t.data ∧ self.argMatch o t.data.regs) → ∃ (μ_step : CoupledState self.Seed D.State r_ds → PMF (CoupledState self.Seed D.State r_ds)) (T_step : CoupledState self.Seed D.State r_ds → ENNReal), (∀ t ∈ ν.support, WordRAM.ExecCodeDist w P.code t.data (PMF.map CoupledState.data (μ_step t)) (T_step t) ∧ ∀ q ∈ (μ_step t).support, ∃ (a : D.Result o), D.step t.state o q.state a ∧ self.decode o q.data.regs = some a ∧ self.rep q.seed q.state q.data ∧ WordRAM.Modifies { base := base, length := self.space }.footprint t.data.mem q.data.mem) ∧ (∀ (θ' : self.Seed), (PMF.map CoupledState.seed (ν.bind μ_step)) θ' ≤ self.seedSlack * self.seedLaw θ') ∧ (self.singleState → ∃ (s' : D.State), ∀ q ∈ (ν.bind μ_step).support, q.state = s') ∧ ∑' (t : CoupledState self.Seed D.State r_ds), ν t * (T_step t + ∑' (q : CoupledState self.Seed D.State r_ds), (μ_step t) q * ↑(self.potential q.seed q.data)) ≤ ∑' (t : CoupledState self.Seed D.State r_ds), ν t * (↑(self.charge t.state o) + ↑(self.potential t.seed t.data))
Coupled one-step execution of
P.codefor any operationofrom a coupled distributionν : PMF (CoupledState Seed D.State r_ds)(supported on a single abstract state whensingleStateholds) with seed marginal bounded byseedSlack * seedLaw: produces a transition kernelμ_stepand expected step countT_steppreserving single-state support (whensingleStateholds) and the seed-marginal bound, angelically realizingD.step t.state o q.state a, modifying only[base, base + space), and satisfying the addition-onlyℝ≥0∞amortized-in-expectation inequality.
Instances For
Canonical embedding of any relational Cslib.DataStructure.WordRAM.StateTransitionImpl
certificate into Cslib.DataStructure.WordRAM.Randomized.StateTransitionImpl (Seed := Unit,
seedLaw := PMF.pure (), seedSlack := 1).
Instances For
Total expected instruction bound for P.initFresh.
Instances For
Construct a randomized StateTransitionImpl certificate for a functional specification
[D.HasStepFn stepFn].
Instances For
Deterministic one-step execution of P.code when [D.HasStepFn stepFn].
Projection 1: Basis lifting (mapSimulates, toStandard) #
Lift a randomized StateTransitionImpl certificate along any defined-evaluation basis
simulation.
Instances For
Lift an exact-basis randomized StateTransitionImpl certificate to Basis.standard.
Instances For
Projection 2: Fresh initialization and register relocation (initFresh_exec, #
Execute P.initFresh on zeroed [base, base + C.space) in C.initTime expected
instructions.
Relocated fresh initialization along any injective register embedding f.
Projection 3: Generic O(space) dirty-memory initialization (zeroFillCode_exec, #
Execute P.initClear on arbitrary dirty memory in
C.initTime + (4 * C.space + 6 : ℕ) expected instructions.
Relocated O(space) dirty-memory initialization along any injective register embedding f.
Projection 4: Caller-to-DS bidirectional framing (frame_caller, frame_caller_dist, #
Any caller state transition that preserves (x'.comap f).Bounded w, leaves persistent DS
registers (P.input i = false) unchanged, and writes only to a set F disjoint from
[base, base + C.space) preserves both C.rep θ s (x'.comap f) and
C.potential θ (x'.comap f).
Coupled caller distribution on CoupledState C.Seed D.State r_caller after a caller transition
kernel μ_caller that does not resample the DS seed or change the abstract DS state.
Instances For
Distributional caller framing: any deterministic or randomized caller transition kernel
μ_caller (including caller steps that execute Instr.rand) that preserves
(x'.comap f).Bounded w, leaves persistent DS registers (P.input i = false) unchanged, and
writes only to a set F disjoint from [base, base + C.space) preserves the coupled seed
marginal bound, C.rep, and expected potential under C.frameStateDist ν μ_caller.
Coupled caller distribution after a caller transition kernel μ_caller that does not resample
the DS seed θ.
Instances For
Single-state distributional caller framing: any deterministic or randomized caller transition
kernel μ_caller that preserves (x'.comap f).Bounded w, leaves persistent DS registers
(P.input i = false) unchanged, and writes only to a set F disjoint from [base, base + C.space)
preserves the coupled seed marginal bound, C.rep, and expected potential under
C.frameDist ν μ_caller.
Projection 5: Relocated inline subroutine calls (code_rename, call_rename, #
Execute P.code.rename f inline when arguments already match (t.data.comap f).regs on the
support of a coupled caller distribution ν : PMF (CoupledState C.Seed D.State r_caller).
Execute P.code.rename f inline for a functional specification [D.HasStepFn stepFn] when
arguments already match (p.2.comap f).regs on the support of a coupled caller distribution
ν : PMF (C.Seed × Data r_caller).
Execute .seq prep (P.code.rename f) inline after a (deterministic or randomized) caller
argument-preparation block prep that preserves persistent DS registers and memory in
[base, base + C.space).
Execute .seq prep (P.code.rename f) inline for a functional specification
[D.HasStepFn stepFn] after a caller argument-preparation block prep that preserves persistent
DS registers and memory in [base, base + C.space).
Projection 6: End-to-end expected-amortized sequence telescope (steps_expected_amortized, #
seq_expected_amortized, steps_expected_amortized_ofFn, seq_expected_amortized_ofFn)
Reuse the signature-level program and argument-delivery API with the actual instruction basis. This projection carries code and the calling convention, without a deterministic certificate.
Instances For
Inductive multi-operation distributional execution relation for a randomized subroutine C
over a relational specification D.
C.ExecSteps ops ν ν_final T_ops C_ops witnesses that starting from coupled distribution
ν : PMF (CoupledState C.Seed D.State r_ds), executing each operation o in ops by delivering
arguments via C.toDynamicProgram.prepare o and running P.code under ExecCodeDist produces the
final coupled distribution ν_final, angelically witnesses a valid transition D.step s o s' a and
decoded observation C.decode o q.data.regs = some a at every step, modifies memory only within
[base, base + C.space), incurs total expected operation body cost T_ops, and accumulates total
expected operation charge C_ops.
- 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 : StateTransitionImpl P D w base params s₀} (ν : PMF (CoupledState C.Seed D.State r_ds)) : C.ExecSteps [] ν ν 0 0
- 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 : StateTransitionImpl P D w base params s₀} {o : D.Op} {ops : List D.Op} {ν ν_final : PMF (CoupledState C.Seed D.State r_ds)} {μ_step : CoupledState C.Seed D.State r_ds → PMF (CoupledState C.Seed D.State r_ds)} {T_step : CoupledState C.Seed D.State r_ds → ENNReal} {T_rest C_rest : ENNReal} : (∀ t ∈ ν.support, WordRAM.ExecCodeDist w P.code (C.toDynamicProgram.prepare o t.data) (PMF.map CoupledState.data (μ_step t)) (T_step t) ∧ ∀ q ∈ (μ_step t).support, ∃ (a : D.Result o), D.step t.state o q.state a ∧ C.decode o q.data.regs = some a ∧ C.rep q.seed q.state q.data ∧ WordRAM.Modifies { base := base, length := C.space }.footprint t.data.mem q.data.mem) → C.ExecSteps ops (ν.bind μ_step) ν_final T_rest C_rest → C.ExecSteps (o :: ops) ν ν_final (∑' (t : CoupledState C.Seed D.State r_ds), ν t * T_step t + T_rest) (∑' (t : CoupledState C.Seed D.State r_ds), ν t * ↑(C.charge t.state o) + C_rest)
Instances For
Multi-operation expected-amortized telescope (steps_expected_amortized).
From any coupled state distribution ν : PMF (CoupledState C.Seed D.State r_ds) satisfying the
seed-marginal bound, C.rep t.seed t.state t.data, and demonic admissibility
D.ValidOpSeq t.state ops on ν.support, executing ops : List D.Op produces a final coupled
distribution ν_final, total expected operation step count T_ops : ℝ≥0∞, and total expected
operation charge C_ops : ℝ≥0∞ witnessing C.ExecSteps ops ν ν_final T_ops C_ops and satisfying
the addition-only ℝ≥0∞ telescope inequality
T_ops + ∑' q, ν_final q * Φ(q) ≤ C_ops + ∑' t, ν t * Φ(t).
End-to-end expected-amortized theorem from fresh initialization (seq_expected_amortized).
Starting from zeroed [base, base + C.space), P.initFresh followed by any demonically admissible
operation sequence ops : List D.Op (D.ValidOpSeq s₀ ops) has total expected instruction cost
C.initTime + T_ops bounded by C.initTime + C.initPotential + C_ops.
Inductive multi-operation distributional execution relation for a randomized subroutine C
over a functional specification [D.HasStepFn stepFn].
- 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 : StateTransitionImpl P D w base params s₀} {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] (s : D.State) (ν : PMF (C.Seed × WordRAM.Data r_ds)) : C.ExecStepsOfFn s [] ν ν 0
- 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 : StateTransitionImpl P D w base params s₀} {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] {s : D.State} {o : D.Op} {ops : List D.Op} {ν ν_final : PMF (C.Seed × WordRAM.Data r_ds)} {μ_step : C.Seed × WordRAM.Data r_ds → PMF (C.Seed × WordRAM.Data r_ds)} {T_step : C.Seed × WordRAM.Data r_ds → ENNReal} {T_rest : ENNReal} : (∀ p ∈ ν.support, WordRAM.ExecCodeDist w P.code (C.toDynamicProgram.prepare o p.2) (PMF.map Prod.snd (μ_step p)) (T_step p) ∧ ∀ q ∈ (μ_step p).support, C.decode o q.2.regs = some (D.stepFn s o).2 ∧ C.rep q.1 (D.stepFn s o).1 q.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint p.2.mem q.2.mem) → C.ExecStepsOfFn (D.stepFn s o).1 ops (ν.bind μ_step) ν_final T_rest → C.ExecStepsOfFn s (o :: ops) ν ν_final (∑' (p : C.Seed × WordRAM.Data r_ds), ν p * T_step p + T_rest)
Instances For
Project a relational ExecSteps derivation to ExecStepsOfFn when [D.HasStepFn stepFn]
and the initial coupled distribution is supported on a single abstract state s.
Multi-operation expected-amortized telescope for functional specifications
(steps_expected_amortized_ofFn).
End-to-end expected-amortized theorem from fresh initialization for functional specifications
(seq_expected_amortized_ofFn).