Lempel–Ziv incremental parsing (LZ78) #
The incremental parsing of [ZL78] cuts a word into phrases from left to right: each
phrase is the shortest prefix of the remaining input that is not an earlier phrase. When the
input runs out first, the last phrase is the whole (nonempty) remainder, which may repeat an
earlier phrase. For example ([CT06], Ch. 13),
ABBABBABBBAABABAA parses as A, B, BA, BB, AB, BBA, ABA, BAA.
Every phrase is an earlier phrase (or []) followed by one symbol, so the parse is encoded by
(pointer, symbol) pairs: the pair (j, a) stands for phrase j (with phrase 0 being [])
followed by a. The example above becomes
(0,A) (0,B) (2,A) (2,B) (1,B) (4,A) (5,A) (3,A).
This file defines the parse, the pair encoder and decoder, and proves that the code is lossless.
The number of phrases is bounded in CslibFrontier.Algorithms.Lean.LempelZiv.LZ78Count, and the
bit-level code and its length bound are in CslibFrontier.Algorithms.Lean.LempelZiv.LZ78Bits. The
functions are reference implementations with quadratic dictionary lookups; no running time is
claimed.
Main definitions #
Cslib.Algorithms.Lean.LempelZiv.LZ78.splitPhrase: the next phrase and the remaining input.Cslib.Algorithms.Lean.LempelZiv.LZ78.parse: the LZ78 incremental parsing.Cslib.Algorithms.Lean.LempelZiv.LZ78.IsTreeStructured: every phrase is an earlier phrase or[]followed by one symbol.Cslib.Algorithms.Lean.LempelZiv.LZ78.encode,Cslib.Algorithms.Lean.LempelZiv.LZ78.decode: the (pointer, symbol) code.
Main results #
Cslib.Algorithms.Lean.LempelZiv.LZ78.flatten_parse: the phrases concatenate to the input.Cslib.Algorithms.Lean.LempelZiv.LZ78.ne_nil_of_mem_parse: every phrase is nonempty.Cslib.Algorithms.Lean.LempelZiv.LZ78.prefix_mem_take_parse,Cslib.Algorithms.Lean.LempelZiv.LZ78.getElem_parse_notMem_take: each phrase is the shortest new prefix: its nonempty proper prefixes are earlier phrases, and it is itself new unless it is the last phrase.Cslib.Algorithms.Lean.LempelZiv.LZ78.nodup_dropLast_parse: the phrases before the last are pairwise distinct.Cslib.Algorithms.Lean.LempelZiv.LZ78.nodup_parse_of_getLast_notMem: all phrases are pairwise distinct when the last phrase is new.Cslib.Algorithms.Lean.LempelZiv.LZ78.isTreeStructured_parse: the parse is tree structured.Cslib.Algorithms.Lean.LempelZiv.LZ78.decode_encode: the pair code is lossless.
References #
Parsing #
The next LZ78 phrase of x against the dictionary dict of earlier phrases, and the
remaining input: the shortest prefix of x not in dict, or all of x if every nonempty prefix
of x is in dict.
The phrase and the remaining input concatenate to the input.
On nonempty input, the phrase consumes at least one symbol.
If input remains after the phrase, the phrase is new.
Every nonempty proper prefix of the phrase is in the dictionary, so the phrase is the shortest prefix of the input that is not.
LZ78 parsing of x against the dictionary dict of earlier phrases, with fuel steps.
Each step consumes at least one symbol, so fuel = x.length suffices.
LZ78 incremental parsing ([ZL78]): cut x into phrases, each the shortest
prefix of the remaining input that is not an earlier phrase (the last phrase may repeat an
earlier one).
The LZ78 phrases concatenate to the input.
The number of phrases is at most the input length.
Prefix closure. Every nonempty proper prefix of an LZ78 phrase is an earlier phrase.
The LZ78 phrases before the last are pairwise distinct.
A phrase sequence is tree structured over the dictionary dict if every phrase is an
earlier phrase, a dictionary entry, or [], followed by one symbol. LZ78 parses are tree
structured over [] ([CT06], Ch. 13).
The LZ78 parse is tree structured.
The (pointer, symbol) code #
Encode each nonempty phrase w as the index of w.dropLast in [] :: dict (the
dictionary grows by every encoded phrase) and the last symbol of w. Empty phrases are
skipped.
LZ78 encoder ([ZL78]): the (pointer, symbol) pairs of the LZ78 parse. Pointer
0 is the empty phrase and pointer j ≥ 1 the j-th phrase.
Decoding inverts encoding for a phrase sequence that is tree structured over dict.
The LZ78 code is lossless.
A tree-structured phrase sequence is encoded with one pair per phrase.
There is one pair per phrase.