Documentation

CslibFrontier.Computability.WordRAM.FlatEndpoint

Flat-program endpoints and wide-width prefix envelopes #

Structured word-RAM proofs establish bounded-time executions ExecWithin w c x y T on Code B r, while final machine endpoints speak about flat instruction lists c.program out, halting runs Executes, step-indexed prefixes Runs, and physical-width-independent memory envelopes across all wider word sizes W ≥ w.

This module packages that transition once (alongside width monotonicity Data.Bounded.mono and the [simp] length equation Code.length_program):

Main definitions #

Main results #

theorem Cslib.WordRAM.Data.Bounded.mono {r w W : ℕ} {x : Data r} (hx : Bounded w x) (hw : w ≤ W) :

Machine data bounded at word size w remains bounded at every larger word size W.

@[simp]
theorem Cslib.WordRAM.Code.length_program {B : Basis} {r : ℕ} (c : Code B r) (out : Fin r) :
List.length (c.program out) = c.size + 1

Compiling a structured program appends one halt instruction to its assembled body.

theorem Cslib.WordRAM.ExecWithin.to_program {B : Basis} {r W T : ℕ} {c : Code B r} {x y : Data r} (he : ExecWithin W c x y T) (out : Fin r) :
∃ n ≤ T, Runs W (c.program out) { pc := 0, data := x } { pc := c.size, data := y } n ∧ Executes W (c.program out) { pc := 0, data := x } (y.regs out) (n + 1)

Lift a bounded structured execution to a flat prefix Runs reaching c.size and a halting Executes run charging one additional halt instruction.

theorem Cslib.WordRAM.ExecWithin.to_program_init {B : Basis} {r W T : ℕ} {c : Code B r} {input : List ℕ} {y : Data r} (he : ExecWithin W c (Data.init input) y T) (hi : InputFits W input) (out : Fin r) :
∃ n ≤ T, Runs W (c.program out) (State.init input) { pc := c.size, data := y } n ∧ Executes W (c.program out) (State.init input) (y.regs out) (n + 1) ∧ Data.Bounded W y

Lift an initialized bounded structured execution at an admitted input width to flat Runs, halting Executes, and word-bounded final data.

theorem Cslib.WordRAM.ExecWithin.prefix_bounds_program {B : Basis} {r w W P T k : ℕ} {c : Code B r} {out : Fin r} {x y : Data r} {s : State r} (he : ExecWithin w c x y T) (hc : ¬c.ReadsWidth) (hw : w ≤ W) (hx : Data.Bounded w x) (hP : 2 ^ w ≤ P) (hr : Runs W (c.program out) { pc := 0, data := x } s k) :
(∀ (i : Fin r), s.data.regs i < P) ∧ (∀ (a : ℕ), s.data.mem a < P) ∧ ∀ (a : ℕ), P ≤ a → s.data.mem a = x.mem a

A structured execution of a width-independent program at minimum width w bounds every reachable prefix of c.program out at any wider physical width W ≥ w by P (2 ^ w ≤ P), preserving caller memory from P onward.

theorem Cslib.WordRAM.ExecWithin.prefix_bounds_program_init {B : Basis} {r w W P T k : ℕ} {c : Code B r} {out : Fin r} {input : List ℕ} {y : Data r} {s : State r} (he : ExecWithin w c (Data.init input) y T) (hc : ¬c.ReadsWidth) (hw : w ≤ W) (hi : InputFits w input) (hP : 2 ^ w ≤ P) (hr : Runs W (c.program out) (State.init input) s k) :
(∀ (i : Fin r), s.data.regs i < P) ∧ (∀ (a : ℕ), s.data.mem a < P) ∧ ∀ (a : ℕ), P ≤ a → s.data.mem a = 0

Initialized form of ExecWithin.prefix_bounds_program: every wider reachable prefix of c.program out has words below P and zero memory from P onward.

structure Cslib.WordRAM.FlatEndpoint {B : Basis} {r : ℕ} {α : Type u_1} (code : Code B r) (out : Fin r) (wMin wordEnv : α → ℕ) (inp : α → List ℕ) (time : α → ℕ) (post : α → Data r → Prop) :

Certificate that a width-independent structured program code halts from State.init (inp a) at minimum width wMin a within time a instructions in a state satisfying post a, with minimum-width word universe 2 ^ wMin a bounded by wordEnv a.

  • not_readsWidth : ¬code.ReadsWidth

    The structured program never inspects the physical word width.

  • inputFits_min (a : α) : InputFits (wMin a) (inp a)

    Every instance's encoded input fits at its minimum admitted width.

  • two_pow_wMin_le (a : α) : 2 ^ wMin a ≤ wordEnv a

    The minimum width's word universe is bounded by the physical-width-independent envelope.

  • exec_min (a : α) : ∃ (y : Data r), ExecWithin (wMin a) code (Data.init (inp a)) y (time a) ∧ post a y

    At wMin a, the structured program reaches a state satisfying post a within time a.

theorem Cslib.WordRAM.FlatEndpoint.program_not_readsWidth {B : Basis} {r : ℕ} {α : Type u_1} {code : Code B r} {out : Fin r} {wMin wordEnv : α → ℕ} {inp : α → List ℕ} {time : α → ℕ} {post : α → Data r → Prop} (E : FlatEndpoint code out wMin wordEnv inp time post) :

The compiled flat program never inspects the physical word width.

theorem Cslib.WordRAM.FlatEndpoint.inputFits {B : Basis} {r : ℕ} {α : Type u_1} {code : Code B r} {out : Fin r} {wMin wordEnv : α → ℕ} {inp : α → List ℕ} {time : α → ℕ} {post : α → Data r → Prop} (E : FlatEndpoint code out wMin wordEnv inp time post) (a : α) {W : ℕ} (hW : wMin a ≤ W) :
InputFits W (inp a)

Every physical width W ≥ wMin a admits the encoded input inp a.

theorem Cslib.WordRAM.FlatEndpoint.runs {B : Basis} {r : ℕ} {α : Type u_1} {code : Code B r} {out : Fin r} {wMin wordEnv : α → ℕ} {inp : α → List ℕ} {time : α → ℕ} {post : α → Data r → Prop} (E : FlatEndpoint code out wMin wordEnv inp time post) (a : α) {W : ℕ} (hW : wMin a ≤ W) :
∃ (y : Data r), ∃ n ≤ time a, Runs W (code.program out) (State.init (inp a)) { pc := code.size, data := y } n ∧ Executes W (code.program out) (State.init (inp a)) (y.regs out) (n + 1) ∧ Data.Bounded W y ∧ post a y

At every physical width W ≥ wMin a, the compiled flat program runs from State.init (inp a) to a W-bounded terminal state satisfying post a within time a instructions and halts in one further instruction.

theorem Cslib.WordRAM.FlatEndpoint.prefix_bounds {B : Basis} {r : ℕ} {α : Type u_1} {code : Code B r} {out : Fin r} {wMin wordEnv : α → ℕ} {inp : α → List ℕ} {time : α → ℕ} {post : α → Data r → Prop} (E : FlatEndpoint code out wMin wordEnv inp time post) (a : α) {W k : ℕ} {s : State r} (hW : wMin a ≤ W) (hr : Runs W (code.program out) (State.init (inp a)) s k) :
(∀ (i : Fin r), s.data.regs i < wordEnv a) ∧ (∀ (q : ℕ), s.data.mem q < wordEnv a) ∧ ∀ (q : ℕ), wordEnv a ≤ q → s.data.mem q = 0

At every physical width W ≥ wMin a, every reachable prefix of code.program out from State.init (inp a) has register and memory words below wordEnv a and zero memory from wordEnv a onward.