URM Execution Semantics #
Single-step and multi-step execution semantics for URMs.
Main definitions #
URM.Step: Single-step execution relationURM.Steps: Multi-step execution (reflexive-transitive closure ofStep)URM.Halts: A program halts on given inputsURM.Diverges: A program diverges on given inputsURM.HaltsWithResult: A program halts on given inputs with a specific result
Bridge lemmas:
isHalted_iff_normal:s.isHalted p ↔ Relation.Normal (Step p) shalts_iff_normalizable:Halts p inputs ↔ Relation.Normalizable (Step p) (State.init inputs)step_confluent: The step relation is confluent (follows from determinism)
Notation (scoped to URM namespace) #
Standard computability theory notation:
p ↓ inputs— programphalts on inputsp ↑ inputs— programpdiverges on inputsp ↓ inputs ≫ result— programphalts on inputs with result in R[0]
Main results #
Step.deterministic: The step relation is deterministicstep_confluent: The step relation is confluent (from determinism)haltsWithResult_iff_eval:p ↓ inputs ≫ result ↔ eval p inputs = Part.some result
Single-step execution relation for URMs.
Each constructor corresponds to one of the four instruction types:
zero: ExecuteZ n(set register n to 0)succ: ExecuteS n(increment register n)transfer: ExecuteT m n(copy register m to register n)jump_eq: ExecuteJ m n qwhen registers m and n are equal (jump to q)jump_ne: ExecuteJ m n qwhen registers m and n differ (proceed to next)
- zero {p : Program} {s : State} {n : ℕ} (h : p[s.pc]? = some (Instr.Z n)) : Step p s { pc := s.pc + 1, regs := s.regs.write n 0 }
- succ {p : Program} {s : State} {n : ℕ} (h : p[s.pc]? = some (Instr.S n)) : Step p s { pc := s.pc + 1, regs := s.regs.write n (s.regs.read n + 1) }
- transfer {p : Program} {s : State} {m n : ℕ} (h : p[s.pc]? = some (Instr.T m n)) : Step p s { pc := s.pc + 1, regs := s.regs.write n (s.regs.read m) }
- jump_eq {p : Program} {s : State} {m n q : ℕ} (h : p[s.pc]? = some (Instr.J m n q)) (heq : s.regs.read m = s.regs.read n) : Step p s { pc := q, regs := s.regs }
- jump_ne {p : Program} {s : State} {m n q : ℕ} (h : p[s.pc]? = some (Instr.J m n q)) (hne : s.regs.read m ≠ s.regs.read n) : Step p s { pc := s.pc + 1, regs := s.regs }
Instances For
Multi-step execution: the reflexive-transitive closure of Step.
Equations
Instances For
A halted state has no successor in the step relation.
A single step preserves registers not written to by the current instruction.
This is a fundamental property of URM execution: each instruction modifies at most one register (Z, S, T write to one register; J writes to none).
Step Properties #
A state is halted iff it is normal (has no successor) in the reduction system.
The step relation is confluent.
For a deterministic relation, any two execution paths from the same state must follow the same sequence of steps, so if both reach some state, they reach the same state. We prove this directly rather than via Diamond since Diamond requires the relation to always have successors.
If two halted states are reachable from the same start, they are equal.
This follows from confluence: since Step p is confluent and both s₁ and s₂
are normal forms reachable from init, they must be equal.
A program halts on given inputs if execution reaches a halted state.
This is equivalent to (Step p).Normalizable (State.init inputs) —
see halts_iff_normalizable.
Equations
- Cslib.URM.Halts p inputs = ∃ (s : Cslib.URM.State), Cslib.URM.Steps p (Cslib.URM.State.init inputs) s ∧ s.isHalted p
Instances For
Halting is equivalent to normalizability in the reduction system.
A program diverges on given inputs if it does not halt.
Equations
- Cslib.URM.Diverges p inputs = ¬Cslib.URM.Halts p inputs
Instances For
A program halts on given inputs with a specific result in R[0].
Equations
- Cslib.URM.HaltsWithResult p inputs result = ∃ (s : Cslib.URM.State), Cslib.URM.Steps p (Cslib.URM.State.init inputs) s ∧ s.isHalted p ∧ s.regs.output = result
Instances For
Notation for halting: p ↓ inputs means program p halts on inputs.
Equations
- Cslib.URM.«term_↓_» = Lean.ParserDescr.trailingNode `Cslib.URM.«term_↓_» 50 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ↓ ") (Lean.ParserDescr.cat `term 51))
Instances For
Notation for divergence: p ↑ inputs means program p diverges on inputs.
Equations
- Cslib.URM.«term_↑_» = Lean.ParserDescr.trailingNode `Cslib.URM.«term_↑_» 50 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ↑ ") (Lean.ParserDescr.cat `term 51))
Instances For
Notation for halting with result: p ↓ inputs ≫ result means program p halts on inputs
with result in R[0].
Equations
- One or more equations did not get rendered due to their size.
Instances For
If a program halts with a result, it halts.
Evaluation returning the full halting state.
Equations
- Cslib.URM.evalState p inputs = { Dom := Cslib.URM.Halts p inputs, get := fun (h : Cslib.URM.Halts p inputs) => Classical.choose h }
Instances For
If a program halts, it halts with the output of the final state.
Evaluation as a partial function using Part.
Defined when the program halts, returning the value in register 0.
Equations
- Cslib.URM.eval p inputs = Part.map (fun (x : Cslib.URM.State) => x.regs.output) (Cslib.URM.evalState p inputs)
Instances For
Two programs are equivalent if they produce the same result for all inputs.
Equations
- Cslib.URM.ProgramEquiv p q = ∀ (inputs : List ℕ), Cslib.URM.eval p inputs = Cslib.URM.eval q inputs
Instances For
Program equivalence is an equivalence relation.
Setoid instance for programs, enabling the ≈ notation.