The evaluation machine #
A small-step abstract machine (CEK style) for the ambient language: a configuration is a control (a program to evaluate, or a value being returned), an environment and a stack of continuation frames. It is the common core of the two "universal" artifacts of the project:
- Mathlib-computability of ambient evaluation (
Cost/Partrec.lean): the step function, transported toData, is primitive recursive and evaluation is itsPFun.fix; - the self-interpreter of the ambient model in the ambient model (route β of the
universal-machine gate): a program implementing the step function inside a
loop.
The machine charges the cost of each Eval rule at a designated step (stepCost), so
that the accumulated cost of a run is exactly the cost of the Eval derivation. The two
directions of the correspondence are eval_steps (a derivation yields a run of the
machine) and eval_of_steps (a halting run of the machine yields a derivation).
Continuation frames.
- cons1
(t : Prog)
(env : Env)
: Frame
Evaluating the head of
cons h t; next evaluatetinenv. - cons2
(a : Data)
: Frame
The head value
aof acons; next returncons a v. - let1
(b : Prog)
(env : Env)
: Frame
Evaluating the binding of
let_ e b; next evaluatebinv :: env. - loop1
(b : Prog)
(env : Env)
: Frame
Evaluating the body of
loop binenv; next dispatch on the value.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons1 t env) (MIPRE.Cost.Machine.Frame.cons2 a) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons1 t env) (MIPRE.Cost.Machine.Frame.let1 b env_1) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons1 t env) (MIPRE.Cost.Machine.Frame.loop1 b env_1) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons2 a) (MIPRE.Cost.Machine.Frame.cons1 t env) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons2 a) (MIPRE.Cost.Machine.Frame.cons2 b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons2 a) (MIPRE.Cost.Machine.Frame.let1 b env) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.cons2 a) (MIPRE.Cost.Machine.Frame.loop1 b env) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.let1 b env) (MIPRE.Cost.Machine.Frame.cons1 t env_1) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.let1 b env) (MIPRE.Cost.Machine.Frame.cons2 a) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.let1 b env) (MIPRE.Cost.Machine.Frame.loop1 b_1 env_1) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.loop1 b env) (MIPRE.Cost.Machine.Frame.cons1 t env_1) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.loop1 b env) (MIPRE.Cost.Machine.Frame.cons2 a) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqFrame.decEq (MIPRE.Cost.Machine.Frame.loop1 b env) (MIPRE.Cost.Machine.Frame.let1 b_1 env_1) = isFalse ⋯
Instances For
Equations
- MIPRE.Cost.Machine.instDecidableEqCtrl.decEq (MIPRE.Cost.Machine.Ctrl.ev a) (MIPRE.Cost.Machine.Ctrl.ev b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqCtrl.decEq (MIPRE.Cost.Machine.Ctrl.ev p) (MIPRE.Cost.Machine.Ctrl.ret v) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqCtrl.decEq (MIPRE.Cost.Machine.Ctrl.ret v) (MIPRE.Cost.Machine.Ctrl.ev p) = isFalse ⋯
- MIPRE.Cost.Machine.instDecidableEqCtrl.decEq (MIPRE.Cost.Machine.Ctrl.ret a) (MIPRE.Cost.Machine.Ctrl.ret b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
One step of the machine. Final configurations (a value with an empty stack) are fixed.
Equations
- One or more equations did not get rendered due to their size.
- MIPRE.Cost.Machine.step { ctrl := MIPRE.Cost.Machine.Ctrl.ev (MIPRE.Cost.Prog.var i), env := env, kont := k } = { ctrl := MIPRE.Cost.Machine.Ctrl.ret (env.get i), env := env, kont := k }
- MIPRE.Cost.Machine.step { ctrl := MIPRE.Cost.Machine.Ctrl.ev MIPRE.Cost.Prog.nil, env := env, kont := k } = { ctrl := MIPRE.Cost.Machine.Ctrl.ret MIPRE.Cost.Data.nil, env := env, kont := k }
- MIPRE.Cost.Machine.step { ctrl := MIPRE.Cost.Machine.Ctrl.ev (MIPRE.Cost.Prog.const d), env := env, kont := k } = { ctrl := MIPRE.Cost.Machine.Ctrl.ret d, env := env, kont := k }
- MIPRE.Cost.Machine.step { ctrl := MIPRE.Cost.Machine.Ctrl.ret v, env := env, kont := [] } = { ctrl := MIPRE.Cost.Machine.Ctrl.ret v, env := env, kont := [] }
Instances For
The Eval cost charged at a step: the rule's own unit (plus the size of the value
read, for var and const); loop rules are charged when the body's value is
dispatched.
Equations
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev (MIPRE.Cost.Prog.var i), env := env, kont := kont } = (env.get i).size + 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev MIPRE.Cost.Prog.nil, env := env, kont := kont } = 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev (MIPRE.Cost.Prog.const d), env := env, kont := kont } = d.size
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev (h.cons t), env := env, kont := kont } = 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev (MIPRE.Cost.Prog.elim i n c), env := env, kont := kont } = 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev (e.let_ b), env := env, kont := kont } = 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ev b.loop, env := env, kont := kont } = 0
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ret v, env := env, kont := MIPRE.Cost.Machine.Frame.loop1 b env_1 :: tail } = 1
- MIPRE.Cost.Machine.stepCost { ctrl := MIPRE.Cost.Machine.Ctrl.ret v, env := env, kont := kont } = 0
Instances For
The cost accumulated over n steps.
Equations
Instances For
Steps c N c' t: N steps lead from c to c', accumulating cost t.
Equations
- MIPRE.Cost.Machine.Steps c N c' t = (MIPRE.Cost.Machine.step^[N] c = c' ∧ MIPRE.Cost.Machine.costSum c N = t)
Instances For
Forward: derivations give machine runs #
Backward: halting runs give derivations #
A final configuration: a value with an empty stack.
Equations
- MIPRE.Cost.Machine.IsFinal c = ∃ (r : MIPRE.Cost.Data) (e : MIPRE.Cost.Env), c = { ctrl := MIPRE.Cost.Machine.Ctrl.ret r, env := e, kont := [] }
Instances For
The two directions together: p on x halts with r iff the machine started at
⟨ev p, [x], []⟩ reaches the final configuration with value r.