The machine run of a derivation of cost takes at most steps
ProvedMIPRE.Cost.Machine.eval_steps_countThe evaluation machine (MIPRE.Cost.Machine) implements the timed big-step semantics (Eval ρ p r t: the program in the environment halts with result at cost ) of the ambient cost model by small steps on configurations , where the control is ("evaluate ") or ("return "), is an environment and a stack of continuation frames (, , , ; see eval_steps_bound). Each step is charged the cost of the evaluation rule it carries out (stepCost) — reading a variable or a literal costs the size of the value (plus one for a variable), the other rules one unit — and the steps that carry out no rule are free: entering a loop, and returning a value to a , or frame or to the empty stack. (Steps) means that steps lead from to with total cost .
Theorem. Let be a derivation and any stack. Then there exist and an environment such that
That is, the machine simulates the derivation above any stack, with accumulated cost exactly , in at most steps.
The theorem sharpens the simulation lemma eval_steps (which gives the run without the bound on ) with the step count needed for the time analysis of the self-interpreter. In the universal program univProg each machine step is one iteration of the interpreter loop, so a simulated computation of cost takes at most iterations, each on a configuration whose encoded size is bounded through eval_steps_bound and size_toData_le; this is the polynomial time overhead of the efficient universal machine, blueprint lem:universal-tm. In the clocked universal machine univTProg, is the step budget that guarantees termination of a simulation with cost budget .
Formalization Note Every rule of the semantics has positive cost (Eval.pos; a literal costs ), so a derivation of cost involves at most paid steps, and the factor comes from the free steps: each is matched with the paid step that pushed the corresponding frame — the two returns of a pair with its cons step, the return of a let's bound value with its let step, the entry of a loop with the dispatch step at its frame — and a paid step has at most two free companions. The bound is in terms of the derivation cost alone, independent of the sizes of the program or of the environment. The stack is arbitrary and returned unchanged, and the final environment is existentially quantified. The cost in is the sum of the Lean's stepCost over the run, which the theorem asserts equals the cost of the derivation.
import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Computability.Primrec.List import Mathlib.Data.List.Basic import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Notation import Mathlib.Data.Nat.Size import Mathlib.Logic.Denumerable 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_Closure import Definitions.Def_MIPRE_Foundations_Cost_Loops import Definitions.Def_MIPRE_Foundations_Cost_Unary import Definitions.Def_MIPRE_Foundations_Cost_Machine import Definitions.Def_MIPRE_Foundations_Cost_Codable import Definitions.Def_MIPRE_Foundations_Cost_MachineData import Definitions.Def_MIPRE_Foundations_Cost_MachineBound open MIPRE open MIPRE.Cost open MIPRE.Cost.Machine
theorem MIPRE.Cost.Machine.eval_steps_count {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 ∧ N ≤ 3 * t := by sorry