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:
- 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 maskinput : Fin r → Bool(such asP.inputonWordRAM.SubroutineCode B r k_init), only thepersCount inputpersistent registers withinput i = falsesurvive between calls:- Standard
w-bit layout (standardLayout): AllocatesS + persCount inputcells of widthw(0extra cells and0extra probes when∀ i, input i = true), reloading persistent registers inpersCount inputreads and spilling them at halt inpersCount inputwrites (2 * persCount inputadditive probes per operation). - Wide-cell single-spill layout (
wideLayout): Packs allpersCount inputpersistent registers in base2 ^ winto1cell of widthwideWidth input w := max (persCount input) 1 * woverS + 1cells, paying0extra probes whenpersCount input = 0and2extra probes (1read +1write) wheneverpersCount input > 0, independent ofr.
- Standard
- Unallocated reads and unbounded Las Vegas loops:
- Replacing Word-RAM memory outside
[base, base + S)by0(zeroOutside base S) keeps loads and stores outside[base, base + S)in a pure-Lean intra-operation map at0probe cost; whenModifies (Block.mk base S).footprintholds at halt, outside memory returns to0at every operation boundary. - Writes inside
[base, base + S)are buffered in pure Lean during a clockedK-step run and flushed only at halt, soreads + flushedWrites ≤ continuingStepsand cell memory remains untouched if execution is still active at stepK. On that> Ktail event (probability tending to0asK → ∞wheneverexpectedTime < ⊤), the simulator reads allSdata cells, selects a reachable halting post-state in pure Lean fromhaltedLim(> 0by almost-sure halting, hence in the target support), and writes the resulting packed memory (2 * S + regCellsextra probes on the tail), preserving 100% zero-error support correctness at finite tree depth while achieving expected probes≤ T + overhead + ηfor anyη > 0.
- Replacing Word-RAM memory outside
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 #
Cslib.CellProbe.persRegs,Cslib.CellProbe.persCount,Cslib.CellProbe.persistentRegCount: persistent register set and count (input i = false).Cslib.CellProbe.zeroOutside: zero Word-RAM memory outside[base, base + S).Cslib.CellProbe.packMem,Cslib.CellProbe.unpackData: standardw-bit packing betweenWordRAM.Data randMem (S + persCount input) w.Cslib.CellProbe.wideWidth,Cslib.CellProbe.wideSubroutineWidth,Cslib.CellProbe.DataCellsBounded,Cslib.CellProbe.packMemWide,Cslib.CellProbe.unpackDataWide: single-cell base-2 ^ wregister packing overS + 1cells of widthmax (persCount input) 1 * w.Cslib.CellProbe.RegLayout,Cslib.CellProbe.standardLayout,Cslib.CellProbe.wideLayout: unified cell-layout interface shared by deterministic and randomized simulators.Cslib.CellProbe.simProgDet,Cslib.CellProbe.simProgInitDet,Cslib.CellProbe.simProgDetAuto,Cslib.CellProbe.simProgRand: clocked and automatic-fuel deterministic (ProbeTree) and buffered randomized (RandProbeTree) flat-program simulators.Cslib.CellProbe.ExecProgramDist: distributional execution contract for flatWordRAM.Programs.
Main results #
Cslib.CellProbe.persistentRegCount_eq_zero_of_all_input,Cslib.CellProbe.persistentRegCount_le: zero-overhead specialization and register-count bound.Cslib.CellProbe.simProgDet_spec,Cslib.CellProbe.simProgDetAuto_spec,Cslib.CellProbe.simExecWithin,Cslib.CellProbe.simExecWithinWide: deterministic flat-program and structuredExecWithinsimulation in≤ T + 2 * r_pers(or≤ T + 2wide) probes.Cslib.CellProbe.simExecRand,Cslib.CellProbe.simExecRandWide: exact-distribution finite-treeExecRandsimulation inRandProbeTreewith zeroηslack.Cslib.CellProbe.ExecProgramDist.haltedLim_eq,Cslib.CellProbe.execProgramDist_of_execCodeDist,Cslib.CellProbe.simProgRand_lasVegas_spec,Cslib.CellProbe.exists_uniform_cutoff: exact halting-law identification, compilation ofExecCodeDisttoExecProgramDist, and uniform-horizon buffered Las Vegas simulation with zero-error support preservation and arbitraryη > 0expected-probe slack.
References #
1. Persistent register accounting #
Number of persistent registers (P.input i = false) of a WordRAM.SubroutineCode.
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).
Wide-cell base-2 ^ w persistent-register codec (wideLayout) #
Subroutine specialization max (persistentRegCount P) 1 * w of wideWidth.
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.
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).
- hw : w ≤ wCell
Cell width is at least the Word-RAM word width
w. - reloadProbes : ℕ
Number of probes used to reload persistent registers at operation entry.
- spillProbes : ℕ
Number of probes used to spill persistent registers at operation exit.
Reload persistent registers and install caller arguments
argRegsoninputregisters.Spill persistent registers from final
regsback to dedicated register cells.Pack a Word-RAM
Data rstate intoMem (S + regCells) wCell.Unpack
Mem (S + regCells) wCellwithargRegsintoData r(0outside[base, base+S)).Well-formedness of
mon untouched data/register cells (TrueonstandardLayout).- nextMem_spill_data (regs : Fin r → ℕ) (m : Mem (S + regCells) wCell) (idx : Fin S) : ((self.spill regs).run m).2 (Fin.castAdd regCells idx) = m (Fin.castAdd regCells idx)
- pack_data (y : WordRAM.Data r) (idx : Fin S) : self.pack y (Fin.castAdd regCells idx) = ⟨↑(WordRAM.wordOfNat w (y.mem (base + ↑idx))), ⋯⟩
3. Intra-operation write buffer and deterministic ProbeTree simulation #
Intra-operation simulator configuration over [base, base + S) with pure-Lean write buffer
writeBuf and outside-footprint memory extMem.
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.
Single-step and clocked deterministic ProbeTree simulation #
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).
Exact single-step correspondence between simStepDet and WordRAM.step.
Run simStepDet for K clocked steps.
Deterministic flat-program and structured ExecWithin entrypoints #
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.
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.
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.
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.
Exact halting step count of p from ⟨0, L.unpack argRegs m⟩ when a halting run exists, or
0 otherwise.
Uniform fuel across all m : Mem (S + regCells) wCell on which p halts.
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.
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).
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).
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
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).
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 ...).
Clocked K-step buffered randomized execution in RandProbeTree.
Exact telescoping of the .halt instruction step #
Halting-limit identification, ExecProgramDist, and zero-error fallback #
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).
Lift a structured ExecCodeDist w c x μ T certificate to ExecProgramDist on c.program out.
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.
Buffered finite-horizon RandProbeTree simulator for a flat WordRAM.Program B r:
- Reloads persistent registers via
L.reload argRegs(regs₀ = (L.unpack argRegs m).regs). - Runs
Kbuffered steps viasimLoopRandwithout mutating cell memorym. - On
.halted v regs' writeBuf' _, flusheswriteBuf'and spills persistent registers viacommitHalted. - On the
> Ktail (.running), reads theSuntouched data cells ofm, reconstructsx₀ = L.unpack argRegs min pure Lean, selectsvy = fallbackOutcome w p x₀(∈ μ.support!), and writesL.pack vy.2(2 * S + regCellsprobes on the tail), preserving 100% zero-error support correctness at finite tree depth.
Unconditional worst-case probe bound for simProgRand on any memory m: every path issues
at most K + 2 * S + regCells + L.overhead cell probes.
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:
- 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 mcomes from somevy ∈ μ.supportwithans = (decode vy.1 vy.2.regs).getD defaultAnsandm' = L.pack vy.2! - Expected probe bound:
expectedProbes ≤ continuingSum K + L.overhead + p_run(K) * (2 * S + regCells). - Continuation coupling inequality: for any bounded continuation
g ≤ B_remon 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) #
Uniform finite-tree fuel across all m : Mem (S + regCells) wCell on which ExecRand holds.
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.
Exact finite-tree ExecRand simulation in standard w-bit layout (S + persCount input cells
of width w, additive overhead 2 * persCount input).
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.
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 η.