Documentation

CslibFrontier.DataStructure.WordRAM.Resizable.StateTransition

Deterministic Resizable Word RAM State-Transition Implementations #

Reusable deterministic (demonic-growth-resilient) subroutine packaging (SubroutineCode) and potential-amortized ([CLRS09], Chapter 17) state-transition implementation certificates (StateTransitionImpl) over the word-granular Resizable Word RAM (Cslib.WordRAM.Resizable), accompanying the word-granular resizable memory models of [LLYZ23a], Section 2.1, and [KLZ26], Section 5.1, and adapting the bit-granular virtual-memory variant of [LLYZ24], Section 3.2, at word granularity.

Unlike fixed-capacity Cslib.DataStructure.WordRAM.StateTransitionImpl (whose workspace [base, base + space) has a single state-independent length space), a Resizable Word RAM implementation owns the active suffix [base, x.frontier) above a caller prefix [0, base) and tracks two state/operation-indexed word bounds:

  1. Resting space bound (spaceBound : D.State → ℕ): after initialization and after every completed operation reaching abstract state s, the hardware frontier satisfies base ≤ x.frontier ∧ x.frontier ≤ base + spaceBound s and x.regs P.baseReg = base.
  2. Intermediate peak bound (peakSpaceBound : D.State → D.Op → ℕ): while executing o : D.Op from s : D.State, every intermediate machine configuration keeps its hardware frontier ≤ base + peakSpaceBound s o (RDemonicExec w (base + peakSpaceBound s o) P.code ...), while preserving caller memory [0, base) (∀ addr < base, y.mem addr = x.mem addr).
  3. Trajectory-relative address-space fit (PeakFitsOpSeq, PeakFitsHistory): multi-operation execution theorems (steps_amortized, seq_amortized, steps_amortized_ofFn, seq_amortized_ofFn) require Fits w (base + peakSpaceBound s_t o_t) only along states actually reached by valid ops, never globally across all s : D.State.

Main definitions #

Main results #

References #

Relocatable Resizable Word RAM SubroutineCode #

Uniform machine code for a relocatable subroutine over the word-granular Resizable Word RAM (RCode B r_ds). Owns the active suffix [base, x.frontier) recorded in baseReg, leaving the caller prefix [0, base) untouched.

  • baseReg : Fin r_ds

    Persistent register holding the base address base of this structure's resizable suffix.

  • initParams : Fin k_init ↪ Fin r_ds

    Injective register map carrying runtime initialization parameters (params) into initCode.

  • input : Fin r_ds → Bool

    Mask marking caller-overwritable argument/scratch registers (false on persistent registers).

  • input_baseReg_false : self.input self.baseReg = false

    baseReg is persistent across standalone argument preparation.

  • initCode : WordRAM.Resizable.RCode B r_ds

    Initializes the structure from x₀.frontier = base, recording base in baseReg.

  • Unified operation dispatcher executing D.Op with .grow / .shrink resizing.

Whether either initCode or code inspects the ambient word width w.

Compiled flat initialization RProgram halting with register out.

Compiled flat operation RProgram halting with register out.

def Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepareRegs {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (regs : Fin r_ds → ℕ) :
Fin r_ds → ℕ

Standalone register-preparation map overwriting P.input registers with encode o.

def Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :

Deliver encoded operation arguments into P.input registers while preserving persistent registers, memory, and x.frontier.

@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_regs {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(P.prepare encode o x).regs = P.prepareRegs encode o x.regs
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_mem {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(P.prepare encode o x).mem = x.mem
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_frontier {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(P.prepare encode o x).frontier = x.frontier
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_regs_of_not_input {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} {encode : Op → Fin r_ds → ℕ} {i : Fin r_ds} (hi : P.input i = false) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(P.prepare encode o x).regs i = x.regs i
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_regs_baseReg {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(P.prepare encode o x).regs P.baseReg = x.regs P.baseReg
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.prepare_bounded {B : WordRAM.Basis} {r_ds k_init : ℕ} (P : SubroutineCode B r_ds k_init) {Op : Type v} {w : ℕ} {encode : Op → Fin r_ds → ℕ} {o : Op} {x : WordRAM.Resizable.RData r_ds} (hx : WordRAM.Resizable.RData.Bounded w x) (hfit : ∀ (i : Fin r_ds), P.input i = true → WordRAM.Fits w (encode o i)) :

prepare preserves RData.Bounded w whenever the encoded input registers fit in w bits.

def Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.mapSimulates {B B' : WordRAM.Basis} {r_ds k_init : ℕ} (φ : B.Simulates B') (P : SubroutineCode B r_ds k_init) :
SubroutineCode B' r_ds k_init

Transport a SubroutineCode bundle along a defined-evaluation basis simulation.

@[reducible, inline]

Transport an exact-basis SubroutineCode to Basis.standard.

@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.SubroutineCode.mapSimulates_prepare {B B' : WordRAM.Basis} {r_ds k_init : ℕ} (φ : B.Simulates B') (P : SubroutineCode B r_ds k_init) {Op : Type v} (encode : Op → Fin r_ds → ℕ) (o : Op) (x : WordRAM.Resizable.RData r_ds) :
(mapSimulates φ P).prepare encode o x = P.prepare encode o x

Trajectory-relative peak-frontier admissibility #

def Cslib.DataStructure.WordRAM.Resizable.PeakFitsOpSeq {D : StateTransitionSpec} (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
List D.Op → Prop

Trajectory-relative peak-frontier fit along a relational operation sequence ops from s: requires Fits w (base + peakSpaceBound s_t o_t) only at states s_t reachable along ops under D.step, never globally across all s : D.State.

@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsOpSeq_nil {D : StateTransitionSpec} (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
PeakFitsOpSeq w base peakSpaceBound s [] ↔ True
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsOpSeq_cons {D : StateTransitionSpec} (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) (o : D.Op) (ops : List D.Op) :
PeakFitsOpSeq w base peakSpaceBound s (o :: ops) ↔ WordRAM.Fits w (base + peakSpaceBound s o) ∧ ∀ (s' : D.State) (a : D.Result o), D.step s o s' a → PeakFitsOpSeq w base peakSpaceBound s' ops
def Cslib.DataStructure.WordRAM.Resizable.PeakFitsHistory {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
List D.Op → Prop

Trajectory-relative peak-frontier fit along a functional operation history ops from s ([D.HasStepFn f]).

@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsHistory_nil {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
PeakFitsHistory w base peakSpaceBound s [] ↔ True
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsHistory_cons {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) (o : D.Op) (os : List D.Op) :
PeakFitsHistory w base peakSpaceBound s (o :: os) ↔ WordRAM.Fits w (base + peakSpaceBound s o) ∧ PeakFitsHistory w base peakSpaceBound (D.stepFn s o).1 os
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsOpSeq_iff_peakFitsHistory {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (w base : ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) (ops : List D.Op) :
PeakFitsOpSeq w base peakSpaceBound s ops ↔ PeakFitsHistory w base peakSpaceBound s ops

On any functional specification [D.HasStepFn f], PeakFitsOpSeq and PeakFitsHistory coincide.

def Cslib.DataStructure.WordRAM.Resizable.maxPeakSpaceHistory {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
List D.Op → ℕ

Maximum peakSpaceBound s_t o_t encountered along the deterministic trajectory of ops from s ([D.HasStepFn f]).

@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.maxPeakSpaceHistory_nil {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) :
maxPeakSpaceHistory peakSpaceBound s [] = 0
@[simp]
theorem Cslib.DataStructure.WordRAM.Resizable.maxPeakSpaceHistory_cons {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (peakSpaceBound : D.State → D.Op → ℕ) (s : D.State) (o : D.Op) (os : List D.Op) :
maxPeakSpaceHistory peakSpaceBound s (o :: os) = max (peakSpaceBound s o) (maxPeakSpaceHistory peakSpaceBound (D.stepFn s o).1 os)
theorem Cslib.DataStructure.WordRAM.Resizable.peakFitsHistory_of_fits_maxPeakSpaceHistory {D : StateTransitionSpec} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] {w base : ℕ} {peakSpaceBound : D.State → D.Op → ℕ} {s : D.State} {ops : List D.Op} (h : WordRAM.Fits w (base + maxPeakSpaceHistory peakSpaceBound s ops)) :
PeakFitsHistory w base peakSpaceBound s ops

Bounding base + maxPeakSpaceHistory peakSpaceBound s ops by 2 ^ w establishes PeakFitsHistory along ops.

Deterministic Resizable Word RAM StateTransitionImpl #

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

Reusable deterministic (demonic-growth-resilient) Resizable Word RAM implementation certificate for P : SubroutineCode B r_ds k_init realizing D : StateTransitionSpec at word width w, base address base, runtime initialization parameters params, and initial state s₀, with potential-amortized operation charges ([CLRS09], Chapter 17), state-dependent resting footprint [base, base + spaceBound s), and intermediate peak bound [base, base + peakSpaceBound s o).

@[reducible, inline]
abbrev Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.ofFn {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (spaceBound : D.State → ℕ) (peakSpaceBound : D.State → D.Op → ℕ) (initTime : ℕ) (initPotential : ℕ := 0) (charge : D.State → D.Op → ℕ) (rep : D.State → WordRAM.Resizable.RData r_ds → Prop) (potential : WordRAM.Resizable.RData r_ds → ℕ := fun (x : WordRAM.Resizable.RData r_ds) => 0) (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 : ∀ {s : D.State} {x : WordRAM.Resizable.RData r_ds}, rep s x → WordRAM.Resizable.RData.Bounded w x) (frontier_le : ∀ {s : D.State} {x : WordRAM.Resizable.RData r_ds}, rep s x → base ≤ x.frontier ∧ x.frontier ≤ base + spaceBound s ∧ x.regs P.baseReg = base) (rep_supported : ∀ {s : D.State} {x x' : WordRAM.Resizable.RData r_ds}, (∀ (i : Fin r_ds), P.input i = false → x'.regs i = x.regs i) → x'.frontier = x.frontier → (∀ (a : ℕ), base ≤ a → a < x.frontier → x'.mem a = x.mem a) → WordRAM.Resizable.RData.Bounded w x' → rep s x → rep s x') (potential_supported : ∀ {s : D.State} {x x' : WordRAM.Resizable.RData r_ds}, (∀ (i : Fin r_ds), P.input i = false → x'.regs i = x.regs i) → x'.frontier = x.frontier → (∀ (a : ℕ), base ≤ a → a < x.frontier → x'.mem a = x.mem a) → rep s x → potential x' = potential 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) (init_exec : ∀ {x₀ : WordRAM.Resizable.RData r_ds}, WordRAM.Resizable.RData.Bounded w x₀ → x₀.frontier = base → (∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) → WordRAM.Fits w (base + spaceBound s₀) → ∃ (y : WordRAM.Resizable.RData r_ds), (WordRAM.Resizable.RDemonicExec w (base + spaceBound s₀) P.initCode x₀ initTime fun (x : WordRAM.Resizable.RData r_ds) => x = y) ∧ rep s₀ y ∧ potential y ≤ initPotential ∧ ∀ addr < base, y.mem addr = x₀.mem addr) (step_exec : ∀ {s : D.State} {x : WordRAM.Resizable.RData r_ds} (o : D.Op), rep s x → D.valid s o → argMatch o x.regs → WordRAM.Fits w (base + peakSpaceBound s o) → ∃ (y : WordRAM.Resizable.RData r_ds) (n : ℕ), (WordRAM.Resizable.RDemonicExec w (base + peakSpaceBound s o) P.code x n fun (x : WordRAM.Resizable.RData r_ds) => x = y) ∧ decode o y.regs = some (D.stepFn s o).2 ∧ rep (D.stepFn s o).1 y ∧ (∀ addr < base, y.mem addr = x.mem addr) ∧ n + potential y ≤ charge s o + potential x) :
StateTransitionImpl P D w base params s₀

Construct a StateTransitionImpl for a deterministic specification ([D.HasStepFn f]) from a functional step_exec proof at D.stepFn s o. Defined as abbrev so D.Result reduces transparently without unfolding StateTransitionSpec.ofFn.

def Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.mapSimulates {B B' : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (φ : B.Simulates B') (C : StateTransitionImpl P D w base params s₀) :

Lift a StateTransitionImpl certificate along any defined-evaluation basis simulation.

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

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

def Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.prepare {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (o : D.Op) (x : WordRAM.Resizable.RData r_ds) :

Prepare registers for operation o on x.

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.prepare_bounded {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) {s : D.State} {o : D.Op} {x : WordRAM.Resizable.RData r_ds} (hx : WordRAM.Resizable.RData.Bounded w x) (hv : D.valid s o) :
theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.prepare_rep {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) {s : D.State} {o : D.Op} {x : WordRAM.Resizable.RData r_ds} (hr : C.rep s x) (hv : D.valid s o) :
C.rep s (C.prepare o x)
theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.prepare_potential {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) {s : D.State} {o : D.Op} {x : WordRAM.Resizable.RData r_ds} (hr : C.rep s x) :
theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.prepare_argMatch {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (o : D.Op) (x : WordRAM.Resizable.RData r_ds) :
C.argMatch o (C.prepare o x).regs
theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.frame_caller {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) {s : D.State} {x x' : WordRAM.Resizable.RData r_ds} (hregs : ∀ (i : Fin r_ds), P.input i = false → x'.regs i = x.regs i) (hfr : x'.frontier = x.frontier) (hmem : ∀ (a : ℕ), base ≤ a → a < x.frontier → x'.mem a = x.mem a) (hb : WordRAM.Resizable.RData.Bounded w x') (hr : C.rep s x) :
C.rep s x' ∧ C.potential x' = C.potential x

Caller-frame preservation: any caller step that preserves persistent registers, frontier, [base, x.frontier), and RData.Bounded w preserves C.rep and C.potential.

Trajectory-relative multi-operation execution and flat RProgram compilation #

inductive Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.ExecSteps {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) :
D.State → WordRAM.Resizable.RData r_ds → List D.Op → D.Transcript → D.State → WordRAM.Resizable.RData r_ds → ℕ → Prop

Structured multi-operation execution relation C.ExecSteps s x ops tr s_fin z t_ops over RDemonicExec: at every step o, P.code executes within peak frontier base + C.peakSpaceBound s o, witnesses a valid transition D.step s o s₁ a with decoded output C.decode o y.regs = some a, preserves C.rep (hence resting frontier base ≤ y.frontier ≤ base + C.spaceBound s₁ and y.regs P.baseReg = base), and preserves caller memory [0, base).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.ExecSteps.caller_mem {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {C : StateTransitionImpl P D w base params s₀} {s s_fin : D.State} {x z : WordRAM.Resizable.RData r_ds} {ops : List D.Op} {tr : D.Transcript} {t_ops : ℕ} (h : C.ExecSteps s x ops tr s_fin z t_ops) (addr : ℕ) :
addr < base → z.mem addr = x.mem addr

ExecSteps preserves caller memory [0, base) across the entire operation sequence.

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.steps_amortized {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (ops : List D.Op) {s : D.State} {x : WordRAM.Resizable.RData r_ds} :
C.rep s x → D.ValidOpSeq s ops → PeakFitsOpSeq w base C.peakSpaceBound s ops → ∃ (tr : D.Transcript) (s_fin : D.State) (z : WordRAM.Resizable.RData r_ds) (t_ops : ℕ), C.ExecSteps s x ops tr s_fin z t_ops ∧ tr.ops = ops ∧ D.ValidTranscript s tr s_fin ∧ C.rep s_fin z ∧ (∀ addr < base, z.mem addr = x.mem addr) ∧ t_ops + C.potential z ≤ D.totalCostTranscript C.charge s tr + C.potential x

Trajectory-relative multi-operation amortized theorem (steps_amortized). Requires PeakFitsOpSeq w base C.peakSpaceBound s ops only along states reached by ops from s, never globally over all D.State.

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.seq_amortized {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) {x₀ : WordRAM.Resizable.RData r_ds} (ops : List D.Op) (hx₀ : WordRAM.Resizable.RData.Bounded w x₀) (hfr₀ : x₀.frontier = base) (hpar : ∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) (hfit₀ : WordRAM.Fits w (base + C.spaceBound s₀)) (hv : D.ValidOpSeq s₀ ops) (hfit_ops : PeakFitsOpSeq w base C.peakSpaceBound s₀ ops) :
∃ (y₀ : WordRAM.Resizable.RData r_ds) (tr : D.Transcript) (s_fin : D.State) (z : WordRAM.Resizable.RData r_ds) (t_ops : ℕ), (WordRAM.Resizable.RDemonicExec w (base + C.spaceBound s₀) P.initCode x₀ C.initTime fun (x : WordRAM.Resizable.RData r_ds) => x = y₀) ∧ C.rep s₀ y₀ ∧ (∀ addr < base, y₀.mem addr = x₀.mem addr) ∧ C.ExecSteps s₀ y₀ ops tr s_fin z t_ops ∧ tr.ops = ops ∧ D.ValidTranscript s₀ tr s_fin ∧ C.rep s_fin z ∧ (∀ addr < base, z.mem addr = x₀.mem addr) ∧ C.initTime + t_ops + C.potential z ≤ C.initTime + C.initPotential + D.totalCostTranscript C.charge s₀ tr

End-to-end deterministic amortized sequence theorem (seq_amortized).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.steps_amortized_ofFn {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (C : StateTransitionImpl P D w base params s₀) (ops : List D.Op) {s : D.State} {x : WordRAM.Resizable.RData r_ds} (hr : C.rep s x) (hv : D.ValidHistory s ops) (hfit : PeakFitsHistory w base C.peakSpaceBound s ops) :
∃ (z : WordRAM.Resizable.RData r_ds) (t_ops : ℕ), C.ExecSteps s x ops (D.canonicalTranscript s ops) (D.run s ops).1 z t_ops ∧ C.rep (D.run s ops).1 z ∧ (∀ addr < base, z.mem addr = x.mem addr) ∧ t_ops + C.potential z ≤ D.totalCost C.charge s ops + C.potential x

Functional-specification specialization of steps_amortized ([D.HasStepFn f]).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.seq_amortized_ofFn {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (C : StateTransitionImpl P D w base params s₀) {x₀ : WordRAM.Resizable.RData r_ds} (ops : List D.Op) (hx₀ : WordRAM.Resizable.RData.Bounded w x₀) (hfr₀ : x₀.frontier = base) (hpar : ∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) (hfit₀ : WordRAM.Fits w (base + C.spaceBound s₀)) (hv : D.ValidHistory s₀ ops) (hfit_ops : PeakFitsHistory w base C.peakSpaceBound s₀ ops) :
∃ (y₀ : WordRAM.Resizable.RData r_ds) (z : WordRAM.Resizable.RData r_ds) (t_ops : ℕ), (WordRAM.Resizable.RDemonicExec w (base + C.spaceBound s₀) P.initCode x₀ C.initTime fun (x : WordRAM.Resizable.RData r_ds) => x = y₀) ∧ C.rep s₀ y₀ ∧ (∀ addr < base, y₀.mem addr = x₀.mem addr) ∧ C.ExecSteps s₀ y₀ ops (D.canonicalTranscript s₀ ops) (D.run s₀ ops).1 z t_ops ∧ C.rep (D.run s₀ ops).1 z ∧ (∀ addr < base, z.mem addr = x₀.mem addr) ∧ C.initTime + t_ops + C.potential z ≤ C.initTime + C.initPotential + D.totalCost C.charge s₀ ops

End-to-end deterministic amortized sequence theorem for functional specifications (seq_amortized_ofFn).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.initProg_exec {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (out : Fin r_ds) {x₀ : WordRAM.Resizable.RData r_ds} (hx₀ : WordRAM.Resizable.RData.Bounded w x₀) (hfr₀ : x₀.frontier = base) (hpar : ∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) (hfit₀ : WordRAM.Fits w (base + C.spaceBound s₀)) :
∃ (y₀ : WordRAM.Resizable.RData r_ds), WordRAM.Resizable.ExecRProgramDist w (P.initProg out) out x₀ (PMF.pure y₀) (↑(C.initTime + 1)) (base + C.spaceBound s₀) ∧ C.rep s₀ y₀ ∧ C.potential y₀ ≤ C.initPotential ∧ ∀ addr < base, y₀.mem addr = x₀.mem addr

Compile P.initCode to the flat RProgram specification ExecRProgramDist (P.initProg out).

inductive Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.ExecProgramSteps {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (p_op : WordRAM.Resizable.RProgram B r_ds) (out : Fin r_ds) :
D.State → WordRAM.Resizable.RData r_ds → List D.Op → D.Transcript → D.State → WordRAM.Resizable.RData r_ds → ℕ → Prop

Sequential flat-RProgram execution relation C.ExecProgramSteps p_op out over ExecRProgramDist: ties every post-state y to the operational halting distribution of p_op at .halted (y.regs out) y, enforcing PeakFrontierLe (base + C.peakSpaceBound s o), output decoding, C.rep, and caller-prefix [0, base) preservation at every step.

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.ExecSteps.toExecProgramSteps {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {C : StateTransitionImpl P D w base params s₀} (out : Fin r_ds) {s s_fin : D.State} {x z : WordRAM.Resizable.RData r_ds} {ops : List D.Op} {tr : D.Transcript} {t_ops : ℕ} (h : C.ExecSteps s x ops tr s_fin z t_ops) :
C.ExecProgramSteps (P.opProg out) out s x ops tr s_fin z (t_ops + ops.length)

Compile any structured C.ExecSteps derivation to C.ExecProgramSteps (P.opProg out) out, charging + 1 instruction per operation for the trailing halt out.

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.seq_program_amortized {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (out : Fin r_ds) {x₀ : WordRAM.Resizable.RData r_ds} (ops : List D.Op) (hx₀ : WordRAM.Resizable.RData.Bounded w x₀) (hfr₀ : x₀.frontier = base) (hpar : ∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) (hfit₀ : WordRAM.Fits w (base + C.spaceBound s₀)) (hv : D.ValidOpSeq s₀ ops) (hfit_ops : PeakFitsOpSeq w base C.peakSpaceBound s₀ ops) :
∃ (y₀ : WordRAM.Resizable.RData r_ds) (tr : D.Transcript) (s_fin : D.State) (z : WordRAM.Resizable.RData r_ds) (t_prog : ℕ), WordRAM.Resizable.ExecRProgramDist w (P.initProg out) out x₀ (PMF.pure y₀) (↑(C.initTime + 1)) (base + C.spaceBound s₀) ∧ C.rep s₀ y₀ ∧ (∀ addr < base, y₀.mem addr = x₀.mem addr) ∧ C.ExecProgramSteps (P.opProg out) out s₀ y₀ ops tr s_fin z t_prog ∧ tr.ops = ops ∧ D.ValidTranscript s₀ tr s_fin ∧ C.rep s_fin z ∧ (∀ addr < base, z.mem addr = x₀.mem addr) ∧ C.initTime + 1 + t_prog + C.potential z ≤ C.initTime + 1 + C.initPotential + D.totalCostTranscript (fun (st : D.State) (o : D.Op) => C.charge st o + 1) s₀ tr

End-to-end flat-RProgram amortized sequence theorem (seq_program_amortized).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.seq_program_amortized_ofFn {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} {f : D.State → (o : D.Op) → D.State × D.Result o} [D.HasStepFn f] (C : StateTransitionImpl P D w base params s₀) (out : Fin r_ds) {x₀ : WordRAM.Resizable.RData r_ds} (ops : List D.Op) (hx₀ : WordRAM.Resizable.RData.Bounded w x₀) (hfr₀ : x₀.frontier = base) (hpar : ∀ (j : Fin k_init), x₀.regs (P.initParams j) = params j) (hfit₀ : WordRAM.Fits w (base + C.spaceBound s₀)) (hv : D.ValidHistory s₀ ops) (hfit_ops : PeakFitsHistory w base C.peakSpaceBound s₀ ops) :
∃ (y₀ : WordRAM.Resizable.RData r_ds) (z : WordRAM.Resizable.RData r_ds) (t_prog : ℕ), WordRAM.Resizable.ExecRProgramDist w (P.initProg out) out x₀ (PMF.pure y₀) (↑(C.initTime + 1)) (base + C.spaceBound s₀) ∧ C.rep s₀ y₀ ∧ (∀ addr < base, y₀.mem addr = x₀.mem addr) ∧ C.ExecProgramSteps (P.opProg out) out s₀ y₀ ops (D.canonicalTranscript s₀ ops) (D.run s₀ ops).1 z t_prog ∧ C.rep (D.run s₀ ops).1 z ∧ (∀ addr < base, z.mem addr = x₀.mem addr) ∧ C.initTime + 1 + t_prog + C.potential z ≤ C.initTime + 1 + C.initPotential + D.totalCost (fun (st : D.State) (o : D.Op) => C.charge st o + 1) s₀ ops

End-to-end flat-RProgram amortized sequence theorem for functional specifications (seq_program_amortized_ofFn).

theorem Cslib.DataStructure.WordRAM.Resizable.StateTransitionImpl.not_execProgramSteps_halt {B : WordRAM.Basis} {r_ds k_init w base : ℕ} {P : SubroutineCode B r_ds k_init} {D : StateTransitionSpec} {params : Fin k_init → ℕ} {s₀ : D.State} (C : StateTransitionImpl P D w base params s₀) (out : Fin r_ds) {s s_fin : D.State} {x z : WordRAM.Resizable.RData r_ds} {o : D.Op} {ops : List D.Op} {tr : D.Transcript} {t_prog : ℕ} (hbad : ∀ (s₁ : D.State) (a : D.Result o), D.step s o s₁ a → ¬(C.decode o (C.prepare o x).regs = some a ∧ C.rep s₁ (C.prepare o x))) :
¬C.ExecProgramSteps [WordRAM.Resizable.RInstr.halt out] out s x (o :: ops) tr s_fin z t_prog

.halt-rejection soundness lemma (not_execProgramSteps_halt): a 1-instruction [.halt out] stub cannot satisfy C.ExecProgramSteps [.halt out] out on (o :: ops) whenever every valid post-state (s₁, a) from (s, o) is incompatible with the unmodified prepared state C.prepare o x.