Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Size bounds on machine configurations along a run

Definition
MIPRE_Foundations_Cost_MachineBound

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

complexity-theorymipre-formalizationself-interpreteruniversal-machine

This bundle defines the bounds that every configuration of the evaluation machine satisfies along the simulation of a derivation, and the resulting bound on the size of its encoding.

MIPRE.Cost.Machine.FrameBound V L PV\ L\ PV L P is a predicate on frames: a frame carrying an environment (cons1\mathtt{cons1}cons1, let1\mathtt{let1}let1, loop1\mathtt{loop1}loop1) must hold a program of size at most PPP and an environment of length at most LLL all of whose values have size at most VVV; a frame cons2(a)\mathtt{cons2}(a)cons2(a) must have size(a)≤V\mathrm{size}(a) \le Vsize(a)≤V.

MIPRE.Cost.Machine.CfgBound V L P K cV\ L\ P\ K\ cV L P K c is the corresponding bound on a configuration ccc, a structure with six clauses:

  1. a returned value has size at most VVV;
  2. a program under evaluation has size at most PPP;
  3. the environment has length at most LLL;
  4. every value in the environment has size at most VVV;
  5. the stack has length at most KKK;
  6. every frame of the stack satisfies FrameBound V L P\mathrm{FrameBound}\ V\ L\ PFrameBound V L P.

MIPRE.Cost.Machine.cfgSizeBound V L P KV\ L\ P\ KV L P K is the explicit bound

V+P+L V+L+K (V+P+L V+L+10)+K+8V + P + L\,V + L + K\,(V + P + L\,V + L + 10) + K + 8V+P+LV+L+K(V+P+LV+L+10)+K+8

on the size of the data encoding of any configuration satisfying CfgBound V L P K\mathrm{CfgBound}\ V\ L\ P\ KCfgBound V L P K.

No lemma is proved inside this bundle.

Formalization Note. Along the machine run simulating a derivation Eval(env,p,r,t)\mathrm{Eval}(\mathit{env}, p, r, t)Eval(env,p,r,t) the bounds hold with VVV any number at least ttt and at least the sizes of the initial values (every value produced is the result of a sub-derivation of cost at most ttt, hence of size at most ttt), LLL the initial environment length plus 2t2t2t, PPP the size of the initial program (every program under evaluation is one of its subterms), and KKK the initial stack length plus ttt (the stack gains at most ttt frames). The uploaded theorems eval_steps_bound and size_toData_le establish this; the consequence, that every configuration handled by the self-interpreter on a halting run has size polynomial in esize(p)+size(input)+t\mathrm{esize}(p) + \mathrm{size}(\mathrm{input}) + tesize(p)+size(input)+t, is what bounds the cost of the universal machine.

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/MachineBound.lean (definition bundle: declarations the uploaded statements rest on);
   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_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_Machine
import Definitions.Def_MIPRE_Foundations_Cost_Codable
import Definitions.Def_MIPRE_Foundations_Cost_MachineData

/-!
# Size bounds along machine runs

Along the run of the evaluation machine that simulates a derivation `Eval env p r t`, every
configuration stays bounded (`CfgBound`): values have size at most `V` (where `t ≤ V` and
the initial values are at most `V`, since every value produced is the result of a
sub-derivation of cost at most `t`), environments have length at most `L + 2 t`, programs
are subterms of the initial ones, and the stack gains at most `t` frames
(`eval_steps_bound`). Consequently the data encoding of every configuration along the run
has size polynomial in the sizes of the program, the input and the cost
(`size_toData_le`). This is what bounds the cost of the self-interpreter.
-/

namespace MIPRE.Cost

namespace Machine

/-! ## Bounds on configurations -/

/-- Bounds on a frame: values of size at most `V`, an environment of length at most `L`,
a program of size at most `P`. -/
def FrameBound (V L P : ℕ) : Frame → Prop
  | .cons1 t env => esize t ≤ P ∧ env.length ≤ L ∧ ∀ v ∈ env, v.size ≤ V
  | .cons2 a => a.size ≤ V
  | .let1 b env => esize b ≤ P ∧ env.length ≤ L ∧ ∀ v ∈ env, v.size ≤ V
  | .loop1 b env => esize b ≤ P ∧ env.length ≤ L ∧ ∀ v ∈ env, v.size ≤ V

/-- Bounds on a configuration: values of size at most `V`, environments of length at most
`L`, programs of size at most `P`, a stack of length at most `K`. -/
structure CfgBound (V L P K : ℕ) (c : Cfg) : Prop where
  ctrl_val : ∀ v, c.ctrl = .ret v → v.size ≤ V
  ctrl_prog : ∀ p, c.ctrl = .ev p → esize p ≤ P
  env_len : c.env.length ≤ L
  env_val : ∀ v ∈ c.env, v.size ≤ V
  kont_len : c.kont.length ≤ K
  frames : ∀ f ∈ c.kont, FrameBound V L P f

/-! ## Program subterms -/

/-! ## Chaining bounds along runs -/

/-! ## Size of the encoded configurations -/

/-- Size of the encoding of a configuration satisfying `CfgBound V L P K`. -/
def cfgSizeBound (V L P K : ℕ) : ℕ :=
  V + P + L * V + L + K * (V + P + L * V + L + 10) + K + 8

/-! ## Runs from the empty stack are bounded forever -/

/-! ## The number of steps of a run -/

/-! ## Cost sums -/

end Machine

end MIPRE.Cost
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/MachineBound.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