URM Core Definitions #
This file contains the core definitions for Unlimited Register Machines (URMs): instructions, register state, programs, and machine configurations.
Main definitions #
URM.Instr: The four URM instructions (Z, S, T, J)URM.Regs: Register contents as a functionโ โ โURM.Program: A finite sequence of instructionsURM.State: Machine state (program counter + registers)
References #
- [N.J. Cutland, Computability: An Introduction to Recursive Function Theory][Cutland1980]
- [J.C. Shepherdson and H.E. Sturgis, Computability of Recursive Functions][ShepherdsonSturgis1963]
Instructions #
Equations
- One or more equations did not get rendered due to their size.
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.Z a) (Cslib.URM.Instr.Z b) = if h : a = b then h โธ isTrue โฏ else isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.Z a) (Cslib.URM.Instr.S a_1) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.Z a) (Cslib.URM.Instr.T a_1 a_2) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.Z a) (Cslib.URM.Instr.J a_1 a_2 a_3) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.S a) (Cslib.URM.Instr.Z a_1) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.S a) (Cslib.URM.Instr.S b) = if h : a = b then h โธ isTrue โฏ else isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.S a) (Cslib.URM.Instr.T a_1 a_2) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.S a) (Cslib.URM.Instr.J a_1 a_2 a_3) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.T a a_1) (Cslib.URM.Instr.Z a_2) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.T a a_1) (Cslib.URM.Instr.S a_2) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.T a a_1) (Cslib.URM.Instr.T b b_1) = if h : a = b then h โธ if h : a_1 = b_1 then h โธ isTrue โฏ else isFalse โฏ else isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.T a a_1) (Cslib.URM.Instr.J a_2 a_3 a_4) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.J a a_1 a_2) (Cslib.URM.Instr.Z a_3) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.J a a_1 a_2) (Cslib.URM.Instr.S a_3) = isFalse โฏ
- Cslib.URM.instDecidableEqInstr.decEq (Cslib.URM.Instr.J a a_1 a_2) (Cslib.URM.Instr.T a_3 a_4) = isFalse โฏ
Instances For
Equations
- Cslib.URM.instReprInstr = { reprPrec := Cslib.URM.instReprInstr.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
The registers read by an instruction.
Equations
- (Cslib.URM.Instr.Z a).readsFrom = โ
- (Cslib.URM.Instr.S n).readsFrom = {n}
- (Cslib.URM.Instr.T m a).readsFrom = {m}
- (Cslib.URM.Instr.J m n a).readsFrom = {m, n}
Instances For
The register written to by an instruction, if any.
Equations
- (Cslib.URM.Instr.Z a).writesTo = some a
- (Cslib.URM.Instr.S n).writesTo = some n
- (Cslib.URM.Instr.T m a).writesTo = some a
- (Cslib.URM.Instr.J m n a).writesTo = none
Instances For
The maximum register index referenced by an instruction.
Equations
- (Cslib.URM.Instr.Z a).maxRegister = a
- (Cslib.URM.Instr.S n).maxRegister = n
- (Cslib.URM.Instr.T m a).maxRegister = max m a
- (Cslib.URM.Instr.J m n a).maxRegister = max m n
Instances For
Shift all jump targets in an instruction by offset.
Used when concatenating programs to maintain correct jump destinations.
Equations
- Cslib.URM.Instr.shiftJumps offset (Cslib.URM.Instr.Z a) = Cslib.URM.Instr.Z a
- Cslib.URM.Instr.shiftJumps offset (Cslib.URM.Instr.S n) = Cslib.URM.Instr.S n
- Cslib.URM.Instr.shiftJumps offset (Cslib.URM.Instr.T m a) = Cslib.URM.Instr.T m a
- Cslib.URM.Instr.shiftJumps offset (Cslib.URM.Instr.J m n a) = Cslib.URM.Instr.J m n (a + offset)
Instances For
Shift all register references in an instruction by offset.
Used to isolate register usage when composing programs.
Equations
- Cslib.URM.Instr.shiftRegisters offset (Cslib.URM.Instr.Z a) = Cslib.URM.Instr.Z (a + offset)
- Cslib.URM.Instr.shiftRegisters offset (Cslib.URM.Instr.S n) = Cslib.URM.Instr.S (n + offset)
- Cslib.URM.Instr.shiftRegisters offset (Cslib.URM.Instr.T m a) = Cslib.URM.Instr.T (m + offset) (a + offset)
- Cslib.URM.Instr.shiftRegisters offset (Cslib.URM.Instr.J m n a) = Cslib.URM.Instr.J (m + offset) (n + offset) a
Instances For
Register Contents #
Register contents: maps register indices to natural number contents.
Uses the functional representation โ โ โ for efficiency with rewrites,
following the advice from the grind tactic documentation.
Equations
- Cslib.URM.Regs = (โ โ โ)
Instances For
Read the contents of register n.
Instances For
Initialize registers with input values in registers 0, 1, ..., k-1. Registers beyond the inputs are initialized to 0.
Equations
- Cslib.URM.Regs.ofInputs inputs n = inputs.getD n 0
Instances For
Extract output from register 0.
Instances For
Programs #
A URM program is a list of instructions.
Equations
Instances For
The maximum register index referenced by any instruction in the program.
Equations
- p.maxRegister = List.foldl (fun (acc : โ) (instr : Cslib.URM.Instr) => max acc instr.maxRegister) 0 p
Instances For
Shift all jump targets in a program by offset.
Used when concatenating programs: the second program's jumps must be adjusted
by the length of the first program.
Equations
- p.shiftJumps offset = List.map (Cslib.URM.Instr.shiftJumps offset) p
Instances For
Shift all register references in a program by offset.
Used to isolate register usage when composing programs.
Equations
- p.shiftRegisters offset = List.map (Cslib.URM.Instr.shiftRegisters offset) p
Instances For
Machine State #
Machine state: program counter (0-indexed) and register contents.
Instances For
Initial state for a program with given inputs. The program counter starts at 0, and inputs are loaded into registers 0, 1, ....
Equations
- Cslib.URM.State.init inputs = { pc := 0, regs := Cslib.URM.Regs.ofInputs inputs }
Instances For
A state is halted if the program counter is at or beyond the program length.
Equations
- s.isHalted p = (List.length p โค s.pc)
Instances For
Equations
- s.instDecidableIsHalted p = inferInstanceAs (Decidable (List.length p โค s.pc))
Equations
- Cslib.URM.State.instInhabited = { default := Cslib.URM.State.init [] }
Equations
- Cslib.URM.State.instRepr = { reprPrec := fun (s : Cslib.URM.State) (x : โ) => Std.Format.text (toString "State(pc=" ++ toString s.pc ++ toString ")") }