Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The canonicity walk accepts exactly the encodings of bit strings that are empty or end in a one

Proved
MIPRE.Cost.Data.canonWalk_iff

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

binary-arithmeticbit-stringslist-programsmip-remipre-formalization

In the ambient cost model, data are binary trees (Data, built from nil and cons), a bit is encoded as false↦nil\mathsf{false} \mapsto \mathtt{nil}false↦nil and true↦cons(nil,nil)\mathsf{true} \mapsto \mathtt{cons}(\mathtt{nil}, \mathtt{nil})true↦cons(nil,nil), and a bit string l∈{0,1}∗l \in \{0,1\}^*l∈{0,1}∗ as the cons\mathtt{cons}cons-chain of its encoded bits ending in nil\mathtt{nil}nil, written encode(l)\mathrm{encode}(l)encode(l). The function canonWalk:Data→Bool→Bool\mathrm{canonWalk} : \mathrm{Data} \to \mathrm{Bool} \to \mathrm{Bool}canonWalk:Data→Bool→Bool walks a datum while recording whether the string read so far is empty or ends in a one: canonWalk(nil,b)=b\mathrm{canonWalk}(\mathtt{nil}, b) = bcanonWalk(nil,b)=b; canonWalk(cons(nil,r),b)=canonWalk(r,false)\mathrm{canonWalk}(\mathtt{cons}(\mathtt{nil}, r), b) = \mathrm{canonWalk}(r, \mathsf{false})canonWalk(cons(nil,r),b)=canonWalk(r,false); canonWalk(cons(cons(nil,nil),r),b)=canonWalk(r,true)\mathrm{canonWalk}(\mathtt{cons}(\mathtt{cons}(\mathtt{nil},\mathtt{nil}), r), b) = \mathrm{canonWalk}(r, \mathsf{true})canonWalk(cons(cons(nil,nil),r),b)=canonWalk(r,true); and canonWalk(cons(h,r),b)=false\mathrm{canonWalk}(\mathtt{cons}(h, r), b) = \mathsf{false}canonWalk(cons(h,r),b)=false for any other head hhh.

For every datum ddd and Boolean bbb,

canonWalk(d,b)=true  ⟺  ∃ l∈{0,1}∗:d=encode(l) ∧ (l=ε⇒b=true) ∧ (l≠ε⇒last(l)=1).\mathrm{canonWalk}(d, b) = \mathsf{true} \iff \exists\, l \in \{0,1\}^*:\quad d = \mathrm{encode}(l)\ \wedge\ \bigl(l = \varepsilon \Rightarrow b = \mathsf{true}\bigr)\ \wedge\ \bigl(l \ne \varepsilon \Rightarrow \mathrm{last}(l) = 1\bigr).canonWalk(d,b)=true⟺∃l∈{0,1}∗:d=encode(l) ∧ (l=ε⇒b=true) ∧ (l=ε⇒last(l)=1).

This is the specification of the walk performed by the program normBinProg, with which the wrapper decider of the halting reduction normalizes the parameter of a description (a canonical binary numeral is a bit string that is empty or ends in a one). Its instance at b=trueb = \mathsf{true}b=true is canonWalk_eq_isCanonBin.

Formalization Note. The statement is MIPRE.Cost.Data.canonWalk_iff. BitStr is List Bool, encode l is Data.ofList Data.ofBool l, and the last-bit condition is l.getLast? = some true; the empty and nonempty cases are stated as two separate implications, (l = [] → b = true) and (l ≠ [] → l.getLast? = some true). For a datum that is not the encoding of any bit string, the right side is false because no l satisfies d = encode l. There are no hypotheses.

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.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

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Data
Formal statement
theorem MIPRE.Cost.Data.canonWalk_iff (d : Data) (b : Bool) :
    canonWalk d b = true ↔
      ∃ l : BitStr, d = encode l ∧ (l = [] → b = true) ∧ (l ≠ [] → l.getLast? = some true) := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Halting/Lists.lean#L115-L183; internal lemma of the format-check programs of the wrapper decider (module docstring); no blueprint label is attached to this declaration

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