Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Evaluation as a partial recursive function on data agrees with the big-step semantics

Proved
MIPRE.Cost.Machine.mem_evalData_iff

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

computabilitycost-modelmipre-formalizationundecidability

The evaluation machine of the ambient cost model has configurations ⟨κ,ρ,k⟩\langle \kappa, \rho, k\rangle⟨κ,ρ,k⟩ (a control ev p\mathtt{ev}\,pevp or ret v\mathtt{ret}\,vretv, an environment and a stack of frames), a total step function step\mathrm{step}step fixing the final configurations ⟨ret r,e,[]⟩\langle \mathtt{ret}\,r, e, []\rangle⟨retr,e,[]⟩, and it implements the big-step semantics: writing p(x)⇓trp(x) \Downarrow_t rp(x)⇓t​r for "the program ppp on input xxx halts with result rrr at cost ttt", one has p(x)⇓trp(x) \Downarrow_t rp(x)⇓t​r for some ttt iff stepN⟨ev p,[x],[]⟩=⟨ret r,e,[]⟩\mathrm{step}^N\langle \mathtt{ev}\,p, [x], []\rangle = \langle \mathtt{ret}\,r, e, []\ranglestepN⟨evp,[x],[]⟩=⟨retr,e,[]⟩ for some N,eN, eN,e (halts_iff). To connect with Mathlib's computability, configurations are encoded as data (Cfg.toData): a control is cons(nil,enc(p))\mathtt{cons}(\mathtt{nil}, \mathrm{enc}(p))cons(nil,enc(p)) or cons(cons(nil,nil),v)\mathtt{cons}(\mathtt{cons}(\mathtt{nil},\mathtt{nil}), v)cons(cons(nil,nil),v), a configuration is cons(control,cons(environment,stack))\mathtt{cons}(\text{control}, \mathtt{cons}(\text{environment}, \text{stack}))cons(control,cons(environment,stack)) with the environment and the stack as cons\mathtt{cons}cons-chains, and frames carry unary tags. On data, stepData\mathrm{stepData}stepData is defined by first-order tree operations alone and agrees with the machine, stepData(enc(c))=enc(step(c))\mathrm{stepData}(\mathrm{enc}(c)) = \mathrm{enc}(\mathrm{step}(c))stepData(enc(c))=enc(step(c)) (stepData_toData); IsFinalD(d)\mathrm{IsFinalD}(d)IsFinalD(d) tests finality on data, resultD(d)\mathrm{resultD}(d)resultD(d) reads the returned value, and initData(p,x)\mathrm{initData}(p, x)initData(p,x) is the encoding of the initial configuration ⟨ev p,[x],[]⟩\langle \mathtt{ev}\,p, [x], [] \rangle⟨evp,[x],[]⟩ for an encoded program ppp. Evaluation on data is the partial function

evalData(p,x):=fix(d↦{inl(resultD(d))if IsFinalD(d)inr(stepData(d))otherwise)(initData(p,x))  ∈  Part Data,\mathrm{evalData}(p, x) := \mathrm{fix}\Bigl(d \mapsto \begin{cases} \mathrm{inl}(\mathrm{resultD}(d)) & \text{if } \mathrm{IsFinalD}(d) \\ \mathrm{inr}(\mathrm{stepData}(d)) & \text{otherwise}\end{cases}\Bigr)\bigl(\mathrm{initData}(p,x)\bigr) \;\in\; \mathrm{Part}\,\mathrm{Data},evalData(p,x):=fix(d↦{inl(resultD(d))inr(stepData(d))​if IsFinalD(d)otherwise​)(initData(p,x))∈PartData,

the PFun.fix of one iteration of the evaluation loop (evalStep); it is partial recursive (partrec_evalData) because the step on data is primitive recursive.

Statement. For every program ccc and data x,rx, rx,r,

r∈evalData(enc(c),x)  ⟺  ∃t, c(x)⇓tr.r \in \mathrm{evalData}(\mathrm{enc}(c), x) \iff \exists t,\ c(x) \Downarrow_t r .r∈evalData(enc(c),x)⟺∃t, c(x)⇓t​r.

Together with partrec_evalData, this is the bridge from the ambient model to Mathlib's computability: a polynomial-time function of the model, precomposed with a computable encoding of its input, has a computable encoded output (PolyTimeFun.computable_encode_comp, computable_comp), which is how the reductions of the halting form of the compression lemmas (blueprint lem:halting-form: recursive_compression_halting, compressibility_criterion_halting) are shown Computable.

Formalization Note: Membership r∈evalData(⋅)r \in \mathrm{evalData}(\cdot)r∈evalData(⋅) is Mathlib's Part membership (the value is defined and equals rrr); the program enters as its serialization c.toData, and no Primcodable instance for Prog is involved — everything is at the level of Data, which is denumerable through Cantor pairing. No cost information survives the transport: the right-hand side is halting with an unspecified cost.

Preamble
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Computability.Partrec
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 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_Machine
import Definitions.Def_MIPRE_Foundations_Cost_Codable
import Definitions.Def_MIPRE_Foundations_Cost_MachineData
import Definitions.Def_MIPRE_Foundations_Cost_Partrec

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Machine
open Primrec
Formal statement
theorem MIPRE.Cost.Machine.mem_evalData_iff (c : Prog) (x r : Data) :
    r ∈ evalData c.toData x ↔ ∃ t, c.Runs x r t := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Partrec.lean#L222-L235; internal lemma of the formalization of blueprint lem:halting-form (the bridge from the ambient model to Mathlib's computability)

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