Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Forward run of the Kleene two-argument program GGG: from a run of F(s(x,enc(x)))F(s(x,\mathrm{enc}(x)))F(s(x,enc(x))) on vvv, at explicit overhead

Proved
MIPRE.Cost.Prog.kleeneProg_runs

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.

Statement. Let U=(u,PU)U = (u, P_U)U=(u,PU​) be a universal machine, FFF a polynomial-time map on programs and xxx a program, and write e′:=s(x,enc(x))e' := s(x, \mathrm{enc}(x))e′:=s(x,enc(x)). If F(e′)(v)⇓trF(e')(v) \Downarrow_t rF(e′)(v)⇓t​r, then there is a cost TTT with G(cons(enc(x),v))⇓TrG(\mathtt{cons}(\mathrm{enc}(x), v)) \Downarrow_T rG(cons(enc(x),v))⇓T​r and

T  ≤  6∣x∣+∣e′∣+TF(∣e′∣)+2 ∣F(e′)∣+2 size(v)+PU(∣F(e′)∣+size(v)+t)+57.T \;\le\; 6|x| + |e'| + T_F(|e'|) + 2\,|F(e')| + 2\,\mathrm{size}(v) + P_U\bigl(|F(e')| + \mathrm{size}(v) + t\bigr) + 57 .T≤6∣x∣+∣e′∣+TF​(∣e′∣)+2∣F(e′)∣+2size(v)+PU​(∣F(e′)∣+size(v)+t)+57.

This is the forward half of the fixed-point construction for the efficient Kleene recursion theorem (blueprint lem:kleene, [MNY, Lemma 2.3]): kleeneFix_runs_of instantiates it with x:=Gx := Gx:=G, for which s(G,enc(G))s(G, \mathrm{enc}(G))s(G,enc(G)) is the fixed point, and efficient_fixed_point uses it for the transfer of halting from F(e)F(e)F(e) to eee.

Formalization Note: The bound is the exact cost of the straight-line program up to the two bounded sub-runs: 6∣x∣6|x|6∣x∣ for the copies of enc(x)\mathrm{enc}(x)enc(x) read in the pairing, in passing the pair to the s-m-n program and inside it; ∣e′∣|e'|∣e′∣ for passing enc(e′)\mathrm{enc}(e')enc(e′) to codeF\mathrm{code}_FcodeF​; TF(∣e′∣)T_F(|e'|)TF​(∣e′∣) bounding that run; 2∣F(e′)∣+2 size(v)2|F(e')| + 2\,\mathrm{size}(v)2∣F(e′)∣+2size(v) for the final pairing and for passing the pair to uuu; PU(⋅)P_U(\cdot)PU​(⋅) bounding the universal run; and 575757 units of rule costs and literals. No hypothesis is placed on xxx: the program whose description is hardcoded need not be closed.

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 MIPRE.Cost.Prog
open Polynomial
Formal statement
theorem MIPRE.Cost.Prog.kleeneProg_runs (U : UniversalMachine) (F : PolyTimeFun Prog Prog) (x : Prog)
    {v r : Data} {t : ℕ} (h : (F (hardcode x (encode x))).Runs v r t) :
    ∃ T ≤ 6 * esize x + esize (hardcode x (encode x)) +
        F.timeBound.eval (esize (hardcode x (encode x))) +
        2 * esize (F (hardcode x (encode x))) + 2 * v.size +
        U.bound.eval (esize (F (hardcode x (encode x))) + v.size + t) + 57,
      (kleeneProg U.univ F).Runs (.cons (encode x) v) r T := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Kleene.lean#L82-L112; internal lemma of the formalization of blueprint lem:kleene

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