Decoding a bit string from data succeeds only on its encoding
ProvedMIPRE.Cost.Data.encode_of_decode_bitStrThe ambient model computes on binary trees: Data has the two constructors nil and cons a b. A bit is encoded as , , and a bit string (BitStr = List Bool) as the cons-chain of its bits ending in nil, so . Decoding, decode : Data → Option BitStr, reads the chain back elementwise: nil decodes to the empty string, cons a d to when decodes to the bit and to , and to none whenever a cell is neither nil nor cons nil nil. The class SizedEncoding guarantees ; this theorem is the converse: for every datum and bit string ,
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.
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.encode_of_decode_bitStr {d : Data} {l : BitStr}
(h : (decode d : Option BitStr) = some l) : (encode l : Data) = d := by sorry