From machine runs to derivations: a run reaching a final configuration contains a derivation of the same cost
ProvedMIPRE.Cost.Machine.eval_of_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. Let , let be a program, an environment, a stack, a datum and an environment, and suppose
that is, the machine started on reaches a final configuration (a returned value on an empty stack) within steps. Then there exist a value , a cost , step counts and with , and an environment such that
the first steps of the run return a value to the stack with accumulated cost exactly , and is the result of a derivation for in of that same cost.
This is the backward direction of the correspondence between derivations and machine runs; with eval_steps it yields halts_iff. It is what makes the self-interpreter sound: a halting run of the universal program is a machine run reaching a final configuration, hence a derivation with the same result (univProg_halts_of, blueprint lem:universal-tm), and likewise for the clocked variant and for the decision procedure for cost budgets.
Formalization Note: The statement is deliberately in "prefix" form, generalized over the stack and with , so that a strong induction on goes through the recursive structure of the machine; it does not identify with the final value — that is done in halts_iff for , using that final configurations are fixed by . Finality requires an empty stack: a returned value under a non-empty stack is not fixed by the machine.
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_of_steps : ∀ (N : ℕ) (p : Prog) (env : Env) (k : List Frame) (r : Data) (e : Env),
step^[N] ⟨.ev p, env, k⟩ = ⟨.ret r, e, []⟩ →
∃ r' t M e' N', N = M + N' ∧ Eval env p r' t ∧ Steps ⟨.ev p, env, k⟩ M ⟨.ret r', e', k⟩ t := by sorry