Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The halting problem of Mathlib's partial recursive codes compiles into the ambient model, computably on descriptions

Proved
MIPRE.Cost.exists_compile

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

computabilitycost-modelmip-remipre-formalizationundecidability

Mathlib's Nat.Partrec.Code is a Gödel numbering of the partial recursive functions: every code pcpcpc has a partial function pc.eval:N→Part Npc.\mathrm{eval} : \mathbb{N} \to \mathrm{Part}\,\mathbb{N}pc.eval:N→PartN, and (pc.eval(0)).Dom(pc.\mathrm{eval}(0)).\mathrm{Dom}(pc.eval(0)).Dom says that pcpcpc halts on the input 000; Computable is Mathlib's notion of computability between types carrying a Primcodable structure. In the ambient cost model, programs (Prog) are encoded as data by their tree serialization enc(p)\mathrm{enc}(p)enc(p), data form a Primcodable type (through a Cantor-pairing bijection with N\mathbb{N}N), and Halts(p,x)\mathrm{Halts}(p, x)Halts(p,x) (Halts) says that the program ppp run on the input xxx halts, with some result at some cost. The s-m-n map 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) runs ppp on the pair of the literal ddd and its input, and nˉ\bar nnˉ denotes the unary numeral of nnn (the list of nnn copies of nil\mathtt{nil}nil).

Statement. There is a map compile:Code→Prog\mathrm{compile} : \mathrm{Code} \to \mathrm{Prog}compile:Code→Prog such that

  1. the description map pc↦enc(compile(pc))pc \mapsto \mathrm{enc}(\mathrm{compile}(pc))pc↦enc(compile(pc)) is computable, and
  2. for every code pcpcpc,
Halts(compile(pc),nil)  ⟺  (pc.eval(0)).Dom.\mathrm{Halts}\bigl(\mathrm{compile}(pc), \mathtt{nil}\bigr) \iff (pc.\mathrm{eval}(0)).\mathrm{Dom} .Halts(compile(pc),nil)⟺(pc.eval(0)).Dom.

This is the seam at which the development meets Mathlib's halting problem (blueprint lem:halting-form). The compression lemmas produce reductions ggg from the halting problem of the cost model; composing with compile\mathrm{compile}compile gives reductions g∘compileg \circ \mathrm{compile}g∘compile from the halting problem of Nat.Partrec.Code, which is what recursive_compression_halting, compressibility_criterion_halting and ultimately the headline undecidability statement consume. Computability of the composite follows from clause 1 together with the Mathlib-computability of polynomial-time functions on computably encoded inputs (PolyTimeFun.computable_comp).

Formalization Note: The compiler carries no time bound — it is a computability-only bridge, which is why this step is available for the computable form of the main theorem but not for a polynomial-time one. Computability is stated for the description enc(compile(pc))\mathrm{enc}(\mathrm{compile}(pc))enc(compile(pc)) as data, since Prog deliberately has no Primcodable instance. The empty input is the datum nil\mathtt{nil}nil (the encoding of the empty bit string), and the witness is compile(pc)=s(ofCode(cu),#pc‾)\mathrm{compile}(pc) = s(\mathrm{ofCode}(c_u), \overline{\#pc})compile(pc)=s(ofCode(cu​),#pc​): the s-m-n hardcoding of the Gödel number #pc\#pc#pc of pcpcpc (Encodable.encode pc), as a unary numeral, into the translation of a ToPartrec code cuc_ucu​ for the universal partial function n↦(decode n).eval(0)n \mapsto (\mathrm{decode}\ n).\mathrm{eval}(0)n↦(decode n).eval(0).

Preamble
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Computability.PartrecCode
import Mathlib.Computability.Primrec.List
import Mathlib.Computability.TuringMachine.Config
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
import Definitions.Def_MIPRE_Foundations_Cost_FromPartrec

open MIPRE
open MIPRE.Cost
open Turing.ToPartrec (Code)
Formal statement
theorem MIPRE.Cost.exists_compile :
    ∃ compile : Nat.Partrec.Code → Prog,
      Computable (fun pc => (encode (compile pc) : Data)) ∧
      ∀ pc : Nat.Partrec.Code, Halts (compile pc) .nil ↔ (pc.eval 0).Dom := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/FromPartrec.lean#L396-L426; internal lemma of the formalization of blueprint lem:halting-form (the bridge from Mathlib's partial recursive functions into the model)

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