Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The step program of the self-interpreter computes one machine step within cost (S+1)(S+40)+200(S+1)(S+40)+200(S+1)(S+40)+200

Proved
MIPRE.Cost.Machine.stepProg_runs

by thomasvidick · Oct 12, 2026 · Mathlib 0df444a (Lean v4.33.1)

mipre-formalizationpolynomial-timeself-interpreteruniversal-machine

We work in the ambient cost model of the formalization: data are binary trees (Data, from nil and cons), size(d)\mathrm{size}(d)size(d) is the number of nodes of ddd, and Eval(env,p,r,t)\mathrm{Eval}(\mathrm{env}, p, r, t)Eval(env,p,r,t) is the timed semantics (the program ppp in the environment env\mathrm{env}env halts with rrr at cost exactly ttt; 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 ppp is its tree encoding toData(p)\mathrm{toData}(p)toData(p), a unary tag (000 to 666 for var, nil, cons, elim, let_, loop, const) paired with the fields.

A configuration c=⟨ctrl,env,kont⟩c = \langle \mathrm{ctrl}, \mathrm{env}, \mathrm{kont}\ranglec=⟨ctrl,env,kont⟩ of the evaluation machine consists of a control (either "evaluate ppp" or "return vvv"), an environment (a list of values) and a stack of frames; its encoding is toData(c)=cons(toData(ctrl),cons(list(env),list(kont)))\mathrm{toData}(c) = \texttt{cons}(\mathrm{toData}(\mathrm{ctrl}), \texttt{cons}(\mathrm{list}(\mathrm{env}), \mathrm{list}(\mathrm{kont})))toData(c)=cons(toData(ctrl),cons(list(env),list(kont))), with toData(evaluate p)=cons(nil,toData(p))\mathrm{toData}(\text{evaluate } p) = \texttt{cons}(\texttt{nil}, \mathrm{toData}(p))toData(evaluate p)=cons(nil,toData(p)) and toData(return v)=cons(cons(nil,nil),v)\mathrm{toData}(\text{return } v) = \texttt{cons}(\texttt{cons}(\texttt{nil},\texttt{nil}), v)toData(return v)=cons(cons(nil,nil),v). The machine's step function step\mathrm{step}step 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 ccc be any configuration and S=size(toData(c))S = \mathrm{size}(\mathrm{toData}(c))S=size(toData(c)). Then there is a cost sss with

s≤(S+1)(S+40)+200andstepProg on the input toData(c) halts with toData(step(c)) at cost s.s \le (S+1)(S+40) + 200 \quad\text{and}\quad \texttt{stepProg}\ \text{on the input}\ \mathrm{toData}(c)\ \text{halts with}\ \mathrm{toData}(\mathrm{step}(c))\ \text{at cost}\ s.s≤(S+1)(S+40)+200andstepProg on the input toData(c) halts with toData(step(c)) at cost s.

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 ttt has size polynomial in the sizes of the program and input and in ttt, 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.

Preamble
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
Formal statement
theorem MIPRE.Cost.Machine.stepProg_runs (c : Cfg) :
    ∃ s ≤ stepBound (Cfg.toData c).size, stepProg.Runs c.toData (step c).toData s := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Interpreter.lean#L835-L905; internal lemma of the formalization of blueprint lem:universal-tm (the step program of the self-interpreter)

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me