Documentation

CslibFrontier.Foundations.Data.List.SelfDelimiting

Concatenations of self-delimiting code words #

A code c : α → List β is self-delimiting when a code word followed by anything determines the word and what follows it: c a ++ r = c a' ++ r' implies a = a' and r = r'. Code words that end in a letter that occurs nowhere else, and code words of one length for an injective code, are of this kind. A concatenation of a known number of such code words can be read back one word after the other (List.flatMap_inj_of_length_eq). The number has to be known because a code word may be empty.

Main results #

theorem List.flatMap_inj_of_length_eq {α : Type u_1} {β : Type u_2} {c : α → List β} (hc : ∀ (a a' : α) (r r' : List β), c a ++ r = c a' ++ r' → a = a' ∧ r = r') {l l' : List α} (hlen : l.length = l'.length) (h : flatMap c l = flatMap c l') :
l = l'

Two words of the same length are equal if the concatenations of the code words of their letters are equal, for a code in which a code word followed by anything determines the letter and what follows.