Theory of Computation, Homework 3 Sample Solution

Transcription

Theory of Computation, Homework 3 Sample Solution
Theory of Computation, Homework 3 Sample Solution
3.8
b.) The following machine M will do:
M = "On input string :
1. Scan the tape and mark the first 1 which has not been marked. If no unmarked 1 is
found, go to step 5. Otherwise, move the head back to the front of the tape.
2. Scan the tape and mark the first 0 which has not been marked. If no unmarked 0 is
found, reject.
3. Move on to mark the next unmarked 0. If no such unmarked 0 is found, reject.
4. Move the head back to the front of the tape and go to step 1.
5. Move the head back to the front of the tape. Scan the tape to see if there is any
unmarked 0 found. If yes, reject. Otherwise, accept.
c.) This machine is identical to 3.8b) if we switch “reject” with “accept”.
M = "On input string :
1. Scan the tape and mark the first 1 which has not been marked. If no unmarked 1 is
found, go to step 5. Otherwise, move the head back to the front of the tape.
2. Scan the tape and mark the first 0 which has not been marked. If no unmarked 0 is
found, accept.
3. Move on to mark the next unmarked 0. If no such unmarked 0 is found, accept.
4. Move the head back to the front of the tape and go to step 1.
5. Move the head back to the front of the tape. Scan the tape to see if there is any
unmarked 0 found. If yes, accept. Otherwise, reject.
3.12
be a Turing machine with left reset and
Let
simulate all the operations that
can perform,
recognizable language. Obviously,
be an ordinary Turing machine. If
recognizes the class of Turing-
can simulate
of
can
without
problems. How
simulates
of
is described as follows.
1. overwrite with a marked
2. reset to the left-hand end
3. shift the whole tape one cell to the right but keep the mark in the same position
4. reset to the left-hand end
5. scan right to find the marked symbol; the next move will treat the marked symbol as a
normal symbol.
We assume the following during the shifting for Step 3:
a. We use states to remember the symbol to be shifted right.
b. The first symbol of the tape after the shift is a symbol not used by the original M.
c. If the current symbol is c and the next symbol is the marked b, after the shifting, c
becomes marked but b is not marked.
d. The shifting stops when we see a blank symbol.
3.15
b.)
Let
and
be two decidable languages and
and
be the corresponding TMs. The
aim is to construct a TM
based on
and
such that the concatenation
is
also decidable. Since a given input concatenation of strings
and
has finite
possible partitions, a nondeterministic TM is chosen to simplifies the description.
NTM
”On input
1. Nondeterministically split into and
2. run
on and
on
3. accept if both
accepts and
accepts ; reject otherwise”
accepts an input
Obviously, the NTM
and
accepts . Besides,
iff there exists a split of
eventually halts because
and
is decidable since there exists an NTM
Therefore,
such that
accepts
are both deciders.
which decides
.
c.)
Let
be a decidable language and
be the corresponding TM. The aim is to construct a TM
based on
such that
is also decidable. Since a given input has finite possible
combinations of strings
where
and
, a nondeterministic TM is
chosen to simplify the description.
NTM
”On input
1. accept if
2. if
3. run
, nondeterministically split
on
for all i.
4. accept if
accepts all
,
into
, where
is not empty.
; reject otherwise”
Obviously, the NTM
accepts an input iff
or there exists a combination of such
that
accepts
. Besides,
eventually halts because
is a decider. Therefore,
is decidable since there exists an NTM
which decides .
d.)
Let
be a decidable language and
based on
such that
is described as follows.
TM
be the corresponding TM. The aim is to construct a TM
, the complement of
, is also decidable. The resulting TM
”On input
1. run
on
rejects
2. accept if
3. reject if
accepts
Obviously,
accepts an input
is a decider. Therefore,
iff
rejects
. Besides,
eventually halts because
is decidable since there exists a TM
which decides
.
e.)
and
be two decidable languages and
and
be the corresponding TMs. The
Let
aim is to construct a TM
based on
and
such that the intersection
is
is described as follows.
also decidable. The resulting TM
”On input
4. run
and
1. accept if both
Obviously, the NTM
eventually halts because
since there exists a TM
on
and
accepts
accepts an input
and
; reject otherwise”
iff
is accepted by
are both deciders. Therefore,
which decides
.
and
. Besides,
is decidable
3.16
b.)
and
be two Turing-recognizable languages and
and
be the corresponding
Let
TMs. The aim is to construct a TM
based on
and
such that the concatenation
is also Turing-recognizable. Since a given input concatenation of strings
and
has finite possible partitions, a nondeterministic TM is chosen to simplify the
description.
NTM
1.
2.
3.
4.
”On input
Nondeterministically split into
on input
run
reject if
halts and rejects
run
on input
5. accept if
accepts ; reject if
and
halts and rejects
recognizes an input
Obviously, the NTM
accepts
and
accepts . However,
are not deciders. Therefore,
which recognizes
iff there exists a partition of
such that
may loop forever on some input because
is Turing-recognizable since there exists an NTM
.
c.)
Let be a Turing-recognizable language and
construct a TM
based on
such that
be the corresponding TM. The aim is to
is also Turing-recognizable. Since a given input
has finite possible combinations of strings
where
nondeterministic TM is chosen to simplify the description.
,
,a
NTM
”On input
1. accept if
2. if
3. run
nondeterministically split
on
for all i.
4. accept if
5. reject if
such that
recognizes an input
accepts
is not a decider. Therefore,
recognizes
.
into
accepts all ,
halts and rejects for any
Obviously, the NTM
and
. However,
, where
is not empty.
;
”
iff
or there exists a combination of
may loop forever on some input because
is Turing-recognizable since there exists an NTM
which
d.)
and
be two Turing-recognizable languages and
and
be the corresponding
Let
TMs. The aim is to construct a TM
based on
and
such that the intersection
is also Turing-recognizable. The resulting TM
is described as follows.
1.
2.
3.
4.
”On input
run
on
rejects if
run
on
accept if
Obviously, the TM
However,
Therefore,
.
halts and rejects
accepts
; reject if
recognizes an input
halts and rejects”
iff
is accepted by
may loop forever on some input because
and
and then
.
both are not deciders.
is Turing-recognizable since there exists a TM
which recognizes
4.4
Since
follows.
is just a special case of
, it is possible to adapt TM S for
as
, where
is a CFG and is an empty string:
TM S = "On input
1. Convert G to an equivalent grammar in Chomsky normal form.
2. If “S -> “ is a production rule in Chomsky normal form, accept; if not, reject."
4.10
To decide
is to determine if there exist strings generated by
at least the pumping length . Let
The construction of TM
TM
be a CFG for
and design a TM
is as follows, deciding
with lengths
that decides
:
= “On input: < >
1. convert to Chomsky normal form
from , where
is the number of variables in
2. calculate the pumping length p =
(in Chomsky normal form, each rule has 0 or two variables at the right, so the pumping
length is
that is computable)
3. accept if
produces a string of length at least because the string can be pumped to
generate infinitely other strings
4. otherwise, reject”
For step 3, it is decidable since it is possible to construct a DFA
such that the regular
language recognized by
is the set of strings of lengths at least . Let
which is a CFL from Problem 2.18a and
be the CFG of
Then TM
decide
. If TM
accepts,
produces no strings of lengths at least
string of length at least p.
be
in Theorem 4.8 can
. If not, produces a
4.12
. Therefore, we can first construct two equivalent DFA
If
and
recognizing
and
decide if the two DFA are equivalent.
TM
and then run TM
= "On input <
>:
1. construct the equivalent NFA
and
for
2. construct the equivalent DFA
and
for the
in theorem 4.5 to
and
and
3. construct a DFA
, accepting
.
4. run TM to decide if
and
are equivalent
5. accept if TM accepts; reject if TM rejects”
4.24
be a CFL containing all the palindromes,
Let
be
the regular language accepted by
and be
. The goal is that
is decidable iff the emptiness of is also decidable. Since
is a CFL from
in theorem 4.8. Let
be the CFG of
Problem 2.18, its emptiness can be decided by TM
The decider
is constructed as follows.
TM
= "On input
1. Let
2.
3.
4.
5.
⟨ ⟨where
is a DFA accepting some palindrome:
be a CFL containing all the palindromes
Let
be the regular language accepted by
derive the CFG for
run TM
to decide
accept if TM accepts; reject if TM rejects.
4.28 Let us prove it by contradiction. Suppose that every decider is in A. Since A is Turingrecognizable, A is also enumerable. Let
be the ith decider in A. We may construct the
following decider
as follows:
”On input ,
(1) decide the order number of , i.e,
(2) accept
if
rejects; rejects if
= , the index of
accepts.”
be ;
is a decider as (1)-(2) halts.
is different from any
Apparently,
contradiction to the assumption that every decider is in A.
in A, which is a
To show that
is different from any
in A, let
be the list of all the
strings in an canonical order of string (length than dictionary order). Then
can be derived
by applying the diagonalization method as illustrated by the following table.
The table below demonstrates an example
.
...
...
Obviously,
reject
accept
accept
...
accept
accept
accept
...
reject
accept
reject
...
...
...
...
...
accept
reject
accept
...
is different from any language decided by
whose description appears in
.