Grammar-based codes or Grammar-based compression are
compression algorithms based on the idea of constructing a
context-free grammar
In formal language theory, a context-free grammar (CFG) is a formal grammar whose production rules are of the form
:A\ \to\ \alpha
with A a ''single'' nonterminal symbol, and \alpha a string of terminals and/or nonterminals (\alpha can be em ...
(CFG) for the string to be compressed. Examples include universal
lossless data compression algorithms. To compress a data sequence
, a grammar-based code transforms
into a context-free grammar
.
The problem of finding a smallest grammar for an input sequence (
smallest grammar problem In data compression and the theory of formal languages, the smallest grammar problem is the problem of finding the smallest context-free grammar that generates a given string of characters (but no other string). The size of a grammar is defined by s ...
) is known to be NP-hard, so many grammar-transform algorithms are proposed from theoretical and practical viewpoints.
Generally, the produced grammar
is further compressed by statistical encoders like
arithmetic coding.
Examples and characteristics
The class of grammar-based codes is very broad. It includes
block codes, the multilevel pattern matching (MPM) algorithm, variations of the incremental parsing
Lempel-Ziv code, and many other new universal lossless compression algorithms.
Grammar-based codes are universal in the sense that they can achieve asymptotically the
entropy rate of any stationary,
ergodic
In mathematics, ergodicity expresses the idea that a point of a moving system, either a dynamical system or a stochastic process, will eventually visit all parts of the space that the system moves in, in a uniform and random sense. This implies tha ...
source with a finite alphabet.
Practical algorithms
The compression programs of the following are available from external links.
*
Sequitur is a classical grammar compression algorithm that sequentially translates an input text into a CFG, and then the produced CFG is encoded by an arithmetic coder.
*
Re-Pair is a greedy algorithm using the strategy of most-frequent-first substitution. The compressive performance is powerful, although the main memory space requirement is very large.
*
GLZA,
which constructs a grammar that may be reducible, i.e., contain repeats, where the entropy-coding cost of "spelling out" the repeats is less than the cost creating and entropy-coding a rule to capture them. (In general, the compression-optimal SLG is not irreducible, and the Smallest Grammar Problem is different from the actual SLG compression problem.)
See also
*
Dictionary coder
A dictionary coder, also sometimes known as a substitution coder, is a class of lossless data compression algorithms which operate by searching for matches between the text to be compressed and a set of strings contained in a data structure (cal ...
*
Grammar induction
*
Straight-line grammar
References
External links
GLZA discussion and paperDescription of grammar-based codes with exampleSequitur codesa version of Gonzalo Navarro.
GrammarViz 2.0- implementation of Sequitur, Re-Pair, and parallel Re-Pair in Java.
{{Compression methods
Data compression
Coding theory
Information theory