Documentation

CslibFrontier.Computability.PointerMachine.WordRAM.Correctness

Correctness of pointer-machine compilation to word RAM #

Given implementations of the scalar primitives, the compiler transfers valid pointer-machine runs to the standard word RAM. All represented data and addresses must fit the chosen word width throughout the source run; scalar calls must satisfy their implementations' headroom conditions. The target starts with a represented source state, so input preparation is not charged here.

Scalars.runs_compile preserves the complete represented state with constant overhead per source instruction. Scalars.executes_compile includes the final halt and retains the represented final state. The target halt returns zero; the machine's data and heap remain in the final state. These are forward simulation results, not a correspondence between source and target faults.

theorem Cslib.PointerMachine.WordRAM.Scalars.length_compile {M : Model} {L : Layout} (S : Scalars M L) (code : List (Instr M L)) :
List.length (S.compile code) = S.blockSize code * code.length

The compiled program occupies a fixed number of target slots per source instruction.

theorem Cslib.PointerMachine.WordRAM.Scalars.runs_compile {M : Model} {L : Layout} (S : Scalars M L) {w n : ℕ} {code : List (Instr M L)} {x x' : State M L} {y : WordRAM.Data (regCount L)} (hv : x.Valid) (hy : Repr S.encode x y) (hr : Runs code x x' n) (hfit : ∀ (z : State M L) (m : ℕ), Runs code x z m → m ≤ n → Fits S.encode w z) (hsafe : ∀ (z : State M L) (m : ℕ), Runs code x z m → m < n → ∀ (i : Instr M L), code[z.pc]? = some i → S.Safe w z i) :
∃ (z : WordRAM.Data (regCount L)), ∃ k ≤ S.overhead code * n, WordRAM.Runs w (S.compile code) { pc := S.blockSize code * x.pc, data := y } { pc := S.blockSize code * x'.pc, data := z } k ∧ Repr S.encode x' z

Compile a run from represented input, preserving the complete final state. The overhead is constant for a fixed source program and scalar implementation. Fitting words are required at every source boundary; scalar admissibility is required only for instructions that execute.

theorem Cslib.PointerMachine.WordRAM.Scalars.executes_compile {M : Model} {L : Layout} (S : Scalars M L) {w time : ℕ} {code : List (Instr M L)} {x x' : State M L} (hv : x.Valid) (he : Executes code x x' time) (hfit : ∀ (z : State M L) (m : ℕ), Runs code x z m → m < time → Fits S.encode w z) (hsafe : ∀ (z : State M L) (m : ℕ), Runs code x z m → m + 1 < time → ∀ (i : Instr M L), code[z.pc]? = some i → S.Safe w z i) :
∃ (z : WordRAM.Data (regCount L)) (k : ℕ), k + 1 ≤ S.overhead code * time ∧ WordRAM.Runs w (S.compile code) { pc := S.blockSize code * x.pc, data := encodeState S.encode x } { pc := S.blockSize code * x'.pc, data := z } k ∧ Repr S.encode x' z ∧ WordRAM.step w (S.compile code) { pc := S.blockSize code * x'.pc, data := z } = WordRAM.Outcome.halt 0

A successful source execution yields a target run ending at a represented final state and then halting with zero. The bound includes that halt. The target starts with the canonical encodeState representation; constructing this preencoded input is not charged here.