2it70 Chap4
2it70 Chap4
Turing Machines
and Computable Functions
We have seen that PDAs, containing a finite control and equipped with a stack-like
memory, can accept a wide range of languages. The class of context-free languages can
be characterized as the class of languages accepted by such a PDA. However, we have
also seen some languages that are not context-free. The language { an b n c n | n > 0 } of
Example ?? and the language { ww | w ∈ {a, b}∗ } of Example ?? cannot be accepted
by a PDA.
In this chapter, we consider reactive Turing machines like the machine depicted in
Figure 4.1. Reactive Turing machines accept a class of languages called the recursively
enumerable languages. This class is wider than the class of context-free languages ac-
cepted by PDAs. In particular, there are Turing machines that accept the languages of
the examples mentioned above.
Tape Tape
The push-down automata of the previous chapter have a memory containing a stack
of symbols which can only be accessed at the top. The Turing machine has a tape as
memory, which also symbols as contents, but can be accessed at any place. It is said
that a Turing machine has random access. This entails that the so-called tape head
can move around the string of symbols on the tape. The Turing machine seems only
like a small advancement over the possibilities of a push-down automaton. Nevertheless,
Turing machines are much more powerful than PDAs. Even, it can be argued that any
computation that can be done by any computer can also be done by a Turing machine.
1
2 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS
We will generalize the case of output of only ‘yes’ or ‘no’ for the reactive Turing
machine to the case where the output is an arbitrary string left at the tape at the end
of a computation. This yields the notion of a classical Turing machine. If a function can
be implemented on a classical Turing machine, we speak of a computable function.
τ [#/#, L]
0 1
Example 4.1. Consider Figure 4.2, depicting a reactive Turing machine with input
alphabet Σ = {a, b}. The tape alphabet ∆ = {1}, hence ∆ # = {1, #}. We start out in
state q0 with h#i in memory. Thus control is in the initial state and the tape head is
reading a blank, also all other cells are empty. We can take the loop of q0 if the symbol a
is on input. Then, a 1 is written in the cell that is currently pointed at and the tape
head moves to the right. Thus we obtain 1h#i as tape content. Alternatively, we can
take silently the edge labeled τ to the final state q1 , keeping h#i as it appears. (In fact,
the tape head has moved to the left, but our notation doesn’t show.) Taking the loop
three times on input aaa gives 111h#i with control in state q0 , then taking the edge
4.1. THE REACTIVE TURING MACHINE 3
Definition 4.2 (Reactive Turing machine). A reactive Turing machine, or Turing ma-
chine for short, is a septuple M = ( Q, Σ, ∆, #, →, q0 , F ) where Q is a finite set of
states, Σ is a finite input alphabet with τ ∈ / Σ, ∆ is a finite data or tape alphabet,
# ∈
/ ∆ a special symbol called blank, → ⊆ Q × Στ × ∆ # × ∆ # × {L, R} × Q, where
Στ = Σ ∪ {τ } and ∆ # = ∆ ∪ {#}, is a finite set of transitions or steps, q0 ∈ Q is the
initial state, and F ⊆ Q is the set of final states.
We use the symbol µ ∈ {L, R} to denote a move of the tape head, either left or right.
a[e/e′ ,µ]
For a ∈ Σ, if (q, a, e, e′ , µ, q ′ ) ∈ →, we write q −−−−−−→M q ′ , and this means that the
Turing machine M , when it is in state q, reading the symbol a on input, and reading the
symbol e on tape, it can consume the input, change the symbol on the tape to e′ , move
one cell left if µ = L or one cell right if µ = R and thereby change control to state q ′ .
It is also possible that e and/or e′ is #: if e is #, we are looking at an empty cell on the
tape; if e ∈ ∆ is a non-blank and e′ is #, then we say that the symbol e is erased.
τ [e/e′ ,µ]
Similarly, if (q, τ, e, e′ , µ, q ′ ) ∈ →, we write q −−−−−−→M q ′ . Now it means that the
Turing machine M , when it is in state q and reading the symbol e on tape, can (without
a change on input) write the symbol e′ under the tape head, move left or right if µ = L
or µ = R, respectively, and change control to state q ′ . As a combined notation we may
α[e/e′ ,µ]
write q −−−−−−→M q ′ with α ranging over Στ .
To record the steps taking by a reactive Turing machine, we need to have a means to
update the tape. Suppose the tape contains xheiy, and we can execute the transition
α[e/e′ ,µ]
q −−−−−−→M q ′ . Note, the data symbol e is both occurring in xheiy as well is in the
label α[e/e′ , µ] of the transition. In this setting, we define the update xheiy [e/e′ , µ] of
tape content xheiy by tape head action [e/e′ , µ] as follows.
Here, in case the left string x or the right string y is empty, we use the full notation
εheiy and xheiε, respectively. When using the shorthand, the empty string cases read
xhei [e/e′ , R] = xe′ h#i and heiy [e/e′ , L] = h#ie′ y.
We see that the content of the cell that is currently scanned is filled with e′ . If the
tape head moves right, the first symbol d of dy comes under the tape head or, in case
of ε, a blank comes under the tape head. If the tape head moves left, two similar cases
apply.
4 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS
Expressions of the form xheiy ∈ ∆*# × ∆ # × ∆*# occur frequently in the remainder of
the chapter. We introduce the class of tape content Z by putting
and have z range over Z. We want the first symbol of x and the last symbol of y to be a
symbol in ∆, if possible. This way, given the position of the tape head, the tape content
is uniquely defined.
With the notion of an update available, we can define a configuration or instanta-
neous description of a Turing machine M = ( Q, Σ, ∆, #, →, q0 , F ), ID for short. A
configuration of the Turing machine M is a triple (q, w, z) of a state q, an input string w
and tape content z. Thus (q, w, z) ∈ Q × Σ∗ × Z. The q and z, respectively, are the
current state and current content of the tape, w represents the input that is not read so
far.
We write (q, w, z) ⊢M (q ′ , w′ , z ′ ) iff either (i) for some a ∈ Σ, e, e′ ∈ ∆ # , and
µ ∈ {L, R}, we have
a[e/e′ ,µ]
q −−−−−−→M q ′ ∧ w = aw′ ∧ z [e/e′ , µ] = z ′
τ [#/#, L] τ [#/#, R]
0 1 2
Example 4.3. Consider the Turing machine depicted in Figure 4.3 with input alphabet
Σ = {a, b}, tape alphabet ∆ = {1} and blank #. When started in q0 , any number of a’s
can be input, each time writing the symbol 1 on the tape and moving the tape head to
the right. At any time, a move to the state q1 can occur, reversing the direction of the
4.1. THE REACTIVE TURING MACHINE 5
tape head. Then, the same number of b’s can be input, each time erasing a 1. Coming
to the beginning of the string of 1’s, while having erased all of them in transit, the tape
is empty again. The tape head is scanning a blank, and termination can take place after
a silent transition from state q1 to q2 .
A computation showing that M accepts the string aaabbb is the following:
(q0 , aaabbb, h#i) ⊢ M (q0 , aabbb, 1h#i) ⊢ M (q0 , abbb, 11h#i) ⊢ M (q0 , bbb, 111h#i) ⊢ M
(q1 , bbb, 11h1i) ⊢ M (q1 , bb, 1h1i) ⊢ M (q1 , b, h1i) ⊢ M (q1 , ε, h#i) ⊢ M (q2 , ε, h#i)
Note, if after a number of a’s, a lower number of b’s is offered on input, the machine
cannot reach state q2 . Also, when a higher of number of b’s is offered, the machine will
get stuck in state q2 . If, after a number of a’s, a lower number of b’s follows, followed
again by an a, the machine gets stuck in state q1 . Finally, if after a number of a’s,
followed by the same number of b’s, yet another a follows, the machine will get stuck
in q2 . Thus, for example for the string aabb we have the computation
The language of the Turing machine of Figure 4.3, a notion formally defined below, is
the set of strings { an bn | n > 0}.
Note that it is required that the computation reaches a final state and consumes all of
the input. However, nothing specific is required for the tape content z in of the end
configuration (q, ε, z).
In the definition above, ⊢∗M denotes the reflexive and transitive closure of the rela-
tion ⊢M . Thus
For a number of languages, Turing machines can be constructed. We start out easy.
6 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS
a[#/#, R]
Example 4.5. A Turing machine that accepts the language {a}∗ = { an | n > 0 } is
shown in Figure 4.4. As long as the input consists of a’s, we move to the right. At any
time, termination can occur. Although the tape head may move, not data symbol is
written on tape.
Example 4.6. Every finite language is accepted by a Turing machine. For example
the finite language {a, ba, cba} over {a, b, c} is accepted by the Turing machine given in
Figure 4.5.
τ [#/#, R] a[#/#, R]
1 4
In fact, a stronger result than Example 4.6 holds: for every regular language L, there
exists a Turing machine that accepts L. Thus the class of regular languages is contained
in the class of recursive enumerable languages.
Theorem 4.7. Let L ⊆ Σ∗ be a language such that L = L(D) for a deterministic finite
automaton D, then there exists a Turing machine M such that L = L(M ).
→ = { (q, a, #, #, R, q ′ ) | δ(q, a) = q ′ }
a[#/#,R]
Thus, the transitions q −−−−−−−→ δ(q, a), for q ∈ Q, a ∈ Σ, are the only transitions
of M . Note, since the tape alphabet of M is the empty set no other symbol than a blank
can be written on tape. So, the tape will remain empty, i.e. all tape cells will contain a
blank, for all computations of M .
4.1. THE REACTIVE TURING MACHINE 7
a[#/#, R]
a[#/#, R] b[#/#, R]
0 1 2 3 b[#/#, R]
b[#/#, R]
(q, w) ⊢D (q ′ , w′ )
⇔ ∃a : w = aw′ ∧ δ(q, a) = q ′
a[#/#,R]
⇔ ∃a : w = aw′ ∧ q −−−−−−−→ q ′
⇔ (q, w, h#i) ⊢M (q ′ , w′ , h#i)
From this it follows that L(M ) = L(D), which proves the theorem.
A reactive Turing machine obtained following the recipe of the proof of Theorem 4.7 for
the DFA of Figure ??, a DFA that accepts the language {w ∈ {a, b}∗ | aab substring of w}.
Note, since the language { an b n | n > 0 } is a recursively enumerable language as we have
seen in Example 4.3, it follows from the theorem that the class of recursively enumerable
languages is strictly larger than the class of regular languages.
Example 4.8. We have seen that the language { an b n cn | n > 0 } is not a context-free
language. However, an extension of the simple Turing machine of Figure 4.3 accepts this
language. See Figure 4.7. Together with Theorem 4.10 below, this implies that the class
of languages accepted by a Turing machine, i.e. the recursively enumerable languages, is
strictly larger than the class of context-free languages.
Example 4.9. With a variation on the Turing machine in Figure 4.7, also a Turing
machine for the language { ww | w ∈ {a, b}∗ } can be constructed. In the initial state q0
for each a and b on input an A or B is written on tape. The Turing machine can non-
deterministically go from state q0 to state q1 . There the tape head moves left to the
first blank left of the sequence of A’s and B’s. The Turing machine goes to state q2 .
Then a sequence of a’s and b’s is input, and it is checked that it matches the sequence
of A’s and B’s on the tape. If the match is exact and all input is read, the input string
is accepted. If the match is not exact the Turing machine blocks.
We have (q0 , abaaba, h#i) ⊢∗ (q3 , ε, h#i) since
Thus, indeed, the string abaaba is accepted by the Turing machine. There are many
more computations for the configuration (q0 , abaaba, h#i), e.g.
Next we prove a result for context-free languages similar to Theorem 4.7 for regular
languages.
Q′ = Q ∪ {q0′ , q0′′ } ∪
α[d/x]
{ [ move, x, q ′ ] | ∃q ∈ Q∃α ∈ Στ ∃d ∈ ∆∅ : q −−−−−→P q ′ } ∪
α[d/x]
{ [ write, y, q ′ ] | ∃q ∈ Q∃α ∈ Στ ∃d ∈ ∆ : q −−−−−→P q ′ ∧ y 4 x }
which together write an empty stack symbol ∅ on tape, positions the tape head on the
empty stack symbol, and moves control to q0 ∈ Q′ , the state of M that is the initial
state of P .
α[∅/x]
For each transition q −−−−−→P q ′ , with q, q ′ ∈ Q, α ∈ Στ , and x ∈ ∆∗ , we have
for M the transitions
α[∅/∅,L]
−−−−−−→M
q [ write, x, q ′ ]
τ [#/d,L]
[ write, yd, q ′ ] −−−−−−→M [ write, y, q ′ ]
τ [#/#,R]
[ write, ε, q ′ ] −−−−−−−→M q′
for yd ∈ ∆∗ ·∆ a prefix of x ∈ ∆∗ . Thus, when the empty stack symbol ∅ is read on tape,
it is written back, while the tape head moves left to an empty cell. Then, starting from
10 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS
state [ write, x, q ′ ], the symbols of the string x are written on tape, symbol by symbol,
from right to left, while the tape head moves left too, with control moving through states
[ write, y, q ′ ] where string y is a prefix of string x. When all symbols of x are written
and state [ write, ε, q ′ ] is reached, the emulation of the transition of P is done, the tape
head moves right, on the leftmost symbol of the ‘stack-on-tape’, and controls moves to
target state q ′ .
α[d/x]
For each transition q −−−−−→P q ′ , with q, q ′ ∈ Q, α ∈ Στ , d ∈ ∆ and x ∈ ∆∗ , and
we have the following transitions for M .
α[d/#,L]
q −−−−−−→M [ move, x, q ′ ]
τ [#/#,R]
[ move, x, q ′ ] −−−−−−−→M [ write, x, q ′ ]
τ [#/d,L]
[ write, ye, q ′ ] −−−−−−→M [ write, y, q ′ ]
τ [#/#,R]
[ write, ε, q ′ ] −−−−−−−→M q′
Thus, since (q0′ , ε, h#i) ⊢∗M (q0 , ε, h∅i), we conclude L(P ) = L(M ).
From the theorem it follows that the class of context-free languages is a subset of the
class of recursively enumerable languages. In view of Examples 4.8 and 4.9 this inclusion
is strict.
Example 4.11. Consider, for an illustration of the application of Theorem 4.10, the
PDA P in Figure 4.9, that accepts the language { wwR | w ∈ {a, b}+ }, i.e., non-empty
4.1. THE REACTIVE TURING MACHINE 11
d[E/DE]
d[∅/D] d[D/ε]
d ∈ {a, b}
τ [D/D] [∅/ε]
0 1 2 D, E ∈ {A, B}
palindromes over {a, b}∗ of even length. With abuse of notation, for d ∈ {a, b} and
D, E ∈ {A, B}, we assume the obvious correspondence.
Following the scheme given by the proof we have the following transitions for the
reactive Turing machine M that accepts L(P ). To begin with,
τ [#/∅,L] τ [#/#,R]
q0′ −−−−−−−→M q0′′ and q0′′ −−−−−−−→M q0
d[∅/D]
to write down the empty-stack marker ∅. To emulate the transition q0 −−−−−→P q0 , we
have
d[∅/∅,L]
q0 −−−−−−−→M [ move, D, q0 ]
τ [#/#,R]
[ move, D, q0 ] −−−−−−−→M [ write, D, q0 ]
τ [#/D,L]
[ write, D, q0 ] −−−−−−−→M [ write, ε, q0 ]
τ [#/#,R]
[ write, ε, q0 ] −−−−−−−→M q0
d[E/DE]
To emulate the transition q0 −−−−−−−→P q0 , we similarly have
d[E/#,L]
q0 −−−−−−−→M [ move, DE, q0 ]
τ [#/#,R]
[ move, DE, q0 ] −−−−−−−→M [ write, DE, q0 ]
τ [#/E,L]
[ write, DE, q0 ] −−−−−−−→M [ write, D, q0 ]
τ [#/D,L]
[ write, D, q0 ] −−−−−−−→M [ write, ε, q0 ]
τ [#/#,R]
[ write, ε, q0 ] −−−−−−−→M q0
Note that the last two transitions were also used to mimic the PDA transition for q0 on
τ [D/D]
empty stack. For the transition q0 −−−−−−→P q1 of P we need
τ [D/#,L]
q0 −−−−−−−→M [ move, D, q1 ]
τ [#/#,R]
[ move, D, q1 ] −−−−−−−→M [ write, D, q1 ]
τ [#/D,L]
[ write, D, q1 ] −−−−−−−→M [ write, ε, q1 ]
τ [#/#,R]
[ write, ε, q1 ] −−−−−−−→M q1
12 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS
d[D/ε]
Likewise, for the transition q1 −−−−−→P q1 of the PDA we put in place
d[D/#,L]
q1 −−−−−−−→M [ move, ε, q1 ]
τ [#/#,R]
[ move, ε, q1 ] −−−−−−−→M [ write, ε, q1 ]
τ [#/#,R]
[ write, ε, q1 ] −−−−−−−→M q1
where the last transition of M was encountered before already. Finally, to emulate the
τ [∅/ε]
transition q1 −−−−−→P q2 we have
τ [∅/∅,L]
q1 −−−−−−−→M [ write, ε, q2 ]
τ [#/#,R]
[ write, ε, q2 ] −−−−−−−→M q2
We have seen that a reactive Turing machine is more powerful than a push-down au-
tomaton. However, one may wonder it the computational power of an rTM will be
severely less, if instead of using a two-way infinite tape, it comes equiped with a one-way
infinite tape. Thus, very much like a stack of a PDA, fresh memory cells can only be
recruted unboundly into one direction. This idea brings us to the notion of a reactive
Turing machine with semi-infinite tape.
Definition 4.12. A Turing machine with a semi-infinite tape is given by an octuple M =
( Q, Σ, ∆, #, ∅, →, q0 , F ) where Q, Σ, ∆, #, q0 and F are as before (see Definition 4.2),
∅∈ / ∆ # , and
→ ⊆ Q × Στ × ∆ # × ∆ # × {L, R} × Q
with Στ = Σ ∪ {τ } and ∆ # = ∆ ∪ {#}.
Note, because ∅ is not an element of ∆ # by definition, there is no transition possible if
the tape-head reads the special symbol ∅. A Turing machine with a semi-infinite tape
can only use the tape cells right of the unique tape cell marked ∅.
The notion of a configuration for a Turing machine with semi-infinite tape, semi-
infinite Turing machine for short, and a reactive Turing machine are similar, as are the
notions of a derivation step and of a computation. However, the initial configuration for a
semi-infinite Turing machine is of the form (q0 , w, h∅i), for some string w. Thus, the tape
is marked initially with the special symbol ∅, and the tape head is initially positioned on
the first cell containing the marker. As soon as the tape head reaches the cell marked ∅,
the Turing machine with semi-infinite tape gets stuck. Still, the notion of a language
accepted by a Turing machine with semi-infinite tape carries over from a reactive Turing
machine. We put L(M1 ) = { w ∈ Σ∗ | ∃q ∈ F, z ∈ Z : (q0 , w, h∅i) ⊢∗1 (q, ε, z) }.
Clearly, a reactive Turing machine, with a two-way infinite tape, can simulate a semi-
infinite Turing machine. Hence, a reactive Turing machine can accept any language a
semi-infinite Turing machine can accept. More precisely,
Theorem 4.13. Let L ⊆ Σ∗ . Suppose L is accepted by a semi-infinite Turing ma-
chine M1 , i.e., L(M1 ) = L. Then exists a reactive Turing machine M2 such that
L(M2 ) = L.
4.1. THE REACTIVE TURING MACHINE 13
e0 e1 e2 e3 ···
··· e -3 e -2 e -1 e0 e1 e2 e3 · · · ∅
∗ e -1 e - 2 e -3 · · ·
Next, we describe how M1 will simulate the transitions of M2 . For this we need
to keep track whether we are working on the top half of the tape, considering the first
symbol e1 of a pair (e1 , e2 ), or on the bottom half of the tape, considering the second
symbol e2 of a pair (e1 , e2 ). Moreover, when working on the top half, simulating a
movement of M2 is for M1 moving in the same direction. However, when working on
the bottom half, simulating a movement of M2 means moving in the opposite direction
for M1 . To record whether we are working on the top half of the bottom half, we
represent may a state q of M2 as (q, T ) or (q, B), where the second component, T and B,
indicate top and bottom, respectively. The initial state for M1 will be state (q0 , T ). In
case we are at the left end of the semi-infinite take, we need to have special measurement.
α[e/e′ , µ]
We have for a transition q −−−−−−−→2 q ′ of M2 the following transitions of M1 .
track is transition (v) of M1 . Now, the symbol e at the upper track is left untouched;
M1 is operating on the lower track.
When the tape head is at the cell next to the marker, the transitions of M1 are similar
to the situation of other cells. However, M1 may need to switch from top half to lower
half, see transition (iii), or from lower half to top half, see transition (vi). Transitions
(iv) and (viii) are in place to deal with the situation that the tape head reads from a
cell that wasn’t visited before, i.e., the tape head reads an ordinary blank #. This is for
example the case for the very first transition in the initial state (q0 , T ).
Putting things together, we have for M1 = ( Q1 , Σ, ∆1 , #, ∅, →1 , (q0 , T ), F1 ) the
following: (i) Q1 = { (q, T ), (q, B) | q ∈ Q2 }, (ii) ∆1 = ∆ # × ∆ # , (iii) →1 as indicated
above, (iv) initial state (q0 , T ), and (v) final states F1 = { (q, T ), (q, B) | q ∈ F2 }.
We note, without a formal proof, that for strings w, w′ ∈ Σ∗ and q ∈ F2 a compu-
tation (q0 , w, z) ⊢∗2 (q, w′ , z ′ ) exists for M2 for some tape content z, z ′ iff a computa-
tion ((q0 , T ), w, z̄) ⊢∗1 ((q, S), w′ , z̄ ′ ) exists for M1 for some tape content z̄, z̄ ′ and S ∈
{T, B}.
Theorem 4.15. Let L ⊆ Σ∗ be a language such that L = L(M ) for a reactive Turing
machine M = ( Q, Σ, ∆, #, →, q0 , F ) with tape alphabet ∆. Then exists a reactive
Turing machine M ′ = ( Q′ , Σ, {0, 1}, #, →′ , q0 , F ) with tape alphabet {0, 1}.
Proof. The general idea is represent the tape alphabet ∆ of M by strings of equal length
over {0, 1}, and to represent the tape content of M as blank-separated blocks of these
strings.
Let k > 0 be such that ∆ has strictly less than 2k elements. Pick a unique string
wd = d1 · · · dk ∈ {0, 1}k , wd 6= 0k , for each element d ∈ ∆. We use w# = 0k to encode a
blank.
We will arrange that in case the tape for M would contain, e.g., d1 d2 d3 d4 , and
wdi = di1 · · · dik for i = 1, 2, 3, 4, the tape of M ′ would look like
If, for example, M would be reading d2 , the tape head of M ′ is positioned at the blank
left of d21 . Thus, the bit string d21 · · · d2k is right of the tape head.
α[d/e′ ,µ]
A transition q −−−−−−→ q ′ of M , for d ∈ ∆, e′ ∈ ∆ # , is emulated by M ′ by a series
of transitions. We assume that the tape head of M ′ is reading a blank and the bit
4.1. THE REACTIVE TURING MACHINE 15
In case of a left move of M the tape head of M ′ needs to move two blocks to the left:
one block because of the read of the current block, another block in order to position
the tape head at the space preceding the block that needs to be read next. Note, if the
block doesn’t contain the complete bit string wd , M ′ will get stuck.
The explicit counting in the second left shift is in place to cover a situation where
the block doesn’t contain a bit string, but k blanks instead. Similarly, for a transition
α[#/e′ ,µ]
q −−−−−−−→ q ′ of M , with e ∈ ∆ # , we need to take into account that the block hasn’t
been visited earlier. For this, we mark the intermediate states with a blank.
α[#/#,R]
q −−−−−−−→ ′ [q, #, 0k , µ, q ′ ]
τ [#/0,R]
[q, #, 0j , µ, q ′ ] −−−−−−→ ′ [q, #, 0j−1 , µ, q ′ ] for 1 6 j 6 k
τ [#/#,R]
[q, #, ε, R, q ′ ] −−−−−−−→ ′ q′
τ [#/#,R]
[q, #, ε, L, q ′ ] −−−−−−−→ ′ [ ℓshift 1 , q ′ ]
Q′ = Q ∪ { [ ℓshift 1 , q ′ ], [ ℓshift 2 , j, q ′ ] | q ′ ∈ Q, 0 6 j 6 k } ∪
{ [q, v, v ′ , µ, q ′ ] | ∃α∈Στ ∃d, d′ ∈∆∃µ∈{L, R} :
α[d/d′ ,µ]
q −−−−−−→ q ′ , v 4 wd , v ′ 4 wd′ , |v| = |v ′ | }
and transition relation →′ as indicated above. We note, without proof, that M ′ can
perform every computation from the initial state
Exercise 4.1.3. Construct a reactive Turing machine for the language L = { wwR |
w ∈ {a, b}∗ }. Give an accepting computation sequence for the string aabbaa. A proof
of correctness is not asked for.
→ ⊆ Q × ∆ # × ∆ # × {L, R} × Q
with ∆ # = ∆ ∪ {#}.
e/e′ ,µ
If, for a Turing machine M as given above, (q, e, e′ , µ, q ′ ) ∈ → we write q −−−−−→M q ′ .
This means that a classical Turing machine, when it is in state q and reads symbol e on
the tape, can replace e by e′ , move one cell left if µ = L and one cell right if µ = R,
and thereby change control to state q ′ . There is no input alphabet Σ as for the reactive
Turing machine; there are no τ -transitions either. Also, there are no final states. For
a classical Turing machine there is no notion of acceptance, but there is a notion of
termination as we will see below.
a/a, R a/a, L
b/b, R b/b, L
#/#, R
is read on tape, the Turing machine M blocks and the computation halts. Similarly, if
in state q2 either the symbol a or a blank is read, the Turing machine M blocks.
Suppose M starts in state q0 , with the string aaabbb written on tape and with the
tape head on the leftmost a. Then M erases this a, the tape head moves to the right,
control to state q1 . Then the string aabbb is skipped while the tape head moves to the
right, and M reads a blank right after the string of a’s and b’s. M moves to the left
and arrives in state q2 . Then the rightmost b is read, erased, the tape head moves left,
control moves to state q3 . Then the Turing machine skips over the remaining string
aabb, till it reads the first blank on the left (where the cell where the tape head started
from initially). Then the tape head moves right reading the symbol a, control is now in
state q0 .
To describe the behaviour concisely, we adapt the notion of a configuration to the situa-
tion of a classical Turing machine. Let M = ( Q, ∆, #, →, q0 ) be a classical Turing ma-
chine according to Definition 4.17. A configuration or an ID of M is a pair (q, z) ∈ Q×Z
with Z as defined in the previous section. We write
e/e′ ,µ
(q, z) ⊢M (q ′ , z ′ ) iffq −−−−−→M q ′ and z ′ = z[e/e′ , µ]
for some e, e′ ∈ ∆ # and µ ∈ {L, R}. The update z[e/e′ , µ] for [e/e′ , µ] on the configura-
tion z is as before. Here, for z ′ = z[e/e′ , µ], the tape content z ′ is obtained from z by
replacing the eye e of z by e′ and moving the tape head in the direction indicated by µ.
Note that this replacement requires that z is of the form xheiy; otherwise the operation
is not defined.
We write (q, z) 0M if for no q ′ and z ′ we have (q, z) ⊢M (q ′ , z ′ ). If z = xheiy and
e/e′ ,µ
there is no transition q −−−→M q ′ with q ′ ∈ Q, e′ ∈ ∆ # and µ ∈ {L, R} , we say that
M halts or blocks in (q, z). As there is no further transition, any computation leading
to the configuration (q, z) terminates there.
For the classical Turing machine M of Figure 4.10 we have the following computation:
Thus (q0 , haiaabbb) ⊢∗M (q0 , haiabb). However, M does not halt in (q0 , haiabb), since
(q0 , haiabb) admits a further transition, viz. to (q1 , haibb). The computation is not com-
plete.
It also holds that (q0 , haiaabbb) ⊢∗M (q0 , h#i). Since (q0 , h#i) 0M the computation
started in the configuration (q0 , haiaabbb) is complete. It terminates in the configura-
tion (q0 , h#i).
(i) termination, i.e., (q0 , hwi) ⊢∗M (q, z) 0M for some q ∈ Q, z ∈ Z with z = hf (w)i;
(ii) determinacy, i.e., if (q0 , hwi) ⊢∗M (q1 , z1 ) 0M and (q0 , hwi) ⊢∗M (q2 , z2 ) 0M , for
q1 , q2 ∈ Q, z1 , z2 ∈ Z, then q1 = q2 and z1 = z2 .
For the classical Turing machine M to compute the function value f (w) ∈ Θ∗ for the
string w ∈ Ω, the scheme is to first write the string w on tape and start the Turing
machine M in its initial state q0 with the tape head on the leftmost symbol of w, i.e. in
the configuration (q0 , hwi). When the Turing machine terminates, say in the configura-
tion (q, z), the tape should contain a unique string from Θ∗ , called f (w). Moreover the
tape head is supposed to be at the leftmost symbol of f (w) is it is non-empty.
For this to work, there must be at least one terminating computation for M starting
from (q0 , hwi) which yields a result in Θ∗ . Moreover, every terminating computation
should yield the same result. The former is captured by the first condition of the defi-
nition. Regarding the latter, this condition is guaranteed if the transition relation →M
represents a partial function Q × ∆ # → ∆ # × {L, R} × Q, i.e. for every q ∈ Q, e ∈ ∆ #
e/e′ ,µ
there is at most one triple e′ ∈ ∆ # , µ ∈ {L, R}, q ′ ∈ Q such that q −−−→M q ′ .
Example 4.19. Figure 4.11 describes a classical Turing machine, say M , that computes
the copying function copy : {a, b}∗ → {a, b}∗ with copy(w) = ww. The trick is to use the
auxiliary symbols A and B to describe a’s and b’s that are already processed. Thus we
have ∆ = {a, b, A, B}. However, Σ = Θ = {a, b}. We have Ω = Σ∗ . The computation
in q0 starts on the leftmost non-blank symbol on the tape. Then M scans to the right for
the first a or b. If there is none, the copying is done and M changes control to state q5
4.2. THE CLASSICAL TURING MACHINE 19
d/d, R d/d, L
#/A, L
1 2 A/a, L
B/b, L
a/A, R #/#, R
b/B, R #/#, R
3 4
#/B, L
d ∈ {a, b, A, B}
d/d, R d/d, L
Figure 4.11: Classical Turing machine for the copying function f (w) = ww.
where is replaces all A’s and B’s by a’s and b’s, respectively. If a blank is in the eye of
the tape head, it moves right and then the Turing machine blocks.
If in q0 an a is read, this symbol needs to be copied at the end of the tape content.
The current a is marked as processed, i.e. replaced by A. In state q1 all non-blanks are
skipped, d/d, R abbreviates a/a, R, b/b, R, A/A, R and B/B, R. When the blank at the
end of the tape content is reached, an A is written and control is in state q2 . There the
tape head is moved to the left of the tape content. When reached, M is in state q0 with
the tape head on the leftmost non-blank symbol (if any).
If in q0 a b is read, a similar sequence of transitions follows. Now the symbol b is
overwritten with B, control changes to state q3 and a B is written at the end of the
tape content, after which the tape head moves the leftmost symbol on tape and control
moves to state q0 .
Dependent on the input string w, for suitable U ∈ {A, B}∗ , we have
∗ ∗
(q0 , U haiv U ) ⊢M (q1 , U Av U h#i) and (q0 , U hbiv U ) ⊢M (q3 , U Bv U h#i)
Functions with more than one argument can be computed too with a classical Turing
machine. For example, for a two-ary function f (w1 , w2 ), that takes two strings w1 and w2
to produce a result, we put both strings on tape, first w1 then w2 , have them separated
by a blank, or an other symbol if desired, and have the tape head positioned at the first,
i.e., leftmost symbol of w1 (or at the separating symbol if w1 = ε).
dealing with non-negative numbers the convention is that the result is 0 if n 6 m. More
concretely, 4 − 3 = 1 and 3 − 4 = 0.
The classical Turing machine of Figure 4.12 can be dissected in four parts: The path
from the initial state q0 up to state q2 , the cycle of state q2 via state q5 , and the two
paths to a state without outgoing transitions, viz. from state q5 to state q9 and from
state q2 to state q11 .
Starting in state q0 , the first concern is to find the right end of the arguments. So,
we first skip to the right over the first number in state q0 , skip over the minus sign
separating the two numbers, and skip over the second number in state q1 .
The loop of state q2 visiting q3 , q4 , q5 , q6 and q7 , respectively, is erasing a 1-symbol
from the second number against a 1-symbol of the first number. This subcomputation
starts at the rightmost symbol of the second number. In q2 if a 1-symbol is read it is
erased, the tape head skips to the left, skipping the remaining 1’s of the second number
in q3 , skipping the separator −, skipping the remaining 1’s of the first number in q4 till
the blank at the left is found. The tape head moves one position back, control is state q5 .
If a matching 1-symbol of the first number is read, this symbol is erased, and the tape
head skips to the right, reaching via q6 , where the remaining 1’s of the first number are
skipped, and via q7 where the remaining 1’s of the second number are skipped the start
of the cycle, state q2 again with the tape head on the rightmost symbol, if any.
However, if in state q5 no matching 1 is found, i.e. the tape head reads the sepa-
rator rather than a 1, the result of the computation should be zero, since the second
number proves larger than the first number. The Turing machine is in configuration
(q5 , h−i1m−n−1 ). Note, in this case m > n. So next, all 1 are swiped from the tape in
state q10 . This stops when a blank is found. The computation terminates and the tape
is empty, representing 10 = ε.
Alternatively, in state q2 if no 1 is read any more, thus we are reading the separator −
rather than a 1-symbol of the second number, we are basically done. The configuration
of the Turing machine is (q2 , 1n−m h−i). We first need to clean up the separator, as this
is no part of the output, and then move the tape head to the leftmost 1 (if any). The
computation terminates leaving the result 1n−m on tape.
1/1, R 1/1, R
−/−, R
0 1
1/1, R 1/1, R 1/1, L
#/#, L
−/−, R #/#, L −/#, L #/#, R
6 7 2 8 9
1/#, R 1/1, L
1/#, R 1/#, L
−/#, R
11 10 5 4 3 1/1, L
#/#, L #/#, R −/−, R
#/#, L
0/Z, R
#/#, L 0/#, L +/+, L
0 1 2 3 4 e/e, R
1/W, R
1/#, L Z/0, L
+/#, L W/1, L
d/d, L 5
8 T /0, L
#/#, L +/+, L
W/0, L
Z/1, L 9
T /1, L
D/D, L 6 #/#, R
#/1, R
0/W, R 1/T, R 10
7
d ∈ {0, 1}
e ∈ {0, 1, +, Z, W, T }
e/e, R D ∈ {Z, W, T }
• Starting in q0 with the tape head at the leftmost digit of the first number, the tape
head is moved to the blank right of the second number. In state q1 the tape head
is positioned at the rightmost digit of the second number.
• If in q1 the digit 0 of the second number is read, the idea is to change the corre-
sponding digit of the first number into Z or W , dependent of the value of the latter
digit. To this end the tape head wobbles to the left. Skipping over 0’s and 1’s first
in state q2 , then encountering a +, then skipping marked digits, i.e. capitals, in
state q3 and encountering the first digit to the left of the +. The digit 0 is marked
as Z; we have read a 0 of the second number and 0 + 0 = Z. The digit 1 is marked
as W ; we have a read a 0 of the second number and 1 + 0 = W . In state q4 the
tape head moves to the right in search of the rightmost blank. Once found, the
tape head is positioned on the rightmost digit of the second number. Control is in
state q1 .
• If in q1 the digit 1 of the second number is read, the Turing machine will change
the corresponding digit of the first number into W or T , again dependent on the
value of the latter digit. In state q5 the tape head moves left over the remainder
of the second number, changing control to state q6 if the + -sign is scanned. In
state q6 capitals are skipped until the first digit on the left of the + -sign is found.
If it is the digit 0 the symbol W is written since 0 + 1 = W . If it is the digit 1 the
symbol T is written since 1 + 1 = T . No carry is processed now. This will be done
at a later stage.
• Note in state q1 the digits of the second number are erased from right to left. If all
digits of the second number have vanished the + -sign remains as rightmost non-
blank. If detected in state q1 the marking phase is finished, the + -sign is erased
and control moves to state q8 . There we change capitals back into digits and take
a possible carry into account.
Exercise 4.2.2. Construct a classical Turing machine that computes a function 2 log :
{1}·{0, 1}∗ → {0, 1}∗ such that 2 log(w) = n if 2n 6 w < 2n+1 with the strings w
and n interpreted as a binary numbers. E.g., 2 log(24) = 2 log(110002 ) = 1002 = 4 since
24 = 16 6 24 < 32 = 25 .
τ [#/#, L] τ [#/#, R]
0 1 2
Answer to Exercise 4.1.2 The reactive Turing machine below accepts the language
L = { an b m cn+m | n, m > 0 }.
Answer to Exercise 4.1.3 The reactive Turing machine below accepts the language
L = { wwR | w ∈ {a, b}∗ }.
a[#/A, L] a[A/#, R]
b[#/B, L] b[B/#, R]
τ [#/#, R]
a[#/#, R]
b[#/#, R] τ [#/#, R]
0 1 2
Accepting computation sequences for the string aaabbbccc and ababa are the following.
(q0 , aabbaa, h#i) ⊢M (q0 , abbaa, h#iA) ⊢M (q0 , bbaa, h#iAA) ⊢M
(q0 , baa, h#iBAA) ⊢M (q1 , baa, hBiAA) ⊢M (q1 , aa, hAiA) ⊢M
(q1 , a, hAi) ⊢M (q1 , ε, h#i) ⊢M (q2 , ε, h#i)
and
(q0 , ababa, h#i) ⊢M (q0 , baba, h#iA) ⊢M (q0 , aba, h#iBA) ⊢M
(q1 , ba, hBiA) ⊢M (q1 , a, hAi) ⊢M (q1 , ε, h#i) ⊢M (q2 , ε, h#i)
Answer to Exercise 4.1.4 The reactive Turing machine below accepts the language
L = { an b n cn | n > 0 }. Note that the machine has exactly one τ -move.
Also note, since q0 is a final state the Turing machine accepts the empty string ε.
Answer to Exercise 4.1.5 The reactive Turing machine below accepts the language
L = { w ∈ {a, b}∗ | #a (w) = 2 ∗ #b (w) }. The idea is that the number of cells that the
tape head is to the right of the marker 0 indicates the surplus of a’s, the number of cells
that the tape head is to the cells indicates twice the surplus of b’s.
a[∗/∗, R]
a[#/0, R] τ [0/#, R]
0 1 3
d/d, R
b/#, L
#/#, L
a/#, R 1 2
a/#, L d/#, L
#/#, R
0 3 d/d, L 8
b/#, L
b/#, R 4 5 #/N, R
#/#, L
a/#, L
#/Y, R 9 10
d/d, R #/Y, R #/#, L
6 7
#/#, L
#/Y, R
Answer to Exercise 4.2.2 We use the fact that n = |w| − 1. So, we increment the
starting value 0 as many times as there are digits following w’s leading 1.
0/0, R
∗/∗, R 1/1, R
4
X/X, L
0, #/1, R 0, #/1, R
∗, X/#, L