Toc 5
Toc 5
1. (Sipser problem 5.21, 20 points) Let AMBIG CFG = {[G] | G is an ambiguis CFG} (where [G] denotes a
string that represents the grammar). Show that AMBIG CFG is undecidable.
Hint: You can use a reduction from PCP. Given an instance
t1 t t
P = , 2 , ... k ,
b1 b2 bk
S → T |B
T → t1 T a1 | . . . | tk T ak | t1 a1 | . . . | tk ak
B → b1 Ba1 | . . . | bk Bak | b1 a1 | . . . | bk ak ,
where a1 , . . . , ak are new terminal symbols. Prove that this reduction works.
Solution:
If P is solvable, then G is ambiguous.
Let i1 , i2 , . . . in be a solution to P . Let
and
S→B
S −→ B
B→bi1 Bai1
−→ bi1 Bai1
B→bi2 Bai2
−→ bi1 bi2 Bai2 ai1
B→···
−→ bi1 bi2 . . . B · · · ai2 ai1
B→bin ain
−→ b i 1 b i 2 · · · b i n ai n · · · ai 2 ai 1
Thus, G is ambibuous.
If G is ambiguous, then P is solvable.
Let GT be the same grammar as G except that it has T as the start variable and likewise for GB .
GT is unambiguous.
This is because the string of ai ’s at the end of any string derived from GT describes the sequence
of steps taken in the derivation. Thus, two strings can have the same suffix of ai ’s iff they have
the same derivation. This means that if GT generates x and y and x = y, then x and y have the
same derivation. Therefore, GT is unambiguous.
GB is unambiguous.
The proof is equivalent to that for GT .
Thus, if w has two derivations in G, one must start with the rule S → T and the other with the rule
S → B. This means that there exist i1 , . . . im such that w = ti1 · · · tim aim · · · ai1 and j1 , . . . jn such
that w = bj1 · · · bjn ajn · · · aj1 . Because the ai ’s don’t appear in any of the t’s or b’s, we have that
m = n, i1 = j1 , i2 = j2 , . . . and in = jn . This means that
t i 1 ti 2 · · · t i n = b i 1 b i 2 · · · bi n
h = # config 0 # config R R
1 # config 2 # config 3 # · · · config m #
(where config m is reversed if m is odd). Let M be at TM and w be a string. I’ll now describe a PDA, P ,
that accepts a string of the form hh iff h describes a valid computational history for M accepting w.
Initially, P pushes each even numbered configuration onto its stack, and then pops each off while verifying
the subsequent odd configuration. The # symbols separate successive configurations; so, P knows when
to change from pushing to popping.
When P sees two consecutive # symbols, it skips the next configuration config 0 . It then pushes each of
the odd numbered confuration onto its stack, and then pops each off while verifying the subsequent even
configuration.
In the course of these actions, P also checks that config 0 is the correct initial configuration for M running
on input w and that config m is an accepting configuration. The languages corresponding to these checks
are regular, and P performs these checks using its finite state (see also HW 9, question 1).
P accepts a string of the form hh iff h is a valid computation history for M accepting w.
Note that P may accept strings that are not of the form hh whether or not M accepts h. In particular, one
could run P on the input:
# config 0 # config R
1 # config 2 ## config 3 # config 4 #
where
config 0 is the correct initial configuration for M running with input w.
config 1 is the correct successor to config 0 .
config 2 is an arbitrary accepting configuration for M . Note that P does not verify that config 2 is a valid
successor of config 1 .
config 3 is an arbitrary configuration. As described above, P does not verify that this is the correct initial
configuration for M running with input w.
config 4 is an arbitrary accepting configuration for M . P does not verify that config 4 is a valid successor
of config 3 .
This string is not of the form ww. P has no way to verify that its input is of the form ww.