The step program of the self-interpreter computes one machine step within cost
ProvedMIPRE.Cost.Machine.stepProg_runsWe work in the ambient cost model of the formalization: data are binary trees (Data, from nil and cons), is the number of nodes of , and is the timed semantics (the program in the environment halts with at cost exactly ; one unit per rule, plus the size of every value read by a variable or literal). The self-interpreter implements, as a program, the step function of a small-step evaluation machine whose configurations are encoded as data: an environment is a cons-chain of values, a stack a cons-chain of encoded frames, and a program is its tree encoding , a unary tag ( to for var, nil, cons, elim, let_, loop, const) paired with the fields.
A configuration of the evaluation machine consists of a control (either "evaluate " or "return "), an environment (a list of values) and a stack of frames; its encoding is , with and . The machine's step function performs one evaluation rule (final configurations, a returned value with an empty stack, are fixed points), and is set up so that the costs charged along a run add up exactly to the cost of the corresponding derivation in the timed semantics.
Let be any configuration and . Then there is a cost with
This is the step of the self-interpreter of the ambient language written in the language itself. The universal program univProg iterates stepProg from the initial configuration of a program on its input until a final configuration is reached, and the clocked variant univTProg does so under a budget; since every configuration along a run of cost has size polynomial in the sizes of the program and input and in , the quadratic cost per step yields the polynomial overhead of the efficient universal machine (blueprint lem:universal-tm) and of its clocked form.
Formalization Note. The bound is stepBound S = (S + 1) * (S + 40) + 200 of MIPRE.Cost.Machine, and the conclusion is stepProg.Runs c.toData (step c).toData s with step the machine's step on Cfg and Cfg.toData the encoding of Cost/MachineData.lean. The proof goes through the data-level step stepData, which agrees with the machine on encoded configurations (stepData_toData), and through the two half-step programs stepEvProg and stepRetProg, whose quadratic and linear bounds are absorbed into stepBound by the two auxiliary inequalities le_stepBound_of_quad and le_stepBound_of_le.
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_Machine import Definitions.Def_MIPRE_Foundations_Cost_Codable import Definitions.Def_MIPRE_Foundations_Cost_MachineData import Definitions.Def_MIPRE_Foundations_Cost_Interpreter open MIPRE open MIPRE.Cost open MIPRE.Cost.Machine open MIPRE.Cost.Prog
theorem MIPRE.Cost.Machine.stepProg_runs (c : Cfg) :
∃ s ≤ stepBound (Cfg.toData c).size, stepProg.Runs c.toData (step c).toData s := by sorry