HOMEWORK 3 SOLUTIONS, CPSC 421/501, FALL 2015

advertisement
HOMEWORK 3 SOLUTIONS, CPSC 421/501, FALL 2015
JOEL FRIEDMAN
3.11 Let L be a language recognized by a Turing machine, M . Consdier a doubly
infinite tape machine with two more states, {q1 , q00 } and one extra tape symbol, e,
that behaves as follows: initially it moves one cell to the left, entering state q1 and
leaving the original cell alone; on the next step it marks its cell with the new tape
symbol, e, enters state q00 and moves to the right; from that point q00 functions as
the initial state, and the transition function, δ, is just like the old machine, with
one exception: if ever we read an e, then we keep the same state, rewrite the e,
and move one to the right (this means that M was at the leftmost cell and its head
would have stayed put).
For the converse our idea is that we fold the doubly inifnite tape over on itself
at the origin. In other words, if the doubly infinite tape has its cells numbered
1, 2, 3, . . . and 0, −1, −2, . . ., our ordinary Turning machine will have a “super cell”
number i ≥ 1 that contains the contents of doubly infinite cells number i and 1 − i;
so double infinite cells 0 and 1 become the ordinary cell 1, and −1 and 2 become 2,
and −2 and 3 become 3, etc. So if L is recognized by a doubly infinite taped Turing
machine, M = (Q, Σ, Γ, δ, q0 , qacc , qrej ), we form a new, ordinary Turing machine
0
0
0
0
, qrej
}, where
, qrej
) as follows: Q0 = Q × {+, −} ∪ {q00 , qacc
M 0 = (Q0 , Σ, Γ0 , δ 0 , q00 , qacc
+ indicates that we are running on M ’s cell i with i ≥ 1, and − indicates that
we are running on M ’s cell 1 − i. We will also mark cell 1 of M 0 with a unique
mark; so we set Γ0 = Γ × Γ × {u, m}, where the first copy of Γ holds the positive
cell value in M , and the second copy holds the non positive paired cell value, and
{u, m} indicates whether the cell is marked or unmarked as cell number 1.
The function δ 0 works roughly like this: when we are in a state (q, +) and we a
symbol (γ1 , γ2 , u), then we know the corresponding situation in M is that we are
on the right half of the tape (cells 1, 2, 3, . . .), and the u tells us that we are not on
cell 1; hence we transition as δ would in M , and we remain on the right half of the
tape; hence if δ(q, γ1 ) = (q̃, γ̃1 , d), where d ∈ {R, L},
δ 0 (q, +), (γ1 , γ2 , u) = (q̃, +), (γ̃1 , γ2 , u), d ;
similarly
δ 0 (q, −), (γ1 , γ2 , u) = (q̃, −), (γ̃1 , γ2 , u), d0 ,
where d0 is the opposite direction of d. Aside from this, we have to specify
(1) Σ lies in Γ0 via the map σ 7→ (σ, blank, u), so that the initial σ is view as
having σ in its first component (corresponding to the right half cell), blank
Research supported in part by an NSERC grant.
1
2
JOEL FRIEDMAN
it its second (corresponding to the iniail blank in the left half cell), and u
meaning all cells are unmarked;
(2) define δ 0 (q00 , (γ1 , blank, u)) to transition as δ, but to mark this cell and
transition to the appropriate (q, ±) state;
(3) define δ 0 on marked cells as switching the + to a − or vice versa if M would
move from cell 1 to cell 0 or vice versa.
0
(4) modify δ 0 so that in a state (qacc , ±) we transition to qacc
, and similarly for
the rejecting states.
We leave it to the interested reader to write out these rules formally.
Question 3.15 For the following problems, assume that L1 and L2 are two
decidable languages with M1 and M2 being the Turing machines that decide them.
Also let w denote the input string.
a Let L = {w | w ∈ L1 ∪ L2 }. One can construct a Turing machine M that
decides L as follows:
1 Run M1 on w and accept if M1 accepts.
2 Run M2 on w and accept if M2 accepts. Reject otherwise.
b Run over all |w| + 1 ways of writing w as a concatenation w1 w2 : run M1 on
w1 , M2 on w2 , and accept if they both accept. Otherwise reject (if this fails
for all |w| + 1 ways). [We run over all ways of writing w as a concatenation
w1 w2 by having a counter advance from 0 to |w|, and when its value is i
we set w1 to the first i letters of w, and w2 to the rest of w.]
c To decide L∗1 : run over all ways of writing w as a concatenation of nonempty substrings w1 . . . wr (any r ≤ |w|): run each wi on the machine that
decides M1 and accept if each substring wi is accepted. Otherwise reject
(if this fails for all ways of writing w as a concatenation). [We can run over
all ways of writing w as a concatenation—in a crude fasion—by running
through all {0, 1} strings, s, of length |w|, and starting a new substring in
position i if the i-th letter of s is a 1.] We remark that there is no need
to consider writing w as w1 . . . wr where some wi ’s are empty, since if such
a decomposition results in being accepted then one can always discard the
empty strings and still be accepted.
d Let M be the TM that decides L. Here is a TM that decides L̄:
1 Run M on w. If it accepts, reject. If it rejects, accept.
e L1 ∩ L2 can be decided by the following TM:
1 Run M1 on w. If it rejects, reject.
2 Run M2 on w. If it rejects, reject. Otherwise, accept.
Question 3.16
a Let L = {w | w ∈ L1 ∪ L2 }. One can construct a Turing machine M that
recognizes L as follows:
1 Run both M1 and M2 on w, i.e., run one step of M1 for one step of
M2 .
2 If either machines halts and accepts, accept. If both halt and reject,
reject.
The major distinction with 3.15a is that M1 and M2 are run simultaneously.
This is to avoid looping in cases where M1 (or M2 ) does not recognize L2
(or L1 ).
HOMEWORK 3 SOLUTIONS, CPSC 421/501, FALL 2015
3
b Let L = {w | w = w1 w2 s.t w1 ∈ L1 , w2 ∈ L2 }. The solution is like that
of 3.15b, except we run one step of each algorithm on w1 and w2 over all
ways of writing w = w1 w2 ; then we run two steps of each algorithm on all
ways; then three steps; etc. This way if any way of writing w = w1 w2 is
accepted, we will accept w in a finite amount of time.
c The idea is to combine the ideas in the solutions of problems 3.15c and
3.16b: we run one step of the algorithm to recognize the langauge over each
of w1 , w2 , . . . , wr , over all ways of writing w as nonempty strings w1 . . . wr ;
then we run two steps; etc.
d L1 ∩ L2 can be decided by the following TM:
1 Run M1 on w. If it halts and rejects, reject.
2 Run M2 on w. If it halts and rejects, reject. Otherwise, accept. Remark: There is no need to run M1 and M2 step by step. For w to be
in the intersection of L1 and L2 , both TMs must halt and accept.
Recognizable Languages Under Complementation
We know that if L is recognizable but not decidable (such as ATM or HALTTM ),
then its complement is not recognizable. So while ATM or HALTTM are recognizable, their complements are not.
Department of Computer Science, University of British Columbia, Vancouver, BC
V6T 1Z4, CANADA, and Department of Mathematics, University of British Columbia,
Vancouver, BC V6T 1Z2, CANADA.
E-mail address: jf@cs.ubc.ca or jf@math.ubc.ca
URL: http://www.math.ubc.ca/~jf
Download