Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The machine run of a derivation of cost ttt takes at most 3t3t3t steps

Proved
MIPRE.Cost.Machine.eval_steps_count

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

cost-modelmipre-formalizationself-interpreteruniversal-machine

The evaluation machine (MIPRE.Cost.Machine) implements the timed big-step semantics ρ⊢p⇓tr\rho \vdash p \Downarrow^{t} rρ⊢p⇓tr (Eval ρ p r t: the program ppp in the environment ρ\rhoρ halts with result rrr at cost ttt) of the ambient cost model by small steps on configurations ⟨γ,ρ,κ⟩\langle \gamma, \rho, \kappa\rangle⟨γ,ρ,κ⟩, where the control γ\gammaγ is ev p\mathrm{ev}\,pevp ("evaluate ppp") or ret v\mathrm{ret}\,vretv ("return vvv"), ρ\rhoρ is an environment and κ\kappaκ a stack of continuation frames (cons1\mathrm{cons}_1cons1​, cons2\mathrm{cons}_2cons2​, let1\mathrm{let}_1let1​, loop1\mathrm{loop}_1loop1​; 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 cons1\mathrm{cons}_1cons1​, cons2\mathrm{cons}_2cons2​ or let1\mathrm{let}_1let1​ frame or to the empty stack. Steps(c,N,c′,t)\mathrm{Steps}(c, N, c', t)Steps(c,N,c′,t) (Steps) means that NNN steps lead from ccc to c′c'c′ with total cost ttt.

Theorem. Let ρ⊢p⇓tr\rho \vdash p \Downarrow^{t} rρ⊢p⇓tr be a derivation and κ\kappaκ any stack. Then there exist N∈NN \in \mathbb{N}N∈N and an environment ρ′\rho'ρ′ such that

Steps(⟨ev p,ρ,κ⟩, N, ⟨ret r,ρ′,κ⟩, t)andN≤3t.\mathrm{Steps}\bigl(\langle \mathrm{ev}\,p, \rho, \kappa\rangle,\ N,\ \langle \mathrm{ret}\,r, \rho', \kappa\rangle,\ t\bigr) \qquad\text{and}\qquad N \le 3t.Steps(⟨evp,ρ,κ⟩, N, ⟨retr,ρ′,κ⟩, t)andN≤3t.

That is, the machine simulates the derivation above any stack, with accumulated cost exactly ttt, in at most 3t3t3t steps.

The theorem sharpens the simulation lemma eval_steps (which gives the run without the bound on NNN) 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 ttt takes at most 3t3t3t 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, 3k+13k + 13k+1 is the step budget that guarantees termination of a simulation with cost budget kkk.

Formalization Note Every rule of the semantics has positive cost (Eval.pos; a literal ddd costs size(d)≥1\mathrm{size}(d) \ge 1size(d)≥1), so a derivation of cost ttt involves at most ttt paid steps, and the factor 333 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 loop1\mathrm{loop}_1loop1​ frame — and a paid step has at most two free companions. The bound is in terms of the derivation cost ttt alone, independent of the sizes of the program or of the environment. The stack κ\kappaκ is arbitrary and returned unchanged, and the final environment ρ′\rho'ρ′ is existentially quantified. The cost ttt in Steps\mathrm{Steps}Steps is the sum of the Lean's stepCost over the run, which the theorem asserts equals the cost of the derivation.

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 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
Formal statement
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
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/MachineBound.lean#L472-L532; internal lemma of the formalization of blueprint lem:universal-tm (via the self-interpreter), https://vidick.github.io/MIPRE-formalization/blueprint/; [MNY] A. Marks, S. S. Nezhadi, H. Yuen, The recursive compression method for proving undecidability results, manuscript, Lemma 2.1

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