Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The step-cost program on an evaluate-configuration reduces to the case program selected by the constructor tag

Proved
MIPRE.Cost.Machine.stepCostProg_ev

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

cost-modelmipre-formalizationself-interpreteruniversal-machine

The clocked self-interpreter needs, at each simulated step, the exact cost stepCost(c)\mathsf{stepCost}(c)stepCost(c) that the evaluation machine charges for the step from the configuration ccc; the program stepCostProg computes it, in unary, from the encoding ⌈c⌉\lceil c\rceil⌈c⌉. On a configuration in evaluation mode, "evaluate ppp", the cost depends only on the constructor of ppp and on its arguments: it is 1+size1 + \mathrm{size}1+size of the variable's value for var i\mathsf{var}\,ivari, size(d)\mathrm{size}(d)size(d) for const d\mathsf{const}\,dconstd, 111 for nil\mathsf{nil}nil, cons\mathsf{cons}cons, elim\mathsf{elim}elim and let\mathsf{let}let, and 000 for loop\mathsf{loop}loop. Accordingly stepCostProg takes the configuration apart and dispatches on the unary constructor tag k∈{0,…,6}k \in \{0, \dots, 6\}k∈{0,…,6} of the program to one of seven fixed case programs costCasesk\mathtt{costCases}_kcostCasesk​ (tags 000 to 666 standing for var\mathsf{var}var, nil\mathsf{nil}nil, cons\mathsf{cons}cons, elim\mathsf{elim}elim, let\mathsf{let}let, loop\mathsf{loop}loop, const\mathsf{const}const), each of which receives the pair (payload of ppp, encoded environment) as its input.

Let k<7k < 7k<7, let body\mathit{body}body (the payload of a program with tag kkk), env\mathit{env}env (an encoded environment), kont\mathit{kont}kont (an encoded stack) and rrr be values, and let t∈Nt \in \mathbb{N}t∈N. Suppose that the kkk-th case program, run on the single input cons  body  env\mathsf{cons}\;\mathit{body}\;\mathit{env}consbodyenv, halts with result rrr at cost ttt. Then there is a cost

s≤t+2 size(body)+2 size(env)+size(kont)+k+14s \le t + 2\,\mathrm{size}(\mathit{body}) + 2\,\mathrm{size}(\mathit{env}) + \mathrm{size}(\mathit{kont}) + k + 14s≤t+2size(body)+2size(env)+size(kont)+k+14

such that stepCostProg, run on the encoded evaluate-configuration

cons  (cons  nil  (cons  (ofNat k)  body))  (cons  env  kont)\mathsf{cons}\;\bigl(\mathsf{cons}\;\mathsf{nil}\;(\mathsf{cons}\;(\mathsf{ofNat}\,k)\;\mathit{body})\bigr)\;(\mathsf{cons}\;\mathit{env}\;\mathit{kont})cons(consnil(cons(ofNatk)body))(consenvkont)

(control "evaluate the program with tag kkk and payload body\mathit{body}body", environment env\mathit{env}env, stack kont\mathit{kont}kont) halts with the same result rrr at cost sss.

This is the common prefix of all seven evaluate-cases of the correctness theorem stepCostProg_runs, which then only has to run each case program on its pair. It serves the clocked universal machine of blueprint lem:universal-tm.

Formalization Note: The case programs are the list costCases of Cost/Universal.lean, indexed with List.getD (default nil\mathsf{nil}nil, never reached since k<7k < 7k<7); the overhead kkk in the bound is the cost of walking the dispatch chain, one elim\mathsf{elim}elim per tag. The hypothesis is a run in the one-element environment [cons  body  env][\mathsf{cons}\;\mathit{body}\;\mathit{env}][consbodyenv] (the case programs are closed), and the conclusion is a run in the one-element environment holding the encoded configuration, that is, a Prog.Runs statement spelled out.

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.stepCostProg_ev (k : ℕ) (body env kont r : Data) {t : ℕ}
    (hk : k < costCases.length)
    (h : Eval [Data.cons body env] (costCases.getD k .nil) r t) :
    ∃ s ≤ t + 2 * body.size + 2 * env.size + kont.size + k + 14,
      Eval [Data.cons (.cons .nil (.cons (.ofNat k) body)) (.cons env kont)] stepCostProg r s := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Universal.lean#L525-L550; 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