Documentation

Cslib.Computability.Encoding.Delimit

Delimited Boolean words #

Defines delimit which turns arbitrary Boolean words into a self-delimiting, prefix-free code. The input words may be empty, contain any bit pattern, or be prefixes of one another.

delimit writes each data bit b as [true, b] and ends the codeword with [false]. This means that true introduces one data bit and false terminates the word, which makes the boundary recognizable in one left-to-right pass, even when arbitrary data follows it. A word of length n has a delimited code of length 2 * n + 1.

delimit_prefix_delimit states prefix-freeness: one delimited codeword is a prefix of another exactly when their original words are equal. undelimit_delimit_append and dropDelimited_delimit_append recover a word and the suffix following its codeword.

The guarantee concerns individual delimited words. A variable-length list of concatenated codewords needs its own delimiter if the entire list encoding is to be prefix-free.

Delimited words #

Each symbol b of w as [true, b], followed by [false].

Read complete tagged bits until the delimiter or end of input. An incomplete trailing tag is ignored.

The suffix after the first delimiter, or [] if the input ends before a delimiter.

@[simp]

Equation lemmas for undelimit and dropDelimited. These are needed by simp because delimit_cons rewrites delimit (b :: w) before the round-trip lemmas below can apply.

theorem Cslib.Encoding.delimit_append_inj {w w' u u' : List Bool} (h : delimit w ++ u = delimit w' ++ u') :
w = w' ∧ u = u'

A delimited word followed by another word determines both.

@[simp]
theorem Cslib.Encoding.delimit_append_inj_iff {w w' u u' : List Bool} :
delimit w ++ u = delimit w' ++ u' ↔ w = w' ∧ u = u'
@[simp]
@[simp]

The image of delimit is prefix-free, independently of the input words.