A random-access machine with a cost model #
A unit-cost random-access machine with natural-number words, for algorithms on integer data:
- the input is a list of natural numbers (
Input.data) together with a random tape (Input.tape : ℕ → ℕ); a deterministic algorithm ignores the tape, a randomized one reads it, and probabilities are taken over the tape; - the output is a list of natural numbers;
- Natural-number multiplication, division and remainder are unit-cost instructions. Division by
zero gives
0, and remainder by zero gives the dividend. readInreads one input word,randone word of the random tape,outNappends one word to the output.
Everything else is unchanged: natural registers and memory, exact real registers and memory, a
program counter, unit cost per executed instruction (RunsWithin charges one step per
instruction and one for the final halt), and a bound W on every natural word along the run
(WordsBounded), which a cost theorem states explicitly.
The instruction set. r, a, b name registers; k is a literal natural; z a literal
integer; l a literal instruction address.
- halt : Instr
Stop; the run has succeeded.
- inputSize
(r : ℕ)
: Instr
nreg r := n, the number of input words. - constN
(r k : ℕ)
: Instr
nreg r := k. - copyN (r a : ℕ) : Instr
- addN (r a b : ℕ) : Instr
- subN (r a b : ℕ) : Instr
- mulN (r a b : ℕ) : Instr
- divN (r a b : ℕ) : Instr
- modN (r a b : ℕ) : Instr
- loadN (r a : ℕ) : Instr
- storeN (a r : ℕ) : Instr
- constR (r : ℕ) (z : ℤ) : Instr
- copyR (r a : ℕ) : Instr
- addR (r a b : ℕ) : Instr
- subR (r a b : ℕ) : Instr
- mulR (r a b : ℕ) : Instr
- divR (r a b : ℕ) : Instr
- loadR (r a : ℕ) : Instr
- storeR (a r : ℕ) : Instr
- readIn (r a : ℕ) : Instr
- rand (r a : ℕ) : Instr
- jump
(l : ℕ)
: Instr
pc := l. - brLtN (a b l : ℕ) : Instr
- brLtR (a b l : ℕ) : Instr
- outN
(a : ℕ)
: Instr
Append
nreg ato the output.
Instances For
A program is a finite list of instructions; instruction addresses are list positions.
Equations
Instances For
The initial configuration: program counter 0, all registers and memory cells zero,
nothing output.
Equations
Instances For
Execute one instruction of prog on input P from configuration c. Returns none on a
fault (program counter out of range, or real division by zero) or when the current instruction
is halt; otherwise the next configuration.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Run k instructions, faulting if any step faults.
Equations
- WordRAM.run prog P 0 x✝ = some x✝
- WordRAM.run prog P k.succ x✝ = (WordRAM.step prog P x✝).bind (WordRAM.run prog P k)
Instances For
The configuration is at a halt instruction.
Equations
- WordRAM.AtHalt prog c = (prog[c.pc]? = some WordRAM.Instr.halt)
Instances For
prog, started on input P in the initial configuration, executes exactly k
instructions without faulting and then sits at halt, every configuration along the way
(including the final one) has its natural words bounded by W, and the output at the end is
out. The run is charged k + 1 steps: one for each executed instruction and one for the final
halt.
Equations
- One or more equations did not get rendered due to their size.