`stepCostProg` computes the exact cost of a machine step, in time quadratic in the configuration size
ProvedMIPRE.Cost.Machine.stepCostProg_runsThe evaluation machine of the ambient cost model charges at each step the cost of the evaluation rule it implements ( of the value read for a variable, for a literal , one unit for , , , and for the dispatch of a loop body's value, and otherwise), so that the charges along a run add up to the cost of the big-step derivation. The clocked self-interpreter must decrement its cost budget by exactly this amount at each simulated step; stepCostProg is the fixed program of the model that computes it from the encoded configuration, returning it as a unary numeral .
For every configuration there is a cost
such that stepCostProg, run on the single input (the encoding Cfg.toData c), halts with result
at cost .
The theorem is one of the two programs iterated by the clocked universal machine of blueprint lem:universal-tm (the other being the step program stepProg); its exactness is what makes the simulated budget agree with the true cost (clockLoop_runs, clockRun_eq), so that the clocked machine returns the result precisely when the simulated program halts within cost .
Formalization Note: The bound is quadratic rather than linear because of the case, where the value of variable is located by walking the encoded environment (getListProg, which copies the remainder of the environment at each of its steps) and its size is then computed in unary (sizeProg, quadratic in the size of the value). The constants of stepCostBound are those produced by the proof, with no attempt at optimality; only polynomiality matters downstream (stepCostPoly).
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 Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring 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_Toolkit 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_Interpreter import Definitions.Def_MIPRE_Foundations_Cost_MachineBound import Definitions.Def_MIPRE_Foundations_Cost_Universal open MIPRE open MIPRE.Cost open MIPRE.Cost.Machine open Polynomial open MIPRE.Cost.Prog
theorem MIPRE.Cost.Machine.stepCostProg_runs (c : Cfg) :
∃ t ≤ stepCostBound (Cfg.toData c).size,
stepCostProg.Runs c.toData (.ofNat (stepCost c)) t := by sorry