I know it's undecidable, but how to prove it?
Let me explain the problem clearer. The problem is not to check whether some given word can be generated, but whether ALL words are possible to generate in this CFG.
I know it's undecidable, but how to prove it?
Let me explain the problem clearer. The problem is not to check whether some given word can be generated, but whether ALL words are possible to generate in this CFG.
Let $T$ be a one-tape Turing machine. A snapshot of a Turing machine is the contents of its tape, where the location of the head is preceded by the current state of the machine (encoded using a disjoint set of symbols).
We can encode a halting computation of $T$ on the empty string as a string $s_0 \# s_1^R s_2 \# s_3^R \# \ldots \# s_n$ (or $s_n^R$, according to the parity of $n$), where $s_0,\ldots,s_n$ is the sequence of snapshots encountered during the run of $T$.
We can check that a string does not code a halting computation as follows:
With some care, we can express all of these conditions as a context-free grammar. Here it is important that we encode the computation by reversing any other snapshot, since this enables us to ascertain that $s_{i+1}$ doesn't follow $s_i$ in a context-free manner (roughly speaking, this is just the language $w\#w^R$ with small modifications).
This context-free grammar generates $\Sigma^*$ if and only if $T$ doesn't halt on the empty string. It follows that universality of context-free grammars is co-r.e.-hard. It is also co-r.e.: if the context-free grammar is not universal, then there is a witness for it, namely a string not generated by the grammar (recall that the word problem for context-free grammars is decidable). Hence universality of context-free grammars is co-r.e.-complete.