Skip to content

Smallest grammar problem

Find the least-cost straight-line grammar that generates exactly one specified string.

Core Idea

The smallest grammar problem turns lossless grammar-based description into an optimization task. Given one target string, choose a straight-line context-free grammar whose productions generate that string and no other; among such grammars, minimize a declared size measure. Repeated substrings can be named by nonterminals and reused instead of written again.

The cost convention matters. Counting symbols on production right-hand sides differs from also charging for rules, and a grammar that is shorter than one direct production is not thereby proven globally smallest. Computational hardness explains why practical methods often return a small or approximately bounded grammar instead of an exact optimum.

Structural Signature

Sig role-phrases:

  • Target string — Fixes the exact output the grammar must generate. It is constitutive. Counterfactual: Without a fixed string there is no instance of this optimization problem.
  • Admissible straight-line grammar — Supplies nonbranching productions that derive only the target string. It is constitutive. Counterfactual: If productions can choose among outputs, the grammar may generate additional strings and fail feasibility.
  • Reusable nonterminals — Name repeated substrings so a derivation can share their description. It is central. Counterfactual: Without reuse, a direct literal production remains feasible but may be more expensive.
  • Size measure — Assigns a comparable cost to each candidate grammar. It is constitutive. Counterfactual: Without a declared metric, 'smallest' has no determinate optimization meaning.
  • Minimum or approximation criterion — Distinguishes proof of global least cost from a small feasible grammar or bounded approximation. It is constitutive. Counterfactual: If the criterion is only any grammar, the optimization problem has been replaced by generation or compression alone.

What It Is Not

  • Not ordinary parsing. The input is a fixed string to generate compactly, not an arbitrary string to recognize with a fixed grammar.
  • Not any grammar-based code. The formal target is the minimum grammar under a specified cost metric.
  • Not a language with multiple strings. Straight-line productions must generate exactly one output.
  • Not proof of optimality from repetition alone. A shorter candidate need not beat every other possible grammar.
  • Closest near-miss. Grammar-based compression may seek short descriptions in practice; this named problem specifies the optimum under a declared grammar size model.

Scope of Application

  • Formal-language theory. Study exact single-string grammars and the cost of their descriptions.
  • Lossless compression. Use repeated substrings to construct compact grammar descriptions.
  • Approximation algorithms. Compare feasible grammar costs with proven or estimated optimum bounds.
  • Pattern extraction. Interpret reusable productions as repeated structure while keeping coding cost explicit.

Clarity

The smallest grammar is relative to both one target string and a cost model. A grammar that generates extra strings is infeasible, and a smaller output than a literal rule is only an improvement, not proof of global minimum. Separating feasibility, metric, and optimality prevents three different claims from being called 'compression'.

Manages Complexity

A straight-line grammar compresses repeated substrings into reusable definitions, replacing a long literal sequence with a shorter derivation graph. The optimization problem then compares many possible reuse schemes. This reduces description length when repetitions pay for their rule overhead, but the enormous candidate space makes exact best-choice reasoning difficult.

Abstract Reasoning

  1. Fix the exact target string and the grammar-size convention.
  2. Build feasible nonbranching productions and verify their unique expansion matches the target.
  3. Locate repeated substrings whose reuse might offset definition and reference cost.
  4. Compare candidate grammar sizes under the same metric.
  5. Distinguish an exact optimum proof from an approximation guarantee or heuristic result.

Knowledge Transfer

The problem transfers literally across strings and alphabets when exact generation and the same cost convention are maintained. General lossless compression shares the goal of short reversible description, but may use dictionaries, coding probabilities, or other objects rather than straight-line grammars. Its optimization skeleton is portable; the one-string grammar feasibility constraint is the domain-specific accent.

Examples

Canonical

Charikar and coauthors give the short phrase “a rose is a rose is a rose” as their original smallest-grammar demonstration. Their straight-line rules are S→BBA, A→“a rose,” and B→A+“ is”; expanding B twice and A once produces the target phrase and no alternative string. The paper counts the total number of symbols on right-hand sides, not merely the number of rules or bytes of a final encoded file, and identifies this grammar as smallest under that convention. The repeated phrase makes the role of reusable nonterminals visible: A names one recurring segment, while B composes A with a following segment. This is a formal worked instance, not evidence that a greedy compressor always finds the global minimum on a long input.

Mapped back: Target string → a rose is a rose is a rose; Admissible straight-line grammar → S→BBA, A→a rose, B→A is; Reusable nonterminals → A for a rose and B for a rose is; Size measure → paper's count of grammar symbols/description cost; Minimum or approximation criterion → paper's claimed smallest grammar for this instance.

Applied / In Practice

Gańczorz and Jeż tested a Re-Pair-based grammar compressor on established real-data corpora, including English-like text and WebGraph data. Their method recursively replaces repeated digrams with new grammar symbols, while an additional Lempel–Ziv-informed penalty changes which pair is chosen. They reported smaller resulting grammars than ordinary Re-Pair for the English-like text and WebGraph cases, but not across all data types examined. This is a practical approximation study of the smallest-grammar objective: the output grammar must regenerate the input string alone, yet its measured size is a heuristic result, not a certificate of global optimality. The corpus-specific outcome shows why an algorithm's objective, size measure, and comparison baseline must accompany any claim that one representation is “smallest.”

Mapped back: Target string → each actual input text or WebGraph sequence in the study; Admissible straight-line grammar → deterministic Re-Pair-style rules generating the input alone; Reusable nonterminals → recursively substituted frequent digrams; Size measure → compared sizes of the constructed grammars; Minimum or approximation criterion → smaller empirical outputs than ordinary Re-Pair on specified corpora, not proven minima.

Structural Tensions

T1 — Short Description versus Rule Overhead. Introducing a nonterminal saves repeated terminals only if the reuse outweighs the cost of defining and referencing it. Which grammar looks smallest can change when rules themselves are charged.

Diagnostic: Under the declared size metric, does a new rule pay for itself?

T2 — Exact Optimum versus Tractable Search. Global minimization has computational hardness, while fast grammar compressors produce candidates without necessarily proving optimality. Treating a small output as the smallest would erase the central optimization distinction.

Diagnostic: Is the claimed result exact, bounded-approximate, or merely a feasible grammar?

T3 — Expressive Grammar versus Single-String Feasibility. A branching context-free grammar can compactly describe a family, but the smallest-grammar problem forbids any extra generated string. Relaxing that condition changes the feasible set rather than improving the original solution.

Diagnostic: Does every derivation yield precisely the target string?

Structural–Framed Character

The smallest grammar problem is structural-leaning within formal computation. Evaluative weight: “smallest” is a cost optimum under a declared grammar-size measure, not an aesthetic verdict about an expression. Human-practice-bound: once the alphabet, candidate grammars, and cost are fixed, feasibility and minimum size are mathematical facts; researchers choose the representation and objective convention. Institutional origin: theoretical computer science supplies definitions and proof methods, but no organization constitutes which grammar generates the input string. Vocabulary travels: candidate set, feasibility, and minimization recur across optimization, while straight-line productions generating exactly one string do not. Import versus recognize: changing the input string while retaining the grammar and cost rules gives another literal instance; minimizing a dictionary encoding is a related compression problem, not the same feasible set.

The portable skeleton is the actual parent prime Optimization: search a constrained feasible set for a best-scoring member. Here the member must be a straight-line grammar with exact single-string generation, and the score is its specified size. Its character: a precise grammar-constrained optimization identity, not a claim that every shortest encoding is a smallest grammar.

Structural Core vs. Domain Accent

Skeletal core. Search a feasible set of descriptions for the lowest-cost exact representation. Domain-bound accent. Candidates must be straight-line grammars that generate one string, and the objective measures grammar size. Replace the productions with arbitrary encodings and it becomes another compression problem. Why not a prime. Optimization travels widely; this grammar-feasibility relation is specialized.

This entry is a kind of Optimization.

  • Strict parent: Optimization. The choice set is straight-line grammars, the constraint is unique generation of the target, and the objective is grammar size. The smallest grammar problem is therefore a strict formal instance of prime Optimization.

  • Related, not identical. Lossless compression is a use case; a compressor's output is not automatically an optimum under this grammar metric.

Relationships to Other Abstractions

Local relationship map for Smallest grammar problemParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Smallestgrammar problemDOMAINPrime abstraction: Optimization — is a kind ofOptimizationPRIME

Current abstraction Smallest grammar problem Domain-specific

Parents (1) — more general patterns this builds on

  • Smallest grammar problem is a kind of Optimization Prime

    Smallest grammar problem is a kind of Optimization; Find the least-cost straight-line grammar that generates exactly one specified string.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Smallest grammar problem sits in a crowded region of the domain-specific corpus (37th percentile for distinctiveness): several abstractions share nearly its structure, so a description that fits it tends to fit its neighbors too.

Family — Language Structure & Grammar Formalisms (23 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-08

Not to Be Confused With

  • Grammar-based compression. Tell: A family of coding methods; ask whether exact minimum grammar size is the specified objective.
  • Context-free language generation. Tell: Can generate many strings; ask whether the grammar is straight-line and unique-output.
  • Kolmogorov complexity. Tell: Minimizes description over programs and a machine model, not the fixed grammar representation here.
  • Straight-line program. Tell: The feasible representation; the smallest grammar problem asks which such representation minimizes a declared cost.

References

  • Frozen Wikipedia discovery revision: https://en.wikipedia.org/wiki/Smallest_grammar_problem (revision 1251547727).
  • Primary research source: Charikar et al., "Approximating the Smallest Grammar: Kolmogorov Complexity in Natural Models," 2002 author manuscript, https://people.csail.mit.edu/arasala/papers/grammar.pdf (Introduction, pp. 1–2: rose-string minimum example and right-hand-side-symbol size measure).
  • Gańczorz and Jeż, “Improvements on Re-Pair Grammar Compressor,” Data Compression Conference (2017), DOI 10.1109/DCC.2017.52: published real-corpus Re-Pair comparison on English-like text and WebGraph data. https://doi.org/10.1109/DCC.2017.52
  • Preserved source candidate: https://www.eti.uni-siegen.de/ti/veroeffentlichungen/12-survey.pdf
  • Preserved source candidate: https://scholar.archive.org/work/kkxmd4etnzahze4vi35kkhnwze
  • Preserved source candidate: http://theory.lcs.mit.edu/~arasala/papers/grammar.pdf
  • Preserved source candidate: https://blog.computationalcomplexity.org/2024/06/cfg-kolm-complexity-is-singleton-sets.html

The cited Wikipedia revision supplies discovery provenance; the author manuscript explicitly identifies the rose-string grammar as smallest under its size definition. The repeated-string comparison is an analytic example, not a claim of global optimality.