Standard Form Programs #
This file defines standard-form programs (those with bounded jump targets) and proves their execution properties.
Main definitions #
Program.IsStandardForm: all jump targets are bounded by program lengthProgram.toStandardForm: convert a program to standard form
Main results #
straight_line_IsStandardForm: straight-line programs are standard formHalts.toStandardForm_iff: halting equivalence with normalized programs
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
- p.IsStandardForm = ā instr ā p, Cslib.URM.Instr.JumpsBoundedBy (List.length p) instr
Instances For
Equations
- p.instDecidableIsStandardForm = inferInstanceAs (Decidable (ā instr ā p, Cslib.URM.Instr.JumpsBoundedBy (List.length p) instr))
Convert a program to standard form by capping all jump targets at the program length.
Equations
Instances For
toStandardForm preserves program length.
toStandardForm produces a standard form program.
Accessing an instruction in toStandardForm gives the capJump'd instruction.
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.
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).
Forward halting: if p reaches a halted state, p.toStandardForm reaches a halted state with the same registers.
Forward halting theorem.
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).
Reverse halting: if p.toStandardForm reaches a halted state, p reaches a halted state with the same registers.
Reverse halting theorem.
Halting equivalence: original halts iff standard form halts.
eval Preservation #
Registers preservation: both reach states with the same registers.
eval equality: both programs produce the same partial result.
A program is equivalent to its standard form.