Tape descriptions #
A work tape is described by the list it holds from cell 0 (blank elsewhere) and its head
position; a configuration by its control and the six descriptions (Desc). Every routine
becomes a transformation of descriptions (D_write, D_copyTree, …), so that the
correctness of a step of the evaluation machine is a chain of such transformations followed
by list algebra (overwrite).
One tape #
theorem
MIPRE.TM.Interp.TapeIs.of_overwrite
{τ : Tape}
{pos : ℤ}
{l : List Sym}
{p : ℕ}
(h : TapeIs τ pos { l := l, p := p })
(hp : p ≤ l.length)
{τ' : Tape}
{pos' : ℤ}
{p' : ℕ}
{w : List Sym}
(hw : Holds τ' (↑p) w)
(hout : ∀ (q : ℤ), q < ↑p ∨ ↑p + ↑w.length ≤ q → τ' q = τ q)
(hpos : pos' = ↑p')
:
w written from p, the rest as before.
theorem
MIPRE.TM.Interp.TapeIs.of_truncate
{τ : Tape}
{pos : ℤ}
{l : List Sym}
{p : ℕ}
(h : TapeIs τ pos { l := l, p := p })
{n : ℕ}
(hn : n ≤ l.length)
{τ' : Tape}
{pos' : ℤ}
{p' : ℕ}
(hout : ∀ (q : ℤ), q < ↑n ∨ ↑l.length ≤ q → τ' q = τ q)
(hbl : BlankFrom τ' (↑n) (l.length - n))
(hpos : pos' = ↑p')
:
Erased from n to the end.
A configuration #
def
MIPRE.TM.Interp.Desc
{input : Fin 7 → List Sym}
(c : Cfg input)
(q : Option Ctl)
(ds : WT → TapeSt)
:
The configuration c has control q and its work tapes are as described by ds.
Equations
- MIPRE.TM.Interp.Desc c q ds = (c.state = q ∧ ∀ (t : Fin 6), MIPRE.TM.Interp.TapeIs (c.workTapes t) (c.workTapePos t) (ds t))
Instances For
theorem
MIPRE.TM.Interp.Desc.of_untouched
{input : Fin 7 → List Sym}
{c : Cfg input}
{q : Option Ctl}
{ds : WT → TapeSt}
(h : Desc c q ds)
{c' : Cfg input}
{SW : List WT}
(hu : Untouched c c' [] SW)
{q' : Option Ctl}
(hq' : c'.state = q')
{ds' : WT → TapeSt}
(hT : ∀ t ∈ SW, TapeIs (c'.workTapes t) (c'.workTapePos t) (ds' t))
(hS : ∀ t ∉ SW, ds' t = ds t)
:
Desc c' q' ds'
A run touching only the tapes in SW, whose new descriptions are given.
The routines on descriptions #
theorem
MIPRE.TM.Interp.D_eraseRight
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{t : WT}
(hins : instrAt k pc = Instr.eraseRight t)
(hpc : ↑pc + 1 < maxPc)
(hd : Desc c (at_ k pc) ds)
(hp : (ds t).p ≤ (ds t).l.length)
(hfr : ∀ s ∈ List.drop (ds t).p (ds t).l, s ≠ Sym.fr)
:
theorem
MIPRE.TM.Interp.D_copyUntil
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{m : Option Sym}
{src dst : WT}
(hins : instrAt k pc = Instr.copyUntil m src dst)
(hpc : ↑pc + 1 < maxPc)
(hsd : src ≠ dst)
(hd : Desc c (at_ k pc) ds)
{l₁ w l₂ : List Sym}
(hsrc : (ds src).l = l₁ ++ w ++ l₂)
(hsp : (ds src).p = l₁.length)
(hm : ∀ s ∈ w, some s ≠ m)
(hend : l₂[0]? = m)
(hdp : (ds dst).p ≤ (ds dst).l.length)
:
theorem
MIPRE.TM.Interp.D_branch_not
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{t : WT}
{s : Option Sym}
{target : ProgId}
(hins : instrAt k pc = Instr.branch t s target)
(hpc : ↑pc + 1 < maxPc)
(hd : Desc c (at_ k pc) ds)
(hs : (ds t).l[(ds t).p]? ≠ s)
:
theorem
MIPRE.TM.Interp.D_leftToMarker
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{m : Sym}
{t : WT}
(hins : instrAt k pc = Instr.leftToMarker m t)
(hpc : ↑pc + 1 < maxPc)
(hd : Desc c (at_ k pc) ds)
{l₁ w l₂ : List Sym}
(hl : (ds t).l = l₁ ++ w ++ l₂)
(hp : (ds t).p = l₁.length + w.length)
(hm : ∀ s ∈ w, s ≠ m)
(hl₁ : l₁ = [] ∨ ∃ (l₀ : List Sym), l₁ = l₀ ++ [m])
:
theorem
MIPRE.TM.Interp.D_popBack
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{m : Sym}
{t : WT}
(hins : instrAt k pc = Instr.popBack m t)
(hpc : ↑pc + 1 < maxPc)
(hd : Desc c (at_ k pc) ds)
{l₁ w : List Sym}
{a : Sym}
(hl : (ds t).l = l₁ ++ w ++ [a])
(hp : (ds t).p = (ds t).l.length)
(hm : ∀ s ∈ w, s ≠ m)
(hl₁ : l₁ = [] ∨ ∃ (l₀ : List Sym), l₁ = l₀ ++ [m])
:
theorem
MIPRE.TM.Interp.D_getEnv
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
(hins : instrAt k pc = Instr.getEnv)
(hpc : ↑pc + 1 < maxPc)
(hd : Desc c (at_ k pc) ds)
{env : Cost.Env}
(hE : ds E = { l := envRepr env, p := (envRepr env).length })
{i : ℕ}
{l₁ l₂ : List Sym}
(hC : (ds C).l = l₁ ++ S (Cost.Data.ofNat i) ++ l₂)
(hCp : (ds C).p = l₁.length)
(hX : (ds X).p ≤ (ds X).l.length)
:
theorem
MIPRE.TM.Interp.D_copyTree
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{src t : WT}
(hins : instrAt k pc = Instr.copyTree src (some t) false)
(hpc : ↑pc + 1 < maxPc)
(hst : src ≠ t)
(hsc : src ≠ CNT)
(htc : t ≠ CNT)
(hd : Desc c (at_ k pc) ds)
(hcnt : ds CNT = { l := [], p := 0 })
{v : Cost.Data}
{l₁ l₂ : List Sym}
(hsrc : (ds src).l = l₁ ++ S v ++ l₂)
(hsp : (ds src).p = l₁.length)
(htp : (ds t).p ≤ (ds t).l.length)
:
theorem
MIPRE.TM.Interp.D_skipTree
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{src : WT}
(hins : instrAt k pc = Instr.copyTree src none false)
(hpc : ↑pc + 1 < maxPc)
(hsc : src ≠ CNT)
(hd : Desc c (at_ k pc) ds)
(hcnt : ds CNT = { l := [], p := 0 })
{v : Cost.Data}
{l₁ l₂ : List Sym}
(hsrc : (ds src).l = l₁ ++ S v ++ l₂)
(hsp : (ds src).p = l₁.length)
:
theorem
MIPRE.TM.Interp.D_copyTree_charge
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{src t : WT}
(hins : instrAt k pc = Instr.copyTree src (some t) true)
(hpc : ↑pc + 1 < maxPc)
(hst : src ≠ t)
(hsc : src ≠ CNT)
(htc : t ≠ CNT)
(hsb : src ≠ BUD)
(htb : t ≠ BUD)
(hd : Desc c (at_ k pc) ds)
(hcnt : ds CNT = { l := [], p := 0 })
{r : ℕ}
(hbud : ds BUD = { l := List.replicate r Sym.one, p := r })
{v : Cost.Data}
{l₁ l₂ : List Sym}
(hsrc : (ds src).l = l₁ ++ S v ++ l₂)
(hsp : (ds src).p = l₁.length)
(htp : (ds t).p ≤ (ds t).l.length)
(hr : v.size ≤ r)
:
∃ n ≤ 4 * v.size + 1,
∃ (c' : Cfg input),
Reach c n c' [] ∧ Desc c' (next_ k pc hpc)
(Function.update
(Function.update (Function.update ds src { l := (ds src).l, p := l₁.length + v.size }) t
{ l := overwrite (ds t).l (ds t).p (S v), p := (ds t).p + v.size })
BUD { l := List.replicate (r - v.size) Sym.one, p := r - v.size })
theorem
MIPRE.TM.Interp.D_copyTree_charge_fail
{input : Fin 7 → List Sym}
{k : ProgId}
{pc : Fin maxPc}
{c : Cfg input}
{ds : WT → TapeSt}
{src t : WT}
(hins : instrAt k pc = Instr.copyTree src (some t) true)
(hpc : ↑pc + 1 < maxPc)
(hst : src ≠ t)
(hsc : src ≠ CNT)
(htc : t ≠ CNT)
(hsb : src ≠ BUD)
(htb : t ≠ BUD)
(hd : Desc c (at_ k pc) ds)
(hcnt : ds CNT = { l := [], p := 0 })
{r : ℕ}
(hbud : ds BUD = { l := List.replicate r Sym.one, p := r })
{v : Cost.Data}
{l₁ l₂ : List Sym}
(hsrc : (ds src).l = l₁ ++ S v ++ l₂)
(hsp : (ds src).p = l₁.length)
(hr : r < v.size)
: