Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Backward run of the Kleene two-argument program GGG: a halting run comes from a run of F(s(x,enc(x)))F(s(x,\mathrm{enc}(x)))F(s(x,enc(x))) on vvv

Proved
MIPRE.Cost.Prog.kleeneProg_halts_of

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

computabilitykleene-recursionmipre-formalizationsmn-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 G(cons(enc(x),v))⇓TrG(\mathtt{cons}(\mathrm{enc}(x), v)) \Downarrow_T rG(cons(enc(x),v))⇓T​r for some cost TTT, then

∃t,F(e′)(v)⇓tr.\exists t,\quad F(e')(v) \Downarrow_t r .∃t,F(e′)(v)⇓t​r.

This is the backward half of the fixed-point construction for the efficient Kleene recursion theorem (blueprint lem:kleene, [MNY, Lemma 2.3]): the fixed point halts only when its image does, with the same result. It enters kleeneFix_halts_iff, hence the input/output equivalence clause of efficient_fixed_point.

Formalization Note: The conclusion carries no time bound, by design: bounding the runs of F(e′)F(e')F(e′) by those of GGG would need a universal machine that is never faster than the program it simulates, a lower-bound clause that the formalization's UniversalMachine does not include (see the departure recorded at efficient_fixed_point).

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_halts_of (U : UniversalMachine) (F : PolyTimeFun Prog Prog) (x : Prog)
    {v r : Data} {T : ℕ} (h : (kleeneProg U.univ F).Runs (.cons (encode x) v) r T) :
    ∃ t, (F (hardcode x (encode x))).Runs v r t := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Kleene.lean#L114-L144; 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