Machine basics #
Elementary lemmas about the machine of WordRAM/Spec.lean:
upd(register/memory update) lemmas;- one lemma per instruction describing
stepwhen that instruction is at the program counter (step_halt,step_constN, …,step_divR,step_divR_zero); runlemmas (run_zero,run_succ,run_add,run_succ_right,run_eq_some_of_le, …);- monotonicity of
WordsBoundedandRunsWithin; - frame lemmas: what a
stepleaves unchanged; BoundedRun/RunsTo, the "every visited configuration is word-bounded" predicates used to buildRunsWithincompositionally.
upd #
One lemma per instruction #
run #
Word bounds and RunsWithin #
Updating a natural register with a value ≤ W preserves the word bound.
Updating a natural memory cell with a value ≤ W preserves the word bound.
Changing only the real registers preserves the word bound.
Changing only the real memory preserves the word bound.
Changing only the output preserves the word bound.
Bounded runs #
BoundedRun prog P W k c says that the k-step run from c succeeds and every configuration
visited (including the first and the last) is WordsBounded W. RunsTo adds the final
configuration. These compose (RunsTo.trans) and give RunsWithin directly
(runsWithin_of_runsTo).
The k-step run from c does not fault and every visited configuration is
WordsBounded W.
Equations
- WordRAM.Machine.BoundedRun prog P W k c = ∀ i ≤ k, ∃ (c' : WordRAM.Config), WordRAM.run prog P i c = some c' ∧ WordRAM.WordsBounded W c'
Instances For
The k-step run from c ends in c', and every visited configuration is WordsBounded W.
Equations
- WordRAM.Machine.RunsTo prog P W k c c' = (WordRAM.run prog P k c = some c' ∧ WordRAM.Machine.BoundedRun prog P W k c)
Instances For
A single step between two bounded configurations.
RunsWithin from a bounded run of initConfig ending at a halt.
The natural register written by an instruction, if any.
Equations
- (WordRAM.Instr.inputSize r).nDest = some r
- (WordRAM.Instr.constN r k).nDest = some r
- (WordRAM.Instr.copyN r a).nDest = some r
- (WordRAM.Instr.addN r a b).nDest = some r
- (WordRAM.Instr.subN r a b).nDest = some r
- (WordRAM.Instr.mulN r a b).nDest = some r
- (WordRAM.Instr.divN r a b).nDest = some r
- (WordRAM.Instr.modN r a b).nDest = some r
- (WordRAM.Instr.loadN r a).nDest = some r
- (WordRAM.Instr.readIn r a).nDest = some r
- (WordRAM.Instr.rand r a).nDest = some r
- x✝.nDest = none
Instances For
The real register written by an instruction, if any.
Equations
- (WordRAM.Instr.constR r z).rDest = some r
- (WordRAM.Instr.copyR r a).rDest = some r
- (WordRAM.Instr.addR r a b).rDest = some r
- (WordRAM.Instr.subR r a b).rDest = some r
- (WordRAM.Instr.mulR r a b).rDest = some r
- (WordRAM.Instr.divR r a b).rDest = some r
- (WordRAM.Instr.loadR r a).rDest = some r
- x✝.rDest = none
Instances For
Does the instruction write natural memory?
Equations
- (WordRAM.Instr.storeN a r).writesNMem = true
- x✝.writesNMem = false
Instances For
Does the instruction write real memory?
Equations
- (WordRAM.Instr.storeR a r).writesRMem = true
- x✝.writesRMem = false
Instances For
Is the instruction a control instruction (halt, jump, brLtN, brLtR)?
Equations
- WordRAM.Instr.halt.isControl = true
- (WordRAM.Instr.jump l).isControl = true
- (WordRAM.Instr.brLtN a b l).isControl = true
- (WordRAM.Instr.brLtR a b l).isControl = true
- x✝.isControl = false
Instances For
A straight-line instruction: anything but halt, jump, brLtN, brLtR. Straight-line
instructions always advance the program counter by one and never depend on it.
Equations
- ins.IsStraight = (ins.isControl = false)
Instances For
Frame lemmas #
What a single step leaves unchanged, classified by the instruction executed.