Grammar-based code
Appearance
nonterminal symbol; they were obtained from a gzip
-compression of the sentence.Grammar-based codes or Grammar-based compression are
lossless data compression algorithms.[1]
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) is known to be NP-hard,[2] 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,[3] variations of the incremental parsing Lempel-Ziv code,[4] and many other new universal lossless compression algorithms. Grammar-based codes are universal in the sense that they can achieve asymptotically the
ergodic
source with a finite alphabet.
Practical algorithms
The compression programs of the following are available from external links.
- Sequitur[5]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[6] 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,[7]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
References
- S2CID 6900082
- S2CID 8191526
- S2CID 2957960
- doi:10.1109/5.892708
- S2CID 3116024.
External links
- GLZA discussion and paper
- Description of grammar-based codes with example
- Sequitur codes Archived 2008-10-13 at the Wayback Machine
- Re-Pair codes
- Re-Pair codes a version of Gonzalo Navarro.
- GrammarViz 2.0 - implementation of Sequitur, Re-Pair, and parallel Re-Pair in Java.