One evaluate-step of the self-interpreter runs within cost in the configuration size
ProvedMIPRE.Cost.Machine.stepEvProg_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 whose control is "evaluate the program ", with environment and stack (both as data), is handled by the step function of the machine on data: by the tag of , it returns the looked-up variable, nil or the literal (controls "return "); or it pushes a frame and moves to a subterm (for cons, let_, loop); or, for elim i n c, it inspects the -th variable and continues with , or with in the environment extended by the two components. The program stepEvProg implements this step: its input is the triple .
Let be a program and data. Write for the size of the program and . Then there is a cost with
Together with its counterpart for "return" controls (stepRetProg_runs_cons), this gives the step program stepProg of the self-interpreter (stepProg_runs), whose iteration is the efficient universal machine of the toolkit: the quadratic bound per step, applied to configurations of size polynomial in the simulated run, is what makes the universal machine's overhead polynomial.
Formalization Note. The bound is the function stepEvBound S = (S + 1) * (S + 30) + 100 of MIPRE.Cost.Machine, and the conclusion is stepEvProg.Runs (cons p.toData (cons env kont)) (stepEv p.toData env kont) s, a run in the one-entry environment; is esize p, the size of the tree encoding Prog.toData p. The result is stated through the data-level step stepEv of Cost/MachineData.lean rather than the machine's step; the two agree on encoded configurations (stepData_toData), which stepProg_runs uses. The quadratic term comes only from the environment walk in the var and elim cases; all other cases are linear in .
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.stepEvProg_runs (p : Prog) (env kont : Data) :
∃ s ≤ stepEvBound (esize p + env.size + kont.size),
stepEvProg.Runs (.cons p.toData (.cons env kont)) (stepEv p.toData env kont) s := by sorry