Documentation

Cslib.Computability.URM.StandardForm

Standard Form Programs #

This file defines standard-form programs (those with bounded jump targets) and proves their execution properties.

Main definitions #

Main results #

Standard Form Definitions #

A program is in standard form if all jump targets are bounded by the program length. Jumps can target any instruction (0..length-1) or the "virtual halt" position (length).

Equations
Instances For

    Convert a program to standard form by capping all jump targets at the program length.

    Equations
    Instances For
      @[simp]

      toStandardForm preserves program length.

      toStandardForm produces a standard form program.

      Accessing an instruction in toStandardForm gives the capJump'd instruction.

      @[simp]

      toStandardForm is idempotent: applying it twice equals applying it once.

      Standard Form Properties #

      Straight-line programs are in standard form.

      Bisimulation #

      p and p.toStandardForm are bisimilar: each step in one program corresponds to a step in the other that either reaches the same state or reaches a halted state with the same registers. This bisimulation implies functional equivalence (eval_toStandardForm). The key insight is that jumps with target q > p.length land in halted states in both programs.

      theorem Cslib.URM.Step.toStandardForm {p : Program} {s s' : State} (hstep : Step p s s') :
      Step p.toStandardForm s s' ∨ s'.isHalted p ∧ ∃ (sā‚‚ : State), Step p.toStandardForm s sā‚‚ ∧ sā‚‚.isHalted p.toStandardForm ∧ s'.regs = sā‚‚.regs

      Forward step correspondence: if p steps from s to s', then either: (1) p.toStandardForm steps from s to s' (same step), or (2) s' is halted in p, and p.toStandardForm steps to a state that is also halted with the same registers (this only happens for jumps with unbounded targets).

      theorem Cslib.URM.Steps.toStandardForm_halts {p : Program} {s s' : State} (hsteps : Steps p s s') (hhalted : s'.isHalted p) :
      ∃ (sā‚‚ : State), Steps p.toStandardForm s sā‚‚ ∧ sā‚‚.isHalted p.toStandardForm ∧ s'.regs = sā‚‚.regs

      Forward halting: if p reaches a halted state, p.toStandardForm reaches a halted state with the same registers.

      theorem Cslib.URM.Halts.toStandardForm {p : Program} {inputs : List ā„•} (h : Halts p inputs) :

      Forward halting theorem.

      theorem Cslib.URM.Step.from_toStandardForm {p : Program} {s s' : State} (hstep : Step p.toStandardForm s s') :
      Step p s s' ∨ s'.isHalted p.toStandardForm ∧ ∃ (sā‚‚ : State), Step p s sā‚‚ ∧ sā‚‚.isHalted p ∧ s'.regs = sā‚‚.regs

      Reverse step correspondence: if p.toStandardForm steps from s to s', then either: (1) p steps from s to s' (same step), or (2) s' is halted in p.toStandardForm, and p steps to a state that is also halted with the same registers (this only happens for jumps with unbounded targets).

      theorem Cslib.URM.Steps.from_toStandardForm_halts {p : Program} {s s' : State} (hsteps : Steps p.toStandardForm s s') (hhalted : s'.isHalted p.toStandardForm) :
      ∃ (sā‚‚ : State), Steps p s sā‚‚ ∧ sā‚‚.isHalted p ∧ s'.regs = sā‚‚.regs

      Reverse halting: if p.toStandardForm reaches a halted state, p reaches a halted state with the same registers.

      theorem Cslib.URM.Halts.of_toStandardForm {p : Program} {inputs : List ā„•} (h : Halts p.toStandardForm inputs) :
      Halts p inputs

      Reverse halting theorem.

      Halting equivalence: original halts iff standard form halts.

      eval Preservation #

      theorem Cslib.URM.evalState_toStandardForm_regs {p : Program} {inputs : List ā„•} (hp : (evalState p inputs).Dom) (hq : (evalState p.toStandardForm inputs).Dom) :
      ((evalState p inputs).get hp).regs = ((evalState p.toStandardForm inputs).get hq).regs

      Registers preservation: both reach states with the same registers.

      theorem Cslib.URM.eval_toStandardForm {p : Program} {inputs : List ā„•} :
      eval p inputs = eval p.toStandardForm inputs

      eval equality: both programs produce the same partial result.

      A program is equivalent to its standard form.