Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The interpreter loop halts only along a machine run that reaches a final configuration with the same value

Proved
MIPRE.Cost.Machine.interpLoop_rev

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

computabilitycost-modelmipre-formalizationself-interpreteruniversal-machine

Let interpBody be the body of the self-interpreter's loop: on the encoding ⌈c⌉\lceil c\rceil⌈c⌉ of a configuration ccc of the evaluation machine it stops with the returned value if ccc is final, and otherwise continues with ⌈step(c)⌉\lceil\mathsf{step}(c)\rceil⌈step(c)⌉. The lemma is the converse of interpLoop_runs: a halting run of the loop can only come from the machine.

Let t∈Nt \in \mathbb{N}t∈N, let ccc be a configuration, ρ\rhoρ an environment and rrr a value. If

Eval  (⌈c⌉::ρ)  (loop  interpBody)  r  t,\mathsf{Eval}\;(\lceil c\rceil :: \rho)\;(\mathsf{loop}\;\mathtt{interpBody})\;r\;t ,Eval(⌈c⌉::ρ)(loopinterpBody)rt,

then there are N∈NN \in \mathbb{N}N∈N and an environment eee with

stepN(c)=⟨ret r,  e,  [ ]⟩,\mathsf{step}^{N}(c) = \langle \mathsf{ret}\,r,\; e,\; [\,]\rangle ,stepN(c)=⟨retr,e,[]⟩,

that is, the machine run from ccc reaches a final configuration, and its value is the result rrr of the loop.

This is the backward half of the efficient universal machine (blueprint lem:universal-tm): if the universal program halts on (⌈p⌉,v)(\lceil p\rceil, v)(⌈p⌉,v) with result rrr, then the machine run of ppp on vvv reaches a final configuration with value rrr, and by the correspondence between machine runs and derivations (halts_iff) the program ppp halts on vvv with result rrr. Without it, the universal program could halt with a value the simulated program never produces.

Formalization Note: The lemma is stated for an arbitrary configuration ccc and arbitrary trailing environment ρ\rhoρ, and for any cost ttt, since it is proved by strong induction on ttt; no bound on ttt or on sizes is needed. The number of machine steps NNN is not related to ttt in the statement.

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

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Machine
open Polynomial
open MIPRE.Cost.Prog
Formal statement
theorem MIPRE.Cost.Machine.interpLoop_rev : ∀ (t : ℕ) (c : Cfg) (env : Env) (r : Data),
    Eval (c.toData :: env) (.loop interpBody) r t → ∃ N e, step^[N] c = ⟨.ret r, e, []⟩ := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Universal.lean#L185-L214; internal lemma of the formalization of blueprint lem:universal-tm, https://vidick.github.io/MIPRE-formalization/blueprint/

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