Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Decoding a bit string from data succeeds only on its encoding

Proved
MIPRE.Cost.Data.encode_of_decode_bitStr

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

bit-stringscost-modelmip-remipre-formalization

The ambient model computes on binary trees: Data has the two constructors nil and cons a b. A bit is encoded as false↦nil\mathrm{false} \mapsto \mathrm{nil}false↦nil, true↦cons(nil,nil)\mathrm{true} \mapsto \mathrm{cons}(\mathrm{nil}, \mathrm{nil})true↦cons(nil,nil), and a bit string l∈{0,1}∗l \in \{0,1\}^*l∈{0,1}∗ (BitStr = List Bool) as the cons-chain of its bits ending in nil, so encode(l)=cons(encode l0,cons(encode l1,…nil))\mathrm{encode}(l) = \mathrm{cons}(\mathrm{encode}\,l_0, \mathrm{cons}(\mathrm{encode}\,l_1, \ldots \mathrm{nil}))encode(l)=cons(encodel0​,cons(encodel1​,…nil)). Decoding, decode : Data → Option BitStr, reads the chain back elementwise: nil decodes to the empty string, cons a d to b::lb :: lb::l when aaa decodes to the bit bbb and ddd to lll, and to none whenever a cell is neither nil nor cons nil nil. The class SizedEncoding guarantees decode(encode l)=some l\mathrm{decode}(\mathrm{encode}\,l) = \mathrm{some}\,ldecode(encodel)=somel; this theorem is the converse: for every datum ddd and bit string lll,

decode(d)=some(l) ⟹ encode(l)=d.\mathrm{decode}(d) = \mathrm{some}(l) \ \Longrightarrow\ \mathrm{encode}(l) = d.decode(d)=some(l) ⟹ encode(l)=d.

So decoding is injective where it succeeds, and the data on which it succeeds are exactly the encodings of bit strings. The descriptions of the halting reduction travel as bit strings and their parameters as binary numerals read back from data; encode_natOf uses this to show that a normalized parameter is the encoding of the number it denotes.

Formalization Note The statement is MIPRE.Cost.Data.encode_of_decode_bitStr, with d : Data and l : BitStr implicit and h : (decode d : Option BitStr) = some l; decode and encode are those of the SizedEncoding BitStr instance, Data.toList? Data.toBool? and Data.ofList Data.ofBool. The type ascription (decode d : Option BitStr) selects the bit-string instance, as Data also decodes to naturals and pairs. No size or well-formedness hypothesis is needed.

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.encode_of_decode_bitStr {d : Data} {l : BitStr}
    (h : (decode d : Option BitStr) = some l) : (encode l : Data) = d := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Halting/Descriptions.lean#L141-L170; 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