<p>This class of grammars is undecidable. Here is a rough idea about how to use it to emulate Turing machines.</p>

<p>At each point, the current partially expanded word would look like</p>

<p>$$[\mbox{tape to the left}][\mbox{head}][\mbox{tape to the right}]$$</p>

<p>Here:</p>

<ul>
<li>$[\mbox{tape to the left}]$, after applying $P$, only contains characters $\overline0$ and $\overline1$.</li>
<li>$[\mbox{tape to the right}]$, after applying $P$, only contains characters $0$ and $1$.</li>
<li>$[\mbox{head}]$ is a single nonterminal, which encodes both the head state and the character at the head position.</li>
</ul>

<p>Suppose that the head is in state $S$, and the character under the head is $i\in\{0,1\}$. Then the head is represented by nonterminal $S_i$. If it needs to transition to state $T$, replace the current character with $j$, and move to the left, there are two transitions $S_i\rightarrow0T_0j$ and $S_i\rightarrow1T_1j$. If it needs to move to the right instead, there are two transitions $S_i\rightarrow\overline jT_0\overline0$ and $S_i\rightarrow\overline jT_1\overline 1$. In some sense, the head has to "guess" the character in the direction it is moving to by producing the matching character. If the guess is wrong, the invariant on $[\mbox{tape to the left}]$ or $[\mbox{tape to the right}]$ would be violated, and it would never recover.</p>

<p>When the machine halts, the head should "consume" its tape on both sides by "guessing" and producing matching characters. After that, it should produce empty word. As a result, empty word would be a member of such grammar if and only if the corresponding Turing machine halts.</p>

CC BY-SA 3.0
2014-10-02T13:41:17.317Z
I am not sure that I understand your reduction. Here is my doubt: If the given Turing machine has $N$ states, then isn't the number of unrestricted productions required to emulate the Turing machine related to $N$? But my problem allows just two fixed unrestricted productions.
Amit. S
CC BY-SA 3.0
2014-10-02T17:21:06.073Z
@Amit.S I provided some more explanation of transitions in the answer.
abacabadabacaba
CC BY-SA 3.0
2014-10-02T11:20:01.940Z
2014-10-03T10:05:01.993Z
2014-10-03T10:05:01.993Z
abacabadabacaba
<p>Consider an arbitrary context-free grammar $G$ over the alphabet $\lbrace 0,1,\overline{0} ,\overline{1} \rbrace$. To the productions of this grammar,  add two fixed non-context-free productions $P$: $\overline{0} 0 \rightarrow  \epsilon$  and $\overline{1} 1 \rightarrow  \epsilon$. Call the resulting grammar $G^P$ standing for "$G$ augmented with the productions $P$". </p>

<p>Is it possible to give an algorithm which takes a grammar $G^P$ and a  string $s$ over $\lbrace 0,1,\overline{0} ,\overline{1} \rbrace$ and decides whether $s \in \mathcal{L}(G^ P)$?</p>

CC BY-SA 3.0
2014-10-02T12:29:07.503Z
Interestingly, while the answer seems to be "no", I think that if $L(G)$ is regular, then so is $L(G^P)$. Essentially, an NFA for $L(G)$ can be transformed into one for $L(G^P)$ by iteratively adding $\epsilon$-transitions $(s,\epsilon,t)$ whenever you have paths $(s,\bar{0},p,0,t),(s,\bar{0},p,\epsilon,q,0,t),(s,\bar{1},p,1,t),(s,\bar{1},p,\epsilon,q,1,t)$ or $(s,\epsilon,p,\epsilon,t)$, and finally performing $\epsilon$-elimination.
Klaus Draeger
CC BY-SA 3.0
2014-10-02T12:59:10.550Z
Yes that is true. In fact, the question arose from a problem in program analysis (liveness based garbage collection). We circumvented the problem by approximating the CFG to a strongly regular grammar (Mohri-Nederhoff transformation), and then doing the $P$ simplifications on the resulting NFA in exactly the way Klaus Draeger mentions.
Amit. S
<context-free><decidability>
Membership problem for certain class of unrestricted grammars
Amit. S
# Membership problem for certain class of unrestricted grammars

(Asked by: username_0 on 2014-10-01)

Consider an arbitrary context-free grammar $G$ over the alphabet $\lbrace 0,1,\overline{0} ,\overline{1} \rbrace$. To the productions of this grammar, add two fixed non-context-free productions $P$: $\overline{0} 0 \rightarrow \epsilon$ and $\overline{1} 1 \rightarrow \epsilon$. Call the resulting grammar $G^P$ standing for "$G$ augmented with the productions $P$".

Is it possible to give an algorithm which takes a grammar $G^P$ and a string $s$ over $\lbrace 0,1,\overline{0} ,\overline{1} \rbrace$ and decides whether $s \in \mathcal{L}(G^ P)$?

**Tags:** context-free, decidability

> **Comments:**
> **username_1**: Interestingly, while the answer seems to be "no", I think that if $L(G)$ is regular, then so is $L(G^P)$. Essentially, an NFA for $L(G)$ can be transformed into one for $L(G^P)$ by iteratively adding $\epsilon$-transitions $(s,\epsilon,t)$ whenever you have paths $(s,\bar{0},p,0,t),(s,\bar{0},p,\epsilon,q,0,t),(s,\bar{1},p,1,t),(s,\bar{1},p,\epsilon,q,1,t)$ or $(s,\epsilon,p,\epsilon,t)$, and finally performing $\epsilon$-elimination.  
> **username_0**: Yes that is true. In fact, the question arose from a problem in program analysis (liveness based garbage collection). We circumvented the problem by approximating the CFG to a strongly regular grammar (Mohri-Nederhoff transformation), and then doing the $P$ simplifications on the resulting NFA in exactly the way username_1 mentions.  

---

## 1 answers

### Answer by username_2 on 2014-10-02. Score: 5 | Accepted answer

This class of grammars is undecidable. Here is a rough idea about how to use it to emulate Turing machines.

At each point, the current partially expanded word would look like

$$[\mbox{tape to the left}][\mbox{head}][\mbox{tape to the right}]$$

Here:

* $[\mbox{tape to the left}]$, after applying $P$, only contains characters $\overline0$ and $\overline1$.
* $[\mbox{tape to the right}]$, after applying $P$, only contains characters $0$ and $1$.
* $[\mbox{head}]$ is a single nonterminal, which encodes both the head state and the character at the head position.

Suppose that the head is in state $S$, and the character under the head is $i\in\{0,1\}$. Then the head is represented by nonterminal $S\_i$. If it needs to transition to state $T$, replace the current character with $j$, and move to the left, there are two transitions $S\_i\rightarrow0T\_0j$ and $S\_i\rightarrow1T\_1j$. If it needs to move to the right instead, there are two transitions $S\_i\rightarrow\overline jT\_0\overline0$ and $S\_i\rightarrow\overline jT\_1\overline 1$. In some sense, the head has to "guess" the character in the direction it is moving to by producing the matching character. If the guess is wrong, the invariant on $[\mbox{tape to the left}]$ or $[\mbox{tape to the right}]$ would be violated, and it would never recover.

When the machine halts, the head should "consume" its tape on both sides by "guessing" and producing matching characters. After that, it should produce empty word. As a result, empty word would be a member of such grammar if and only if the corresponding Turing machine halts.

> **Comments:**
> **username_0**: I am not sure that I understand your reduction. Here is my doubt: If the given Turing machine has $N$ states, then isn't the number of unrestricted productions required to emulate the Turing machine related to $N$? But my problem allows just two fixed unrestricted productions.  
> **username_2**: @Amit.S I provided some more explanation of transitions in the answer.  

---

