Sei sulla pagina 1di 3

CpSc 421 Homework 10 Solutions

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

of the Post Correspondence Problem, construct a CFG G with the rules

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

w = ti1 ti2 · · · tin ain · · · ai2 ai1


= bi1 bi2 · · · bin ain · · · ai2 ai1

The string w has two derivations:


S→T
S −→ T
T →ti1 T ai1
−→ t i 1 T ai 1
T →ti2 T ai2
−→ ti1 ti2 T ai2 ai1
T →···
−→ t i 1 t i 2 . . . T · · · ai 2 ai 1
T →tin ain
−→ ti1 ti2 · · · tin ain · · · ai2 ai1

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

This is a solution to P . Thus, P is solvable as required.


2. (Sipser problems 5.22 and 5.23, 20 points)
(a) Show that A is Turing-recognizable iff A ≤m ATM .
Solution:
If A ≤m ATM , then A is Turing recognizable.
Assume that A ≤m ATM . I’ll construct MA , a TM that recognizes A. On input w, MA uses the
reduction for A ≤m ATM to compute the description of a Turing machine M 0 and a string w0
such that M 0 accepts w0 iff w ∈ A. MA then runs M 0 . If M 0 accepts (resp. rejects or loops), then
MA accepts (resp. rejects or loops). MA accepts w iff w ∈ A; otherwise MA rejects or loops.
MA is a TM that recognizes A, thus A is Turing-recognizable.
If A is Turing-recognizable, then A ≤m ATM .
Assume that A is Turing-recognizable. Thus, there is some TM that recognizes A. Let MA be
such a T M , and let [MA ] denote the string that describes MA . For any string, w, w ∈ A iff
[MA ]#w ∈ ATM . Clearly, the function that maps w to [MA ]#w is Turing computable. Thus,
we’ve shown that A ≤m ATM as required.
Note: these proofs are nearly trivial. They’re just using the definitions of reduction, Turing-recognizable,
and ATM . The point behind this problem is to make sure that you understand what it means for one
language to be Turing-reducible to another.
(b) Show that A is Turing-decidable iff A ≤m 0∗ 1∗ .
Solution:
If A ≤m 0∗ 1∗ , then A is Turing-decidable.
Assume that A ≤m 0∗ 1∗ . I’ll construct MA , a TM that decides A. On input w, MA uses the
reduction for A ≤m 0∗ 1∗ to compute a new string, x such that x ∈ 0∗ 1∗ iff w ∈ A. MA then
uses its finite control to implement a DFA that determines whether or not x ∈ 0∗ 1∗ . If x ∈ 0∗ 1∗ ,
then MA accepts; otherwise, MA rejects. Note that the reduction step can’t loop (by the definition
of Turing-reducible) and the DFA step can’t loop (because the DFA reads one symbol of x at each
step and decides when it finishes reading x). Thus, MA never loops. Therefore, MA is a decider
for A which means that A is Turing-decidable.
If A is Turing-decidable, then A ≤m 0∗ 1∗ .
Assume that A is Turing-decidable. Thus, there is some TM that decides A. Let MA be such a
T M . To reduce A to 0∗ 1∗ , construct a Turing machine, M , that does the following on input w:
Run MA on input w.
If MA accepts w, erase the tape.
If MA rejects w, erase the tape and write the string 10.
MA cannot loop, it’s a decider.
Thus, if w ∈ A, then M writes  on its tape, and  ∈ 0∗ 1∗ . Otherwise, M writes 01 on its tape,
and 01 6∈ 0∗ 1∗ . Thus, M reduces A to 0∗ 1∗ .
Note: notice the cut-and-paste job I did to take the solution to part (a) and rewrite it into a solution for
part (b). While these proofs are very simple, they give you the basic template for reduction proofs.
3. (Sipser problem 5.24, 20 points) Let J = {w | either w = 0x for some x ∈ ATM or w = 1y for some y 6∈ ATM }.
Show that neither J nor J is Turing-recognizable.
Solution:
J is not Turing-recognizable.
We reduce ATM to J by constructing MATM , a TM that recognizes ATM using MJ , a TM that
recognizes J. On input [M ]#w, MATM moves every input symbol on square to the right and writes a
0 on the leftmost square. It then moves its head to the leftmost square and runs MJ . If MJ accepts then
[M ]#w 6∈ ATM ⇔ [M ]#w ∈ ATM . We have reduced ATM to J; ATM is not Turing-recognizable,
therefore, J is not Turing-recognizable either.
J is not Turing-recognizable.
We use basically the same construction as before, but this time we replace [M ]#w with 0[M ]#w.
4. (Sipser problem 5.34, 30 points) Consider the problem of determing whether a PDA accepts some string of the
form {ww | w ∈ {0, 1}∗ }. Use the computation history method to show that this problem is undecidable.
Solution: Let h be a computational history. We can write h as

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.

Potrebbero piacerti anche