COT4420 Theory of Computation April 7, 2016

advertisement
COT4420
Theory of Computation
April 7, 2016
Problem Set 6
Due: April 19, 2016
This assignment will not be graded.
1. Find a phrase structure grammar (it will basically be a context sensitive grammar with
one rule that goes to λ) for the following language:
L = {an**2 : n ≥ 1}.
2. What is a universal Turing machine? What are the inputs? What is the output or the
result of running the universal Turing machine?
3. What is the halting problem for Turing machines? Is it decidable? Explain.
4. How are recursive enumerable languages and recursive languages related to Turing
machines? Using Turing machines, show that recursively enumerable languages are
closed under union and intersection. Are they closed under complementation?
5. Design a Turing machine with no more than three states that accepts the language
a(a+b)*. Assume Σ = {a,b}. Can you find a two-state machine to do this? If so what
is it?
6. Outline a Turing machine that accepts the following language:
L = {anbncn : n ≥ 1}.
7. Outline a Turing machine that converts binary numbers to their unary representations.
8. Define the complexity classes P and NP.
9. Can a Turing machine be simulated by a pda with two stacks? Explain why or why
not and its ramification.
10. Read up on how Len Adleman solved an instance of the Hamilton path problem by
using DNA molecules. Briefly describe the novelty of this work.
1
COT4420
Theory of Computation
Due: April 19, 2016
Problem Set 6
Solutions
This assignment was not graded.
1. Find a grammar for the following language:
L = {an**2 : n ≥ 1}.
Consider the grammar with the following production rules. Note that superscripts with 1
are to indicate primes and thus different variables but related to the original. S is the start
symbol.
S → LS1MR
S1 → AS1
S1 → A
AM → M1A1
A1M → MA1
AM1 → M1A
LM1 → LMR
MRA → aAMR
MRA1 → aA1MR
Aa → aA
A1a → aA1
La → aL
MRR → MR
LM → ME
MEA1 → ME
M ER → λ
Note that the first set of productions simply creates a given set of n A’s that are bracketed
by L and MR respectively. The second set has M moving left over A1s, changing the first
A to an A1, and changing to an M1 which then moves over the A’s until it hits L. The
third set has MR creating an a for each A or A1. Thus the primes on the A remember how
many times a’s have to be created. The fourth set simply moves the little a’s to the left of
the L. The fifth set is some cleanup at the end. Try an example with 3 A’s.
Note that the above is a phrase structure grammar and is not context sensitive. However,
it is possible to find a slightly modified grammar that is context-sensitive and does a
similar thing but relies on the A’s themselves to act as the elements moving left and right.
This would however not be as clear as the above.
1
2. What is a universal Turing machine? What are the inputs? What is the output or the
result of running the universal Turing machine?
A universal Turing machine U is a Turing machine that can simulate the behavior of any
Turing machine M. To simulate the behavior of M, we need to simulate the operation of M
on any input w. The inputs of the universal Turing machine U are thus a description of M
and the string w.
Note that the description of M is a representation of the Turing machine in terms of the
finite states Q, the tape alphabet Γ (which includes the inputs Σ and the blank symbol), the
initial and final states of M, and the transition function of the Turing machine which can
be represented as a finite set of 5 tuples ( Q × Γ → Q × Γ × {L, R}. It can be seen that this
can, for example, be encoded using the binary symbols 1 and 0. For instance, the states Q
= {q1, …, qn} could be encoded as 1, 11, 111, … with the last being n ones. We could
assume that the initial state was the first state and the final state was a single second state
or we could separately list the set of final states. In order to separate states and lists, we
could use 0, 00, etc. as delimiters. The rest of the elements of the Turing machine can thus
be encoded also. Since each part is finite, the result is a finite string over {0, 1} that
represents a specific Turing machine. This is thus the description that is one of the inputs
to the universal Turing machine. The other input is the string w whose elements are a subset
of Γ and thus can also be encoded as a binary string.
One example of implementing the operational behavior of the universal Turing machine
would be to use three tapes, with the first having the description of M, the second having
the current state of M and the current tape symbol being scanned, and the third representing
the tape of M. The finite control of U is the states needed to look at the description of M,
the current status of M (on tape 2), and then decide how to modify the third track, and the
second track. Clearly this can be done by scanning the description of M on the first tape to
match the information on the second tape, and then decide on a move and execute it by
looking at the 5 tuples representing the behavior of M on the first tape. It should be clear
that this can be done with the finite control of U and the three tapes.
The result of running the universal Turing machine is equivalent to running M on tape
3. Thus, if M were to halt at some point with some configuration on tape 3, this would be
what the universal Turing machine would do. If M never halted, then neither would the
operations of U on tape 3.
2
3. What is the halting problem for Turing machines? Is it decidable?
The halting problem for Turing machines asks whether there exists an algorithm (some
Turing machine H) that will take as input the description of an arbitrary Turing machine
M, say D(M) and an arbitrary input w and decide if M would halt and say yes (or halt and
say no) or if M would never halt on w (q0w |─* ∞). Note that it is required that H halt for
every input since we want an algorithm and not simply a procedure. It can be proven that
there is no such H and thus the halting problem is not decidable.
4. How are recursive enumerable languages and recursive languages related to Turing
machines? Using Turing machines, show that recursively enumerable languages are
closed under union and intersection. Are they closed under complementation?
Turing Machines are a precise mathematical model for the concept of a procedure or
“black-box” previously considered.
R.E. languages are closed under union as follows:
Consider languages L1 and L2 that are r.e. Then there exists a Turing machine T1 that
halts with yes for any w ϵ L1 and a Turing machine T2 that halts with yes for any w ϵ L2.
We can construct a third Turing machine T3 that essentially runs T1 and T2 in parallel by
first executing a move of the first machine and then executing a move of the second
machine and so on for 2nd, third, etc. moves. As soon as T1 or T2 halts and says yes and
only then, T3 will halt and say yes. Thus T3 will accept exactly L1 ⋃ L2.
R.E. languages are closed under intersection as follows:
Run T1 and T2 above as before, but have T3 halt and say yes only if both machines T1 and
T2 halt and say yes. This can clearly be done by executing a move of T1 and a move of T2
and checking if any are in the accepting state. We continue until both are in the accepting
state (we can ignore moves of the one that halted when looking for second to halt.) Thus
this T3 will accept exactly L1 ⋂ L2.
R.E. languages are not closed under complementation.
We have shown by a diagonalization argument that there exists an r.e. language whose
complement is not r.e. (Theorem 11.3). Thus the set of r.e. languages is not closed under
complementation.
3
5. Design a Turing machine with no more than three states that accepts the language
a(a+b)*. Assume Σ = {a,b}. Can you find a two-state machine to do this? If so what
is it?
The following is a straight forward design with 3 states. q0 is the initial state and F =
{q2}. The blank symbol is “blank”.
δ(q0, a) = (q1, a, R)
δ(q1, a) = (q1, a, R)
δ(q1, b) = (q1, b, R)
δ(q1, blank) = (q2, blank, R)
This machine first checks if there is an a. If no a, there is no move and the machine
does not accept. Once it finds an a, it moves over a or b until a “blank” when it halts
in an accepting state.
The following is a two state machine that accepts the same language. Here F = {q1}.
δ(q0, a) = (q1, a, R)
Note that once you have the first a, the rest is irrelevant and you can accept.
4
6. Outline a Turing machine that accepts the following language:
L = {anbncn : n ≥ 1}.
We will use two tracks and check symbols off as we find them.
In the start state we first check if there is an a and if not we halt in a non-accepting
state.
If there is an a, we change state and check off the first a and move right over the a’s
looking for a b. (If we hit a c or a  we again stop in a non-accepting state.)
If we find a b, we check the b and then look for a c. (Again, if we don’t find a c we halt
in a non-accepting state.). When we find a c, we check this off.
We then move to the last checked a (first checked moving left).
We then move right and check if there is another a to check. If so we check this a also
and repeat the process above of checking for a b and a c.
If there are no more a’s to check and we are at a checked b, we wrap-up, else halt nonaccepting.
In wrap-up we first move right only over checked b’s. If we encounter any unchecked
b’s we halt non-accepting.
If we encounter a checked c we change state and move over only checked c’s until we
hit a . Only at this point will we halt in the accept state.
a
x
a
x
b
x
b
c
x
c
In the above we have checked the second a and are moving right looking for a b and c
to check. Note that if anything else happens, for example we don’t find the second b
we would stop in a non-accepting state.
a
x
a
x
b
x
b
x
c
x
c
x
c
In this case, suppose we have move left and found the last checked a and then moved
right over checked b’s and then are moving over the checked c’s. If we find the
unchecked c before a  then we would halt in a non-accepting state.
Other strings not in the language would similarly result in a non-accepting halt.
5
7. Outline a Turing Machine that converts binary numbers to their unary
representation.
Tape 1
Tape 2
Tape 3
1
0
1
1
Use a three tape T.M. where the first tape in the input, the second tape is used for
intermediate work and the third tape is used for the result. All tape heads initially start
at the left most symbol on their respective tapes.
Starting in the initial state move the head of the first tape and start further actions
from the rightmost non blank symbol. If the 1st tape symbol is 1 then write a 1 on the
3rd tape else do not do this and change state. Write a 11 on the 2nd tape.
Assume now that we have a subroutine Double, in which we can simply double the
number of 1’s on the second tape. This is fairly easy to implement but not trivial. See
if you can implement such a subroutine.
On the first tape move left. If it is a 1 add the contents of the second tape to the 3rd
tape else don’t do this. Call subroutine double and move left on the first tape.
Continue doing this until there is blank when you move left on the first tape. Halt at
this point.
Note: there were many state transitions required in implementing the conditionals
and calling the subroutine but there are only a finite number of such states that are
needed.
6
8. Define the complexity classes P and NP.
A Turing machine M decides a language L in time T(n) if for every w ϵ L with |w| = n,
M decides L in T(n) moves (worst case time for an input of size n). Note that the moves
allowed is a function of the length of w. Decides means that M halts and says yes or
halts and says no. (Thus the language of M is recursive.) For a non-deterministic TM,
this means that there exists some sequence of moves that satisfies the time bound. We
allow multi-tape machines (finite number of tapes) for both deterministic and nondeterministic machines.
Note that decision problems, such as finding the shortest path in a graph which has a
specific solution, can be reformulated as a language problem that is to be decided (yes
or no). The size of the problem is the length n of the input string representing the
problem.
The complexity class P is the set of those decision problems (languages) that can be
decided in time O (nk) for some k by a deterministic Turing machine. Equivalently,
these problems can be decided in polynomial time by a deterministic Turing machine.
The complexity class NP is the set of those decision problems (languages) that can be
decided in time O (nk) for some k by a non deterministic Turing machine. Equivalently,
these problems can be decided in polynomial time by a non deterministic Turing
machine.
Note: It should be clear that P ⊆ NP. The open problem is whether P = NP or is P a
proper subset of NP.
7
9. Can a Turing machine be simulated by a pda with two stacks? Explain why or why
not and its ramification.
Yes a Turing Machine can be simulated by a pad with two stacks. This implies that the
power of a pda is at least equivalent that of a Turing Machine.
Consider two stacks gro
Z1
C
B
A
Z2
F
E
D
Consider now a one tape Turing Machine, currently pointing at the tape symbol A:
C
B
A
D
E
F
Consider what happens if the T.M. moves to the right.
Consider what happens if it moves to the left.
Consider what happens if a stack pointer gets to Z1 or Z2.
Note: a move can easily be defined for the pda that corresponds to a move by the T.M.
8
Download