Documentation

CslibFrontier.DataStructure.WordRAM.Randomized.HighProbability

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 #

  1. Exact operational coupling via ExecRand and clocked evalRand:

    • First, Cslib.WordRAM.ExecRand.tsum_le_eval_runRand_assemble and Cslib.WordRAM.ExecRand.toOuterMeasure_le_evalRand_program prove that for any fault-free structured randomized execution ExecRand w c x m (even when rare fallback branches take more than B instructions), every execution path (y, n) with n ≤ B already halts cleanly at RandCfg.halted (y.regs out) y in the clocked flat-machine distribution evalRand w (c.program out) (B + 1) ⟨0, x⟩.
    • In HighProbStateTransitionImpl, each step o : D.Op from 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 with ExecRand w P.code t.data (m_step t) via (μ_step t).map (fun p => (p.1.data, p.2)) = (m_step t).eval, realizing D.step, decode, rep, and Modifies (Block.mk base space).footprint on every supported branch while bounding the slow-path probability (ν.bind μ_step).toOuterMeasure {p | worstCaseTime < p.2} by failureProb (averaged over ν, so both static-seed hash tables and per-operation randomized algorithms are covered uniformly).
  2. Both per-operation (step_whp) and whole-sequence (seq_whp) worst-case bounds:

    • step_whp and step_whp_ofFn certify that from any reachable coupled distribution ν (after an oblivious prefix of any length), running P.code.program outReg at deterministic horizon worstCaseTime + 1 is fault-free across all horizons and halts within worstCaseTime + 1 instructions in a valid successor state with probability at least 1 - failureProb.
    • ExecWhpSteps, steps_whp, seq_whp, and seq_whp_ofFn track the trajectory record WhpSeqOutcome (recording the current coupled state, the accumulated transcript List (Sigma D.Result), and maxSteps : ℕ, the maximum body instruction count across all operations in ops), proving via a union bound that τ_final.toOuterMeasure {tr | worstCaseTime < tr.maxSteps} ≤ ops.length * failureProb and hence every operation in ops runs in at most worstCaseTime worst-case body instructions with probability at least 1 - ops.length * failureProb.
  3. Basis transport and embeddings:

Main definitions #

Main results #

References #

theorem Cslib.Probability.PMF.one_sub_le_toOuterMeasure_compl {α : Type u_1} (p : PMF α) (s : Set α) {δ : ENNReal} (hδ : p.toOuterMeasure s ≤ δ) :

Complementary lower bound for discrete PMF outer measure: if p.toOuterMeasure s ≤ δ, then 1 - δ ≤ p.toOuterMeasure sᶜ.

theorem Cslib.WordRAM.ExecRand.tsum_le_eval_runRand_assemble {B : Basis} {r w : ℕ} {c : Code B r} {x : Data r} {m : ProbComp (Data r × ℕ)} {p : Program B r} {pc : ℕ} (h : ExecRand w c x m) (hp : p.Contains pc (c.assemble pc)) (T : ℕ) (cfg₀ : RandCfg r) :
(∑' (z : Data r × ℕ), m.eval z * if z.2 ≤ T then (runRand w p (T - z.2) (RandCfg.running { pc := pc + c.size, data := z.1 })).eval cfg₀ else 0) ≤ (runRand w p T (RandCfg.running { pc := pc, data := x })).eval cfg₀

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.

theorem Cslib.WordRAM.ExecRand.toOuterMeasure_le_evalRand_program {B : Basis} {r w : ℕ} {c : Code B r} {x : Data r} {m : ProbComp (Data r × ℕ)} (h : ExecRand w c x m) (out : Fin r) (B_hor : ℕ) (y : Data r) :
m.eval.toOuterMeasure {z : Data r × ℕ | z.1 = y ∧ z.2 ≤ B_hor} ≤ (evalRand w (c.program out) (B_hor + 1) { pc := 0, data := x }) (RandCfg.halted (y.regs out) y)

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⟩.

theorem Cslib.WordRAM.ExecRand.one_sub_le_evalRand_program {B : Basis} {r w : ℕ} {c : Code B r} {x : Data r} {m : ProbComp (Data r × ℕ)} {Q : Data r → Prop} {δ : ENNReal} (h : ExecRand w c x m) (out : Fin r) (B_hor : ℕ) (hQ : ∀ z ∈ m.eval.support, Q z.1) (hfail : m.eval.toOuterMeasure {z : Data r × ℕ | B_hor < z.2} ≤ δ) :
1 - δ ≤ (evalRand w (c.program out) (B_hor + 1) { pc := 0, data := x }).toOuterMeasure {cfg : RandCfg r | ∃ (y : Data r), cfg = RandCfg.halted (y.regs out) y ∧ Q y}

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.

  • transcript : List (Sigma D.Result)

    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.

def Cslib.DataStructure.WordRAM.Randomized.WhpSeqOutcome.appendStep {Seed : Type} {D : StateTransitionSpec} {r : ℕ} (tr : WhpSeqOutcome Seed D r) (o : D.Op) (q : CoupledState Seed D.State r) (a : D.Result o) (n : ℕ) :
WhpSeqOutcome Seed D r

Append one operation outcome (q, a, n) to tr : WhpSeqOutcome.

structure Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : WordRAM.SubroutineCode B r_ds k_init) (D : StateTransitionSpec) (w base : ℕ) (params : Fin k_init → ℕ) (s₀ : D.State) :
Type (max u v z 1)

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.

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.rep {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₀) (θ : C.Seed) (s : D.State) (x : WordRAM.Data r_ds) :

Existentially projected representation invariant ∃ g, C.ghostRep g θ s x.

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ghostRun {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₀) (g : C.Ghost) (ops : List D.Op) :

Deterministic ghost state reached after oblivious operation prefix ops.

noncomputable def Cslib.DataStructure.WordRAM.StateTransitionImpl.toHighProb {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₀) (worstCaseTime : ℕ) (hpot : ∀ (x : WordRAM.Data r_ds), C.potential x = 0) (hcharge : ∀ {s : D.State} {o : D.Op}, D.valid s o → C.charge s o ≤ worstCaseTime) :

Canonical embedding of an unamortized deterministic StateTransitionImpl (potential = 0 and uniform per-operation step bound worstCaseTime) into HighProbStateTransitionImpl with failureProb = 0.

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initTime {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₀) :

Deterministic worst-case body instruction bound for P.initFresh (spanTime + setupTime).

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initClearTime {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₀) :

Deterministic worst-case body instruction bound for P.initClear (initTime + (4 * space + 6)).

@[reducible, inline]

Extract next data structure state from a step outcome pair ((seed, data), steps).

@[reducible, inline]

Extract next seed from a step outcome pair ((seed, data), steps).

@[reducible, inline]
noncomputable abbrev Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ofFnGhost {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} {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] (Ghost : Type) (ghostInit : Ghost) (ghostStep : Ghost → D.Op → Ghost) (Seed : Type) (seedLaw : PMF Seed) (seedSlack : ENNReal := 1) (seedSlack_ne_top : seedSlack ≠ ⊤ := by simp) (space spanTime setupTime setupRandCalls worstCaseTime : ℕ) (failureProb : ENNReal) (ghostRep : Ghost → Seed → D.State → WordRAM.Data r_ds → Prop) (encode : D.Op → Fin r_ds → ℕ) (argMatch : D.Op → (Fin r_ds → ℕ) → Prop) (decode : (o : D.Op) → (Fin r_ds → ℕ) → Option (D.Result o)) (bounded : ∀ {g : Ghost} {θ : Seed} {s : D.State} {x : WordRAM.Data r_ds}, ghostRep g θ s x → WordRAM.Data.Bounded w x) (arguments_fit : ∀ {s : D.State} (o : D.Op), D.valid s o → ∀ (i : Fin r_ds), P.input i = true → WordRAM.Fits w (encode o i)) (encode_matches : ∀ (o : D.Op) (regs : Fin r_ds → ℕ), argMatch o fun (i : Fin r_ds) => if P.input i = true then encode o i else regs i) (rep_supported : ∀ {g : Ghost} {θ : 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 := space }.footprint, x'.mem a = x.mem a) → WordRAM.Data.Bounded w x' → ghostRep g θ s x → ghostRep g θ s x') (clear_nodup : [P.curReg, P.zeroReg, P.oneReg, P.baseReg, P.frontierReg].Nodup) (params_not_clear : ∀ (j : Fin k_init), P.initParams j ∉ [P.curReg, P.zeroReg, P.oneReg]) (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))) (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₁ spanTime ∧ x₁.mem = x.mem ∧ x₁.regs P.baseReg = base ∧ x₁.regs P.frontierReg = base + space ∧ ∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j) (setup_exec : ∀ {x₁ : WordRAM.Data r_ds}, WordRAM.Data.Bounded w x₁ → x₁.regs P.baseReg = base → x₁.regs P.frontierReg = base + space → (∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j) → (∀ a ∈ { base := base, length := space }.footprint, x₁.mem a = 0) → ∃ (m₀ : ProbComp (WordRAM.Data r_ds × ℕ)) (ν₀ : PMF (Seed × WordRAM.Data r_ds)), WordRAM.ExecRand w P.initSetup x₁ m₀ ∧ OracleComp.IsQueryBounded m₀ setupRandCalls ∧ (∀ z ∈ OracleComp.support m₀, z.2 ≤ setupTime) ∧ PMF.map Prod.snd ν₀ = (Prod.fst <$> m₀).eval ∧ (∀ (θ : Seed), (PMF.map Prod.fst ν₀) θ ≤ seedSlack * seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + space ∧ ghostRep ghostInit p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := space }.footprint x₁.mem p.2.mem) (step_exec : ∀ {s : D.State} (g : Ghost) (o : D.Op) (ν : PMF (Seed × WordRAM.Data r_ds)), D.valid s o → (∀ (θ : Seed), (PMF.map Prod.fst ν) θ ≤ seedSlack * seedLaw θ) → (∀ p ∈ ν.support, ghostRep g p.1 s p.2 ∧ argMatch o p.2.regs) → ∃ (m_step : Seed × WordRAM.Data r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_step : Seed × WordRAM.Data r_ds → PMF ((Seed × WordRAM.Data r_ds) × ℕ)), (∀ p ∈ ν.support, WordRAM.ExecRand w P.code p.2 (m_step p) ∧ PMF.map (fun (q : (Seed × WordRAM.Data r_ds) × ℕ) => (stepData q, q.2)) (μ_step p) = (m_step p).eval ∧ ∀ q ∈ (μ_step p).support, decode o (stepData q).regs = some (D.stepFn s o).2 ∧ ghostRep (ghostStep g o) (stepSeed q) (D.stepFn s o).1 (stepData q) ∧ WordRAM.Modifies { base := base, length := space }.footprint p.2.mem (stepData q).mem) ∧ (∀ (θ' : Seed), (PMF.map Prod.fst (PMF.map Prod.fst (ν.bind μ_step))) θ' ≤ seedSlack * seedLaw θ') ∧ (ν.bind μ_step).toOuterMeasure {q : (Seed × WordRAM.Data r_ds) × ℕ | worstCaseTime < q.2} ≤ failureProb) :
HighProbStateTransitionImpl P D w base params s₀

Construct a HighProbStateTransitionImpl certificate with deterministic oblivious ghost state Ghost for a functional specification [D.HasStepFn stepFn].

@[reducible, inline]
noncomputable abbrev Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ofFn {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} {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] (Seed : Type) (seedLaw : PMF Seed) (seedSlack : ENNReal := 1) (seedSlack_ne_top : seedSlack ≠ ⊤ := by simp) (space spanTime setupTime setupRandCalls worstCaseTime : ℕ) (failureProb : ENNReal) (rep : Seed → D.State → WordRAM.Data r_ds → Prop) (encode : D.Op → Fin r_ds → ℕ) (argMatch : D.Op → (Fin r_ds → ℕ) → Prop) (decode : (o : D.Op) → (Fin r_ds → ℕ) → Option (D.Result o)) (bounded : ∀ {θ : Seed} {s : D.State} {x : WordRAM.Data r_ds}, rep θ s x → WordRAM.Data.Bounded w x) (arguments_fit : ∀ {s : D.State} (o : D.Op), D.valid s o → ∀ (i : Fin r_ds), P.input i = true → WordRAM.Fits w (encode o i)) (encode_matches : ∀ (o : D.Op) (regs : Fin r_ds → ℕ), argMatch o fun (i : Fin r_ds) => if P.input i = true then encode o i else regs i) (rep_supported : ∀ {θ : 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 := space }.footprint, x'.mem a = x.mem a) → WordRAM.Data.Bounded w x' → rep θ s x → rep θ s x') (clear_nodup : [P.curReg, P.zeroReg, P.oneReg, P.baseReg, P.frontierReg].Nodup) (params_not_clear : ∀ (j : Fin k_init), P.initParams j ∉ [P.curReg, P.zeroReg, P.oneReg]) (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))) (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₁ spanTime ∧ x₁.mem = x.mem ∧ x₁.regs P.baseReg = base ∧ x₁.regs P.frontierReg = base + space ∧ ∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j) (setup_exec : ∀ {x₁ : WordRAM.Data r_ds}, WordRAM.Data.Bounded w x₁ → x₁.regs P.baseReg = base → x₁.regs P.frontierReg = base + space → (∀ (j : Fin k_init), x₁.regs (P.initParams j) = params j) → (∀ a ∈ { base := base, length := space }.footprint, x₁.mem a = 0) → ∃ (m₀ : ProbComp (WordRAM.Data r_ds × ℕ)) (ν₀ : PMF (Seed × WordRAM.Data r_ds)), WordRAM.ExecRand w P.initSetup x₁ m₀ ∧ OracleComp.IsQueryBounded m₀ setupRandCalls ∧ (∀ z ∈ OracleComp.support m₀, z.2 ≤ setupTime) ∧ PMF.map Prod.snd ν₀ = (Prod.fst <$> m₀).eval ∧ (∀ (θ : Seed), (PMF.map Prod.fst ν₀) θ ≤ seedSlack * seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + space ∧ rep p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := space }.footprint x₁.mem p.2.mem) (step_exec : ∀ {s : D.State} (o : D.Op) (ν : PMF (Seed × WordRAM.Data r_ds)), D.valid s o → (∀ (θ : Seed), (PMF.map Prod.fst ν) θ ≤ seedSlack * seedLaw θ) → (∀ p ∈ ν.support, rep p.1 s p.2 ∧ argMatch o p.2.regs) → ∃ (m_step : Seed × WordRAM.Data r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_step : Seed × WordRAM.Data r_ds → PMF ((Seed × WordRAM.Data r_ds) × ℕ)), (∀ p ∈ ν.support, WordRAM.ExecRand w P.code p.2 (m_step p) ∧ PMF.map (fun (q : (Seed × WordRAM.Data r_ds) × ℕ) => (stepData q, q.2)) (μ_step p) = (m_step p).eval ∧ ∀ q ∈ (μ_step p).support, decode o (stepData q).regs = some (D.stepFn s o).2 ∧ rep (stepSeed q) (D.stepFn s o).1 (stepData q) ∧ WordRAM.Modifies { base := base, length := space }.footprint p.2.mem (stepData q).mem) ∧ (∀ (θ' : Seed), (PMF.map Prod.fst (PMF.map Prod.fst (ν.bind μ_step))) θ' ≤ seedSlack * seedLaw θ') ∧ (ν.bind μ_step).toOuterMeasure {q : (Seed × WordRAM.Data r_ds) × ℕ | worstCaseTime < q.2} ≤ failureProb) :
HighProbStateTransitionImpl P D w base params s₀

Construct a HighProbStateTransitionImpl certificate for a functional specification [D.HasStepFn stepFn] without auxiliary ghost state (Ghost = Unit).

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.step_exec_ofFn {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₀) {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] {s : D.State} (g : C.Ghost) (o : D.Op) (ν : PMF (C.Seed × WordRAM.Data r_ds)) (hv : D.valid s o) (hseed : ∀ (θ : C.Seed), (PMF.map Prod.fst ν) θ ≤ C.seedSlack * C.seedLaw θ) (hsupp : ∀ p ∈ ν.support, C.ghostRep g p.1 s p.2 ∧ C.argMatch o p.2.regs) :
∃ (m_step : C.Seed × WordRAM.Data r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_step : C.Seed × WordRAM.Data r_ds → PMF ((C.Seed × WordRAM.Data r_ds) × ℕ)), (∀ p ∈ ν.support, WordRAM.ExecRand w P.code p.2 (m_step p) ∧ PMF.map (fun (q : (C.Seed × WordRAM.Data r_ds) × ℕ) => (stepData q, q.2)) (μ_step p) = (m_step p).eval ∧ ∀ q ∈ (μ_step p).support, C.decode o (stepData q).regs = some (D.stepFn s o).2 ∧ C.ghostRep (C.ghostStep g o) (stepSeed q) (D.stepFn s o).1 (stepData q) ∧ WordRAM.Modifies { base := base, length := C.space }.footprint p.2.mem (stepData q).mem) ∧ (∀ (θ' : C.Seed), (PMF.map Prod.fst (PMF.map Prod.fst (ν.bind μ_step))) θ' ≤ C.seedSlack * C.seedLaw θ') ∧ (ν.bind μ_step).toOuterMeasure {q : (C.Seed × WordRAM.Data r_ds) × ℕ | C.worstCaseTime < q.2} ≤ C.failureProb

Single-state specialization of step_exec when [D.HasStepFn stepFn].

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.mapSimulates {B 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} (φ : B.Simulates B') (C : HighProbStateTransitionImpl P D w base params s₀) :

Lift a HighProbStateTransitionImpl certificate along any defined-evaluation basis simulation φ : B.Simulates B'.

@[reducible, inline]
abbrev Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.toStandard {r_ds k_init w base : ℕ} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {P : WordRAM.SubroutineCode WordRAM.Basis.exact r_ds k_init} (C : HighProbStateTransitionImpl P D w base params s₀) :

Lift an exact-basis HighProbStateTransitionImpl certificate to Basis.standard.

def Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare {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₀) (o : D.Op) (x : WordRAM.Data r_ds) :

Deliver externally encoded arguments, preserving maintained memory and persistent registers. This mathematical register replacement is not a charged native instruction sequence.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_bounded {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₀) {o : D.Op} {x : WordRAM.Data r_ds} (hx : WordRAM.Data.Bounded w x) (ho : ∀ (i : Fin r_ds), P.input i = true → WordRAM.Fits w (C.encode o i)) :
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_regs_of_not_input {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₀) {i : Fin r_ds} (hi : P.input i = false) (o : D.Op) (x : WordRAM.Data r_ds) :
(C.prepare o x).regs i = x.regs i
@[simp]
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_mem {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₀) (o : D.Op) (x : WordRAM.Data r_ds) :
(C.prepare o x).mem = x.mem
@[simp]
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_regs {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₀) (o : D.Op) (x : WordRAM.Data r_ds) (i : Fin r_ds) :
(C.prepare o x).regs i = if P.input i = true then C.encode o i else x.regs i
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.rep_bounded {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₀) {θ : C.Seed} {s : D.State} {x : WordRAM.Data r_ds} (hr : C.rep θ s x) :
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_ghostRep {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₀) {g : C.Ghost} {θ : C.Seed} {s : D.State} {o : D.Op} {x : WordRAM.Data r_ds} (hr : C.ghostRep g θ s x) (hv : D.valid s o) :
C.ghostRep g θ s (C.prepare o x)
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_rep {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₀) {θ : C.Seed} {s : D.State} {o : D.Op} {x : WordRAM.Data r_ds} (hr : C.rep θ s x) (hv : D.valid s o) :
C.rep θ s (C.prepare o x)
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.prepare_argMatch {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₀) (o : D.Op) (x : WordRAM.Data r_ds) :
C.argMatch o (C.prepare o x).regs
theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initFresh_exec {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₀) {x : WordRAM.Data r_ds} (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) (hz : ∀ a ∈ { base := base, length := C.space }.footprint, x.mem a = 0) :
∃ (m_init : ProbComp (WordRAM.Data r_ds × ℕ)) (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)), WordRAM.ExecRand w P.initFresh x m_init ∧ OracleComp.IsQueryBounded m_init C.setupRandCalls ∧ (∀ z ∈ OracleComp.support m_init, z.2 ≤ C.initTime) ∧ PMF.map Prod.snd ν₀ = (Prod.fst <$> m_init).eval ∧ (∀ (θ : C.Seed), (PMF.map Prod.fst ν₀) θ ≤ C.seedSlack * C.seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + C.space ∧ C.ghostRep C.ghostInit p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint x.mem p.2.mem

Execute P.initFresh on zeroed [base, base + C.space) within C.initTime deterministic worst-case instructions and C.setupRandCalls rand calls.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initFresh_program {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) {x : WordRAM.Data r_ds} (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) (hz : ∀ a ∈ { base := base, length := C.space }.footprint, x.mem a = 0) :
∃ (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)), WordRAM.RandHaltsWithin w (P.initFresh.program out) { pc := 0, data := x } (C.initTime + 1) ∧ WordRAM.RandCallsBounded w (P.initFresh.program out) { pc := 0, data := x } (C.initTime + 1) C.setupRandCalls ∧ WordRAM.evalRand w (P.initFresh.program out) (C.initTime + 1) { pc := 0, data := x } = PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WordRAM.RandCfg.halted (p.2.regs out) p.2) ν₀ ∧ (∀ (θ : C.Seed), (PMF.map Prod.fst ν₀) θ ≤ C.seedSlack * C.seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + C.space ∧ C.ghostRep C.ghostInit p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint x.mem p.2.mem

Flat-program corollary for P.initFresh.program out: halts fault-free within C.initTime + 1 instructions on every path.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.initClear_exec {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₀) {x : WordRAM.Data r_ds} (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) :
∃ (m_clear : ProbComp (WordRAM.Data r_ds × ℕ)) (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)), WordRAM.ExecRand w P.initClear x m_clear ∧ OracleComp.IsQueryBounded m_clear C.setupRandCalls ∧ (∀ z ∈ OracleComp.support m_clear, z.2 ≤ C.initClearTime) ∧ PMF.map Prod.snd ν₀ = (Prod.fst <$> m_clear).eval ∧ (∀ (θ : C.Seed), (PMF.map Prod.fst ν₀) θ ≤ C.seedSlack * C.seedLaw θ) ∧ ∀ p ∈ ν₀.support, p.2.regs P.frontierReg = base + C.space ∧ C.ghostRep C.ghostInit p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint x.mem p.2.mem

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) #

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.step_whp {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₀) {g : C.Ghost} (out : Fin r_ds) (o : D.Op) (ν : PMF (CoupledState C.Seed D.State r_ds)) (hv : ∀ t ∈ ν.support, D.valid t.state o) (hseed : ∀ (θ : C.Seed), (PMF.map CoupledState.seed ν) θ ≤ C.seedSlack * C.seedLaw θ) (hrep : ∀ t ∈ ν.support, C.ghostRep g t.seed t.state t.data) (hsingle : C.singleState → ∃ (s : D.State), ∀ t ∈ ν.support, t.state = s := by intro h; cases h) :
∃ (m_op : CoupledState C.Seed D.State r_ds → ProbComp (WordRAM.Data r_ds × ℕ)) (μ_op : CoupledState C.Seed D.State r_ds → PMF (CoupledState C.Seed D.State r_ds × ℕ)), (∀ t ∈ ν.support, have 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 × ℕ) => (p.1.data, p.2)) (μ_op 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 ∈ (μ_op t).support, ∃ (a : D.Result o), D.step t.state o p.1.state a ∧ C.decode o p.1.data.regs = some a ∧ C.ghostRep (C.ghostStep g o) p.1.seed p.1.state p.1.data ∧ WordRAM.Data.Bounded w p.1.data ∧ WordRAM.Modifies { base := base, length := C.space }.footprint t.data.mem p.1.data.mem) ∧ (∀ (θ' : C.Seed), (PMF.map CoupledState.seed (PMF.map Prod.fst (ν.bind μ_op))) θ' ≤ C.seedSlack * C.seedLaw θ') ∧ (C.singleState → ∃ (s' : D.State), ∀ p ∈ (ν.bind μ_op).support, p.1.state = s') ∧ (ν.bind μ_op).toOuterMeasure {p : CoupledState C.Seed D.State r_ds × ℕ | C.worstCaseTime < p.2} ≤ C.failureProb ∧ 1 - C.failureProb ≤ (ν.bind fun (t : CoupledState C.Seed D.State r_ds) => WordRAM.evalRand w (P.code.program out) (C.worstCaseTime + 1) { pc := 0, data := C.prepare o t.data }).toOuterMeasure {cfg : WordRAM.RandCfg r_ds | ∃ (t : CoupledState C.Seed D.State r_ds) (q : CoupledState C.Seed D.State r_ds) (a : D.Result o), t ∈ ν.support ∧ cfg = WordRAM.RandCfg.halted (q.data.regs out) q.data ∧ D.step t.state o q.state a ∧ C.decode o q.data.regs = some a ∧ C.ghostRep (C.ghostStep g o) q.seed q.state q.data ∧ WordRAM.Data.Bounded w q.data ∧ WordRAM.Modifies { base := base, length := C.space }.footprint t.data.mem q.data.mem}

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.step_whp_ofFn {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₀) {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] {g : C.Ghost} (out : Fin r_ds) {s : D.State} (o : D.Op) (ν : PMF (C.Seed × WordRAM.Data r_ds)) (hv : D.valid s o) (hseed : ∀ (θ : C.Seed), (PMF.map Prod.fst ν) θ ≤ C.seedSlack * C.seedLaw θ) (hrep : ∀ p ∈ ν.support, C.ghostRep g p.1 s p.2) :
1 - C.failureProb ≤ (ν.bind fun (p : C.Seed × WordRAM.Data r_ds) => WordRAM.evalRand w (P.code.program out) (C.worstCaseTime + 1) { pc := 0, data := C.prepare o p.2 }).toOuterMeasure {cfg : WordRAM.RandCfg r_ds | ∃ (p : C.Seed × WordRAM.Data r_ds) (q : C.Seed × WordRAM.Data r_ds), p ∈ ν.support ∧ cfg = WordRAM.RandCfg.halted (q.2.regs out) q.2 ∧ C.decode o q.2.regs = some (D.stepFn s o).2 ∧ C.ghostRep (C.ghostStep g o) q.1 (D.stepFn s o).1 q.2 ∧ WordRAM.Data.Bounded w q.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint p.2.mem q.2.mem}

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)

@[reducible, inline]
abbrev Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.whpState {Seed : Type} {State : Type u} {r_ds : ℕ} {Res : Type v} (p : (CoupledState Seed State r_ds × Res) × ℕ) :
CoupledState Seed State r_ds

Extract coupled state from an operational step outcome ((coupledState, res), steps).

@[reducible, inline]
abbrev Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.whpRes {Seed : Type} {State : Type u} {r_ds : ℕ} {Res : Type v} (p : (CoupledState Seed State r_ds × Res) × ℕ) :
Res

Extract operation result from an operational step outcome ((coupledState, res), steps).

inductive Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ExecWhpSteps {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) :
List D.Op → PMF (WhpSeqOutcome C.Seed D r_ds) → PMF (WhpSeqOutcome C.Seed D r_ds) → Prop

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.steps_whp {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₀) {g : C.Ghost} (out : Fin r_ds) (ops : List D.Op) (τ : PMF (WhpSeqOutcome C.Seed D r_ds)) (hv : ∀ t ∈ (PMF.map WhpSeqOutcome.current τ).support, D.ValidOpSeq t.state ops) (hseed : ∀ (θ : C.Seed), (PMF.map CoupledState.seed (PMF.map WhpSeqOutcome.current τ)) θ ≤ C.seedSlack * C.seedLaw θ) (hrep : ∀ t ∈ (PMF.map WhpSeqOutcome.current τ).support, C.ghostRep g t.seed t.state t.data) (hsingle : C.singleState → ∃ (s : D.State), ∀ t ∈ (PMF.map WhpSeqOutcome.current τ).support, t.state = s := by intro h; cases h) :
∃ (τ_final : PMF (WhpSeqOutcome C.Seed D r_ds)), C.ExecWhpSteps out ops τ τ_final ∧ (∀ (θ : C.Seed), (PMF.map CoupledState.seed (PMF.map WhpSeqOutcome.current τ_final)) θ ≤ C.seedSlack * C.seedLaw θ) ∧ (∀ t ∈ (PMF.map WhpSeqOutcome.current τ_final).support, C.ghostRep (C.ghostRun g ops) t.seed t.state t.data) ∧ τ_final.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | C.worstCaseTime < tr.maxSteps} ≤ τ.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | C.worstCaseTime < tr.maxSteps} + ↑ops.length * C.failureProb

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.seq_whp {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) {x : WordRAM.Data r_ds} (ops : List D.Op) (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) (hz : ∀ a ∈ { base := base, length := C.space }.footprint, x.mem a = 0) (hv : D.ValidOpSeq s₀ ops) :
∃ (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)) (τ_final : PMF (WhpSeqOutcome C.Seed D r_ds)), WordRAM.RandHaltsWithin w (P.initFresh.program out) { pc := 0, data := x } (C.initTime + 1) ∧ WordRAM.evalRand w (P.initFresh.program out) (C.initTime + 1) { pc := 0, data := x } = PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WordRAM.RandCfg.halted (p.2.regs out) p.2) ν₀ ∧ (∀ p ∈ ν₀.support, WordRAM.Data.Bounded w p.2 ∧ p.2.regs P.frontierReg = base + C.space ∧ C.rep p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint x.mem p.2.mem) ∧ C.ExecWhpSteps out ops (PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WhpSeqOutcome.ofCoupled { seed := p.1, state := s₀, data := p.2 }) ν₀) τ_final ∧ (∀ tr ∈ τ_final.support, C.ghostRep (C.ghostRun C.ghostInit ops) tr.current.seed tr.current.state tr.current.data) ∧ (∀ (θ : C.Seed), (PMF.map CoupledState.seed (PMF.map WhpSeqOutcome.current τ_final)) θ ≤ C.seedSlack * C.seedLaw θ) ∧ τ_final.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | C.worstCaseTime < tr.maxSteps} ≤ ↑ops.length * C.failureProb ∧ 1 - ↑ops.length * C.failureProb ≤ τ_final.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | tr.maxSteps ≤ C.worstCaseTime}

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.ExecWhpSteps.transcript_eq_ofFn {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₀} {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] {out : Fin r_ds} {s : D.State} {acc : List (Sigma D.Result)} {ops : List D.Op} {τ τ_final : PMF (WhpSeqOutcome C.Seed D r_ds)} (hex : C.ExecWhpSteps out ops τ τ_final) (hinit : ∀ tr ∈ τ.support, tr.current.state = s ∧ tr.transcript = acc) (tr : WhpSeqOutcome C.Seed D r_ds) :
tr ∈ τ_final.support → tr.current.state = (D.run s ops).1 ∧ tr.transcript = acc ++ (D.run s ops).2

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.seq_whp_ofFn {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₀) {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] (out : Fin r_ds) {x : WordRAM.Data r_ds} (ops : List D.Op) (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) (hz : ∀ a ∈ { base := base, length := C.space }.footprint, x.mem a = 0) (hv : D.ValidHistory s₀ ops) :
∃ (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)) (τ_final : PMF (WhpSeqOutcome C.Seed D r_ds)), WordRAM.RandHaltsWithin w (P.initFresh.program out) { pc := 0, data := x } (C.initTime + 1) ∧ WordRAM.evalRand w (P.initFresh.program out) (C.initTime + 1) { pc := 0, data := x } = PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WordRAM.RandCfg.halted (p.2.regs out) p.2) ν₀ ∧ (∀ p ∈ ν₀.support, WordRAM.Data.Bounded w p.2 ∧ p.2.regs P.frontierReg = base + C.space ∧ C.rep p.1 s₀ p.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint x.mem p.2.mem) ∧ C.ExecWhpSteps out ops (PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WhpSeqOutcome.ofCoupled { seed := p.1, state := s₀, data := p.2 }) ν₀) τ_final ∧ (∀ tr ∈ τ_final.support, tr.current.state = (D.run s₀ ops).1 ∧ tr.transcript = (D.run s₀ ops).2 ∧ C.rep tr.current.seed (D.run s₀ ops).1 tr.current.data) ∧ τ_final.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | C.worstCaseTime < tr.maxSteps} ≤ ↑ops.length * C.failureProb ∧ 1 - ↑ops.length * C.failureProb ≤ τ_final.toOuterMeasure {tr : WhpSeqOutcome C.Seed D r_ds | tr.maxSteps ≤ C.worstCaseTime ∧ tr.transcript = (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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.reachable_step_whp_ofFn {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₀) {stepFn : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn stepFn] (out : Fin r_ds) {x : WordRAM.Data r_ds} (ops : List D.Op) (o : D.Op) (hx : WordRAM.Data.Bounded w x) (hfr : x.regs P.frontierReg = base) (hpar : ∀ (j : Fin k_init), x.regs (P.initParams j) = params j) (hz : ∀ a ∈ { base := base, length := C.space }.footprint, x.mem a = 0) (hv : D.ValidHistory s₀ ops) (hvo : D.valid (D.run s₀ ops).1 o) :
∃ (ν₀ : PMF (C.Seed × WordRAM.Data r_ds)) (τ_pref : PMF (WhpSeqOutcome C.Seed D r_ds)), C.ExecWhpSteps out ops (PMF.map (fun (p : C.Seed × WordRAM.Data r_ds) => WhpSeqOutcome.ofCoupled { seed := p.1, state := s₀, data := p.2 }) ν₀) τ_pref ∧ 1 - C.failureProb ≤ ((PMF.map (fun (tr : WhpSeqOutcome C.Seed D r_ds) => (tr.current.seed, tr.current.data)) τ_pref).bind fun (p : C.Seed × WordRAM.Data r_ds) => WordRAM.evalRand w (P.code.program out) (C.worstCaseTime + 1) { pc := 0, data := C.prepare o p.2 }).toOuterMeasure {cfg : WordRAM.RandCfg r_ds | ∃ (p : C.Seed × WordRAM.Data r_ds) (q : C.Seed × WordRAM.Data r_ds), p ∈ (PMF.map (fun (tr : WhpSeqOutcome C.Seed D r_ds) => (tr.current.seed, tr.current.data)) τ_pref).support ∧ cfg = WordRAM.RandCfg.halted (q.2.regs out) q.2 ∧ C.decode o q.2.regs = some (D.stepFn (D.run s₀ ops).1 o).2 ∧ C.rep q.1 (D.stepFn (D.run s₀ ops).1 o).1 q.2 ∧ WordRAM.Data.Bounded w q.2 ∧ WordRAM.Modifies { base := base, length := C.space }.footprint p.2.mem q.2.mem}

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.

theorem Cslib.DataStructure.WordRAM.Randomized.HighProbStateTransitionImpl.poly_seq_failureProb_le {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₀) {n_max c c₀ : ℕ} {ops : List D.Op} (hlen : ops.length ≤ max n_max 1 ^ c₀) (hfp : C.failureProb ≤ (↑(max n_max 1))⁻¹ ^ (c + c₀)) :
↑ops.length * C.failureProb ≤ (↑(max n_max 1))⁻¹ ^ c

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.