RAMs with arbitrary data values #
The control labels of a RAM are natural numbers; its memory addresses and data values need not be.
Model specifies operations and tests by signatures, a separate type of constant symbols,
admissible produced values, and an explicit partial interpretation of values as addresses.
Neither a real nor a field element is implicitly converted into an integer address.
The configuration parameter has no prescribed meaning in the core; an instance may use a
natural address-word width, or a singleton configuration type.
Operations, tests, constant interpretation and address extraction may fail. Constants and operations check admissibility of their result; moves and halts have a separate configurable validity check. Control labels are checked before instructions and after continuing steps. A successful run costs one per instruction, including its final halt. Interpretations are mathematical functions: executable instances require executable interpretations. No bit-cost bound or simulation of real arithmetic by a Turing machine is claimed.
This factors the finite-register, indirect-memory semantics of Cslib.WordRAM, adapted from
MIT–ULB CompGeom Group. Cslib.WordRAM.Basis.genericModel represents the word
semantics exactly in this core, and the word RAM's interpreter properties, such as
Cslib.WordRAM.Executes.unique, are the results below transported along that representation.
Main definitions #
Model: data values, constant symbols, operation/test signatures and their semantics.Op,Cond,Instr,Program: data instructions, tests and flat programs.Data,State,Outcome: machine data, control state and step outcomes.step,run,Executes: single steps, fuel-bounded interpretation and exact halting cost.Data.init: an input convention with explicit default registers and initial memory.
Main results #
executes_iff_exists_run_eq: the interpreter characterizes exact halting executions.Executes.unique: a halting output and its instruction count are unique.
References #
The data and primitive operations of a RAM. The parameter is an external configuration, not an implicit conversion between values and addresses.
- Value : Type u
Values stored in registers and memory.
- Address : Type a
Memory addresses, distinct from natural control labels and from data values.
- decAddress : DecidableEq self.Address
Addresses support functional updates.
- Config : Type c
External machine configuration (for example a word width).
- Const : Type v
Literal symbols permitted in a finite program, separately from arbitrary data values.
- operations : Circuits.Signature
The operation symbols and their arities.
- tests : Circuits.Signature
The test symbols and their arities.
Interpret a constant symbol, possibly failing.
- evalOp : self.Config → (f : self.operations.Op) → (Fin (self.operations.Arity f) → self.Value) → Option self.Value
Interpret an operation on its register arguments, possibly failing.
- evalTest : self.Config → (f : self.tests.Op) → (Fin (self.tests.Arity f) → self.Value) → Option Bool
Interpret a test on its register arguments, possibly failing.
Check a newly produced constant or operation result.
Explicitly extract an address. Failure causes a load or store to fault.
Check existing values moved by copy/load/store or returned by halt.
Check control labels before an instruction and after a continuing step.
Instances For
A data instruction. Operations and constants are supplied by the model.
- const {M : Model} {r : ℕ} (d : Fin r) (c : M.Const) : Op M r
Interpret a literal into a register.
- copy {M : Model} {r : ℕ} (d s : Fin r) : Op M r
Copy a register.
- alu {M : Model} {r : ℕ} (f : M.operations.Op) (d : Fin r) (args : Fin (M.operations.Arity f) → Fin r) : Op M r
Apply a primitive operation.
- load {M : Model} {r : ℕ} (d a : Fin r) : Op M r
Read the address extracted from register
a. - store {M : Model} {r : ℕ} (a s : Fin r) : Op M r
Write to the address extracted from register
a.
Instances For
Flat instructions, with natural control labels.
- op {M : Model} {r : ℕ} (o : Op M r) : Instr M r
Perform a data instruction and advance.
- jump {M : Model} {r : ℕ} (target : ℕ) : Instr M r
Jump to a label.
- branch {M : Model} {r : ℕ} (c : Cond M r) (target : ℕ) : Instr M r
Jump when the test returns true; advance on false; fault on test failure.
- halt {M : Model} {r : ℕ} (i : Fin r) : Instr M r
Return a register's value.
Instances For
A finite instruction sequence.
Instances For
A step continues, halts with a data value, or faults.
- next {M : Model} {r : ℕ} (s : State M r) : Outcome M r
Continue in a state.
- halt {M : Model} {r : ℕ} (v : M.Value) : Outcome M r
Halt with an output value.
- fault {M : Model} {r : ℕ} : Outcome M r
Undefined instruction, primitive, test, address, or inadmissible result.
Instances For
Run with an instruction budget. none means a fault or exhausted fuel, never a halting
output. On success, retain the output and exact number of executed instructions.
Instances For
A halting run is determined by the program, the configuration and the state: its output and its number of instructions are unique.