Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Initial and final configurations of the evaluation machine, as data (machine-data addendum)

Definition
MIPRE_Foundations_Cost_MachineData_B

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

cost-modelmip-remipre-formalizationself-interpreter

This bundle adds three theorems, and no new definitions, to the already published bundle MIPRE_Foundations_Cost_MachineData, which encodes the configurations of the evaluation machine as Data (Cfg.toData: a configuration is cons ctrl (cons env kont)\mathrm{cons}\,\mathit{ctrl}\,(\mathrm{cons}\,\mathit{env}\,\mathit{kont})consctrl(consenvkont), with the control cons nil (toData p)\mathrm{cons}\,\mathrm{nil}\,(\mathrm{toData}\,p)consnil(toDatap) for "evaluate ppp" and cons (cons nil nil) v\mathrm{cons}\,(\mathrm{cons}\,\mathrm{nil}\,\mathrm{nil})\,vcons(consnilnil)v for "return vvv") and transports the step function to data. The added lemmas relate three data-level operations to the machine: initData p x, the initial configuration of a program given as data on the input xxx, satisfies initData (toData p) x=toData ⟨ev p,[x],[ ]⟩\mathrm{initData}\,(\mathrm{toData}\,p)\,x = \mathrm{toData}\,\langle \mathrm{ev}\,p, [x], [\,]\rangleinitData(toDatap)x=toData⟨evp,[x],[]⟩ for every program ppp; the finality test IsFinalD (first component of the control not nil, empty stack) characterizes the encoded final configurations,

IsFinalD (toData c)  ⟷  ∃ r e, c=⟨ret r, e, [ ]⟩;\mathrm{IsFinalD}\,(\mathrm{toData}\,c) \;\longleftrightarrow\; \exists\, r\ e,\ c = \langle \mathrm{ret}\,r,\ e,\ [\,]\rangle;IsFinalD(toDatac)⟷∃r e, c=⟨retr, e, []⟩;

and the result extraction satisfies resultD (toData ⟨ret r,e,[ ]⟩)=r\mathrm{resultD}\,(\mathrm{toData}\,\langle \mathrm{ret}\,r, e, [\,]\rangle) = rresultD(toData⟨retr,e,[]⟩)=r. These are the equations under which the data-level evaluation loop of Cost/Partrec.lean and the interpreter programs of Cost/Universal.lean recognize the start and the end of a simulated run.

Formalization Note IsFinalD d unfolds to d.left.left ≠ .nil ∧ d.right.right = .nil, resultD d to d.left.right, and initData p x to .cons (evD p) (.cons (.cons x .nil) .nil); the characterization is stated for every c : Cfg with an existential over the returned value r : Data and the environment e : Env. The theorems are initData_eq, isFinalD_toData and resultD_toData.

Definition code
/-
Copyright (c) 2026 Thomas Vidick. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Vidick
-/
/- Generated for Prove2Me from vidick/MIPRE-formalization@70cbf1c, MIPRE/Foundations/Cost/MachineData.lean (delta bundle: declarations the new statements need that the published bundle Def_MIPRE_Foundations_Cost_MachineData does not carry);
   produced mechanically by prove2me/tools/gen.py, never edited by hand. -/
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_Basic_B
import Definitions.Def_MIPRE_Foundations_Cost_Encoding
import Definitions.Def_MIPRE_Foundations_Cost_Encoding_B
import Definitions.Def_MIPRE_Foundations_Cost_PolyTime
import Definitions.Def_MIPRE_Foundations_Cost_Closure
import Definitions.Def_MIPRE_Foundations_Cost_Machine
import Definitions.Def_MIPRE_Foundations_Cost_Machine_B
import Definitions.Def_MIPRE_Foundations_Cost_Loops
import Definitions.Def_MIPRE_Foundations_Cost_Loops_B
import Definitions.Def_MIPRE_Foundations_Cost_Codable
import Definitions.Def_MIPRE_Foundations_Cost_Codable_B
import Definitions.Def_MIPRE_Foundations_Cost_MachineData

/-!
# The evaluation machine on data

Configurations of the evaluation machine (`Cost/Machine.lean`) encoded as `Data`
(`Machine.Cfg.toData`), and the step function transported to `Data` (`Machine.stepData`),
defined by the first-order operations `left`, `right`, `cons`, `unaryToNat`, `getList`
only — so that it is primitive recursive (`Cost/Partrec.lean`) and implementable by a
program of the ambient model (the self-interpreter). The correspondence is
`stepData_toData : stepData c.toData = (step c).toData`.

Encoding: a control is `cons nil (toData p)` ("evaluate `p`") or `cons (cons nil nil) v`
("return `v`"); a configuration is `cons ctrl (cons env kont)` with the environment and the
stack as `cons`-chains; a frame is `cons (ofNat tag) payload` with tags `0`–`3` for
`cons1 t env` (payload `cons t env`), `cons2 a` (payload `a`), `let1 b env`, `loop1 b env`.
-/

namespace MIPRE.Cost

namespace Machine

/-! ## Encoding -/

theorem initData_eq (p : Prog) (x : Data) : initData p.toData x = Cfg.toData ⟨.ev p, [x], []⟩ :=
  rfl

theorem isFinalD_toData (c : Cfg) : IsFinalD c.toData ↔ ∃ r e, c = ⟨.ret r, e, []⟩ := by
  obtain ⟨ctrl, env, kont⟩ := c
  cases ctrl with
  | ev p =>
    simp [IsFinalD, Cfg.toData, Ctrl.toData, evD]
  | ret v =>
    cases kont with
    | nil => simp [IsFinalD, Cfg.toData, Ctrl.toData, retD]
    | cons f k => simp [IsFinalD, Cfg.toData, Ctrl.toData, retD]

theorem resultD_toData (r : Data) (e : Env) : resultD (Cfg.toData ⟨.ret r, e, []⟩) = r := rfl

/-! ## The step function on data -/

end Machine

end MIPRE.Cost
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/MachineData.lean

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