Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The clocked universal program returns the budgeted result `clockedResult c v k` in time polynomial in k+∣c∣+∣v∣k + |c| + |v|k+∣c∣+∣v∣

Proved
MIPRE.Cost.Machine.univTProg_runs

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

mip-remipre-formalizationpolynomial-timeself-interpreteruniversal-machine

Fix the ambient cost model: programs c∈Progc \in \mathsf{Prog}c∈Prog act on values v∈Datav \in \mathsf{Data}v∈Data (binary trees), Eval  [v]  c  r  t\mathsf{Eval}\;[v]\;c\;r\;tEval[v]crt (in Lean c.Runs v r t) says that ccc on input vvv halts with result rrr at cost ttt, every program is encoded as a value ⌈c⌉\lceil c\rceil⌈c⌉ (encode c, the tree encoding Prog.toData) of size ∣c∣=esize(c)|c| = \mathrm{esize}(c)∣c∣=esize(c), and natural numbers used as budgets are passed in unary, ofNat(k)\mathsf{ofNat}(k)ofNat(k) being the list of kkk copies of nil\mathsf{nil}nil. The budgeted result of ccc on vvv under the cost budget kkk is

clockedResult(c,v,k)={cons (cons nil nil) rif c halts on v with result r at some cost t≤k,nilotherwise (timeout),\mathtt{clockedResult}(c, v, k) = \begin{cases} \mathsf{cons}\,(\mathsf{cons}\,\mathsf{nil}\,\mathsf{nil})\,r & \text{if } c \text{ halts on } v \text{ with result } r \text{ at some cost } t \le k, \\ \mathsf{nil} & \text{otherwise (timeout)}, \end{cases}clockedResult(c,v,k)={cons(consnilnil)rnil​if c halts on v with result r at some cost t≤k,otherwise (timeout),​

which is well defined because the semantics is deterministic.

univTProg is a fixed closed program, the clocked self-interpreter: on the input (ofNat k,(⌈c⌉,v))(\mathsf{ofNat}\,k, (\lceil c\rceil, v))(ofNatk,(⌈c⌉,v)) it computes X=k+∣c∣+∣v∣X = k + |c| + |v|X=k+∣c∣+∣v∣ and a size guard Θ(X)\Theta(X)Θ(X) in unary, builds the initial configuration of the evaluation machine for ccc on vvv, and runs the clocked interpreter loop with cost budget kkk, step budget 3k+13k+13k+1 and guard Θ(X)\Theta(X)Θ(X). The theorem states its correctness and its time bound.

For every program ccc, every value vvv and every k∈Nk \in \mathbb{N}k∈N there is a cost

t≤univTBoundFun(k+∣c∣+∣v∣)t \le \mathtt{univTBoundFun}(k + |c| + |v|)t≤univTBoundFun(k+∣c∣+∣v∣)

such that univTProg, run on the single input cons (ofNat k) (cons ⌈c⌉ v)\mathsf{cons}\,(\mathsf{ofNat}\,k)\,(\mathsf{cons}\,\lceil c\rceil\,v)cons(ofNatk)(cons⌈c⌉v), halts with result clockedResult(c,v,k)\mathtt{clockedResult}(c, v, k)clockedResult(c,v,k) at cost ttt. The function univTBoundFun\mathtt{univTBoundFun}univTBoundFun is an explicit polynomial (univTPoly): with Y(X)=9X+4Y(X) = 9X + 4Y(X)=9X+4, T1(X)=Y(2Y+2)+1T_1(X) = Y(2Y+2) + 1T1​(X)=Y(2Y+2)+1 and Θ(X)=Y(T1+1)+1\Theta(X) = Y(T_1 + 1) + 1Θ(X)=Y(T1​+1)+1,

univTBoundFun(X)=2 sizeBound(X)+2 addBound(X,X)+2 tripleBound(X,1)+tripleBound(3X+1,1)+repBound(Y,2Y+1,1)+repBound(Y,T1,1)+sizeBound(Θ)+(3X+2)(clockBodyBound(Θ,X)+1)+20Θ+20T1+60Y+100X+500,\mathtt{univTBoundFun}(X) = 2\,\mathtt{sizeBound}(X) + 2\,\mathtt{addBound}(X,X) + 2\,\mathtt{tripleBound}(X,1) + \mathtt{tripleBound}(3X+1,1) + \mathtt{repBound}(Y, 2Y+1, 1) + \mathtt{repBound}(Y, T_1, 1) + \mathtt{sizeBound}(\Theta) + (3X+2)\bigl(\mathtt{clockBodyBound}(\Theta, X) + 1\bigr) + 20\Theta + 20T_1 + 60Y + 100X + 500 ,univTBoundFun(X)=2sizeBound(X)+2addBound(X,X)+2tripleBound(X,1)+tripleBound(3X+1,1)+repBound(Y,2Y+1,1)+repBound(Y,T1​,1)+sizeBound(Θ)+(3X+2)(clockBodyBound(Θ,X)+1)+20Θ+20T1​+60Y+100X+500,

where sizeBound\mathtt{sizeBound}sizeBound, addBound\mathtt{addBound}addBound, tripleBound\mathtt{tripleBound}tripleBound, repBound\mathtt{repBound}repBound are the (quadratic) cost bounds of the unary size, addition, tripling and replication programs and clockBodyBound(Θ,k)\mathtt{clockBodyBound}(\Theta, k)clockBodyBound(Θ,k) is the polynomial cost bound of one iteration of the clocked loop.

This theorem is the run field of the clocked universal machine selfClockedUniversal, and so proves exists_clocked_universal, half of blueprint lem:universal-tm ([MNY, Lemma 2.1]). The clocked machine is the primitive with which the deciders of the compression pipeline simulate other deciders under a budget, and with which the recursive compression argument runs a description "for log⁡n\log nlogn steps".

Formalization Note: The budget kkk counts cost units of the big-step semantics (not machine steps), is supplied in unary (so the input has size 2k+1+∣c∣+∣v∣+22k + 1 + |c| + |v| + 22k+1+∣c∣+∣v∣+2), and the bound is polynomial in kkk itself. The result is total: the program halts on every input, also when the simulated run does not halt, which is what the step budget 3k+13k+13k+1 and the size guard Θ\ThetaΘ are for; the guard never fires on a run that halts within the budget, whose configurations have size at most sigmaFun(X)≤Θ(X)\mathtt{sigmaFun}(X) \le \Theta(X)sigmaFun(X)≤Θ(X). The constants in the bound are those produced by the proof.

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_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
Formal statement
theorem MIPRE.Cost.Machine.univTProg_runs (c : Prog) (v : Data) (k : ℕ) :
    ∃ t ≤ univTBoundFun (k + esize c + v.size),
      univTProg.Runs (.cons (.ofNat k) (.cons (encode c) v)) (clockedResult c v k) t := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Universal.lean#L1251-L1407; internal lemma of the formalization of blueprint lem:universal-tm, https://vidick.github.io/MIPRE-formalization/blueprint/

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