Algorithm Search⌘K

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 (x,y)(x, y) be an instance of Post's correspondence problem with lists x=(x1,…,xm)x = (x_1, \ldots, x_m) and y=(y1,…,ym)y = (y_1, \ldots, y_m) over Σ\Sigma. Let I={1,…,m}I = \{1, \ldots, m\} be a set of new symbols, I∩Σ=∅I \cap \Sigma = \emptyset, and Δ=Σ∪I\Delta = \Sigma \cup I. For a sequence s=(i1,…,ik)s = (i_1, \ldots, i_k) of indices write xs=xi1⋯xikx_s = x_{i_1} \cdots x_{i_k}, ys=yi1⋯yiky_s = y_{i_1} \cdots y_{i_k} and s←=ik⋯i1∈I∗\overleftarrow{s} = i_k \cdots i_1 \in I^*. Define

Gx: A→xi A i∣xi i,Gy: B→yi B i∣yi i(i∈I),G_x:\ A \to x_i\, A\, i \mid x_i\, i, \qquad G_y:\ B \to y_i\, B\, i \mid y_i\, i \qquad (i \in I),

with start symbols AA and BB.

Lemma 1. L(Gx)={xs s←:s∈Ik, k≥1}L(G_x) = \{ x_s\, \overleftarrow{s} : s \in I^k,\ k \ge 1 \}, and every string of L(Gx)L(G_x) has exactly one parse tree.

Proof. Every sentential form derived from AA is xi1⋯xij A ij⋯i1x_{i_1} \cdots x_{i_j}\, A\, i_j \cdots i_1 or a terminal string xi1⋯xik ik⋯i1x_{i_1} \cdots x_{i_k}\, i_k \cdots i_1, by induction on the number of steps, since each step replaces the only nonterminal AA by xiAix_i A i or xiix_i i. Conversely every sequence ss with k≥1k \ge 1 gives the derivation that uses A→xijA ijA \to x_{i_j} A\, i_j for j<kj < k and A→xikikA \to x_{i_k} i_k last. For uniqueness, a string w=xs s←w = x_s\, \overleftarrow{s} has s←\overleftarrow{s} as its longest suffix in I∗I^*, because xs∈Σ∗x_s \in \Sigma^* and the last symbol of xsx_s, if any, is not in II. So ww determines ss, and ss determines the sequence of productions, and the grammar is linear, so the derivation is the only one. □\square

The same holds for GyG_y.

Lemma 2. L(Gx)∩L(Gy)={xs s←:s is a solution}L(G_x) \cap L(G_y) = \{ x_s\, \overleftarrow{s} : s \text{ is a solution} \}.

Proof. Let w∈L(Gx)∩L(Gy)w \in L(G_x) \cap L(G_y). By Lemma 1, w=xss←=ytt←w = x_s \overleftarrow{s} = y_t \overleftarrow{t} for some nonempty ss and tt. Both s←\overleftarrow{s} and t←\overleftarrow{t} are the longest suffix of ww in I∗I^*, so s=ts = t, and then xs=ysx_s = y_s is the part of ww before that suffix. So ss is a solution. Conversely, if ss is a solution, xss←=yss←x_s \overleftarrow{s} = y_s \overleftarrow{s} is in both languages. □\square

Lemma 3. If the instance has a solution, it has infinitely many, and L(Gx)∩L(Gy)L(G_x) \cap L(G_y) is infinite.

Proof. If ss is a solution, so is the sequence sjs^j, ss repeated jj times, for every j≥1j \ge 1, and the strings xsjsj←x_{s^j} \overleftarrow{s^j} are different because their index suffixes have different lengths. □\square

Part 2. The map (x,y)↦(Gx,Gy)(x, y) \mapsto (G_x, G_y) is computable. By Lemmas 2 and 3, the instance has a solution if and only if L(Gx)∩L(Gy)≠∅L(G_x) \cap L(G_y) \ne \emptyset. 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 Δ∗\Delta^* 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, L(Gx)∩L(Gy)L(G_x) \cap L(G_y) 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. GxG_x and GyG_y are linear, with at most one nonterminal on each right side, and unambiguous by Lemma 1. A deterministic pushdown automaton PxP_x accepts L(Gx)L(G_x):

  • In state pp, it reads symbols of Σ\Sigma and pushes each one.
  • On reading an index symbol ii, in state pp or qq, it pops ∣xi∣|x_i| symbols one at a time with ε\varepsilon-moves through ∣xi∣|x_i| intermediate states that remember ii and the position in xix_i, checking that they are the symbols of xix_i 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 qq.
  • In state qq it reads no symbol of Σ\Sigma: a symbol of Σ\Sigma leads to the dead state. It accepts in qq when the bottom marker is on top.

Every configuration has at most one move, so PxP_x is deterministic. It accepts ww exactly when w=u ik⋯i1w = u\, i_k \cdots i_1 with u∈Σ∗u \in \Sigma^*, k≥1k \ge 1, and uu consumed from its end as xikx_{i_k}, then xik−1x_{i_{k-1}}, and so on, with nothing left: that is, u=xi1⋯xiku = x_{i_1} \cdots x_{i_k}. So L(Px)=L(Gx)L(P_x) = L(G_x) by Lemma 1, and the language is deterministic context-free. The same holds for GyG_y. Hence the problems of parts 2 and 3 remain undecidable for linear, unambiguous grammars of deterministic languages. ■\blacksquare

Back to Undecidability of CFL intersection