Documentation

LeanPool.PlanarSeparator.WordRAM.Machine.Basic

Machine basics #

Elementary lemmas about the machine of WordRAM/Spec.lean:

upd #

@[simp]
theorem WordRAM.Machine.upd_same {α : Type} (f : ℕ → α) (i : ℕ) (v : α) :
upd f i v i = v
@[simp]
theorem WordRAM.Machine.upd_other {α : Type} (f : ℕ → α) (i : ℕ) (v : α) {j : ℕ} (h : j ≠ i) :
upd f i v j = f j
theorem WordRAM.Machine.upd_apply {α : Type} (f : ℕ → α) (i : ℕ) (v : α) (j : ℕ) :
upd f i v j = if j = i then v else f j
@[simp]
theorem WordRAM.Machine.upd_upd_same {α : Type} (f : ℕ → α) (i : ℕ) (v w : α) :
upd (upd f i v) i w = upd f i w
theorem WordRAM.Machine.upd_upd_comm {α : Type} (f : ℕ → α) {i j : ℕ} (v w : α) (h : i ≠ j) :
upd (upd f i v) j w = upd (upd f j w) i v
@[simp]
theorem WordRAM.Machine.upd_eq_self {α : Type} (f : ℕ → α) (i : ℕ) :
upd f i (f i) = f
theorem WordRAM.Machine.upd_le {f : ℕ → ℕ} {W : ℕ} (hf : ∀ (j : ℕ), f j ≤ W) {i v : ℕ} (hv : v ≤ W) (j : ℕ) :
upd f i v j ≤ W

Bound on all entries after an update.

One lemma per instruction #

theorem WordRAM.Machine.step_none_of_none {prog : Program} {P : Input} {c : Config} (h : prog[c.pc]? = none) :
step prog P c = none
theorem WordRAM.Machine.step_none_of_length_le {prog : Program} {P : Input} {c : Config} (h : List.length prog ≤ c.pc) :
step prog P c = none

A program counter outside the program faults.

theorem WordRAM.Machine.step_halt {prog : Program} {P : Input} {c : Config} (h : prog[c.pc]? = some Instr.halt) :
step prog P c = none
theorem WordRAM.Machine.step_inputSize {prog : Program} {P : Input} {c : Config} {r : ℕ} (h : prog[c.pc]? = some (Instr.inputSize r)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r P.data.length, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_constN {prog : Program} {P : Input} {c : Config} {r k : ℕ} (h : prog[c.pc]? = some (Instr.constN r k)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r k, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_copyN {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.copyN r a)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_addN {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.addN r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a + c.nreg b), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_subN {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.subN r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a - c.nreg b), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_mulN {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.mulN r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a * c.nreg b), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_divN {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.divN r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a / c.nreg b), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_modN {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.modN r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nreg a % c.nreg b), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_loadN {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.loadN r a)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (c.nmem (c.nreg a)), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_storeN {prog : Program} {P : Input} {c : Config} {a r : ℕ} (h : prog[c.pc]? = some (Instr.storeN a r)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := upd c.nmem (c.nreg a) (c.nreg r), rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_constR {prog : Program} {P : Input} {c : Config} {r : ℕ} {z : ℤ} (h : prog[c.pc]? = some (Instr.constR r z)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r ↑z, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_copyR {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.copyR r a)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rreg a), nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_addR {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.addR r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rreg a + c.rreg b), nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_subR {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.subR r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rreg a - c.rreg b), nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_mulR {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.mulR r a b)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rreg a * c.rreg b), nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_divR {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.divR r a b)) (hb : c.rreg b ≠ 0) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rreg a / c.rreg b), nmem := c.nmem, rmem := c.rmem, output := c.output }

Division with a nonzero divisor.

theorem WordRAM.Machine.step_divR_zero {prog : Program} {P : Input} {c : Config} {r a b : ℕ} (h : prog[c.pc]? = some (Instr.divR r a b)) (hb : c.rreg b = 0) :
step prog P c = none

Division by zero faults.

theorem WordRAM.Machine.step_loadR {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.loadR r a)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := upd c.rreg r (c.rmem (c.nreg a)), nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_storeR {prog : Program} {P : Input} {c : Config} {a r : ℕ} (h : prog[c.pc]? = some (Instr.storeR a r)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := upd c.rmem (c.nreg a) (c.rreg r), output := c.output }
theorem WordRAM.Machine.step_readIn {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.readIn r a)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (P.data.getD (c.nreg a) 0), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_rand {prog : Program} {P : Input} {c : Config} {r a : ℕ} (h : prog[c.pc]? = some (Instr.rand r a)) :
step prog P c = some { pc := c.pc + 1, nreg := upd c.nreg r (P.tape (c.nreg a)), rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_jump {prog : Program} {P : Input} {c : Config} {l : ℕ} (h : prog[c.pc]? = some (Instr.jump l)) :
step prog P c = some { pc := l, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtN {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtN a b l)) :
step prog P c = some { pc := if c.nreg a < c.nreg b then l else c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtN_true {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtN a b l)) (ht : c.nreg a < c.nreg b) :
step prog P c = some { pc := l, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtN_false {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtN a b l)) (ht : ¬c.nreg a < c.nreg b) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtR {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtR a b l)) :
step prog P c = some { pc := if c.rreg a < c.rreg b then l else c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtR_true {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtR a b l)) (ht : c.rreg a < c.rreg b) :
step prog P c = some { pc := l, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_brLtR_false {prog : Program} {P : Input} {c : Config} {a b l : ℕ} (h : prog[c.pc]? = some (Instr.brLtR a b l)) (ht : ¬c.rreg a < c.rreg b) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }
theorem WordRAM.Machine.step_outN {prog : Program} {P : Input} {c : Config} {a : ℕ} (h : prog[c.pc]? = some (Instr.outN a)) :
step prog P c = some { pc := c.pc + 1, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output ++ [c.nreg a] }

run #

@[simp]
theorem WordRAM.Machine.run_zero {prog : Program} {P : Input} (c : Config) :
run prog P 0 c = some c
theorem WordRAM.Machine.run_succ {prog : Program} {P : Input} (k : ℕ) (c : Config) :
run prog P (k + 1) c = (step prog P c).bind (run prog P k)
theorem WordRAM.Machine.run_one {prog : Program} {P : Input} :
run prog P 1 = step prog P
theorem WordRAM.Machine.run_succ_of_step {prog : Program} {P : Input} {k : ℕ} {c c₁ : Config} (h : step prog P c = some c₁) :
run prog P (k + 1) c = run prog P k c₁
theorem WordRAM.Machine.run_succ_of_step_none {prog : Program} {P : Input} {k : ℕ} {c : Config} (h : step prog P c = none) :
run prog P (k + 1) c = none
theorem WordRAM.Machine.run_add {prog : Program} {P : Input} (a b : ℕ) (c : Config) :
run prog P (a + b) c = (run prog P a c).bind (run prog P b)

Running a + b steps is running a steps and then b steps.

theorem WordRAM.Machine.run_succ_right {prog : Program} {P : Input} (k : ℕ) (c : Config) :
run prog P (k + 1) c = (run prog P k c).bind (step prog P)

Peeling off the last step.

theorem WordRAM.Machine.run_add_of_run {prog : Program} {P : Input} {a b : ℕ} {c c₁ : Config} (h : run prog P a c = some c₁) :
run prog P (a + b) c = run prog P b c₁
theorem WordRAM.Machine.run_eq_some_of_le {prog : Program} {P : Input} {k : ℕ} {c c' : Config} (h : run prog P k c = some c') {i : ℕ} (hi : i ≤ k) :
∃ (c'' : Config), run prog P i c = some c''

If a run of k steps succeeds, so does every shorter run from the same start.

theorem WordRAM.Machine.run_eq_of_le {prog : Program} {P : Input} {k : ℕ} {c c' : Config} (h : run prog P k c = some c') {i : ℕ} (hi : i ≤ k) :
∃ (c'' : Config), run prog P i c = some c'' ∧ run prog P (k - i) c'' = some c'

The intermediate configuration after i ≤ k steps determines the rest of the run.

Word bounds and RunsWithin #

theorem WordRAM.Machine.WordsBounded.mono {W W' : ℕ} {c : Config} (h : WordsBounded W c) (hW : W ≤ W') :
theorem WordRAM.Machine.wordsBounded_iff {W : ℕ} {c : Config} :
WordsBounded W c ↔ (∀ (r : ℕ), c.nreg r ≤ W) ∧ ∀ (a : ℕ), c.nmem a ≤ W

WordsBounded does not look at the program counter, the real registers, the real memory or the output.

@[simp]
theorem WordRAM.Machine.wordsBounded_setPc {W : ℕ} {c : Config} {p : ℕ} :
WordsBounded W { pc := p, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output } ↔ WordsBounded W c
theorem WordRAM.Machine.WordsBounded.nreg {W : ℕ} {c : Config} (h : WordsBounded W c) (r : ℕ) :
c.nreg r ≤ W
theorem WordRAM.Machine.WordsBounded.nmem {W : ℕ} {c : Config} (h : WordsBounded W c) (a : ℕ) :
c.nmem a ≤ W
theorem WordRAM.Machine.WordsBounded.upd_nreg {W : ℕ} {c : Config} (h : WordsBounded W c) {r v : ℕ} (hv : v ≤ W) (pc : ℕ) :
WordsBounded W { pc := pc, nreg := upd c.nreg r v, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := c.output }

Updating a natural register with a value ≤ W preserves the word bound.

theorem WordRAM.Machine.WordsBounded.upd_nmem {W : ℕ} {c : Config} (h : WordsBounded W c) {a v : ℕ} (hv : v ≤ W) (pc : ℕ) :
WordsBounded W { pc := pc, nreg := c.nreg, rreg := c.rreg, nmem := upd c.nmem a v, rmem := c.rmem, output := c.output }

Updating a natural memory cell with a value ≤ W preserves the word bound.

theorem WordRAM.Machine.WordsBounded.set_rreg {W : ℕ} {c : Config} (h : WordsBounded W c) (f : ℕ → ℝ) (pc : ℕ) :
WordsBounded W { pc := pc, nreg := c.nreg, rreg := f, nmem := c.nmem, rmem := c.rmem, output := c.output }

Changing only the real registers preserves the word bound.

theorem WordRAM.Machine.WordsBounded.set_rmem {W : ℕ} {c : Config} (h : WordsBounded W c) (f : ℕ → ℝ) (pc : ℕ) :
WordsBounded W { pc := pc, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := f, output := c.output }

Changing only the real memory preserves the word bound.

theorem WordRAM.Machine.WordsBounded.set_output {W : ℕ} {c : Config} (h : WordsBounded W c) (out : List ℕ) (pc : ℕ) :
WordsBounded W { pc := pc, nreg := c.nreg, rreg := c.rreg, nmem := c.nmem, rmem := c.rmem, output := out }

Changing only the output preserves the word bound.

theorem WordRAM.Machine.RunsWithin.mono_W {prog : Program} {P : Input} {W W' steps : ℕ} {out : List ℕ} (h : RunsWithin prog P W steps out) (hW : W ≤ W') :
RunsWithin prog P W' steps out
theorem WordRAM.Machine.RunsWithin.mono_steps {prog : Program} {P : Input} {W steps steps' : ℕ} {out : List ℕ} (h : RunsWithin prog P W steps out) (hs : steps ≤ steps') :
RunsWithin prog P W steps' out
theorem WordRAM.Machine.RunsWithin.mono {prog : Program} {P : Input} {W W' steps steps' : ℕ} {out : List ℕ} (h : RunsWithin prog P W steps out) (hW : W ≤ W') (hs : steps ≤ steps') :
RunsWithin prog P W' steps' out

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).

def WordRAM.Machine.BoundedRun (prog : Program) (P : Input) (W k : ℕ) (c : Config) :

The k-step run from c does not fault and every visited configuration is WordsBounded W.

Equations
Instances For
    def WordRAM.Machine.RunsTo (prog : Program) (P : Input) (W k : ℕ) (c c' : Config) :

    The k-step run from c ends in c', and every visited configuration is WordsBounded W.

    Equations
    Instances For
      theorem WordRAM.Machine.BoundedRun.wb_start {prog : Program} {P : Input} {W k : ℕ} {c : Config} (h : BoundedRun prog P W k c) :
      theorem WordRAM.Machine.BoundedRun.mono_k {prog : Program} {P : Input} {W k k' : ℕ} {c : Config} (h : BoundedRun prog P W k c) (hk : k' ≤ k) :
      BoundedRun prog P W k' c
      theorem WordRAM.Machine.BoundedRun.mono_W {prog : Program} {P : Input} {W k W' : ℕ} {c : Config} (h : BoundedRun prog P W k c) (hW : W ≤ W') :
      BoundedRun prog P W' k c
      theorem WordRAM.Machine.BoundedRun.zero {prog : Program} {P : Input} {W : ℕ} {c : Config} (h : WordsBounded W c) :
      BoundedRun prog P W 0 c
      theorem WordRAM.Machine.BoundedRun.cons {prog : Program} {P : Input} {W k : ℕ} {c c₁ : Config} (hw : WordsBounded W c) (hs : step prog P c = some c₁) (h : BoundedRun prog P W k c₁) :
      BoundedRun prog P W (k + 1) c
      theorem WordRAM.Machine.BoundedRun.add {prog : Program} {P : Input} {W a b : ℕ} {c c₁ : Config} (h₁ : BoundedRun prog P W a c) (hr : run prog P a c = some c₁) (h₂ : BoundedRun prog P W b c₁) :
      BoundedRun prog P W (a + b) c
      theorem WordRAM.Machine.BoundedRun.run_eq_some {prog : Program} {P : Input} {W k : ℕ} {c : Config} (h : BoundedRun prog P W k c) :
      ∃ (c' : Config), run prog P k c = some c' ∧ WordsBounded W c'
      theorem WordRAM.Machine.RunsTo.run_eq {prog : Program} {P : Input} {W k : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') :
      run prog P k c = some c'
      theorem WordRAM.Machine.RunsTo.bounded {prog : Program} {P : Input} {W k : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') :
      BoundedRun prog P W k c
      theorem WordRAM.Machine.RunsTo.wb_start {prog : Program} {P : Input} {W k : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') :
      theorem WordRAM.Machine.RunsTo.wb_end {prog : Program} {P : Input} {W k : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') :
      theorem WordRAM.Machine.RunsTo.zero {prog : Program} {P : Input} {W : ℕ} {c : Config} (h : WordsBounded W c) :
      RunsTo prog P W 0 c c
      theorem WordRAM.Machine.RunsTo.cons {prog : Program} {P : Input} {W k : ℕ} {c c₁ c' : Config} (hw : WordsBounded W c) (hs : step prog P c = some c₁) (h : RunsTo prog P W k c₁ c') :
      RunsTo prog P W (k + 1) c c'

      Prepend one step.

      theorem WordRAM.Machine.RunsTo.single {prog : Program} {P : Input} {W : ℕ} {c c₁ : Config} (hw : WordsBounded W c) (hw₁ : WordsBounded W c₁) (hs : step prog P c = some c₁) :
      RunsTo prog P W 1 c c₁

      A single step between two bounded configurations.

      theorem WordRAM.Machine.RunsTo.trans {prog : Program} {P : Input} {W a b : ℕ} {c c₁ c' : Config} (h₁ : RunsTo prog P W a c c₁) (h₂ : RunsTo prog P W b c₁ c') :
      RunsTo prog P W (a + b) c c'
      theorem WordRAM.Machine.RunsTo.snoc {prog : Program} {P : Input} {W k : ℕ} {c c₁ c' : Config} (h : RunsTo prog P W k c c₁) (hs : step prog P c₁ = some c') (hw : WordsBounded W c') :
      RunsTo prog P W (k + 1) c c'

      Append one step.

      theorem WordRAM.Machine.RunsTo.cast {prog : Program} {P : Input} {W k k' : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') (hk : k = k') :
      RunsTo prog P W k' c c'

      Replace the step count by an equal one (for arithmetic normalisation).

      theorem WordRAM.Machine.RunsTo.mono_W {prog : Program} {P : Input} {W k W' : ℕ} {c c' : Config} (h : RunsTo prog P W k c c') (hW : W ≤ W') :
      RunsTo prog P W' k c c'
      theorem WordRAM.Machine.RunsTo.unique {prog : Program} {P : Input} {W k : ℕ} {c c₁ c₂ : Config} (h₁ : RunsTo prog P W k c c₁) (h₂ : RunsTo prog P W k c c₂) :
      c₁ = c₂

      Steps are deterministic: two runs of the same length from the same start agree.

      theorem WordRAM.Machine.runsWithin_of_runsTo {prog : Program} {P : Input} {W k : ℕ} {c : Config} (h : RunsTo prog P W k initConfig c) (hh : AtHalt prog c) :
      RunsWithin prog P W (k + 1) c.output

      RunsWithin from a bounded run of initConfig ending at a halt.

      theorem WordRAM.Machine.runsWithin_iff {prog : Program} {P : Input} {W steps : ℕ} {out : List ℕ} :
      RunsWithin prog P W steps out ↔ ∃ (k : ℕ) (c : Config), k + 1 ≤ steps ∧ RunsTo prog P W k initConfig c ∧ AtHalt prog c ∧ c.output = out

      RunsWithin unfolded through RunsTo.

      The real register written by an instruction, if any.

      Equations
      Instances For

        Does the instruction write natural memory?

        Equations
        Instances For

          Does the instruction write real memory?

          Equations
          Instances For

            Is the instruction an outN?

            Equations
            Instances For

              Is the instruction a control instruction (halt, jump, brLtN, brLtR)?

              Equations
              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
                Instances For
                  @[simp]
                  @[simp]

                  Frame lemmas #

                  What a single step leaves unchanged, classified by the instruction executed.

                  theorem WordRAM.Machine.step_pc_of_isStraight {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hs : ins.IsStraight) (hst : step prog P c = some c') :
                  c'.pc = c.pc + 1

                  A straight-line instruction advances the program counter by exactly one.

                  theorem WordRAM.Machine.step_nreg_frame {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hst : step prog P c = some c') {j : ℕ} (hj : ins.nDest ≠ some j) :
                  c'.nreg j = c.nreg j

                  Natural registers other than the destination are unchanged.

                  theorem WordRAM.Machine.step_rreg_frame {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hst : step prog P c = some c') {j : ℕ} (hj : ins.rDest ≠ some j) :
                  c'.rreg j = c.rreg j

                  Real registers other than the destination are unchanged.

                  theorem WordRAM.Machine.step_nmem_frame {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hst : step prog P c = some c') (hw : ins.writesNMem = false) :
                  c'.nmem = c.nmem

                  Natural memory is unchanged unless the instruction is storeN.

                  theorem WordRAM.Machine.step_rmem_frame {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hst : step prog P c = some c') (hw : ins.writesRMem = false) :
                  c'.rmem = c.rmem

                  Real memory is unchanged unless the instruction is storeR.

                  theorem WordRAM.Machine.step_output_frame {prog : Program} {P : Input} {c c' : Config} {ins : Instr} (h : prog[c.pc]? = some ins) (hst : step prog P c = some c') (hw : ins.isEmit = false) :

                  The output is unchanged unless the instruction is outN.

                  theorem WordRAM.Machine.step_output_append {prog : Program} {P : Input} {c c' : Config} (hst : step prog P c = some c') :
                  ∃ (l : List ℕ), c'.output = c.output ++ l

                  The output only ever grows: a step appends a (possibly empty) list.

                  theorem WordRAM.Machine.run_output_append {prog : Program} {P : Input} {c c' : Config} {k : ℕ} (h : run prog P k c = some c') :
                  ∃ (l : List ℕ), c'.output = c.output ++ l

                  Over a whole run the output only grows.