Proofs: Undecidability of CFL intersection
These are the human proofs of Undecidability of CFL intersection, at full length.
Proof that emptiness of the intersection of two context-free languages is undecidable full
This proof shows: statement.
Part 1 of the statement is proved on the page on closure properties. We prove parts 2 to 4.
Let be an instance of Post's correspondence problem with lists and over . Let be a set of new symbols, , and . For a sequence of indices write , and . Define
with start symbols and .
Lemma 1. , and every string of has exactly one parse tree.
Proof. Every sentential form derived from is or a terminal string , by induction on the number of steps, since each step replaces the only nonterminal by or . Conversely every sequence with gives the derivation that uses for and last. For uniqueness, a string has as its longest suffix in , because and the last symbol of , if any, is not in . So determines , and determines the sequence of productions, and the grammar is linear, so the derivation is the only one.
The same holds for .
Lemma 2. .
Proof. Let . By Lemma 1, for some nonempty and . Both and are the longest suffix of in , so , and then is the part of before that suffix. So is a solution. Conversely, if is a solution, is in both languages.
Lemma 3. If the instance has a solution, it has infinitely many, and is infinite.
Proof. If is a solution, so is the sequence , repeated times, for every , and the strings are different because their index suffixes have different lengths.
Part 2. The map is computable. By Lemmas 2 and 3, the instance has a solution if and only if . So PCP many-one reduces to intersection nonemptiness. If intersection emptiness were decidable, so would be PCP, which is undecidable (Post 1946). Nonemptiness is recursively enumerable: enumerate the strings of in order of length and accept when one is in both languages, which is decidable for each string by the CYK algorithm. Since PCP is complete for the recursively enumerable sets, so is intersection nonemptiness.
Part 3. By Lemmas 2 and 3, is infinite if and only if it is nonempty, if and only if the instance has a solution. So the same reduction shows that infiniteness of the intersection is undecidable.
Part 4. and are linear, with at most one nonterminal on each right side, and unambiguous by Lemma 1. A deterministic pushdown automaton accepts :
- In state , it reads symbols of and pushes each one.
- On reading an index symbol , in state or , it pops symbols one at a time with -moves through intermediate states that remember and the position in , checking that they are the symbols of from the last to the first. If a check fails or the bottom marker appears too early, it moves to a dead state. After the last check it goes to state .
- In state it reads no symbol of : a symbol of leads to the dead state. It accepts in when the bottom marker is on top.
Every configuration has at most one move, so is deterministic. It accepts exactly when with , , and consumed from its end as , then , and so on, with nothing left: that is, . So by Lemma 1, and the language is deterministic context-free. The same holds for . Hence the problems of parts 2 and 3 remain undecidable for linear, unambiguous grammars of deterministic languages.