theoremwriteWidth_eval (k d : ℕ) (a : Data k) (h14 : a.stacks (low k 14) = []) :
∃ b, Eval (writeWidth k d) (2 * d.bits.length + 1) a b ∧
b.stacks = Function.update a.stacks (low k 14) d.bits :=by
proof · 13
lines
obtain ⟨rf, he⟩ :=ArithmeticExpressionSupport.pushWord_eval
(low k 14) d.bits (projectState reg id a)
let b := embedState reg id a
⟨rf, Function.update (projectState reg id a).stacks (low k 14)
(d.bits ++ (projectState reg id a).stacks (low k 14))⟩
refine ⟨b, eval_liftCommand_from_state _ _ _ reg id a reg_injective
Function.injective_id he, ?_⟩
funext i
have hp := embedState_stack reg id a
(⟨rf, Function.update (projectState reg id a).stacks (low k 14)
(d.bits ++ (projectState reg id a).stacks (low k 14))⟩ : State8 (k + 34))
Function.injective_id i
simpa [b, projectState, h14] using hp
theoremcopyThreshold_eval (k d : ℕ) (hd : d ≤ k) (a : Data k)
(h25 : a.stacks (low k 25) = []) :
Eval (copyThreshold k d hd) (7 * (a.stacks (bank k d hd)).length + 5)
a (copiedThreshold d hd a) :=by
proof · 5
lines
apply Eval.call
exact ListRegisterProgram.copy_run (bank k d hd) (low k 15) (low k 25) 01
(bank_ne_low k d hd 15) (bank_ne_low k d hd 25)
(by intro h; have he := congrArg Fin.val h; change (25 : ℕ) = 15 at he; omega)
(by decide) a.regs a.stacks h25
theoremcommand_eval (k d : ℕ) (hd : d ≤ k) (a : Data k)
(h25 : a.stacks (low k 25) = []) :
∃ b, Eval (command k d hd) (bound k d hd a) a b ∧
b.stacks (low k 14) = d.bits ∧
b.stacks (low k 15) = a.stacks (bank k d hd) ∧
(∀ i, i ≠ low k 14→ i ≠ low k 15→ b.stacks i = a.stacks i) :=by
proof · 29
lines
let b := cleared (low k 14) a
let c := cleared (low k 15) b
haveh1415 : low k 14≠ low k 15:= (low_injective k).ne (by decide)
havehc14 : c.stacks (low k 14) = [] :=by
simp [c, b, StackRoutines.clearStacks, h1415]
obtain ⟨e, he, hes⟩ := writeWidth_eval k d c hc14
havehe25 : e.stacks (low k 25) = [] :=by
rw [hes]
simpa [c, b, cleared, StackRoutines.clearStacks, low, Function.update_apply] using h25
havehe15 : e.stacks (low k 15) = [] :=by
simp [hes, c, StackRoutines.clearStacks, h1415.symm]
havehebank : e.stacks (bank k d hd) = a.stacks (bank k d hd) :=by
simp [hes, c, b, StackRoutines.clearStacks,
bank_ne_low k d hd 14, bank_ne_low k d hd 15]
havehb15 : b.stacks (low k 15) = a.stacks (low k 15) :=by
simp [b, StackRoutines.clearStacks, h1415.symm]
refine ⟨copiedThreshold d hd e, ?_, ?_, ?_, ?_⟩
· have ht :=Eval.seq (clear_eval (low k 14) a)
(Eval.seq (clear_eval (low k 15) b)
(Eval.seq he (copyThreshold_eval k d hd e he25)))
havehc : (2 * (a.stacks (low k 14)).length + 3) +
((2 * (b.stacks (low k 15)).length + 3) +
((2 * d.bits.length + 1) + (7 * (e.stacks (bank k d hd)).length + 5))) =
bound k d hd a :=by rw [hb15, hebank]; unfold bound; omega
simpa only [hc] using ht
· simp [ StackRoutines.copyStacks, h1415, hes]
· simp [ StackRoutines.copyStacks, he15, hebank]
· intro i hi14 hi15
simp [ StackRoutines.copyStacks, hes, c, b, StackRoutines.clearStacks, hi14, hi15]
theoremprogram_runs (k d : ℕ) (hd : d ≤ k) (a : Data k)
(h25 : a.stacks (low k 25) = []) :
∃b : Data k, RunsIn (program k d hd) (bound k d hd a + 1)
(a.withPC (some (program k d hd).entry)) (b.withPC none) ∧
b.stacks (low k 14) = d.bits ∧ b.stacks (low k 15) = a.stacks (bank k d hd) ∧
(∀ i, i ≠ low k 14→ i ≠ low k 15→ b.stacks i = a.stacks i) :=by
proof · 3
lines
obtain ⟨b, he, h14, h15, hf⟩ := command_eval k d hd a h25
exact ⟨b, ⟨bound k d hd a + 1, le_rfl,
compiled_halt_trace he (bank k d hd) (low k 15)⟩, h14, h15, hf⟩