0% found this document useful (0 votes)
52 views26 pages

2it70 Chap4

The document discusses Turing machines and their operation. It introduces the concept of a reactive Turing machine, which has a tape as memory that can be accessed randomly through a tape head. Reactive Turing machines are more powerful than PDAs and can accept a wider class of languages called recursively enumerable languages. The document provides examples and formally defines a reactive Turing machine as a 7-tuple that describes its states, input alphabet, tape alphabet, transitions, initial state, and final states.

Uploaded by

gode ghytr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views26 pages

2it70 Chap4

The document discusses Turing machines and their operation. It introduces the concept of a reactive Turing machine, which has a tape as memory that can be accessed randomly through a tape head. Reactive Turing machines are more powerful than PDAs and can accept a wider class of languages called recursively enumerable languages. The document provides examples and formally defines a reactive Turing machine as a 7-tuple that describes its states, input alphabet, tape alphabet, transitions, initial state, and final states.

Uploaded by

gode ghytr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Chapter 4

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.

Input Automaton yes no

Tape Tape

Figure 4.1: Architecture of the Reactive Turing machine.

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.

4.1 The reactive Turing machine


We will first introduce some notation that is useful to describe Turing machines. The
memory tape, or just tape for short, of a Turing machine consists of an infinite supply of
sequentially ordered non-numbered cells, and each cell will contain a data element d ∈ ∆
or is empty. We use the special symbol #, the blank, to denote an empty cell (# ∈ / ∆).
The extended tape alphabet ∆ # , that we use besides the input alphabet Σ, consists of
all symbols in ∆ together with the blank, i.e. ∆ # = ∆ ∪ {#}. So, one can also say that
a tape cell always contains a symbol, a non-blank d ∈ ∆ or the blank symbol #.
At each point in an execution, the tape head of the Turing machine is positioned at
exactly one particular cell, the cell in the eye of the tape head. From this cell the Turing
machine can read a data element or a blank and can write a data element or erase the
content (i.e. replace it with a blank). Then the tape head will move one cell to the right
or one cell to the left.
We use the expression xheiy, with x, y ∈ ∆*# , e ∈ ∆ # , to denote a tape containing the
string xey: the tape head is at a cell holding e, the cells left of the tape head together
contain the string x, the cells right of the tape head together contain the string y. To
define a unique expression xheiy we require for x 6= ε that the leftmost symbol of x
is not a blank. Likewise, if y 6= ε then its rightmost symbol is assumed not to be a
blank. Thus, on the left, leading blanks are ignored, and on the right, trailing blanks
are ignored. We write hei as shorthand for εheiε, and heiy and xhei for εheiy and xheiε,
respectively. Note, h#i denotes the empty tape.
a[#/1, R] b[1/#, L]

τ [#/#, L]
0 1

Figure 4.2: A simple reactive Turing machine.

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

to q1 , consuming no input, gives 11h1i, at which point, in q1 , we can either terminate,


or execute the loop on input b to obtain 1h1i. Maximally three b’s can be read at the
expense of erasing a 1 for each b.

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.

• xheiε[e/e′ , R] = xe′ h#iε for x ∈ ∆*# ,

• xheidy[e/e′ , R] = xe′ hdiy for d ∈ ∆ # , x, y ∈ ∆*# ,

• εheiy[e/e′ , L] = εh#ie′ y for y ∈ ∆*# ,

• xdheiy[e/e′ , L] = xhdie′ y for d ∈ ∆ # , x, y ∈ ∆*# .

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

Z = { xheiy | x ∈ ∆*# : x = ε ∨ first(x) 6= #, (4.1)


e ∈ ∆ # , y ∈ ∆*# : y = ε ∨ last(y) 6= # }

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 ′

or, (ii) for some e, e′ ∈ ∆ # , and µ ∈ {L, R}, we have


τ [e/e′ ,µ]
q −−−−−−→M q ′ ∧ w = w′ ∧ z [e/e′ , µ] = z ′

Thus, we have (q, w, z) ⊢M (q ′ , w′ , z ′ ) if Turing machine M can move from configura-


tion (q, w, z) in one step to configuration (q ′ , w′ , z ′ ). Note, this does not exclude that
(q, w, z) ⊢M (q ′′ , w′′ , z ′′ ) for a configuration (q ′′ , w′′ , z ′′ ) different from (q ′ , w′ , z ′ ). We
write (q, w, z) 0M if for no q ′ , w′ and z ′ we have (q, w, z) ⊢M (q ′ , w′ , z ′ ). In such a
situation we say that the Turing machine M blocks or halts.
At the start of an execution of a reactive Turing machine, we will assume the Turing
machine is in the initial state, and that the memory tape is empty. Thus, the initial
configuration of a reactive Turing machine with initial state q0 and the string w on input
is (q0 , w, h#i).
a[#/1, R] b[1/#, L]

τ [#/#, L] τ [#/#, R]
0 1 2

Figure 4.3: Another simple reactive Turing machine.

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

(q0 , aabba, h#i) ⊢ M (q0 , abba, 1h#i) ⊢ M


(q0 , bba, 11h#i) ⊢ M (q1 , bba, 1h1i) ⊢ M (q1 , ba, h1i) ⊢ M (q1 , a, h#i) 0M

The language of the Turing machine of Figure 4.3, a notion formally defined below, is
the set of strings { an bn | n > 0}.

Definition 4.4. Let M = ( Q, Σ, ∆, #, →, q0 , F ) be a reactive Turing machine. Then


the language L(M ) ⊆ Σ∗ accepted by M is defined by

L(M ) = { w ∈ Σ∗ | ∃q ∈ F ∃z ∈ Z : (q0 , w, h#i) ⊢M (q, ε, z) }

A language L ⊆ Σ∗ is called recursively enumerable if L = L(M ) for a reactive Turing


machine with input alphabet Σ.

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

(q, w, z) ⊢∗M (q ′ , w′ , z ′ ) iff


∃n > 0 ∃q0 , . . . , qn ∃w0 , . . . , wn ∃z0 , . . . , zn :
(q0 , w0 , z0 ) = (q, w, z) ∧
∀i, 1 6 i 6 n : (qi−1 , wi−1 , zi−1 ) ⊢M (qi , wi , zi ) ∧
(qn , wn , zn ) = (q ′ , w′ , z ′ )

For a number of languages, Turing machines can be constructed. We start out easy.
6 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

a[#/#, R]

Figure 4.4: A reactive Turing machine for {a}∗ .

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

τ [#/#, R] b[#/#, R] a[#/#, R]


0 2 5 7

c[#/#, R] b[#/#, R] a[#/#, R]


3 6 8 9
τ [#/#, R]

Figure 4.5: A reactive Turing machine for {a, ba, cba}.

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 ).

Proof. Suppose D = ( Q, Σ, δ, q0 , F, ) is a DFA that accepts L. Define the Turing ma-


chine M = ( Q, Σ, ∅, #, →, q0 , F ) with the same set of states, the same input alphabet,
the empty tape alphabet, the standard blank, the same initial state and the same set of
final states and a transition relation → given by

→ = { (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

b[#/#, R] a[#/#, R] a[#/#, R]

a[#/#, R]
a[#/#, R] b[#/#, R]
0 1 2 3 b[#/#, R]
b[#/#, R]

Figure 4.6: Reactive Turing machine for DFA of Example ??

By definition of → it holds that

(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)

Thus it also holds, as can be shown by induction, that


∗ ∗
(q0 , w) ⊢D (q, ε) ⇐⇒ (q0 , w, h#i) ⊢M (q, ε, 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.

a[#/1, R] b[1/1, L] c[1/#, R]

τ [#/#, L] τ [#/#, R] τ [#/#, L]


0 1 2 3

Figure 4.7: A reactive Turing machine for { an b n cn | n > 0 }.


8 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

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

(q0 , abaaba, h#i)


⊢ (q0 , baaba, Ah#i) ⊢ (q0 , aaba, ABh#i)
⊢ (q0 , aba, ABAh#i) ⊢ (q1 , aba, ABhAi)
⊢ (q1 , aba, AhBiA) ⊢ (q1 , aba, hAiBA)
⊢ (q1 , aba, h#iABA) ⊢ (q2 , aba, hAiBA)
⊢ (q2 , ba, hBiA) ⊢ (q2 , a, hAi)
⊢ (q2 , ε, h#i) ⊢ (q3 , ε, h#i)

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.

(q0 , abaaba, h#i) ⊢∗ (q0 , ba, ABAAh#i),


(q0 , abaaba, h#i) ⊢∗ (q0 , a, ABAABh#i),
(q0 , abaaba, h#i) ⊢∗ (q1 , a, ABAAhBi),
(q0 , abaaba, h#i) ⊢∗ (q2 , a, hAiBAAB),
(q0 , abaaba, h#i) ⊢∗ (q2 , ε, hBiAAB),

but these do not lead to the accepting state q3 .


The configuration (q0 , abaabab, h#i) does have a derivation sequence to q3 . It holds
that (q0 , abaabab, h#i) ⊢∗ (q3 , b, h#i). However, not all input has been read; the right-
most symbol b is not processed. Therefore, the string abaabab is not accepted by the
Turing machine.
The crucial point is the non-determinism in state q0 . With a blank at the tape head
and a symbol a or b on input, either the input symbol can be processed by the transition
looping on q0 , or a silent step can be taken leading to the state q1 .

Next we prove a result for context-free languages similar to Theorem 4.7 for regular
languages.

Theorem 4.10. Let L ⊆ Σ∗ be a language such that L = L(P ) for a push-down


automaton P , then there exists a Turing machine M such that L = L(M ).
4.1. THE REACTIVE TURING MACHINE 9

a[#/A, R] τ [A/A, L] a[A/#, R]

τ [#/#, L] τ [#/#, R] τ [#/#, L]


0 1 2 3

b[#/B, R] τ [B/B, L] b[B/#, R]

Figure 4.8: A reactive Turing machine for { ww | w ∈ {a, b}∗ }.

Proof. Let P = ( Q, Σ, ∆, ∅, →P , q0 , F ) be a push-down automaton accepting L. De-


fine the reactive Turing machine M = ( Q′ , Σ, ∆∅ , #, →M , q0′ , F ) with an extended set
of states Q′ ⊇ Q, the same input alphabet, the same tape alphabet to which the empty
stack symbol ∅ is added, a new initial state q0′ , and the same set of final states. We put

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 }

for two fresh states q0′ , q0′′ ∈


/ Q. The states of the Turing machine include the states of
the PDA. However, instead of stepping from one state q of P to another state q ′ of P
directly, a number of extra states, viz. states of the form [ move, x, q ′ ] and [ write, y, q ′ ],
dependent on the particular transition of P involved. The intuition of states [ move, x, q ′ ]
is that the tape head should be moved right first, before the string x is written on tape,
and state q ′ is entered. The intuition of states [ write, y, q ′ ] is that the string y should
be written on tape, from right to left, after which state q ′ is entered. The states q0′ , q0′′
are only visited once and are there to write an empty stack symbol on tape.
For M we have the transitions
τ [#/∅,L] τ [#/#,R]
q0′ −−−−−−−→ q0′′ and q0′′ −−−−−−−→ q0

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′

for ye ∈ ∆∗ ·∆ a prefix of x ∈ ∆∗ . In this case, an intermediate step via state [ move, x, q ′ ]


is needed to position the tape head on the rightmost blank that is left of the stack-on-
tape. After the symbol d as been erased, also here the string x is added on the stack-on-
tape from right to left, such that the first element of x is on ‘top’ of the stack-on-tape,
i.e., the first element of x is the leftmost non-blank on the tape.
Now, define the tape content function tc : ∆∗ → Z by

tc(ε) = h∅i and tc(dx) = hdix∅

Then it can be shown by induction that



(q, w, x) ⊢P (q ′ , w′ , x′ ) ⇐⇒ (q, w, tc(x)) ⊢M (q ′ , w′ , tc(x′ ))

for all q, q ′ ∈ Q, w, w′ ∈ Σ∗ and x, x′ ∈ ∆∗ . From this it follows that


∗ ∗
(q, w, x) ⊢P (q ′ , w′ , x′ ) ⇐⇒ (q, w, tc(x)) ⊢M (q ′ , w′ , tc(x′ ))

In particular, taking q = q0 and q ′ ∈ F , we obtain


∗ ∗
(q0 , w, ε) ⊢P (q ′ , ε, x′ ) ⇐⇒ (q0 , w, h∅i) ⊢M (q ′ , ε, tc(x′ ))

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}

Figure 4.9: PDA accepting non-empty palindromes of even length.

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

Proof. Put M2 = ( Q, Σ, ∆ ∪ {∅}, #, →, q0 , F ). In particular, M2 has exactly the same


transitions and set of final states as M1 does. Therefore, L = L(M2 ).

Maybe more surprisingly, the reverse of Theorem 4.13 holds as well.

Theorem 4.14. Let L ⊆ Σ∗ . Suppose L is accepted by a reactive Turing machine M2 .


Then exists a semi-infinite Turing machine M1 such that L(M1 ) = L.

Proof. Suppose M2 = ( Q2 , Σ, ∆2 , #, →2 , q0 , F2 ). The semi-infinite Turing machine M1


will be provided with a ‘two-track tape’ by augmenting the alphabet ∆ with pairs (e, e′ ) ∈
∆ # × ∆ # . To recognize the cell next to the marker we use new symbols (e, ∗), for e ∈ ∆ # ,
assuming ∗ to be a fresh symbol not in ∆ # . The idea is to fold a two-way infinite tape
in two, taking special care at the left-end of the one-way infinite tape. Schematically
indicated below, a two-way infinite tape with content e -3 , e -2 , e -1 , e0 , e1 , e2 , e3 by a one-
way infinite tape with content ∅ (e0 , ∗)(e1 , e -1 )(e2 , e -2 )(e3 , e -3 ).

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 .

α[(e,e)/(e′ ,e), µ] α[(e,e)/(e,e′ ), µ]


(i) (q, T ) −−−−−−−−−−−→1 (q ′ , T ) (v) (q, B) −−−−−−−−−−−→1 (q ′ , B)
α[(e,∗)/(e′ ,∗),R] α[(e,∗)/(e′ ,∗),R]
(ii) (q, T ) −−−−−−−−−−−→1 (q, T ) if µ = R (vi) (q, B) −−−−−−−−−−−→1 (q, T ) if µ = R
α[(e,∗)/(e′ ,∗),R] α[(e,∗)/(e′ ,∗),R]
(iii) (q, T ) −−−−−−−−−−−→1 (q, B) if µ = L (vii) (q, B) −−−−−−−−−−−→1 (q, B) if µ = L
α[#/(e′ ,#),µ] α[#/(e′ ,#),µ]
(iv) (q, T ) −−−−−−−−−→1 (q, B) if e = # (viii) (q, B) −−−−−−−−−→1 (q, B) if e = #
for all e ∈ ∆ # , and where µ is the opposite direction of µ, i.e., µ = L if µ = R, and
µ = R if µ = L.
Processing of input for M1 is exactly the same for M2 . Movement is different because
of the tape is only one-way infinite. Moreover, writing needs to be adapted because of
the two tracks that are on the tape of M1 .
Transition (i) of M1 copies directly the transition of M2 , the symbol e is ignored
since M1 is working on the upper track. The corresponding transition for the lower
14 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

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}.

As another variation of the reactive Turing machine, we consider a restriction on the


tape alphabet. However, this doesn’t impair the power of acceptance.

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

# d11 . . . d1k # d21 . . . d2k # d31 . . . d3k # d41 . . . d4k #

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

representations of d and d′ are wd = d1 · · · dk and we′ = d′1 · · · d′k , respectively.


α[#/#,R]
q −−−−−−−→ ′ [q, wd , wd′ , µ, q ′ ]
τ [dj /e′j ,R]
[q, dj · · · dk , e′j · · · e′k , µ, q ′ ] −−−−−−−→ ′ [q, dj+1 · · · dk , e′j+1 · · · e′k , µ, q ′ ] for 1 6 j 6 k
τ [#/#,R]
[q, ε, ε, R, q ′ ] −−−−−−−→ ′ q ′
τ [#/#,R]
[q, ε, ε, L, q ′ ] −−−−−−−→ ′ [ ℓshift 1 , q ′ ]
τ [b/b,L]
[ ℓshift 1 , q ′ ] −−−−−−→ ′ [ ℓshift 1 , q ′ ] for b = 0, 1
τ [#/#,L]
[ ℓshift 1 , q′] −−−−−−→ ′ [ ℓshift 2 , q′]
τ [b/b,L]
[ ℓshift 2 , j, q ′ ] −−−−−−→ ′ [ ℓshift 2 , j−1, q ′ ] for 1 6 j 6 k and b = 0, 1, #
τ [#/#,L]
[ ℓshift 2 , 0, q ′ ] −−−−−−→ ′ q′

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 ′ ]

In view of the above we have M ′ = ( Q′ , Σ, {0, 1}, #, →′ , q0 , F ) where

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

Exercises for Section 4.1

Exercise 4.1.1. Construct a reactive Turing machine for the language L = { an b m cℓ |


n, m, ℓ > 0 }. Give an accepting computation sequence for the string abbccc. Argue why
the strings aaccbb and bca are not accepted. A proof of correctness is not asked for.
16 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

Exercise 4.1.2. Construct, for the language L = { an b m cn+m | n, m > 0 }, a reactive


Turing machine. Give an accepting computation sequence for the string aaabcccc. Argue
why the strings aabbcc and abccc are not accepted. A proof of correctness is not asked
for.

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.

Exercise 4.1.4. Construct a Turing machine for the language L = { an b n cn | n > 0 }


that has at most one τ -move. A proof of correctness is not asked for.

Exercise 4.1.5. Construct a reactive Turing machine for the language L = { w ∈


{a, b}∗ | #a (w) = 2 ∗ #b (w) } with at most 4 states. A proof of correctness is not asked
for.

4.2 The classical Turing machine


The reactive Turing machine introduced in the previous section is used as a language
acceptor. However, with some conventions and simplifications a Turing machine can be
used to compute a function too. The latter variant of a Turing machine is referred to as
the classical Turing machine.

Definition 4.16 (Classical Turing machine). A classical Turing machine is a quintuple


M = ( Q, ∆, #, →, q0 ) where Q, ∆, #, and q0 are as before (see Definition 4.2), and

→ ⊆ 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.

Example 4.17. An example of a classical Turing M is given in Figure 4.10. We have


∆ = {a, b}. Note that the Turing machine has no transition for the symbol b in state q0
and no transition for the symbols a and # in state q2 . Thus, if in state q0 the symbol b
4.2. THE CLASSICAL TURING MACHINE 17

a/a, R a/a, L
b/b, R b/b, L

a/#, R #/#, L b/#, L


0 1 2 3

#/#, R

Figure 4.10: A classical Turing machine.

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:

(q0 , haiaabbb) ⊢M (q1 , haiabbb) ⊢M (q1 , ahaibbb) ⊢M (q1 , aahbibb) ⊢M


(q1 , aabhbib) ⊢M (q1 , aabbhbi) ⊢M (q1 , aabbbh#i) ⊢M (q2 , aabbhbi) ⊢M
(q3 , aabhbi) ⊢M (q3 , aahbib) ⊢M (q3 , ahaibb) ⊢M (q3 , haiabb) ⊢M
(q3 , h#iaabb) ⊢M (q0 , haiabb)
18 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

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).

We are about to introduce the notion of a function computed by a classical Turing


machine. However, we first need a means to relate tape content and strings.
We will use the notation hwi, for a string w ∈ ∆∗ , to denote a tape containing w and
with the tape head at the leftmost symbol of w, if available. Formally, hεi = h#i and
hdwi = hdiw. Thus, we have h·i : ∆∗ → Z. Note, for a tape content z and non-empty
string w, if z = hwi then z contains a consecutive block of symbols from ∆ comprising w,
the tape is empty everywhere else. If w = ε is the empty string, hεi = h#i represents the
empty tape.

Definition 4.18. A classical Turing machine M = ( Q, ∆, #, →, q0 ) computes a func-


tion f : Ω → Θ∗ for Ω ⊆ Σ∗ and two alphabets Σ and Θ (with Σ ∪ Θ ⊆ ∆) iff, for all
strings w ∈ Σ∗ , we have

(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

A/A, R #/#, L #/#, R


0 5 6
B/B, 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 = ε).

Example 4.20. As a first example of a function computing with numbers we consider


subtraction for non-negative integer numbers in unary notation. See Figure 4.12. In
unary notation a number n is represented by the string 1n , i.e. a string of n times the
symbol 1. For simplicity, we assume that the two numbers involved are positive integers.
As discussed above, we choose the numbers to be separated by a minus sign ‘−’. Thus
the input to compute n − m is the string 1n −1m ∈ {1, #}∗ with n, m > 1. As we are
20 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

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.

Example 4.21. A Turing machine computing addition of binary numbers is depicted


in Figure 4.13. For simplicity, we assume the two numbers that are to be added to
have an equal number of digits, having leading 0’s padded to the shortest number if
necessary. The numbers are separated by a plus sign ‘+’. The tape alphabet is the set
∆ = { 0, 1, +, Z, W, T }. The digits 0 and 1 as well as the + -sign speak for themselves.
The capitals Z, W and T represent processed digits: Z for 0 (zero), W for 1 (one) (to
avoid confusion between the digit 0 and the capital O we use W instead), T for 2 (two)
being the sum of two digits 1.
The Turing machine computes a function + : Ω → ∆∗ . Only in case w is a string
of the form w1 + w2 with w1 , w2 ∈ {0, 1}n for some n > 1, Swe assure that the binary
representation of the number w1 + w2 is computed. So, Ω = ∞ n n
n=1 {0, 1} · {+} · {0, 1} .
For conciseness, in Figure 4.13 we use the symbol d to range over 0, 1, the symbol D to
range over Z, W, T , and the symbol e to range over all non-blanks.
4.2. THE CLASSICAL TURING MACHINE 21

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

Figure 4.12: Classical Turing machine for unary subtraction.

#/#, L

e/e, R d/d, L D/D, 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 }

Figure 4.13: A classical Turing machine for binary addition.


22 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

• 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.

• State q8 represents a situation where there is no carry; state q9 represents a situa-


tion where there is a carry. The tape head moves right to left over the symbols Z,
W and T . If in q8 a Z is read a 0 is written. If in q8 a W is read a 1 is written.
However, if in q8 a T is read a 0 is written, but since a carry is to be remembered
control changes to state q9 . Similarly, in state q9 on symbol Z the symbol 1 is
written, because of the carry, but since the carry has been handled control returns
to state q8 . On symbol W a 0 is written but a carry remains. On symbol T a 1 is
written and again a carry remains.

• Both in q8 and in q9 the computation is done if a blank is encountered. Then


we have scanned over all of the marked digits, i.e. the string of Z’s, W ’s and T ’s
that replaced the first number. However, in q8 nothing is added; in q9 the carry is
processed by writing a final 1 in front of the string of digits written so far.
4.2. THE CLASSICAL TURING MACHINE 23

Exercises for Section 4.2

Exercise 4.2.1. Construct a classical Turing machine that computes a function p :


{a, b}∗ → {Y, N }∗ such that p(w) = Y if w is a palindrome, i.e., w = wR , and p(w) = N
if w is not a palindrome. Give a computation sequence for the strings ababa and abba
producing Y , and for the strings the strings aaba and baa producing N . A proof of
correctness is not asked for.

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 .

Answers to exercises from Chapter 4


Answers to exercises from Section 4.1
Answer to Exercise 4.1.1 The reactive Turing machine below accepts the language
L = { an b m cℓ | n, m, ℓ > 0 }.
a[#/#, R] b[#/#, L] c[#/#, L]

τ [#/#, L] τ [#/#, R]
0 1 2

An accepting computation sequence for the string abbccc is


(q0 , abbccc, h#i) ⊢M (q0 , bbccc, h#i) ⊢M (q1 , bbccc, h#i) ⊢M (q1 , bccc, h#i) ⊢M
(q1 , ccc, h#i) ⊢M (q2 , ccc, h#i) ⊢M (q2 , cc, h#i) ⊢M (q2 , c, h#i) ⊢M (q2 , ε, h#i)
For the strings aaccbb and bca we have maximally input processing derivations
(q0 , aaccbb, h#i) ⊢M (q0 , accbb, h#i) ⊢M (q0 , ccbb, h#i) ⊢M (q1 , ccbb, h#i) ⊢M
(q2 , ccbb, h#i) ⊢M (q2 , cbb, h#i) ⊢M (q2 , bb, h#i) 0M , and
(q0 , bca, h#i) ⊢M (q1 , bca, h#i) ⊢M (q1 , ca, h#i) ⊢M (q2 , ca, h#i) ⊢M
(q2 , a, h#i) 0M
that get stuck, but no computations processing all of the input.

Answer to Exercise 4.1.2 The reactive Turing machine below accepts the language
L = { an b m cn+m | n, m > 0 }.

a[#/1, R] b[#/1, R] c[1/#, L]

τ [#/#, R] τ [#/#, L] τ [#/#, L] τ [#/#, R]


0 1 2 3 4
24 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

For the string aaabcccc we have the accepting computation sequence


(q0 , aaabcccc, h#i) ⊢M (q0 , aabcccc, 1h#i) ⊢M (q0 , abcccc, 11h#i) ⊢M
(q0 , bcccc, 111h#i) ⊢M (q1 , bcccc, 111#h#i) ⊢M (q2 , bcccc, 111h#i) ⊢M
(q2 , cccc, 1111h#i) ⊢M (q3 , cccc, 111h1i) ⊢M (q3 , ccc, 11h1i) ⊢M
(q3 , cc, 1h1i) ⊢M (q3 , c, h1i) ⊢M (q3 , ε, h#i)(q4 , ε, h#i)
However, for the strings aabbcc and abccc we have as maximally input consuming com-
putations
(q0 , aabbcc, h#i) ⊢M (q0 , abbcc, 1h#i) ⊢M (q0 , bbcc, 11h#i) ⊢M
(q1 , bbcc, 11#h#i) ⊢M (q2 , bbcc, 11h#i) ⊢M (q2 , bcc, 111h#i) ⊢M
(q2 , cc, 1111h#i) ⊢M (q3 , cc, 111h1i) ⊢M (q3 , c, 11h1i) ⊢M (q3 , ε, 1h1i) 0M
and
(q0 , abccc, h#i) ⊢M (q0 , bccc, 1h#i) ⊢M (q1 , bccc, 1#h#i) ⊢M (q2 , bccc, 1h#i) ⊢M
(q2 , ccc, 11h#i) ⊢M (q3 , ccc, 1h1i) ⊢M (q3 , cc, h1i) ⊢M (q3 , c, h#i) 0M
Therefore, these strings are not accepted by the Turing machine.

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.

a[#/1, L] b[1/1, R] c[1/#, L]

τ [#/#, L] a[#/#, R] b[#/#, L] c[#/#, R]


0 1 2 3 4
4.2. THE CLASSICAL TURING MACHINE 25

For the string aaabbbccc we have the accepting computation sequence

(q0 , aaabbbccc, h#i) ⊢M (q1 , aaabbbccc, h#i) ⊢M (q1 , aabbbccc, h#i1) ⊢M


(q1 , abbbccc, h#i11) ⊢M (q2 , bbbccc, h1i1) ⊢M (q2 , bbccc, 1h1i) ⊢M
(q2 , bccc, 11h#i) ⊢M (q3 , ccc, 1h1i) ⊢M (q3 , cc, h1i) ⊢M
(q3 , c, h#i) ⊢M (q4 , ε, h#i)

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

b[#/0, L] τ [∗/∗, L] b[∗/∗, L]

Here, a transition labeled α[∗/∗, µ], for α = a, b, µ = L, R abbreviates two transitions,


viz. one labeled α[0/0, µ] and one labeled α[#/#, µ].
An accepting derivation for baaaab is the following

(q0 , baaaab, h#i) ⊢M (q2 , aaaab, h#i0) ⊢M (q1 , aaaab, h#i# 0) ⊢M


(q1 , aaab, h#i0) ⊢M (q1 , aab, h0i) ⊢M (q1 , ab, 0h#i) ⊢M (q1 , b, 0#h#i) ⊢M
(q2 , ε, 0h#i) ⊢M (q1 , ε, h0i) ⊢M (q3 , ε, h#i)

Answers to exercises from Section 4.2

Answer to Exercise 4.2.1


26 CHAPTER 4. TURING MACHINES AND COMPUTABLE FUNCTIONS

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

1. (q0 , haibaba) 7. ⊢ (q0 , hbiab) 13. ⊢ (q0 , hai)


2. ⊢ (q1 , hbiaba) 8. ⊢ (q4 , haib) 14. ⊢ (q1 , h#i)
3. ⊢∗ (q1 , babah#i) 9. ⊢∗ (q4 , abh#i) 15. ⊢ (q2 , h#i)
4. ⊢ (q2 , babhai) 10. ⊢ (q5 , ahbi 16. ⊢ (q6 , Y h#i)
5. ⊢ (q3 , bahbi) 11. ⊢ (q3 , hai) 17. ⊢ (q7 , hY i)
6. ⊢∗ (q3 , h#ibab) 12. ⊢ (q3 , h#ia)
Computations for abba, aaba, and baa not elaborated.

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

1/∗, R 0, 1/X, L ∗/∗, L


0 1 2 3 5 1/1, L
1/0, L
#/#, L
X/X, R
#/#, R
6 7

∗, X/#, L

You might also like