Canonicalization of the concrete binary List Nat codec
TheoremSuccessful block parsing reconstructs the input#✓fully proved
Successful block parsing reconstructs the entire input.
theorem blocks_decode_sound {fuel : Nat} {x : List Bool}
{bs : List (List Bool)} (h : undelimitBlocksAux fuel x = some bs) :
x = (bs.map delimit).flatten
def undelimitBlocksAux : ℕ → List Bool → Option (List (List Bool))
| _, [] => some []
| 0, _ :: _ => none
| fuel + 1, input =>
(undelimit input).bind fun p => (undelimitBlocksAux fuel p.2).map (p.1 :: ·)
MathlibExt/Computability/Complexity.lean:95
def delimit : List Bool → List Bool
| [] => [false]
| b :: l => true :: b :: delimit l
MathlibExt/Computability/Complexity.lean:68
Uses 4 · Used by 5
TheoremDecoding natural-number payloads never fails#✓fully proved
Nat payload decoding never fails, including on noncanonical bits.
theorem mapM_decode_nat (bs : List (List Bool)) :
bs.mapM (bitDecode (α := Nat)) = some (bs.map decodeNat)
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
Uses 2 · Used by 1
TheoremDecoding a list of naturals is block parsing then number decoding#✓fully proved
List Nat decoding is precisely framed-payload parsing followed by the existing total Nat decoder.
theorem decode_list_nat (x : List Bool) :
bitDecode (α := List Nat) x =
(undelimitBlocks x).map (List.map decodeNat)
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
def undelimitBlocks (input : List Bool) : Option (List (List Bool)) :=
undelimitBlocksAux input.length input
MathlibExt/Computability/Complexity.lean:102
Uses 9 · Used by 5
TheoremRe-encoding decoded payloads normalizes each one#✓fully proved
Canonical re-encoding normalizes each payload without changing list order or multiplicity.
theorem encode_decoded_nat_blocks (bs : List (List Bool)) :
bitEncode (bs.map decodeNat) =
(bs.map (fun p => delimit (normalizeNat p))).flatten
def bitEncode [BitstringEncoding α] (a : α) : List Bool := toEncoding.encode a
MathlibExt/Computability/Complexity.lean:55
def delimit : List Bool → List Bool
| [] => [false]
| b :: l => true :: b :: delimit l
MathlibExt/Computability/Complexity.lean:68
def normalizeNat (bits : List Bool) : List Bool :=
if bits.getLast? = some false then bits ++ [true] else bits
CSLibExt/Computability/Complexity/FramedCNF/Normalize.lean:27
Uses 10 · Used by 2
TheoremNormalizing framed number payloads at most triples the length#✓fully proved
Normalizing every framed Nat payload increases length by at most threefold, even for noncanonical input.
theorem normalized_nat_blocks_length_le (bs : List (List Bool)) :
((bs.map (fun p => delimit (normalizeNat p))).flatten).length ≤
3 * ((bs.map delimit).flatten).length
def delimit : List Bool → List Bool
| [] => [false]
| b :: l => true :: b :: delimit l
MathlibExt/Computability/Complexity.lean:68
def normalizeNat (bits : List Bool) : List Bool :=
if bits.getLast? = some false then bits ++ [true] else bits
CSLibExt/Computability/Complexity/FramedCNF/Normalize.lean:27
Uses 3 · Used by 2
TheoremRe-encoded decoded list of naturals is linear in raw input#✓fully proved
Re-encoding a successfully decoded List Nat is linear in the raw input, not in the decoded numeric values.
theorem decoded_list_nat_encode_length_le {x : List Bool} {as : List Nat}
(h : bitDecode x = some as) : (bitEncode as).length ≤ 3 * x.length
def bitDecode [BitstringEncoding α] (l : List Bool) : Option α := toEncoding.decode l
MathlibExt/Computability/Complexity.lean:58
def bitEncode [BitstringEncoding α] (a : α) : List Bool := toEncoding.encode a
MathlibExt/Computability/Complexity.lean:55
Uses 13 · Used by 1
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.