The interpreter machine: alphabet, tapes, instructions and programs #
The interpreter U (planning/succinct-cook-levin.md, S2) is a multi-input Turing machine
that runs the evaluation machine of the ambient model (MIPRE.Cost.Machine) on a
configuration held on its work tapes. Its control is a small language of routine
instructions — copy a subtree, copy to a marker, push and pop, locate an environment entry,
charge the budget — each executed over a few phases, organized in short straight-line
programs, one per case of the evaluation step. This file has the alphabet, the tape names,
the instructions and the programs; Machine.lean interprets them.
Tapes #
Seven input tapes: the program 𝒟 as the preorder bits of 𝒟.toData; the bits of
encode n, encode x, encode y; the budget T in unary; the answers a', b' as raw
bit strings. Six work tapes: C (the control), E (the environment), K (the stack), X
(scratch), CNT (a unary depth counter), BUD (the unary budget).
Representation (Repr.lean) #
Values v : Data as v.toBits, over the symbols 0, 1. The control on C: 0 · S(p.toData)
for ev p, 1 · S(v) for ret v, from cell 0. The environment [v₁, …, vₙ] (v₁ the
innermost) on E as S(vₙ) # … # S(v₁) #, head after the last #. The stack on K, frames
bottom to top, each tag · payload · $, closures carrying their environment in the same
form after a ¶.
Equations
- MIPRE.TM.Interp.instReprSym.repr MIPRE.TM.Interp.Sym.zero prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Sym.zero")).group prec✝
- MIPRE.TM.Interp.instReprSym.repr MIPRE.TM.Interp.Sym.one prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Sym.one")).group prec✝
- MIPRE.TM.Interp.instReprSym.repr MIPRE.TM.Interp.Sym.sep prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Sym.sep")).group prec✝
- MIPRE.TM.Interp.instReprSym.repr MIPRE.TM.Interp.Sym.fr prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Sym.fr")).group prec✝
- MIPRE.TM.Interp.instReprSym.repr MIPRE.TM.Interp.Sym.en prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Sym.en")).group prec✝
Instances For
Equations
- MIPRE.TM.Interp.instReprSym = { reprPrec := MIPRE.TM.Interp.instReprSym.repr }
The work tapes.
Equations
Instances For
The input tapes.
Equations
Instances For
The control tape.
Equations
Instances For
The environment tape.
Equations
Instances For
The stack tape.
Equations
Instances For
The scratch tape.
Equations
Instances For
The depth counter.
Equations
Instances For
The budget.
Equations
Instances For
The program 𝒟.
Equations
Instances For
encode n.
Equations
Instances For
encode x.
Equations
Instances For
encode y.
Equations
Instances For
The answer a'.
Equations
Instances For
The answer b'.
Equations
Instances For
The programs: one per case of the evaluation step, the dispatcher, the initialization and the final check.
- init : ProgId
- dispatch : ProgId
- ret0x : ProgId
- evDispatch : ProgId
- evVar : ProgId
- evNil : ProgId
- evConst : ProgId
- evCons : ProgId
- evElim : ProgId
- evElimNil : ProgId
- evElimCons : ProgId
- evLet : ProgId
- evLoop : ProgId
- retCons1 : ProgId
- retCons2 : ProgId
- retLet1 : ProgId
- retLoop1 : ProgId
- retLoopNil : ProgId
- retLoopStop : ProgId
- retLoopCont : ProgId
- final : ProgId
- finalA : ProgId
- finalB : ProgId
- accept : ProgId
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
The routine instructions. Every instruction leaves the heads it does not name where they are.
- copyTree (src : WT) (dst : Option WT) (charge : Bool) : Instr
- copyUntil
(m : Option Sym)
(src dst : WT)
: Instr
Copy from
srctodstup to the symbolm(nonethe blank), which is not copied; thesrchead ends on it. - write
(t : WT)
(s : Sym)
: Instr
Write
sand move right. - move
(t : WT)
(dir : Bool)
: Instr
Move right (
dir = true) or left. - rewind
(t : WT)
: Instr
One left, then left to the blank, then one right: to cell
0when cells0 … pos - 1are not blank (the head may sit on the blank after the content). - toEnd
(t : WT)
: Instr
Move right to the first blank.
- eraseRight
(t : WT)
: Instr
Erase rightwards to the first blank (the cells erased must not contain
$, which marks the start meanwhile), ending where it started. - leftToMarker
(m : Sym)
(t : WT)
: Instr
Move one left, then left to the marker
mor a blank, then one right. - popBack
(m : Sym)
(t : WT)
: Instr
From the end: erase the last cell and everything before it back to the marker
mor a blank (exclusive), ending right after the marker; nothing on an empty tape. - getEnv : Instr
- charge
(two : Bool)
: Instr
Pop one (or two) budget cells; halt if the budget is exhausted.
- branch
(t : WT)
(s : Option Sym)
(target : ProgId)
: Instr
Jump to the start of
targetif the symbol under the head oftiss. - jump
(target : ProgId)
: Instr
Jump to the start of
target. - emit
(s : Sym)
: Instr
Emit an output symbol.
- halt : Instr
Halt.
- copyUnary
(j : IT)
(dst : WT)
: Instr
Write one
1ondstper symbol of inputj, up to the blank. - copyInputBits
(j : IT)
(dst : WT)
: Instr
Copy the bits of input
jtodst, up to the blank. - buildAnswer
(j : IT)
(dst : WT)
: Instr
Write
S(encode l)ondstfor the bit stringlon inputj:1 0per0,1 1 0 0per1, then0. - checkLen
(j ref : IT)
: Instr
Halt unless input
jis at most as long as inputref; both heads advance. - rewindInput
(j : IT)
: Instr
Move the head of input
jto the blank before the input. - moveInput
(j : IT)
(dir : Bool)
: Instr
Move the head of input
jright or left.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p0 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p0")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p1 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p1")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p2 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p2")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p3 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p3")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p4 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p4")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p5 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p5")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p6 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p6")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p7 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p7")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p8 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p8")).group prec✝
- MIPRE.TM.Interp.instReprPhase.repr MIPRE.TM.Interp.Phase.p9 prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "MIPRE.TM.Interp.Phase.p9")).group prec✝
Instances For
Equations
The initialization: the budget, the length checks of the answers, and the initial
configuration ⟨ev 𝒟, [encode (n, x, y, a', b')], []⟩.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The dispatcher of a step: on ev, read the tag; on ret, the top frame's tag, or
finish when the stack is empty.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The tag of the program to evaluate: (10)^k 0 for k = 0 … 6; every case starts with
the head of C on the final 0 of the tag.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (var i): return env.get i, at cost its size plus one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev nil: return nil, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (const d): return d, at cost its size.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (cons h t): push the frame cons1 t env, evaluate h, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (elim i n c): fetch env.get i and dispatch on it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
env.get i = nil: evaluate n, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
env.get i = cons a b: push b then a, evaluate c, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (let_ e b): push the frame let1 b env, evaluate e, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ev (loop b): push the frame loop1 b env, evaluate b, at no cost.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ret v to cons1 t env': environment env', push cons2 v, evaluate t.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ret v to cons2 a: return cons a v.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ret v to let1 b env': environment v :: env', evaluate b.
Equations
- One or more equations did not get rendered due to their size.
Instances For
ret v to loop1 b env': dispatch on the shape of v.
Equations
- One or more equations did not get rendered due to their size.
Instances For
v = nil: return nil in env', at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
v = cons nil r: return r in env', at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
v = cons (cons _ _) v': environment v' :: env'.tail, the frame updated, evaluate
b, at cost one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The final check: the result must be encode true = cons nil nil, bits 1 0 0.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The programs.
Equations
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.init = MIPRE.TM.Interp.initProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.dispatch = MIPRE.TM.Interp.dispatchProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.ret0x = MIPRE.TM.Interp.ret0xProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evDispatch = MIPRE.TM.Interp.evDispatchProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evVar = MIPRE.TM.Interp.evVarProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evNil = MIPRE.TM.Interp.evNilProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evConst = MIPRE.TM.Interp.evConstProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evCons = MIPRE.TM.Interp.evConsProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evElim = MIPRE.TM.Interp.evElimProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evElimNil = MIPRE.TM.Interp.evElimNilProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evElimCons = MIPRE.TM.Interp.evElimConsProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evLet = MIPRE.TM.Interp.evLetProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.evLoop = MIPRE.TM.Interp.evLoopProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retCons1 = MIPRE.TM.Interp.retCons1Prog
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retCons2 = MIPRE.TM.Interp.retCons2Prog
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retLet1 = MIPRE.TM.Interp.retLet1Prog
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retLoop1 = MIPRE.TM.Interp.retLoop1Prog
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retLoopNil = MIPRE.TM.Interp.retLoopNilProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retLoopStop = MIPRE.TM.Interp.retLoopStopProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.retLoopCont = MIPRE.TM.Interp.retLoopContProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.final = MIPRE.TM.Interp.finalProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.finalA = MIPRE.TM.Interp.finalAProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.finalB = MIPRE.TM.Interp.finalBProg
- MIPRE.TM.Interp.prog MIPRE.TM.Interp.ProgId.accept = MIPRE.TM.Interp.acceptProg
Instances For
The length bound on the programs.