Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

One step of the postorder stack machine increases the total size on the stack by at most one

Proved
MIPRE.Cost.Data.size_sum_stackStep_le

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

bit-stringscost-modelmip-remipre-formalization

Data are binary trees (nil, cons a b) with size\mathrm{size}size the number of nodes, nil counting one. A datum is serialized in postorder, nil↦0\mathrm{nil} \mapsto 0nil↦0 and cons(a,b)↦a⋅b⋅1\mathrm{cons}(a,b) \mapsto a \cdot b \cdot 1cons(a,b)↦a⋅b⋅1 (Data.toBitsPost), and read back by a stack machine whose step stackStep s bit on a stack sss (a list of data, top first) is: on the bit 000, push nil; on the bit 111 with at least two entries, pop bbb then aaa and push cons(a,b)\mathrm{cons}(a, b)cons(a,b); on the bit 111 with fewer than two entries, leave the stack unchanged. For every stack sss and bit bbb,

∑e∈stackStep(s,b)size(e)  ≤  ∑e∈ssize(e)+1.\sum_{e \in \mathrm{stackStep}(s, b)} \mathrm{size}(e) \;\le\; \sum_{e \in s} \mathrm{size}(e) + 1.e∈stackStep(s,b)∑​size(e)≤e∈s∑​size(e)+1.

A 000 adds a node of size one; a 111 replaces two entries of sizes σa,σb\sigma_a, \sigma_bσa​,σb​ by one of size σa+σb+1\sigma_a + \sigma_b + 1σa​+σb​+1, or does nothing. Summed over a run, the total size on the stack after reading a string is at most its length, which is how the datum a string parses to is bounded by the string's length (size_parse_le) and, through natOf_lt, how a short description names a small parameter.

Formalization Note The statement is MIPRE.Cost.Data.size_sum_stackStep_le, with s : List Data and bit : Bool explicit; the sums are ((stackStep s bit).map size).sum and (s.map size).sum over ℕ. stackStep is total: the degenerate case of a 1 on a stack with fewer than two entries is covered, and the pop reads the top two entries with head?.getD nil, which the length test makes exact. The bound is on one step alone; the run stackRun is List.foldl stackStep.

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

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Data
Formal statement
theorem MIPRE.Cost.Data.size_sum_stackStep_le (s : List Data) (bit : Bool) :
    ((stackStep s bit).map size).sum ≤ (s.map size).sum + 1 := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Halting/Descriptions.lean#L283-L298; internal lemma of the formalization of blueprint rem:compression-abstract, item 1 (descriptions as bit strings), used in thm:halting, 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