Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The increment program computes the successor of a binary numeral within an explicit cost bound

Proved
MIPRE.Cost.Prog.incProg_runs

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

binary-arithmeticcost-modellist-programsmip-remipre-formalization

Let lll be a bit string, read as a binary numeral least significant bit first, and let inc l be its successor ([]↦[true][] \mapsto [\mathrm{true}][]↦[true], false::l↦true::l\mathrm{false} :: l \mapsto \mathrm{true} :: lfalse::l↦true::l, true::l↦false::inc l\mathrm{true} :: l \mapsto \mathrm{false} :: \mathrm{inc}\ ltrue::l↦false::inc l). The increment program is incProg = let_ (cons (var 0) nil) (let_ (loop incBody) revOntoProg): it pairs the input with an empty accumulator, runs the carry loop incBody (which moves the carried bits onto the accumulator and stops at the first false bit or at the end), and reverses the accumulator back onto the rest with revOntoProg. p.Runs x r t means Eval [x] p r t: the program ppp on the input xxx halts with result rrr at cost ttt, in the timed big-step semantics of the ambient model. Then

∃ t≤(∣l∣+2) (8 ∣encode l∣+8 ∣l∣+60),incProg.Runs (encode l) (encode (inc l)) t,\exists\, t \le (|l| + 2)\,\big(8\,|\mathrm{encode}\ l| + 8\,|l| + 60\big),\qquad \mathrm{incProg}.\mathrm{Runs}\ (\mathrm{encode}\ l)\ (\mathrm{encode}\ (\mathrm{inc}\ l))\ t ,∃t≤(∣l∣+2)(8∣encode l∣+8∣l∣+60),incProg.Runs (encode l) (encode (inc l)) t,

where ∣encode l∣|\mathrm{encode}\ l|∣encode l∣ is the size (node count) of the encoded string.

incProg_runs_nat specializes this to canonical numerals n.bits, where inc n.bits = (n + 1).bits; that is the form in which the compressor's reading loop steps from the bit query iii to i+1i + 1i+1.

Formalization Note encode l is the list encoding Data.ofList Data.ofBool l, of size at most 4∣l∣+14|l| + 14∣l∣+1 (esize_bitStr_le), so the bound is quadratic in ∣l∣|l|∣l∣. inc is defined on all bit strings and the statement assumes no canonicity (no condition on the last bit). incProg is closed (incProg_wellScoped). The argument l is explicit and the proposition is MIPRE.Cost.Prog.incProg_runs.

Preamble
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Algebra.Polynomial.Eval.Degree
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.Tactic.Linarith
import Mathlib.Tactic.Ring
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_Cost_Unary
import Definitions.Def_MIPRE_Foundations_Halting_Descriptions
import Definitions.Def_MIPRE_Foundations_Cost_Numeric
import Definitions.Def_MIPRE_Foundations_Cost_Numeric_B
import Definitions.Def_MIPRE_Foundations_Halting_Lists
import Definitions.Def_MIPRE_Foundations_Cost_Growth
import Definitions.Def_MIPRE_Foundations_Halting_Arith

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Prog
open Polynomial
open MIPRE.Cost.Data
Formal statement
theorem MIPRE.Cost.Prog.incProg_runs (l : BitStr) :
    ∃ t ≤ (l.length + 2) * (8 * (encode l : Data).size + 8 * l.length + 60),
      incProg.Runs (encode l) (encode (inc l)) t := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Halting/Arith.lean#L298-L346

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