Revised Section 9.1

Transcription

Revised Section 9.1
44
9.1
1. Turing Machines
Post Machines
A Post Machine over the alphabet Σ = {a, b} with the auxiliary symbol #, can be
viewed as a flowchart whose statements operate on a queue. That queue is represented as
a list x = [x1 , . . . , xn ] with the operations head, tail, cons, and append (denoted by the
infix operator @) which are defined as usual. The empty list is denoted by nil (see also
Figure 16).
In the flowchart of a Post Machine P we have the following statements:
(i) one start statement (with indegree 0 and outdegree 1),
(ii) 0 or more accept or reject statements (with indegree 1 and outdegree 0),
(iii) some enqueue statements (called assignment statements in [25, page 24]) (with indegree 1 and outdegree 1) of the form enqueue(x, e), for e ∈ {a, b, #}, which given
the queue represented by the list x, produces the queue represented by the list x@[e],
and
(iv) some dequeue statements (called test statements in [25, page 24]) (with indegree 1 and
outdegree 4) is of the form dequeue(x)[η, α, β, χ] which given the queue represented
by the list x, behaves as follows:
if x = nil then goto η else begin h = head(x); x = tail (x);
if h = a then goto α else
if h = b then goto β else
if h = # then goto χ
end
where η, α, β, and χ are labels associated with some (not necessarily distinct) statements of the flowchart of the Post Machine P (see Figure 16). Every goto statement
is an arc of the flowchart. Every dequeue statement includes a test on the value of
head(x), if the list x is not nil, that is, if the queue is not empty.
dequeue(x)[η,α,β,χ] !
x1 . . . xh xh+1 . . . xn ! enqueue(x, e)
Fig. 16. The enqueue(x, e) and dequeue(x)[η,α,β,χ] statements on a queue represented by
the list x = [x1 , . . . , xn . We have that: head (x) = x1 and tail (x) = [x2 , . . . , xn ].
The language L ⊆ Σ ∗ accepted (or rejected) by a Post Machine P is the set of words w
such that if the queue x is equal to w before the execution of the flowchart of P , then
eventually the Post Machine P executes an accept statement (or a reject statement,
respectively).
For some initial value of x, a Post Machine may run forever, without executing any
accept or reject statement.
There is no loss of generality if we assume that the Post Machine has the symbols a, b,
and # only. Indeed, if there are extra symbols, besides a, b, and #, we may encode them
by sequences of a’s and b’s. For instance, if a Post Machine P " has the extra symbol ∆,
45
9. Other Models of Computation
then we may encode the symbol a by the string a a and, similarly, b by a b, # by b a, and
∆ by b b. Obviously, a Post Machine that uses that encoding, has to execute two dequeue
statements (or two enqueue statements) for simulating a single dequeue statement (or a
single enqueue statement, respectively) of the Post Machine P " .
Now we will prove the equivalence between Turing Machines and Post Machines, that
is, we will prove that: (1) for any Turing Machine there exists a Post Machine which
accepts the same language, and (2) vice versa.
Without loss of generality, we will assume that:
(i) the tape alphabet of the Turing Machine is Γ = {a, b, B}, where B is the blank symbol
which is not printable,
(ii) the Turing Machine cannot make a left move when its tape head scans the leftmost
cell (recall that the position of the tape head can be tested by simulating a tape with
two tracks), and
(iii) the Post Machine has symbols a,b, and # only.
Proof of Point (1). Let us consider a tape configuration of the Turing Machine of the form:
(tape of
the Turing Machine)
!
c1
!
. . . ch−1 ch ch+1 . . . ck
!
B
B
...
where the rightmost cell with a non-blank symbol is ck and the scanned cell (marked by !)
is ch , with 1 ≤ h ≤ k. That tape configuration is represented by the following queue q of
the Post Machine:
(queue q of
!
the Post Machine)
!
!
ch ch+1 . . . ck
#
c1
. . . ch−1 !
(†)
Thus, (i) the tape head of the Turing Machine scans the leftmost cell of the tape iff #
is the rightmost element of the queue of the Post Machine (that is, the cells c1 , . . . , ch−1
are absent), and (ii) the tape head of the Turing Machine scans the leftmost blank symbol B iff # is the leftmost element of the queue of the Post Machine (that is, the cells
ch , ch+1 , . . . , ck are absent). In Case (ii) if the tape of the Turing Machine has the nonblank symbols in its leftmost cells c1 , . . . , ch−1 , then the queue of the Post Machine is of
the form:
!
#
c1
. . . ch−1 !
(Here we slightly depart from the representation of the tape of the Turing Machine used
in [25], but no problem arises because we assumed that when the tape head of the Turing
Machine scans the leftmost cell, it cannot make a left move.) In particular, if the tape of
the Turing Machine has blank symbols only and the tape head scans the leftmost blank
symbol B, then the queue of the Post Machine is of the form:
!
#
!
46
1. Turing Machines
Recall that, since the blank symbol B is not printable, the tape head of the Turing Machine
scans the leftmost cell with the blank symbol B, only when the tape has blank symbols
only.
We have that, before and after the simulation of a move of the Turing Machine, the
queue q of the Post Machine is not empty and it has at least the element #.
Starting from the queue q on page 45 (see queue (†)), the move of the Turing Machine
that writes c!h in the place of ch (here and in what follows, when no confusion arises, we
identify a cell with the symbol written in that cell) and goes to the right, transforms q
into the following queue:
(after a right move !
from queue q (†))
ch+1 . . . ck
#
c1
. . . ch−1 c!h
!
Analogously, the move of the Turing Machine which writes c!h in the place of ch and goes
to the left, transforms the queue q on page 45 (see queue (†)) into the following queue:
(after a left move
!
ch−1 c!h ch+1 . . . ck # c1 . . . ch−2 !
from queue q (†))
Now we show how the Post Machine may simulate via fragments of flowcharts both the
right move and the left move of the Turing Machine. Thus, by suitably composing those
fragments, according to the definition of the transition function of the Turing Machine,
we get the simulation of the Turing Machine by a Post Machine.
In Figure 17 on page 47 we show some left and right moves of the Turing Machine and
the corresponding queue configurations of the Post Machine that simulates the Turing
Machine. This figure will help the reader to understand the statements of the simulating
Post Machine. Here is the simulation of the right move and the left move.
Simulation of the right move. The right move of the Turing Machine that writes !
c
before moving, is simulated by the Post Machine by performing the following operations:
(i) dequeue;
(ii) if the dequeued element is # then insert the element # into the queue from its left
end (this insertion is performed when the queue, which may or may not be empty,
has no element #);
(iii) enqueue of !
c.
Thus, formally, we have that the right move is simulated by:
dequeue(q)[η, α, α, χ];
χ: enqueue(q, #);
enqueue(q, #);
ω: dequeue(q)[η1 , α1 , β1 , α]; α1 : enqueue(q, a); goto ω; β1 : enqueue(q, b); goto ω;
α: enqueue(q, !
c);
Note that there is no need for the statements with label η or η1 because the control never
goes to those statements.
Simulation of the left move. The left move of the Turing Machine that writes !
c
before moving, is simulated by the Post Machine by performing the following operations:
(i) dequeue;
(ii) if the dequeued element is # then insert the element # into the queue from its left
end;
(iii) )-enqueue the element !
c; r-dequeue one element, call it e; )-enqueue the element e (††)
47
9. Other Models of Computation
Turing B B B. . .
!
Machine
r
)
(T 1)
)
!
c B B. . .
!
Post
←#←
Machine
r
)
a b B B. . .
!
(P 1)
← #!
c←
ab!
c B. . .
!
(T 2)
r
ab!
c B. . .
!
← # a b ← (P 2)
)
r
a b c d e B. . .
!
)
(T 3)
r
ab!
c d e B. . . a b !
c d e B. . .
!
!
←cde#ab←
)
(P 3)
r
← b!
c#a ← ← #ab!
c ← ← b!
cde#a ← ← de#ab!
c←
Fig. 17. Simulation of the Turing Machine by the Post Machine. Arcs with labels ) and r
denote the moves to the left and to the right, respectively. The ! symbol shows the
scanned cell. The symbol !
c is written in the scanned cell before moving to the left or to
the right. The dashed arcs are not followed. The moves of the Turing Machine from the
configurations (T i)’s (for i = 1, 2, 3) are simulated by the moves of the Post Machine from
the corresponding configurations (P i)’s.
where )-enqueue(q, e) denotes the insertion of the element e to the left of the queue q, and
r-dequeue(q)[η, α, β, χ] denotes the extraction of the rightmost element from the queue q.
The labels η, α, β, and χ are the labels of the statements which are performed next if the
queue q is empty, or the extracted element from the right is a, or b, or #, respectively.
We will define the )-enqueue and the r-dequeue operations below.
The operations of Point (iii) (see (††) above) are performed when in the queue there
is the element # and the element e is either a or b. Note that e cannot be # because the
left move is not allowed when the tape head of the Turing Machine scans the leftmost cell
and only in that case the rightmost element of the queue is #.
Thus, formally, we have that the left move is simulated by:
dequeue(q)[η, α, α, χ];
χ: enqueue(q, #);
enqueue(q, #);
ω: dequeue(q)[η1 , α1 , β1 , α]; α1 : enqueue(q, a); goto ω; β1 : enqueue(q, b); goto ω;
α: )-enqueue(q, !
c);
r-dequeue(q)[η1 , α1 , β1 , χ1 ];
α1 : )-enqueue(q, a); goto ϕ;
β1 : )-enqueue(q, b); goto ϕ;
where the next statement to be executed has label ϕ. Note that there is no need for the
statements with label η or η1 or χ1 .
Here is the definition of the )-enqueue(q, e) operation. We assume that in the queue
there is the element # and the element e is either a or b. We realize the )-enqueue(q, e)
operation as follows: we insert a second element # in the queue, then we insert the
48
1. Turing Machines
element e, and finally, we make a complete rotation of the elements of the queue, but we
do not reinsert to the right the second element #. Thus, we have that:
)-enqueue(q, e) =
λ: enqueue(q, #); enqueue(q, e);
ω: dequeue(q)[η, α, β, χ]; α: enqueue(q, a); goto ω; β: enqueue(q, b); goto ω;
χ: enqueue(q, #);
ω1 : dequeue(q)[η1 , α1 , β1 , χ1 ]; α1 : enqueue(q, a); goto ω1 ; β1 : enqueue(q, b); goto ω1 ;
where χ1 is the label of the statement to be executed next. Note that there is no need for
the statements with label η or η1 . Note also that at label χ1 the second element # that
was inserted in the queue q by the statement at label λ, is deleted, and the element e
occurs as the first (leftmost) element of the queue q, as desired.
Here is the definition of the r-dequeue(q)[η, α, β, χ] operation. We assume that in the
queue there is the element # which is not in the rightmost position (recall that the left
move cannot take place when the tape head scans the leftmost cell), and the dequeued
element is a or b. We realize the r-dequeue(q)[η, α, β, χ] operation as follows. We insert a
second element # in the queue and then we make a complete rotation of the elements of
the queue, reinserting to the right neither the second element # nor the element which was
in the queue to the left of that second element #. This requires a delay of the reinsertion
for checking whether or not the second element # follows the present element. Thus, we
have that (see also Figure 18):
r-dequeue(q)[η, α, β, χ] =
λ: enqueue(q, #);
ω0 : dequeue(q)[η0 , α0 , β0 , χ0 ];
α0 : enqueue(q, a); goto ω0 ; β0 : enqueue(q, b); goto ω0 ;
dequeue(q)[η1 , α1 , β1 , χ];
α1 : dequeue(q)[αη , αa , αb , α];
αa : enqueue(q, a); goto α1 ; αb : enqueue(q, a); goto β1 ;
β1 : dequeue(q)[βη , βa , βb , β];
βa : enqueue(q, b); goto α1 ;
βb : enqueue(q, b); goto β1 ;
χ0 : enqueue(q, #);
Note that there is no need for statements with label η or η0 or η1 or αη or βη or χ (recall
that: (i) we have assumed that the given queue q is not empty, (ii) at label λ we have
inserted in the queue q a second element #, and (iii) the first element # is not in the
rightmost position).
Proof of Point (2). The proof that for any Post Machine there exists a Turing Machine,
say M, which accepts the same language, follows from the fact that the queue of the Post
Machine can represented by the leftmost part of the tape of the Turing Machine M and
the operations on the queue can be simulated by operations on the tape. We leave to the
reader the details of the construction of the Turing Machine M.
Now let us introduce the following definition.
We say that a function f from N to N is computable by a Post Machine P iff starting
with the string an b af (n) in the queue, P eventually performs an accept statement.
49
9. Other Models of Computation
r-dequeue(q)[η, α, β, χ] =
λ: enqueue(q, #)
ω0 : dequeue(q)[η0 , α0 , β0 , χ0 ]
empty?
η0
a?
α0
empty?
η1
a
b
←
←
dequeue(q)[η1 , α1 , β1 , χ]
a?
b?
a
←
αη
αa
αb
#?
βη
βa
χ0
#?
β1 : dequeue(q)[βη , βa , βb , β]
empty? a?
a b
← ←
α
#
←
β0
b?
α1 : dequeue(q)[αη , αa , αb , α]
empty? a?
#?
b?
b?
χ
#?
b
←
βb
β
Fig. 18. Diagram that illustrates the statements for the r-dequeue(q)[η, α, β, χ] operation.
#
a b
We have written ←, ←, and ←, instead of enqueue(q, a), enqueue(q, b), and enqueue(q, #),
respectively. The dashed arcs (those with label empty?) are not followed because the
queue q is never empty. There is no need for statements with label η or η0 or η1 or αη
or βη or χ.
Thus, as a consequence of the equivalence between Turing Machines and Post Machines
which preserves the accepted language, we have that a function f from N to N is Turing
computable iff f is computable by a Post Machine.

Documents pareils