6

I can't find straight answer on this via googling around. Can you provide a reference?

The smallest grammar problem over a singleton alphabet is to find the smallest CFG $g$ that produces one and only one string of $a$'s, i.e. $s = a^n$ for some fixed $n\in \Bbb{N}$ taken to be the input size.

So, a polynomial time algorithm would be $O(|s|^k)$ if it existed. I'm wondering whether this subproblem of the more general problem of any finite alphabet size, is NP-complete.

If so, I'd like to know how they have reasoned this.

So for example,

$$ g = \begin{cases} S \to B^2A \\ B \to A^2 \\ A \to a^2 \end{cases} $$

Is (one such) smallest grammar for $s = a^{10}$. The size is measured by the sum of the lengths of the strings appearing on the rhs of $\to$. Using that measure of size, you cannot find a smaller CFG that produces and only produces $s = a^{10}$, for example. You can only find other examples of grammars that are the same size or larger.

Thanks!

Daniel Donnelly
  • 628
  • 3
  • 12

2 Answers2

6

A related problem: If you limit the right-hand side to have at most two symbols, and measure size by the number of rules, this is the addition chain problem. I think it is an open question whether the addition chain problem is NP-complete, but it is suspected to be hard. There is a variant of the addition chain problem, where you have to hit multiple targets, that is NP-complete. You could try exploring the literature on that to see if any of those methods can be applied to your problem. See, e.g., https://cstheory.stackexchange.com/q/912/5038.

D.W.
  • 167,959
  • 22
  • 232
  • 500
4

With a singleton alphabet $\{a\}$, you can construct a grammar for $a^n$ of size at most $3\log_2{n} + 1$, using one rule of size 2 or 3 for every bit in the binary representation of $n$.

The number of grammars of size $g$ is something like $O(g)!$, or $e^{O(g\log{g})}$, and we have $g = O(\log(n))$. You can check if a grammar generates only $a^n$ in linear time. So you can search for the smallest grammar in time $n^{O(\log\log{n})}$. Not quite polynomial but close.

Li-yao Xia
  • 1,128
  • 5
  • 6