Indata compression and the theory offormal languages, thesmallest grammar problem is the problem of finding the smallestcontext-free grammar that generates a givenstring of characters (but no other string). The size of a grammar is defined by some authors as the number of symbols on the right side of the production rules.[1]Others also add the number of rules to that.[2] A grammar that generates only a single string, as required for the solution to this problem, is called astraight-line grammar.[3]
The (decision version of the) smallest grammar problem isNP-complete.[1]It can be approximated inpolynomial time to within a logarithmicapproximation ratio; more precisely, the ratio is where is the length of the given string and is the size of its smallest grammar. It is hard to approximate to within a constant approximation ratio. An improvement of the approximation ratio to would also improve certain algorithms for approximateaddition chains.[5]
^Florian Benz and Timo Kötzing, “An effective heuristic for the smallest grammar problem,” Proceedings of the fifteenth annual conference on Genetic and evolutionary computation conference - GECCO ’13, 2013.ISBN978-1-4503-1963-8doi:10.1145/2463372.2463441