11

Question: Say that a CFG (context-free grammar) is minimal if none of its rules can be removed without changing the language generated. Let $MIN_{\text{CFG}}$ = $\{\, \langle G \rangle$ | $G$ is a minimal CFG$\}$.

a) Show that $MIN_{\text{CFG}}$ is Turing-recognizable.

b) Show that $MIN_{\text{CFG}}$ is undecidable.

Now part a) is relatively straightforward. If all rules are indispensable for some CFG $G$, we just need to find for each rule $R$ of $G$ a string $w_R$ that can be generated by $G$, but not with $R$ omitted. Thus, enumerating all the strings one by one for potential "certificates" for indispensability yields a recognizer.

However, I got stuck on part b). It would be easier (to prove undecidability) if the question concerns a specific rule of $G$, because then it can be reduced from the known undecidable language $ALL_{\text{CFG}} = \{\, \langle G \rangle$ | $G$ generates all strings $\}$. But I'm not sure whether it is possible to reduce between those two variants.

Thank you for any help!

Qinxuan
  • 111

2 Answers2

6

Here is @Lwins answer expressed in another way. All credit goes to @Lwins for the idea.

Claim 1: Let $ALL_\mathsf{CFG}$ be the language of CFGs that accept all strings in some finite alphabet $\Sigma$. This language is undecidable.

Proof 1: (also Theorem 5.13 in Sipser) A decider could be used, for any given Turing machine $M$ and input $w$, to construct a CFG that rejects accepting computation histories for that $M$ on that $w$. Running the decider for $ALL_\mathsf{CFG}$ on this CFG would also decide $A_\mathsf{TM}$, the language of pairs $\langle M, w \rangle$ where $M$ accepts $w$. However, this would be impossible because $A_\mathsf{TM}$ is not decidable.

Claim 2: Let $MIN_\mathsf{CFG}$ be the language of minimum CFGs, i.e. CFGs for which all of its rules are necessary, and none can be omitted without losing strings. Let $ALL_\mathsf{MINCFG} \subset MIN_\mathsf{CFG}$ be the language of minimum CFGs that accept all strings. The language $ALL_\mathsf{MINCFG}$ is undecidable.

Proof 2: If we had such a decider, we could also decide $ALL_\mathsf{CFG}$ for any $G$ by running on subsets of rules of $G$.

Claim 3: Let $A_\mathsf{CFG}$ be the language of pairs $\langle G, w \rangle$ where the CFG $G$ accepts the input $w$. This language is decidable. (Proof is omitted here and can easily be found elsewhere).

Claim 4: For any necessary rule $R$ in some CFG $G$, it is possible to compute in finite time some string $w_R \in G$ which could not be generated without $R$.

Proof 4: Lexicographically generate all strings $w$ and use the $A_\mathsf{CFG}$ decider on $w$ and $G$ with and without $R$. Since $R$ is necessary, some $w_R$ exists and this procedure is guaranteed to halt.

Claim 5: Suppose it were possible to decide $MIN_\mathsf{CFG}$. Suppose also that we are given a minimum $G$ and a string $v$ that for all rules $R$ is longer than at least one $w_R$. Then it would be decidable whether $v \Sigma^\star \subseteq G$.

Proof 5: Augment $G$ to $G_v$ by adding the rules $S \rightarrow v T$ (where $S$ is the start variable of $G$ and $T$ is a new variable) along with $T \rightarrow \varepsilon$ and $T \rightarrow T \sigma$ for every $\sigma \in \Sigma$. These new rules generate only $v \Sigma^\star$. The original rules $R$ are guaranteed to still be necessary in $G_v$, since $|w_R| < |v|$.

We then ask if any of the new rules are necessary. To answer this, we repeatedly run our $MIN_\mathsf{CFG}$ decider, each time keeping a different non-empty subset of the $T$ rules. If $MIN_\mathsf{CFG}$ ever accepts, then we know that some strings in $v \Sigma^\star$ are missing in $G$. Otherwise, none of the new rules in $G_v$ are necessary, and thus $v \Sigma^\star \subseteq G$.

Main result:

A decider for $MIN_\mathsf{CFG}$ would imply a decider for $ALL_\mathsf{MINCFG}$ (Hence, $MIN_\mathsf{CFG}$ is undecidable).

Proof

Suppose we had a decider for $MIN_\mathsf{CFG}$ and input $G$. If this decider rejects $G$, then $ALL_\mathsf{MINCFG}$ must also reject.

Otherwise, we know $G \in MIN_\mathsf{CFG}$ and thus for each rule $R$ in $G$, we can (Claim 4) compute a $w_R$ for which that $R$ is necessary. Choose some integer $\ell$ larger than the length of the longest $w_R$ we happened to find, and use $A_\mathsf{CFG}$ to check if $u \subseteq G$ for all $|u| < \ell$, and (Claim 5) also if $v \Sigma^\star \subseteq G$ for all $|v| = \ell$. $ALL_\mathsf{MINCFG}$ accepts if and only if both of these are true.

xdavidliu
  • 716
4

It suffices to focus on the case $\Sigma = \{0,1\}$. We argue that $ALL_{\textsf{minCFG}} \leq_T MIN_{\textsf{CFG}}$. That is, we can determine whether a minimal CFG can generate all possible strings, by using the oracle for $MIN_{\textsf{CFG}}$.

Let $G$ denote the minimal CFG we are interested. Since $G$ is minimal, there exists a length $p$ such that, for each rule $R$ in $G$ there exists a string $w_R$ with $|w_R|<p$ that can be generated by $G$, but not with $R$ deleted. Note here that $p$ is computable in a brute force manner. Construct $G^+_{a_1a_2\cdots a_p}$ where $a_i \in \Sigma$, by adding following rules in $G$: $$ S \to a_1 a_2 \cdots a_pT \\ T \to T0 \ | \ T1 \ | \ \epsilon $$ First, consider what will happen if $G^+_{a_1a_2\cdots a_p}$ is not minimal, thus, there exists a rule $R$ in $G^+$ being dispensable. By our construction it is clear that each rule $R$ in $G$ is indispensable.

  • If $S \to a_1 a_2 \cdots a_pT$ or $T \to \epsilon$ is dispensable, then we have $a_1 a_2 \cdots a_p \Sigma^* \subseteq L(G)$.
  • If $T \to T0$ is dispensable, then we have $(a_1 a_2 \cdots a_p \Sigma^* - a_1 a_2 \cdots a_p 1^*) \subseteq L(G)$. Because whether $a_1 a_2 \cdots a_p1^* \subseteq L(G)$ is easy to determine by some classical algorithm, we can also determine whether $a_1 a_2 \cdots a_p \Sigma^* \subseteq L(G)$.
  • It is similar for $T \to T1$.

Therefore, if $G^+_{a_1a_2\cdots a_p}$ is not minimal, we can determine whether $a_1 a_2 \cdots a_p \Sigma^* \subseteq L(G)$. What if it is minimal? In this case we will immediately know $L(G) \neq \Sigma^*$. So we can suppose that all possible $G^+_{a_1a_2\cdots a_p}$ is not minimal. Then by checking whether $a_1 a_2 \cdots a_p \Sigma^* \subseteq L(G)$ one by one and checking those strings of less-than-$p$ length, we can still decide whether $L(G) = \Sigma^*$.

Update. (Oct 12, 2020) After a short discussion with @xdavidliu I realized that the argument above can directly prove what we want, without a justification of uncomputability of $ALL_{\textsf{minCFG}}$. Recall that the reduction we have established achieves the following: Given a minimal CFG $G$, determine whether $L(G) = \Sigma^*$. Now if we want to decide whether $L(G_0) = \Sigma^*$ for an arbitrary CFG $G_0$, just simply feed into the (reduction) algorithm all minimal sub-CFG (test each sub-CFG by the $MIN_{\mathsf{CFG}}$ oracle to determine whether it is minimal) of $G_0$ and see if there is one that generates all strings.


Since this problem appears in Chapter 5, in which Turing reduction has not introduced. I personally believe that there is an elegant proof using only mapping reduction.


Update. @Sylvain gives an elegant proof on https://cstheory.stackexchange.com/a/39454/46760, by showing $$ PCP \leq_T FullPCP \leq_m MIN_{\textsf{CFG}}$$ in which I personally thought the key is that context-free language is closed under $h^{-1}$ he defined.

Lwins
  • 644
  • @xdavidliu Check https://cstheory.stackexchange.com/a/39454/46760 (I forgot to update here) – Lwins Oct 12 '20 at 16:04
  • @xdavidliu Sorry. There’s something wrong with my app and I cannot get the link to the question. Please check the OP of my link but not the answer. – Lwins Oct 12 '20 at 16:08
  • @xdavidliu It has been a while and I almost forget the details. But I’m sure it’s just adding some stuff the existing proof from the book, to justify that all CFG constructed in the proof are minimal. Nothing new or insightful. – Lwins Oct 12 '20 at 16:18
  • I don't think it's that easy; Sipser's proof for $A_{\textsf{TM}} \leq_T ALL_{\textsf{CFG}}$ involves first constructing a PDA that rejects computation histories, then converting it to a CFG using the procedure from Lemma 2.27. You are claiming that it is straightforward to ensure that the resulting CFG from Lemma 2.27 is minimal; however that is not obvious at all, and really requires a proof. – xdavidliu Oct 12 '20 at 17:04
  • 1
    @xdavidliu Just an ad: If you are reading Sipser's book this might be helpful (or indeed, you are welcome to make it helpful to others!): https://github.com/lwins-lights/Introduction-to-the-Theory-of-Computation-Hints/tree/solution – Lwins Oct 12 '20 at 19:01
  • is there an obvious way to compute $p$? I'm guessing $p = 1 + \max_R |w_R|$, but is it straightforward to compute $w_R$? – xdavidliu Oct 12 '20 at 20:01
  • @xdavidliu If we don't consider efficiency then just do it by brute force: Note that for any CFG $G$ we can first convert it to the Chomsky normal form and then it is easy to determine $L(G) \cap \Sigma^k$ for finite $k$ (well the complexity unfortunately explodes, but who cares?). – Lwins Oct 12 '20 at 20:06
  • @xdavidliu Pumping lemma (for CFG). Basically there is a $N$ depending on the size of $G$, where if you know $a_1a_2 \dots a_p 1^j \in L(G)$ for all $j<N$ then it also holds for $j \geq N$. – Lwins Oct 12 '20 at 20:42
  • 1
    @xdavidliu No, the same strategy no longer works for larger $\Sigma$. So we only use the oracle to solve the binary case of $ALL_{\mathsf{CFG}}$, which is already Turing complete. Thanks for pointing it out. (Actually I change that sentence today, but seemingly I was right and I am wrong now; the previous version is “only consider the binary case” or so...) – Lwins Oct 12 '20 at 21:01
  • I'm confused about something: if $T \rightarrow 0$ is dispensable but $T \rightarrow 1$ is necessary, then isn't it guaranteed that $a_1 a_2 \ldots a_p 1^$ is not* a subset of $L(G)$? – xdavidliu Oct 12 '20 at 21:27
  • @xdavidliu That’s right but its benefit isn’t utilized in my answer. The trick I did here is to just analyze for each possible cases but not actually compute (with or without the oracle) which case I’m in. We always ask only one question: is $G_{a_1 a_2 \dots a_p}^+$ minimal? And we always check for $a_1 \dots a_p 0^$ and $\dots 1^$. – Lwins Oct 12 '20 at 21:36
  • Another question: once we construct $G^+$, suppose we find that $G^+$ is no longer minimal, but all of the new rules are now necessary, while some of the old rules from G are now dispensable. In this case, would it still be possible to determine if $a_1 a_2 \cdots a_p \Sigma^* \subseteq L(G)$? – xdavidliu Oct 12 '20 at 23:02
  • 1
    @xdavidliu This is impossible because new rules only generates strings that have length no less than $p$. – Lwins Oct 13 '20 at 02:54
  • 1
    Thanks for all the clarifications. I wrote an alternate version of your proof, and simplified some of the arguments around $G^+$. Feel free to comment / critique. – xdavidliu Oct 13 '20 at 14:13