From derivations to machine runs: the evaluation machine simulates a run of cost at accumulated cost exactly
ProvedMIPRE.Cost.Machine.eval_stepsThe evaluation machine (Machine) is a small-step, CEK-style machine for the ambient language of the cost model. A configuration (Cfg) consists of a control , which is either ("evaluate the program ") or ("return the value "), an environment (a list of data, variable first) and a stack of continuation frames: (the head of a is being evaluated; evaluate in next), (the head value is ; return next), and . The step function (step) is total and deterministic, and it leaves final configurations unchanged. Each configuration is charged a cost : a configuration is charged the unit of the evaluation rule for the head constructor of — for , for , for , for , and , and for , whose unit is charged instead when the value of the body is dispatched at a frame; all other returns cost . Write (costSum) for the cost accumulated over steps, and (Steps) for " and ". The big-step semantics (Eval) is the timed evaluation relation that the machine implements: in the environment halts with result at cost .
Statement. If , then for every stack there are a step count and an environment such that
This is the forward direction of the correspondence between derivations and machine runs; with the converse eval_of_steps it gives halts_iff. The machine is the common core of the two universal artifacts of the formalization: the self-interpreter that realizes the efficient universal machine (blueprint lem:universal-tm), whose time bound starts from this simulation (refined to steps in eval_steps_count), and the proof that evaluation is partial recursive (mem_evalData_iff).
Formalization Note: The machine does not restore environments on return — elim extends the environment in place and a loop1 dispatch replaces it — so the environment at the return is existentially quantified, while the stack is restored exactly. The cost identity is exact, by the choice of stepCost matching the evaluation rules one for one. The statement is about the machine on Cfg, before configurations are encoded as data.
import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Data.List.Basic import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Notation import Mathlib.Data.Nat.Size import Mathlib.Logic.Function.Iterate import Definitions.Def_MIPRE_Foundations_Cost_Basic import Definitions.Def_MIPRE_Foundations_Cost_Encoding import Definitions.Def_MIPRE_Foundations_Cost_PolyTime import Definitions.Def_MIPRE_Foundations_Cost_Machine open MIPRE open MIPRE.Cost open MIPRE.Cost.Machine
theorem MIPRE.Cost.Machine.eval_steps {env : Env} {p : Prog} {r : Data} {t : ℕ} (h : Eval env p r t)
(k : List Frame) :
∃ N env', Steps ⟨.ev p, env, k⟩ N ⟨.ret r, env', k⟩ t := by sorry