One step of the postorder stack machine increases the total size on the stack by at most one
ProvedMIPRE.Cost.Data.size_sum_stackStep_leData are binary trees (nil, cons a b) with the number of nodes, nil counting one. A datum is serialized in postorder, and (Data.toBitsPost), and read back by a stack machine whose step stackStep s bit on a stack (a list of data, top first) is: on the bit , push nil; on the bit with at least two entries, pop then and push ; on the bit with fewer than two entries, leave the stack unchanged. For every stack and bit ,
A adds a node of size one; a replaces two entries of sizes by one of size , 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.
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
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