Documentation

CslibFrontier.Computability.CellProbe.OfWordRAM

Simulating Word-RAM Programs in the Adaptive Cell-Probe Model #

This file builds the computational simulation bridge (Cslib.CellProbe) from deterministic, finite-tree randomized, and unbounded Las Vegas Word-RAM executions (Cslib.WordRAM) to adaptive deterministic cell-probe trees (ProbeTree; [Mil99], §1.2, pp. 1–2) and internal-coin randomized cell-probe trees (RandProbeTree; coin-fixing reduction after [Yao77]).

On a w-bit Word RAM with r registers and contiguous memory footprint [base, base + S), two model differences require explicit accounting in a formal simulation:

  1. Persistent registers across operations: A cell-probe scheme keeps state between operations solely in Mem cells wCell (Fin cells → Fin (2 ^ wCell)), with no registers surviving across operation boundaries. Given an input-register mask input : Fin r → Bool (such as P.input on WordRAM.SubroutineCode B r k_init), only the persCount input persistent registers with input i = false survive between calls:
    • Standard w-bit layout (standardLayout): Allocates S + persCount input cells of width w (0 extra cells and 0 extra probes when ∀ i, input i = true), reloading persistent registers in persCount input reads and spilling them at halt in persCount input writes (2 * persCount input additive probes per operation).
    • Wide-cell single-spill layout (wideLayout): Packs all persCount input persistent registers in base 2 ^ w into 1 cell of width wideWidth input w := max (persCount input) 1 * w over S + 1 cells, paying 0 extra probes when persCount input = 0 and 2 extra probes (1 read + 1 write) whenever persCount input > 0, independent of r.
  2. Unallocated reads and unbounded Las Vegas loops:
    • Replacing Word-RAM memory outside [base, base + S) by 0 (zeroOutside base S) keeps loads and stores outside [base, base + S) in a pure-Lean intra-operation map at 0 probe cost; when Modifies (Block.mk base S).footprint holds at halt, outside memory returns to 0 at every operation boundary.
    • Writes inside [base, base + S) are buffered in pure Lean during a clocked K-step run and flushed only at halt, so reads + flushedWrites ≤ continuingSteps and cell memory remains untouched if execution is still active at step K. On that > K tail event (probability tending to 0 as K → ∞ whenever expectedTime < ⊤), the simulator reads all S data cells, selects a reachable halting post-state in pure Lean from haltedLim (> 0 by almost-sure halting, hence in the target support), and writes the resulting packed memory (2 * S + regCells extra probes on the tail), preserving 100% zero-error support correctness at finite tree depth while achieving expected probes ≤ T + overhead + η for any η > 0.

While [Mil99], §1.2, p. 2 notes only that cell-probe lower bounds transfer up to a constant factor to unit-cost RAMs of the same word size whose instructions touch a constant number of registers, the zeroOutside footprint framing, multi-register persistentRegCount / wide-cell spill layouts, intra-operation write buffering, and finite-horizon Las Vegas truncation are local library constructions connecting Cslib.WordRAM to Cslib.CellProbe. For data-structure Impl bridges and contrapositive lower-bound transfer corollaries, see CslibFrontier.DataStructure.CellProbe.OfWordRAM.

Main definitions #

Main results #

References #

1. Persistent register accounting #

def Cslib.CellProbe.persRegs {r : ℕ} (input : Fin r → Bool) :

Subset of registers i : Fin r that persist across calls (input i = false).

def Cslib.CellProbe.persCount {r : ℕ} (input : Fin r → Bool) :

Number of persistent registers (input i = false) under calling-convention mask input.

@[simp]
theorem Cslib.CellProbe.mem_persRegs {r : ℕ} {input : Fin r → Bool} {i : Fin r} :
i ∈ persRegs input ↔ input i = false
@[simp]
theorem Cslib.CellProbe.persCount_eq_zero_of_all_input {r : ℕ} {input : Fin r → Bool} (h : ∀ (i : Fin r), input i = true) :
persCount input = 0
theorem Cslib.CellProbe.persCount_le {r : ℕ} (input : Fin r → Bool) :
persCount input ≤ r

Number of persistent registers (P.input i = false) of a WordRAM.SubroutineCode.

@[simp]
def Cslib.CellProbe.persReg {r : ℕ} (input : Fin r → Bool) (k : Fin (persCount input)) :
Fin r

Canonical order-preserving enumeration of persistent registers Fin (persCount input) → Fin r.

theorem Cslib.CellProbe.persReg_input_eq_false {r : ℕ} (input : Fin r → Bool) (k : Fin (persCount input)) :
input (persReg input k) = false
def Cslib.CellProbe.persIdx {r : ℕ} (input : Fin r → Bool) (i : Fin r) (hi : input i = false) :
Fin (persCount input)

Inverse index of a persistent register i : Fin r (input i = false) in Fin (persCount input).

@[simp]
theorem Cslib.CellProbe.persReg_persIdx {r : ℕ} (input : Fin r → Bool) (i : Fin r) (hi : input i = false) :
persReg input (persIdx input i hi) = i
@[simp]
theorem Cslib.CellProbe.persIdx_persReg {r : ℕ} (input : Fin r → Bool) (k : Fin (persCount input)) :
persIdx input (persReg input k) ⋯ = k

2. zeroOutside framing, standard & wide-cell memory packing, and RegLayout #

Replace Word-RAM memory outside [base, base + S) with 0, preserving registers and [base, base + S).

@[simp]
theorem Cslib.CellProbe.zeroOutside_regs {r : ℕ} (base S : ℕ) (x : WordRAM.Data r) :
(zeroOutside base S x).regs = x.regs
theorem Cslib.CellProbe.zeroOutside_mem_of_mem_footprint {r base S a : ℕ} (x : WordRAM.Data r) (ha : a ∈ { base := base, length := S }.footprint) :
(zeroOutside base S x).mem a = x.mem a
theorem Cslib.CellProbe.zeroOutside_mem_of_not_owns {r base S a : ℕ} (x : WordRAM.Data r) (ha : ¬(base ≤ a ∧ a < base + S)) :
(zeroOutside base S x).mem a = 0
def Cslib.CellProbe.packMem {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) (x : WordRAM.Data r) :
Mem (S + persCount input) w

Pack x : Data r ([base, base + S) plus persistent registers) into Mem (S + persCount input) w.

def Cslib.CellProbe.unpackData {r : ℕ} (input : Fin r → Bool) (argRegs : Fin r → ℕ) (base S w : ℕ) (m : Mem (S + persCount input) w) :

Unpack m : Mem (S + persCount input) w with caller-supplied input registers argRegs into Data r (with 0 outside [base, base + S)).

theorem Cslib.CellProbe.unpackData_bounded {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) (m : Mem (S + persCount input) w) :
WordRAM.Data.Bounded w (unpackData input argRegs base S w m)
theorem Cslib.CellProbe.unpackData_packMem_regs {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} {x : WordRAM.Data r} (hx : WordRAM.Data.Bounded w x) (i : Fin r) :
(unpackData input argRegs base S w (packMem input base S w x)).regs i = if input i = true then argRegs i else x.regs i
theorem Cslib.CellProbe.unpackData_packMem_mem {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} {x : WordRAM.Data r} (hx : WordRAM.Data.Bounded w x) (a : ℕ) :
(unpackData input argRegs base S w (packMem input base S w x)).mem a = (zeroOutside base S x).mem a

Wide-cell base-2 ^ w persistent-register codec (wideLayout) #

def Cslib.CellProbe.wideWidth {r : ℕ} (input : Fin r → Bool) (w : ℕ) :

Wide cell bit-width max (persCount input) 1 * w packing all persistent registers into 1 cell while remaining at least w bits wide when persCount input = 0.

Subroutine specialization max (persistentRegCount P) 1 * w of wideWidth.

theorem Cslib.CellProbe.le_wideWidth {r : ℕ} (input : Fin r → Bool) (w : ℕ) :
w ≤ wideWidth input w
theorem Cslib.CellProbe.persCount_mul_le_wideWidth {r : ℕ} (input : Fin r → Bool) (w : ℕ) :
persCount input * w ≤ wideWidth input w
def Cslib.CellProbe.packDigits (k w : ℕ) :
(Fin k → Fin (2 ^ w)) → ℕ

Encode k w-bit words as a single natural number < 2 ^ (k * w) in base 2 ^ w.

theorem Cslib.CellProbe.packDigits_lt (k w : ℕ) (f : Fin k → Fin (2 ^ w)) :
packDigits k w f < 2 ^ (k * w)
def Cslib.CellProbe.unpackDigits (k w val : ℕ) :
Fin k → Fin (2 ^ w)

Decode k w-bit words in base 2 ^ w from a natural number val.

@[simp]
theorem Cslib.CellProbe.unpackDigits_packDigits (k w : ℕ) (f : Fin k → Fin (2 ^ w)) :
unpackDigits k w (packDigits k w f) = f
theorem Cslib.CellProbe.packDigits_eq_zero_of_zero {k w : ℕ} (hk : k = 0) (f : Fin k → Fin (2 ^ w)) :
packDigits k w f = 0
def Cslib.CellProbe.DataCellsBounded (S w wCell : ℕ) (m : Mem (S + 1) wCell) :

Invariant asserting that data cells 0 .. S - 1 of a wide-cell memory hold w-bit values.

def Cslib.CellProbe.packMemWide {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) (x : WordRAM.Data r) :
Mem (S + 1) (wideWidth input w)

Pack x : Data r into Mem (S + 1) (wideWidth input w): cells 0 .. S - 1 hold x.mem (base + j), and cell S holds all persCount input persistent registers in base 2 ^ w.

theorem Cslib.CellProbe.dataCellsBounded_packMemWide {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) (x : WordRAM.Data r) :
DataCellsBounded S w (wideWidth input w) (packMemWide input base S w x)
def Cslib.CellProbe.unpackDataWide {r : ℕ} (input : Fin r → Bool) (argRegs : Fin r → ℕ) (base S w : ℕ) (m : Mem (S + 1) (wideWidth input w)) :

Unpack m : Mem (S + 1) (wideWidth input w) with argRegs into Data r.

theorem Cslib.CellProbe.unpackDataWide_bounded {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) (m : Mem (S + 1) (wideWidth input w)) :
WordRAM.Data.Bounded w (unpackDataWide input argRegs base S w m)
theorem Cslib.CellProbe.unpackDataWide_packMemWide_regs {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} {x : WordRAM.Data r} (hx : WordRAM.Data.Bounded w x) (i : Fin r) :
(unpackDataWide input argRegs base S w (packMemWide input base S w x)).regs i = if input i = true then argRegs i else x.regs i
theorem Cslib.CellProbe.unpackDataWide_packMemWide_mem {r : ℕ} {input : Fin r → Bool} {argRegs : Fin r → ℕ} {base S w : ℕ} {x : WordRAM.Data r} (hx : WordRAM.Data.Bounded w x) (a : ℕ) :
(unpackDataWide input argRegs base S w (packMemWide input base S w x)).mem a = (zeroOutside base S x).mem a

Finite multi-cell read/write helpers and unified RegLayout #

def Cslib.CellProbe.readFin {cells wCell n : ℕ} :
(Fin n → Fin cells) → ProbeTree cells wCell (Fin n → Fin (2 ^ wCell))

Read n cells idx 0, …, idx (n - 1) sequentially in n probes without mutating memory.

@[simp]
theorem Cslib.CellProbe.run_readFin {cells wCell n : ℕ} (idx : Fin n → Fin cells) (m : Mem cells wCell) :
(readFin idx).run m = (fun (j : Fin n) => m (idx j), m)
@[simp]
theorem Cslib.CellProbe.probes_readFin {cells wCell n : ℕ} (idx : Fin n → Fin cells) (m : Mem cells wCell) :
(readFin idx).probes m = n
def Cslib.CellProbe.writeFin {cells wCell n : ℕ} :
(Fin n → Fin cells) → (Fin n → Fin (2 ^ wCell)) → ProbeTree cells wCell PUnit.{1}

Write vals 0, …, vals (n - 1) to idx 0, …, idx (n - 1) sequentially in n probes.

@[simp]
theorem Cslib.CellProbe.probes_writeFin {cells wCell n : ℕ} (idx : Fin n → Fin cells) (vals : Fin n → Fin (2 ^ wCell)) (m : Mem cells wCell) :
(writeFin idx vals).probes m = n
theorem Cslib.CellProbe.nextMem_writeFin_of_forall_ne {cells wCell n : ℕ} (idx : Fin n → Fin cells) (vals : Fin n → Fin (2 ^ wCell)) (m : Mem cells wCell) (c : Fin cells) :
(∀ (j : Fin n), c ≠ idx j) → ((writeFin idx vals).run m).2 c = m c
theorem Cslib.CellProbe.nextMem_writeFin_apply {cells wCell n : ℕ} {idx : Fin n → Fin cells} :
Function.Injective idx → ∀ (vals : Fin n → Fin (2 ^ wCell)) (m : Mem cells wCell) (j : Fin n), ((writeFin idx vals).run m).2 (idx j) = vals j
structure Cslib.CellProbe.RegLayout (r : ℕ) (input : Fin r → Bool) (base S w regCells wCell : ℕ) :

Unified register/memory layout for Word-RAM-to-cell-probe simulation over S + regCells cells of width wCell (w ≤ wCell). Instantiated by standardLayout (regCells = persCount input, wCell = w) and wideLayout (regCells = 1, wCell = wideWidth input w).

def Cslib.CellProbe.RegLayout.overhead {r : ℕ} {input : Fin r → Bool} {base S w regCells wCell : ℕ} (L : RegLayout r input base S w regCells wCell) :

Total reload + spill probe overhead per operation.

theorem Cslib.CellProbe.RegLayout.unpack_bounded {r : ℕ} {input : Fin r → Bool} {base S w regCells wCell : ℕ} (L : RegLayout r input base S w regCells wCell) {argRegs : Fin r → ℕ} (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) (m : Mem (S + regCells) wCell) :
theorem Cslib.CellProbe.RegLayout.unpack_pack_mem {r : ℕ} {input : Fin r → Bool} {base S w regCells wCell : ℕ} (L : RegLayout r input base S w regCells wCell) (argRegs : Fin r → ℕ) {x : WordRAM.Data r} (hx : WordRAM.Data.Bounded w x) (a : ℕ) :
(L.unpack argRegs (L.pack x)).mem a = (zeroOutside base S x).mem a
def Cslib.CellProbe.standardLayout {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
RegLayout r input base S w (persCount input) w

Standard w-bit cell layout over S + persCount input cells (overhead = 2 * persCount input, equal to 0 when ∀ i, input i = true).

@[simp]
theorem Cslib.CellProbe.standardLayout_overhead {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(standardLayout input base S w).overhead = 2 * persCount input
@[simp]
theorem Cslib.CellProbe.standardLayout_spillProbes {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(standardLayout input base S w).spillProbes = persCount input
theorem Cslib.CellProbe.standardLayout_validMem {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) (m : Mem (S + persCount input) w) :
(standardLayout input base S w).ValidMem m
@[simp]
theorem Cslib.CellProbe.standardLayout_pack {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(standardLayout input base S w).pack = packMem input base S w
@[simp]
theorem Cslib.CellProbe.standardLayout_unpack {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(standardLayout input base S w).unpack = fun (argRegs : Fin r → ℕ) (m : Mem (S + persCount input) w) => unpackData input argRegs base S w m
def Cslib.CellProbe.wideLayout {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
RegLayout r input base S w 1 (wideWidth input w)

Wide-cell single-spill layout over S + 1 cells of width wideWidth input w (0 probes for reload + spill when persCount input = 0, 2 probes when persCount input > 0).

@[simp]
theorem Cslib.CellProbe.wideLayout_overhead {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(wideLayout input base S w).overhead = if persCount input = 0 then 0 else 2
theorem Cslib.CellProbe.wideLayout_overhead_le {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(wideLayout input base S w).overhead ≤ 2
@[simp]
theorem Cslib.CellProbe.wideLayout_pack {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(wideLayout input base S w).pack = packMemWide input base S w
@[simp]
theorem Cslib.CellProbe.wideLayout_unpack {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) :
(wideLayout input base S w).unpack = fun (argRegs : Fin r → ℕ) (m : Mem (S + 1) (wideWidth input w)) => unpackDataWide input argRegs base S w m
@[simp]
theorem Cslib.CellProbe.wideLayout_validMem_iff {r : ℕ} (input : Fin r → Bool) (base S w : ℕ) (m : Mem (S + 1) (wideWidth input w)) :
(wideLayout input base S w).ValidMem m ↔ DataCellsBounded S w (wideWidth input w) m ∧ (persCount input = 0 → ↑(m (Fin.last S)) = 0)

3. Intra-operation write buffer and deterministic ProbeTree simulation #

inductive Cslib.CellProbe.SimOutcome (S w r : ℕ) :

Intra-operation simulator configuration over [base, base + S) with pure-Lean write buffer writeBuf and outside-footprint memory extMem.

def Cslib.CellProbe.dirtyCount {S w : ℕ} (writeBuf : Fin S → Option (Fin (2 ^ w))) :

Number of modified cells buffered in writeBuf.

def Cslib.CellProbe.reconstructData {r S regCells w wCell : ℕ} (base : ℕ) (m : Mem (S + regCells) wCell) (regs : Fin r → ℕ) (writeBuf : Fin S → Option (Fin (2 ^ w))) (extMem : ℕ → ℕ) :

Reconstruct the full Word-RAM Data r represented by (regs, writeBuf, extMem) over base memory m.

def Cslib.CellProbe.liftCellWord {w wCell : ℕ} (hw : w ≤ wCell) (v : Fin (2 ^ w)) :
Fin (2 ^ wCell)

Embed a w-bit word into Fin (2 ^ wCell) when w ≤ wCell.

def Cslib.CellProbe.flushAux {S regCells w wCell : ℕ} (hw : w ≤ wCell) (writeBuf : Fin S → Option (Fin (2 ^ w))) (j : ℕ) :
j ≤ S → ProbeTree (S + regCells) wCell PUnit.{1}

Flush modified cells from writeBuf (0 .. j - 1) to data cells 0 .. S - 1.

def Cslib.CellProbe.flushWriteBuf {S regCells w wCell : ℕ} (hw : w ≤ wCell) (writeBuf : Fin S → Option (Fin (2 ^ w))) :
ProbeTree (S + regCells) wCell PUnit.{1}

Flush all modified cells of writeBuf to Mem (S + regCells) wCell in dirtyCount writeBuf write probes.

theorem Cslib.CellProbe.probes_flushWriteBuf {S regCells w wCell : ℕ} (hw : w ≤ wCell) (writeBuf : Fin S → Option (Fin (2 ^ w))) (m : Mem (S + regCells) wCell) :
(flushWriteBuf hw writeBuf).probes m = dirtyCount writeBuf
def Cslib.CellProbe.commitHalted {r : ℕ} {input : Fin r → Bool} {base S w regCells wCell : ℕ} (L : RegLayout r input base S w regCells wCell) (regs : Fin r → ℕ) (writeBuf : Fin S → Option (Fin (2 ^ w))) :
ProbeTree (S + regCells) wCell PUnit.{1}

Flush writeBuf and spill persistent registers according to L, producing L.pack y whenever y = reconstructData base m regs writeBuf extMem and y.Bounded w and L.ValidMem m.

theorem Cslib.CellProbe.commitHalted_spec {r : ℕ} {input : Fin r → Bool} {base S w regCells wCell : ℕ} (L : RegLayout r input base S w regCells wCell) {m : Mem (S + regCells) wCell} (hm : L.ValidMem m) (regs : Fin r → ℕ) (writeBuf : Fin S → Option (Fin (2 ^ w))) (extMem : ℕ → ℕ) :
((commitHalted L regs writeBuf).run m).2 = L.pack (reconstructData base m regs writeBuf extMem) ∧ (commitHalted L regs writeBuf).probes m = dirtyCount writeBuf + L.spillProbes

Single-step and clocked deterministic ProbeTree simulation #

def Cslib.CellProbe.simStepDet {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) :
SimOutcome S w r → ProbeTree (S + regCells) wCell (SimOutcome S w r)

One step of buffered deterministic flat-program simulation in ProbeTree (issuing 1 read probe on an uncached .load inside [base, base + S) and 0 probes on all other instructions).

theorem Cslib.CellProbe.simStepDet_nextMem {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) (st : SimOutcome S w r) (m : Mem (S + regCells) wCell) :
((simStepDet base p st).run m).2 = m
theorem Cslib.CellProbe.simStepDet_spec {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) (pc : ℕ) {regs : Fin r → ℕ} {writeBuf : Fin S → Option (Fin (2 ^ w))} {extMem : ℕ → ℕ} (m : Mem (S + regCells) wCell) (hx : WordRAM.Data.Bounded w (reconstructData base m regs writeBuf extMem)) :
have x := reconstructData base m regs writeBuf extMem; have t := simStepDet base p (SimOutcome.running pc regs writeBuf extMem); (t.run m).2 = m ∧ match WordRAM.step w p { pc := pc, data := x } with | WordRAM.Outcome.next s' => ∃ (writeBuf' : Fin S → Option (Fin (2 ^ w))) (extMem' : ℕ → ℕ), (t.run m).1 = SimOutcome.running s'.pc s'.data.regs writeBuf' extMem' ∧ reconstructData base m s'.data.regs writeBuf' extMem' = s'.data ∧ t.probes m + dirtyCount writeBuf' ≤ 1 + dirtyCount writeBuf | WordRAM.Outcome.halt v => (t.run m).1 = SimOutcome.halted v regs writeBuf extMem ∧ t.probes m = 0 | WordRAM.Outcome.fault => (t.run m).1 = SimOutcome.faulted ∧ t.probes m = 0

Exact single-step correspondence between simStepDet and WordRAM.step.

def Cslib.CellProbe.simLoopDet {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) :
ℕ → SimOutcome S w r → ProbeTree (S + regCells) wCell (SimOutcome S w r)

Run simStepDet for K clocked steps.

theorem Cslib.CellProbe.nextMem_writeFin_id {cells wCell : ℕ} (vals m : Mem cells wCell) :
((writeFin (fun (i : Fin cells) => i) vals).run m).2 = vals

Deterministic flat-program and structured ExecWithin entrypoints #

def Cslib.CellProbe.simProgDet {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) (K : ℕ) :
ProbeTree (S + regCells) wCell Out

Clocked deterministic ProbeTree simulator for a flat WordRAM.Program B r: reloads persistent registers according to L, runs K buffered steps of p from pc = 0, and on clean halt flushes modified data cells and spills persistent registers.

theorem Cslib.CellProbe.simProgDet_spec {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) {m : Mem (S + regCells) wCell} (hm : L.ValidMem m) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {t : WordRAM.State r} {n v K : ℕ} (hruns : WordRAM.Runs w p { pc := 0, data := L.unpack argRegs m } t n) (hhalt : WordRAM.step w p t = WordRAM.Outcome.halt v) (hK : n + 1 ≤ K) :
(simProgDet L p argRegs decode defaultAns K).run m = ((decode v t.data.regs).getD defaultAns, L.pack t.data) ∧ (simProgDet L p argRegs decode defaultAns K).probes m ≤ n + L.overhead

Any halting run of p from ⟨0, L.unpack argRegs m⟩ with n continuing steps (n + 1 ≤ K) is simulated identically by simProgDet in at most n + L.overhead cell probes, leaving L.pack t.data in memory.

def Cslib.CellProbe.simProgInitDet {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (initRegs : Fin r → ℕ) (K : ℕ) :
ProbeTree (S + regCells) wCell PUnit.{1}

Clocked deterministic ProbeTree initializer simulator: starts from externally supplied initial registers initRegs (0 reload probes), runs K buffered steps of p on zeroed cell memory, and on clean halt flushes modified data cells and spills persistent registers in L.spillProbes probes.

theorem Cslib.CellProbe.simProgInitDet_spec {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (initRegs : Fin r → ℕ) (hm₀ : L.ValidMem fun (x : Fin (S + regCells)) => 0) (hregs : ∀ (i : Fin r), WordRAM.Fits w (initRegs i)) {t : WordRAM.State r} {n v K : ℕ} (hruns : WordRAM.Runs w p { pc := 0, data := { regs := initRegs, mem := fun (x : ℕ) => 0 } } t n) (hhalt : WordRAM.step w p t = WordRAM.Outcome.halt v) (hK : n + 1 ≤ K) :
((simProgInitDet L p initRegs K).run fun (x : Fin (S + regCells)) => 0) = (PUnit.unit, L.pack t.data) ∧ ((simProgInitDet L p initRegs K).probes fun (x : Fin (S + regCells)) => 0) ≤ n + L.spillProbes

Starting from zeroed cell memory fun _ => 0 (when hm₀ : L.ValidMem (fun _ => 0)), any halting run of p from ⟨0, { regs := initRegs, mem := fun _ => 0 }⟩ in n continuing steps (n + 1 ≤ K) is simulated by simProgInitDet in at most n + L.spillProbes cell probes, leaving L.pack t.data in memory.

noncomputable def Cslib.CellProbe.haltFuel {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (m : Mem (S + regCells) wCell) :

Exact halting step count of p from ⟨0, L.unpack argRegs m⟩ when a halting run exists, or 0 otherwise.

noncomputable def Cslib.CellProbe.autoFuel {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) :

Uniform fuel across all m : Mem (S + regCells) wCell on which p halts.

theorem Cslib.CellProbe.le_autoFuel_of_runs_halt {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) {p : WordRAM.Program B r} {argRegs : Fin r → ℕ} {m : Mem (S + regCells) wCell} {t : WordRAM.State r} {n v : ℕ} (hruns : WordRAM.Runs w p { pc := 0, data := L.unpack argRegs m } t n) (hhalt : WordRAM.step w p t = WordRAM.Outcome.halt v) :
n + 1 ≤ autoFuel L p argRegs
noncomputable def Cslib.CellProbe.simProgDetAuto {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) :
ProbeTree (S + regCells) wCell Out

Automatic-fuel deterministic ProbeTree simulator: chooses fuel uniformly over the finite memory space Mem (S + regCells) wCell so callers need not supply an external step bound K.

theorem Cslib.CellProbe.simProgDetAuto_spec {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) {m : Mem (S + regCells) wCell} (hm : L.ValidMem m) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {t : WordRAM.State r} {n v : ℕ} (hruns : WordRAM.Runs w p { pc := 0, data := L.unpack argRegs m } t n) (hhalt : WordRAM.step w p t = WordRAM.Outcome.halt v) :
(simProgDetAuto L p argRegs decode defaultAns).run m = ((decode v t.data.regs).getD defaultAns, L.pack t.data) ∧ (simProgDetAuto L p argRegs decode defaultAns).probes m ≤ n + L.overhead

Automatic-fuel simulation of any deterministic halting run of p in ≤ n + L.overhead cell probes (≤ T_flat - 1 + L.overhead when Executes w p ⟨0, x₀⟩ v T_flat).

theorem Cslib.CellProbe.simExecWithin {B : WordRAM.Basis} {r S w : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (c : WordRAM.Code B r) (retReg : Fin r) (argRegs : Fin r → ℕ) (decode : (Fin r → ℕ) → Option Out) (defaultAns : Out) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) (m : Mem (S + persCount input) w) {y : WordRAM.Data r} {T : ℕ} (hexec : WordRAM.ExecWithin w c (unpackData input argRegs base S w m) y T) :
have tree := simProgDetAuto (standardLayout input base S w) (c.program retReg) argRegs (fun (x : ℕ) (regs : Fin r → ℕ) => decode regs) defaultAns; tree.run m = ((decode y.regs).getD defaultAns, packMem input base S w y) ∧ tree.probes m ≤ T + 2 * persCount input

Structured ExecWithin simulation in standard w-bit layout (S + persCount input cells of width w): simulates c in at most T + 2 * persCount input probes (≤ T when persCount input = 0).

theorem Cslib.CellProbe.simExecWithinWide {B : WordRAM.Basis} {r S w : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (c : WordRAM.Code B r) (retReg : Fin r) (argRegs : Fin r → ℕ) (decode : (Fin r → ℕ) → Option Out) (defaultAns : Out) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {m : Mem (S + 1) (wideWidth input w)} (hm : (wideLayout input base S w).ValidMem m) {y : WordRAM.Data r} {T : ℕ} (hexec : WordRAM.ExecWithin w c (unpackDataWide input argRegs base S w m) y T) :
have tree := simProgDetAuto (wideLayout input base S w) (c.program retReg) argRegs (fun (x : ℕ) (regs : Fin r → ℕ) => decode regs) defaultAns; tree.run m = ((decode y.regs).getD defaultAns, packMemWide input base S w y) ∧ tree.probes m ≤ T + if persCount input = 0 then 0 else 2

Structured ExecWithin simulation in wide-cell single-spill layout (S + 1 cells of width wideWidth input w): simulates c in at most T + (if persCount input = 0 then 0 else 2) probes (≤ T + 2 regardless of r).

4. Randomized (ExecRand) and unbounded Las Vegas (ExecProgramDist / ExecCodeDist) #

simulation in RandProbeTree

def Cslib.CellProbe.SimOutcome.toRandCfg {r S regCells w wCell : ℕ} (base : ℕ) (m : Mem (S + regCells) wCell) :

Project a buffered SimOutcome over base memory m to the corresponding WordRAM.RandCfg r.

Number of buffered modified cells carried by a SimOutcome.

Boolean predicate for active configurations not yet positioned at Instr.halt (the only configurations on which simStepRand can increase probes + dirty by 1).

def Cslib.CellProbe.simStepRand {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) :
SimOutcome S w r → RandProbeTree (S + regCells) wCell (SimOutcome S w r)

One step of buffered randomized flat-program simulation in RandProbeTree: maps Instr.rand to 0-probe RandProbeTree.sample (ProbComp.unifFin ...) and delegates all other instructions to RandProbeTree.ofProbeTree (simStepDet ...).

def Cslib.CellProbe.simLoopRand {B : WordRAM.Basis} {r S regCells w wCell : ℕ} (base : ℕ) (p : WordRAM.Program B r) :
ℕ → SimOutcome S w r → RandProbeTree (S + regCells) wCell (SimOutcome S w r)

Clocked K-step buffered randomized execution in RandProbeTree.

Exact telescoping of the .halt instruction step #

Halting-limit identification, ExecProgramDist, and zero-error fallback #

noncomputable def Cslib.CellProbe.haltedLim {B : WordRAM.Basis} {r : ℕ} (w : ℕ) (p : WordRAM.Program B r) (x : WordRAM.Data r) (vy : ℕ × WordRAM.Data r) :

Supremum halting probability of p from ⟨0, x⟩ at (vy.1, vy.2).

Distributional execution contract for a flat WordRAM.Program B r: from ⟨0, x⟩, p never faults, has expected instruction count at most T, and dominates μ : PMF (ℕ × Data r) at its supremum halting probabilities. Because ∑' vy, μ vy = 1 and ∑' vy, haltedLim w p x vy ≤ 1, domination forces exact equality haltedLim w p x vy = μ vy (ExecProgramDist.haltedLim_eq) and almost-sure halting (ExecProgramDist.almostSurelyHalts).

theorem Cslib.CellProbe.ExecProgramDist.haltedLim_eq {B : WordRAM.Basis} {r w : ℕ} {p : WordRAM.Program B r} {x : WordRAM.Data r} {μ : PMF (ℕ × WordRAM.Data r)} {T : ENNReal} (h : ExecProgramDist w p x μ T) (vy : ℕ × WordRAM.Data r) :
haltedLim w p x vy = μ vy
theorem Cslib.CellProbe.ExecProgramDist.evalRand_halted_le {B : WordRAM.Basis} {r w : ℕ} {p : WordRAM.Program B r} {x : WordRAM.Data r} {μ : PMF (ℕ × WordRAM.Data r)} {T : ENNReal} (h : ExecProgramDist w p x μ T) (K : ℕ) (vy : ℕ × WordRAM.Data r) :
(WordRAM.evalRand w p K { pc := 0, data := x }) (WordRAM.RandCfg.halted vy.1 vy.2) ≤ μ vy
theorem Cslib.CellProbe.execProgramDist_of_execCodeDist {B : WordRAM.Basis} {r w : ℕ} {c : WordRAM.Code B r} {x : WordRAM.Data r} {μ : PMF (WordRAM.Data r)} {T : ENNReal} (h : WordRAM.ExecCodeDist w c x μ T) (out : Fin r) :
ExecProgramDist w (c.program out) x (PMF.map (fun (y : WordRAM.Data r) => (y.regs out, y)) μ) (T + 1)

Lift a structured ExecCodeDist w c x μ T certificate to ExecProgramDist on c.program out.

noncomputable def Cslib.CellProbe.fallbackOutcome {B : WordRAM.Basis} {r : ℕ} (w : ℕ) (p : WordRAM.Program B r) (x : WordRAM.Data r) :

Pure-Lean fallback halting outcome for p from ⟨0, x⟩: selects a reachable (v, y) with positive halting limit 0 < haltedLim w p x (v, y) when one exists, or (0, x) otherwise.

noncomputable def Cslib.CellProbe.simProgRand {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) (K : ℕ) :
RandProbeTree (S + regCells) wCell Out

Buffered finite-horizon RandProbeTree simulator for a flat WordRAM.Program B r:

  1. Reloads persistent registers via L.reload argRegs (regs₀ = (L.unpack argRegs m).regs).
  2. Runs K buffered steps via simLoopRand without mutating cell memory m.
  3. On .halted v regs' writeBuf' _, flushes writeBuf' and spills persistent registers via commitHalted.
  4. On the > K tail (.running), reads the S untouched data cells of m, reconstructs x₀ = L.unpack argRegs m in pure Lean, selects vy = fallbackOutcome w p x₀ (∈ μ.support!), and writes L.pack vy.2 (2 * S + regCells probes on the tail), preserving 100% zero-error support correctness at finite tree depth.
theorem Cslib.CellProbe.simProgRand_worstCase_probes {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) (K : ℕ) (m : Mem (S + regCells) wCell) (z : (Out × Mem (S + regCells) wCell) × ℕ) :
z ∈ ((simProgRand L p argRegs decode defaultAns K).run m).support → z.2 ≤ K + 2 * S + regCells + L.overhead

Unconditional worst-case probe bound for simProgRand on any memory m: every path issues at most K + 2 * S + regCells + L.overhead cell probes.

theorem Cslib.CellProbe.simProgRand_expectedProbes_le_worstCase {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) (K : ℕ) (m : Mem (S + regCells) wCell) :
(simProgRand L p argRegs decode defaultAns K).expectedProbes m ≤ ↑(K + 2 * S + regCells + L.overhead)
theorem Cslib.CellProbe.simProgRand_lasVegas_spec {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (p : WordRAM.Program B r) (argRegs : Fin r → ℕ) (decode : ℕ → (Fin r → ℕ) → Option Out) (defaultAns : Out) (K : ℕ) {m : Mem (S + regCells) wCell} (hm : L.ValidMem m) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {μ : PMF (ℕ × WordRAM.Data r)} {T : ENNReal} (hdist : ExecProgramDist w p (L.unpack argRegs m) μ T) :
have x₀ := L.unpack argRegs m; have tree := simProgRand L p argRegs decode defaultAns K; have p_run := (WordRAM.evalRand w p K { pc := 0, data := x₀ }).toOuterMeasure (WordRAM.RandCfg.runningSet r); (∀ z ∈ (tree.run m).support, ∃ vy ∈ μ.support, z.1 = ((decode vy.1 vy.2.regs).getD defaultAns, L.pack vy.2)) ∧ tree.expectedProbes m ≤ ∑ t ∈ Finset.range K, (WordRAM.evalRand w p t { pc := 0, data := x₀ }).toOuterMeasure {cfg : WordRAM.RandCfg r | isContinuingCfg p cfg = true} + ↑L.overhead + p_run * ↑(2 * S + regCells) ∧ ∀ (g : Out × Mem (S + regCells) wCell → ENNReal) (B_rem : ENNReal), (∀ om ∈ (PMF.map Prod.fst (tree.run m)).support, g om ≤ B_rem) → ∑' (om : Out × Mem (S + regCells) wCell), (PMF.map Prod.fst (tree.run m)) om * g om ≤ ∑' (vy : ℕ × WordRAM.Data r), μ vy * g ((decode vy.1 vy.2.regs).getD defaultAns, L.pack vy.2) + p_run * B_rem

Main single-step Las Vegas simulation theorem (simProgRand_lasVegas_spec): Under hm : L.ValidMem m, harg, and hdist : ExecProgramDist w p (L.unpack argRegs m) μ T:

  1. 100% zero-error support soundness (at any finite K): every outcome (ans, m') in the support of (simProgRand L p argRegs decode defaultAns K).run m comes from some vy ∈ μ.support with ans = (decode vy.1 vy.2.regs).getD defaultAns and m' = L.pack vy.2!
  2. Expected probe bound: expectedProbes ≤ continuingSum K + L.overhead + p_run(K) * (2 * S + regCells).
  3. Continuation coupling inequality: for any bounded continuation g ≤ B_rem on support, E_{simProgRand}[g] ≤ E_{vy ~ μ}[g (decode vy, L.pack vy.2)] + p_run(K) * B_rem!

Exact finite-tree ExecRand simulation (simExecRand, simExecRandWide) #

noncomputable def Cslib.CellProbe.probCompMaxSnd {α : Type} :
ProbComp (α × ℕ) → ℕ

Maximum step count across all leaves of a finite ProbComp (α × ℕ) computation tree.

noncomputable def Cslib.CellProbe.autoRandFuel {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (c : WordRAM.Code B r) (argRegs : Fin r → ℕ) :

Uniform finite-tree fuel across all m : Mem (S + regCells) wCell on which ExecRand holds.

theorem Cslib.CellProbe.le_autoRandFuel_of_execRand {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) {c : WordRAM.Code B r} {argRegs : Fin r → ℕ} {m : Mem (S + regCells) wCell} {mc : ProbComp (WordRAM.Data r × ℕ)} (hexec : WordRAM.ExecRand w c (L.unpack argRegs m) mc) {z : WordRAM.Data r × ℕ} (hz : z ∈ OracleComp.support mc) :
z.2 + 1 ≤ autoRandFuel L c argRegs
theorem Cslib.CellProbe.simExecRandLayout {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (L : RegLayout r input base S w regCells wCell) (c : WordRAM.Code B r) (retReg : Fin r) (argRegs : Fin r → ℕ) (decode : (Fin r → ℕ) → Option Out) (defaultAns : Out) {m : Mem (S + regCells) wCell} (hm : L.ValidMem m) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {mc : ProbComp (WordRAM.Data r × ℕ)} (hexec : WordRAM.ExecRand w c (L.unpack argRegs m) mc) :
have tree := simProgRand L (c.program retReg) argRegs (fun (x : ℕ) (regs : Fin r → ℕ) => decode regs) defaultAns (autoRandFuel L c argRegs); PMF.map Prod.fst (tree.run m) = PMF.map (fun (z : WordRAM.Data r × ℕ) => ((decode z.1.regs).getD defaultAns, L.pack z.1)) mc.eval ∧ tree.expectedProbes m ≤ (mc.expect fun (z : WordRAM.Data r × ℕ) => ↑z.2) + ↑L.overhead

Exact finite-tree ExecRand simulation over an arbitrary RegLayout: reproduces the exact (output, postMem) distribution of mc with zero η slack and expected probes bounded by (ProbComp.expect mc fun z => (z.2 : ℝ≥0∞)) + L.overhead.

theorem Cslib.CellProbe.simExecRand {B : WordRAM.Basis} {r S w : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (c : WordRAM.Code B r) (retReg : Fin r) (argRegs : Fin r → ℕ) (decode : (Fin r → ℕ) → Option Out) (defaultAns : Out) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) (m : Mem (S + persCount input) w) {mc : ProbComp (WordRAM.Data r × ℕ)} (hexec : WordRAM.ExecRand w c (unpackData input argRegs base S w m) mc) :
have L := standardLayout input base S w; have tree := simProgRand L (c.program retReg) argRegs (fun (x : ℕ) (regs : Fin r → ℕ) => decode regs) defaultAns (autoRandFuel L c argRegs); PMF.map Prod.fst (tree.run m) = PMF.map (fun (z : WordRAM.Data r × ℕ) => ((decode z.1.regs).getD defaultAns, packMem input base S w z.1)) mc.eval ∧ tree.expectedProbes m ≤ (mc.expect fun (z : WordRAM.Data r × ℕ) => ↑z.2) + ↑(2 * persCount input)

Exact finite-tree ExecRand simulation in standard w-bit layout (S + persCount input cells of width w, additive overhead 2 * persCount input).

theorem Cslib.CellProbe.simExecRandWide {B : WordRAM.Basis} {r S w : ℕ} {input : Fin r → Bool} {base : ℕ} {Out : Type} (c : WordRAM.Code B r) (retReg : Fin r) (argRegs : Fin r → ℕ) (decode : (Fin r → ℕ) → Option Out) (defaultAns : Out) (harg : ∀ (i : Fin r), input i = true → WordRAM.Fits w (argRegs i)) {m : Mem (S + 1) (wideWidth input w)} (hm : (wideLayout input base S w).ValidMem m) {mc : ProbComp (WordRAM.Data r × ℕ)} (hexec : WordRAM.ExecRand w c (unpackDataWide input argRegs base S w m) mc) :
have L := wideLayout input base S w; have tree := simProgRand L (c.program retReg) argRegs (fun (x : ℕ) (regs : Fin r → ℕ) => decode regs) defaultAns (autoRandFuel L c argRegs); PMF.map Prod.fst (tree.run m) = PMF.map (fun (z : WordRAM.Data r × ℕ) => ((decode z.1.regs).getD defaultAns, packMemWide input base S w z.1)) mc.eval ∧ tree.expectedProbes m ≤ (mc.expect fun (z : WordRAM.Data r × ℕ) => ↑z.2) + ↑(if persCount input = 0 then 0 else 2)

Exact finite-tree ExecRand simulation in wide-cell single-spill layout (S + 1 cells of width wideWidth input w, additive overhead if persCount input = 0 then 0 else 2 ≤ 2).

Antitone tail decay and uniform finite-horizon cutoff selection #

Active-configuration probability (evalRand w p K s).toOuterMeasure (RandCfg.runningSet r) is antitone in K because .halted and .faulted are absorbing.

theorem Cslib.CellProbe.exists_cutoff_mul_le {a : ℕ → ENNReal} (ha : Antitone a) (hsum : ∑' (t : ℕ), a t ≠ ⊤) (A B : ℕ) {η : ENNReal} (hη : 0 < η) :
∃ (K₀ : ℕ), 1 ≤ K₀ ∧ ∀ K ≥ K₀, a K * (↑A + ↑B * ↑K) ≤ η

For any antitone sequence a : ℕ → ℝ≥0∞ with ∑' t, a t ≠ ⊤, (A + B * K) * a K → 0 as K → ∞.

theorem Cslib.CellProbe.exists_uniform_cutoff {Op : Type u_1} {B : WordRAM.Basis} {r S regCells w wCell : ℕ} {input : Fin r → Bool} {base : ℕ} (L : RegLayout r input base S w regCells wCell) (opsAlphabet : Finset Op) (Good : Op → Mem (S + regCells) wCell → Prop) (prog : Op → WordRAM.Program B r) (argRegs : Op → Fin r → ℕ) (hfin : ∀ o ∈ opsAlphabet, ∀ (m : Mem (S + regCells) wCell), Good o m → WordRAM.expectedTime w (prog o) { pc := 0, data := L.unpack (argRegs o) m } ≠ ⊤) (A B✝ : ℕ) {η : ENNReal} (hη : 0 < η) :
∃ (K : ℕ), 1 ≤ K ∧ ∀ o ∈ opsAlphabet, ∀ (m : Mem (S + regCells) wCell), Good o m → (WordRAM.evalRand w (prog o) K { pc := 0, data := L.unpack (argRegs o) m }).toOuterMeasure (WordRAM.RandCfg.runningSet r) * (↑A + ↑B✝ * ↑K) ≤ η

Uniform finite-horizon cutoff selection across a finite operation alphabet opsAlphabet and the finite memory space Mem (S + regCells) wCell: produces a single K ≥ 1 such that for every o ∈ opsAlphabet and m satisfying Good o m, the active-tail product p_run(K, o, m) * (A + B * K) is at most η.