Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Explicit time transfer of the Kleene fixed point e=kleeneFix(U,F)e = \mathrm{kleeneFix}(U,F)e=kleeneFix(U,F): runs of F(e)F(e)F(e) bound runs of eee

Proved
MIPRE.Cost.kleeneFix_runs_of

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

kleene-recursionmipre-formalizationpolynomial-timesmn-theoremuniversal-machine

Programs of the ambient cost model (Prog) read their input as variable 000 and are closed (WellScoped 1) when they read no other variable; p(x)⇓trp(x) \Downarrow_t rp(x)⇓t​r (p.Runs x r t) says that ppp run on the input xxx halts with result rrr at cost ttt in the timed big-step semantics, and size(v)\mathrm{size}(v)size(v) is the number of nodes of a datum vvv. Programs are encoded as data by their tree serialization enc(p)\mathrm{enc}(p)enc(p), with ∣p∣:=size(enc(p))|p| := \mathrm{size}(\mathrm{enc}(p))∣p∣:=size(enc(p)) (esize), and s(p,d)=let cons(const d,var 0) in ps(p, d) = \mathtt{let}\ \mathtt{cons}(\mathtt{const}\ d, \mathtt{var}\ 0)\ \mathtt{in}\ ps(p,d)=let cons(const d,var 0) in p (hardcode p d) is the s-m-n map, running ppp on the pair of the literal ddd and its input. A universal machine U=(u,PU)U = (u, P_U)U=(u,PU​) (UniversalMachine) is a closed program uuu with a polynomial PU∈N[X]P_U \in \mathbb{N}[X]PU​∈N[X] such that (i) whenever c(v)⇓trc(v) \Downarrow_t rc(v)⇓t​r there is t′≤PU(∣c∣+size(v)+t)t' \le P_U(|c| + \mathrm{size}(v) + t)t′≤PU​(∣c∣+size(v)+t) with u(cons(enc(c),v))⇓t′ru(\mathtt{cons}(\mathrm{enc}(c), v)) \Downarrow_{t'} ru(cons(enc(c),v))⇓t′​r (time_le), and (ii) whenever u(cons(enc(c),v))⇓t′ru(\mathtt{cons}(\mathrm{enc}(c), v)) \Downarrow_{t'} ru(cons(enc(c),v))⇓t′​r there is ttt with c(v)⇓trc(v) \Downarrow_t rc(v)⇓t​r (halts_of). A polynomial-time map on programs FFF (PolyTimeFun Prog Prog) is a function F:Prog→ProgF : \mathrm{Prog} \to \mathrm{Prog}F:Prog→Prog with a closed program codeF\mathrm{code}_FcodeF​ and an explicit polynomial TFT_FTF​ such that codeF(enc(x))⇓tenc(F(x))\mathrm{code}_F(\mathrm{enc}(x)) \Downarrow_{t} \mathrm{enc}(F(x))codeF​(enc(x))⇓t​enc(F(x)) for some t≤TF(∣x∣)t \le T_F(|x|)t≤TF​(∣x∣), for every xxx.

The two-argument program of the fixed-point construction is G=kleeneProg(u,F)G = \mathrm{kleeneProg}(u, F)G=kleeneProg(u,F) (kleeneProg): on an input cons(enc(x),v)\mathtt{cons}(\mathrm{enc}(x), v)cons(enc(x),v) it forms the pair (enc(x),enc(x))(\mathrm{enc}(x), \mathrm{enc}(x))(enc(x),enc(x)), applies the s-m-n program smnProg to obtain enc(s(x,enc(x)))\mathrm{enc}(s(x, \mathrm{enc}(x)))enc(s(x,enc(x))), applies codeF\mathrm{code}_FcodeF​ to obtain enc(F(s(x,enc(x))))\mathrm{enc}(F(s(x, \mathrm{enc}(x))))enc(F(s(x,enc(x)))), pairs the result with vvv and runs uuu on that pair. The fixed point of FFF through UUU is

e:=kleeneFix(U,F)=s(G,enc(G))(‘kleeneFix U F‘),e := \mathrm{kleeneFix}(U, F) = s\bigl(G, \mathrm{enc}(G)\bigr) \qquad\text{(`kleeneFix U F`)},e:=kleeneFix(U,F)=s(G,enc(G))(‘kleeneFix U F‘),

and the fixed part of its overhead is the number (kleeneOverhead U F)

kleeneOverhead(U,F):=7∣G∣+∣e∣+TF(∣e∣)+2∣F(e)∣+60.\mathrm{kleeneOverhead}(U, F) := 7|G| + |e| + T_F(|e|) + 2|F(e)| + 60 .kleeneOverhead(U,F):=7∣G∣+∣e∣+TF​(∣e∣)+2∣F(e)∣+60.

Statement. If F(e)(v)⇓trF(e)(v) \Downarrow_t rF(e)(v)⇓t​r, then there is a cost t′t't′ with e(v)⇓t′re(v) \Downarrow_{t'} re(v)⇓t′​r and

t′  ≤  PU(size(v)+t+∣F(e)∣)+3 size(v)+kleeneOverhead(U,F).t' \;\le\; P_U\bigl(\mathrm{size}(v) + t + |F(e)|\bigr) + 3\,\mathrm{size}(v) + \mathrm{kleeneOverhead}(U, F) .t′≤PU​(size(v)+t+∣F(e)∣)+3size(v)+kleeneOverhead(U,F).

This is the quantitative core of the efficient Kleene recursion theorem (blueprint lem:kleene, [MNY, Lemma 2.3]); efficient_fixed_point packages the right-hand side into a single polynomial in size(v)+t\mathrm{size}(v) + tsize(v)+t. The construction and its overhead are exposed as definitions (kleeneFix, kleeneOverhead) because the polynomial-time halting reduction needs the overhead of the fixed point of a family of maps FMF_MFM​ to be bounded uniformly in MMM, which only the explicit form shows.

Formalization Note: The overhead decomposes as the universal machine's polynomial at the argument size(v)+t+∣F(e)∣\mathrm{size}(v) + t + |F(e)|size(v)+t+∣F(e)∣; 3 size(v)3\,\mathrm{size}(v)3size(v) for the three copies of the input made along the way (by the hardcoding prefix, the final pairing and the call of uuu); and the constant kleeneOverhead(U,F)\mathrm{kleeneOverhead}(U,F)kleeneOverhead(U,F), which gathers seven copies of enc(G)\mathrm{enc}(G)enc(G) (∣G∣|G|∣G∣ each), the time TF(∣e∣)T_F(|e|)TF​(∣e∣) of computing F(e)F(e)F(e) from enc(e)\mathrm{enc}(e)enc(e), two copies of enc(F(e))\mathrm{enc}(F(e))enc(F(e)) and 606060 units of rule costs. Only this direction — runs of F(e)F(e)F(e) bound runs of eee — is formalized; see efficient_fixed_point for the departure from [MNY].

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
import Definitions.Def_MIPRE_Foundations_Cost_Kleene

open MIPRE
open MIPRE.Cost
open Polynomial
Formal statement
theorem MIPRE.Cost.kleeneFix_runs_of (U : UniversalMachine) (F : PolyTimeFun Prog Prog) {v r : Data}
    {t : ℕ} (h : (F (kleeneFix U F)).Runs v r t) :
    ∃ t' ≤ U.bound.eval (v.size + t + esize (F (kleeneFix U F))) + 3 * v.size +
        kleeneOverhead U F,
      (kleeneFix U F).Runs v r t' := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Kleene.lean#L182-L201; blueprint lem:kleene, 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.3

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