Documentation

CslibFrontier.Computability.PointerMachine.Simulation

Execution through heap embeddings #

Injectively embedding a valid heap in a larger valid heap preserves and reflects execution, with the same program and exact instruction count. Allocation extends the initial address map; it never changes the images of previously allocated source records. Extra target records need not be absent, blank, or disconnected from the embedded records.

Main results #

This is a theorem about the machine in Defs, not a simulation of Tarjan's undefined-value traps.

theorem Cslib.PointerMachine.State.Embeds.step {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x x' y : State M L} (h : Embeds f x y) (hs : PointerMachine.step code x = some x') :
∃ (y' : State M L) (g : ℕ → ℕ), PointerMachine.step code y = some y' ∧ Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

A source step is matched by one target step and an extension of the address map.

theorem Cslib.PointerMachine.State.Embeds.step_back {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x y y' : State M L} (h : Embeds f x y) (hs : PointerMachine.step code y = some y') :
∃ (x' : State M L) (g : ℕ → ℕ), PointerMachine.step code x = some x' ∧ Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

A target step also has a source step; extra target records cannot change control flow.

theorem Cslib.PointerMachine.Runs.embed {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x x' y : State M L} {n : ℕ} (hr : Runs code x x' n) (h : State.Embeds f x y) :
∃ (y' : State M L) (g : ℕ → ℕ), Runs code y y' n ∧ State.Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

Transport a run into a larger heap, preserving its exact length and all old address images.

theorem Cslib.PointerMachine.Runs.of_embed {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x y y' : State M L} {n : ℕ} (hr : Runs code y y' n) (h : State.Embeds f x y) :
∃ (x' : State M L) (g : ℕ → ℕ), Runs code x x' n ∧ State.Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

Reflect a target run back to the source heap, retaining the same number of instructions.

theorem Cslib.PointerMachine.Executes.embed {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x x' y : State M L} {time : ℕ} (hr : Executes code x x' time) (h : State.Embeds f x y) :
∃ (y' : State M L) (g : ℕ → ℕ), Executes code y y' time ∧ State.Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

A successful execution transports through a heap embedding, including the halt charge.

theorem Cslib.PointerMachine.Executes.of_embed {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x y y' : State M L} {time : ℕ} (hr : Executes code y y' time) (h : State.Embeds f x y) :
∃ (x' : State M L) (g : ℕ → ℕ), Executes code x x' time ∧ State.Embeds g x' y' ∧ ∀ a < x.heap.length, g a = f a

A successful target execution reflects to the source, with identical cost.

theorem Cslib.PointerMachine.State.Embeds.halts_iff {M : Model} {L : Layout} {f : ℕ → ℕ} {code : List (Instr M L)} {x y : State M L} {time : ℕ} (h : Embeds f x y) :
(∃ (x' : State M L), Executes code x x' time) ↔ ∃ (y' : State M L), Executes code y y' time

Heap placement and extra target records cannot change successful termination or its cost.