Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The step function on encoded configurations agrees with the evaluation machine

Proved
MIPRE.Cost.Machine.stepData_toData

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

computabilitycost-modelmipre-formalizationself-interpreteruniversal-machine

The evaluation machine of the ambient cost model is a small-step abstract machine (of CEK type) whose configurations ccc consist of a control (either "evaluate the program ppp" or "return the value vvv"), an environment (a list of values) and a stack of continuation frames (cons1, cons2, let1, loop1, recording the pending work of a cons\mathsf{cons}cons, a let\mathsf{let}let or a loop\mathsf{loop}loop). Its transition function is step:Cfg→Cfg\mathsf{step} : \mathsf{Cfg} \to \mathsf{Cfg}step:Cfg→Cfg, with final configurations (a returned value and an empty stack) fixed.

Configurations are encoded as data: a configuration is cons  ctrl  (cons  env  kont)\mathsf{cons}\;\mathit{ctrl}\;(\mathsf{cons}\;\mathit{env}\;\mathit{kont})consctrl(consenvkont), where the control is cons nil ⌈p⌉\mathsf{cons}\,\mathsf{nil}\,\lceil p \rceilconsnil⌈p⌉ ("evaluate ppp", with ⌈p⌉\lceil p\rceil⌈p⌉ the tree encoding of ppp) or cons (cons nil nil) v\mathsf{cons}\,(\mathsf{cons}\,\mathsf{nil}\,\mathsf{nil})\,vcons(consnilnil)v ("return vvv"), and the environment and the stack are cons\mathsf{cons}cons-chains, each frame being cons (ofNat tag) payload\mathsf{cons}\,(\mathsf{ofNat}\,\mathit{tag})\,\mathit{payload}cons(ofNattag)payload with tags 000 to 333 in unary. This encoding is c↦⌈c⌉c \mapsto \lceil c \rceilc↦⌈c⌉, in Lean Cfg.toData. On data, a function stepData:Data→Data\mathsf{stepData} : \mathsf{Data} \to \mathsf{Data}stepData:Data→Data is defined directly, using only the first-order operations left\mathsf{left}left, right\mathsf{right}right, cons\mathsf{cons}cons, unary decoding and list indexing, by cases on the encoded control and the encoded top frame.

For every configuration ccc,

stepData(⌈c⌉)=⌈step(c)⌉.\mathsf{stepData}(\lceil c \rceil) = \lceil \mathsf{step}(c) \rceil .stepData(⌈c⌉)=⌈step(c)⌉.

The lemma transports the machine to data. It is the basis of two results: that evaluation in the ambient model is partial recursive in Mathlib's sense (the step on data is primitive recursive, Cost/Partrec.lean), and that the step can be implemented by a program of the model itself (stepProg, Cost/Interpreter.lean), which is the engine of the self-interpreter and hence of the efficient universal machine (blueprint lem:universal-tm).

Formalization Note: stepData is a total function on all data, defined by nested conditionals on Data.unaryToNat of tag fields and on Data.getList for variable lookup; the lemma only concerns its values on well-formed encodings ⌈c⌉\lceil c \rceil⌈c⌉. Programs are encoded by Prog.toData with constructor tags 000 to 666 in unary, and the control, frame and configuration encodings are those of Cost/MachineData.lean. The iterated form stepData^[N] (toData c) = toData (step^[N] c) follows immediately.

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 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

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Machine
Formal statement
theorem MIPRE.Cost.Machine.stepData_toData (c : Cfg) : stepData c.toData = (step c).toData := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/MachineData.lean#L128-L167; 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