Turing
Turing
Introduction
In this lecture we look at the Turing machine model of computation. A Turing machine is a kind of
automaton that is more powerful than a PDA since it has an infinite memory with less restriction on
how the memory is accessed. Turing machines are just as powerful as the computers we use today.
We’ll give some justification for this statement in a later section. Although Turing machines can
seem very difficult to work with in practice, they have the following theoretical advantages.
Turing machines can be easily described in the abstract (as a 7-tuple), which makes them preferable
to work with when developing a theoretical argument about general computation.
Turing machines highlight the two features that yield general computation: a finite control together
with full memory access
Turing machines closely resemble PDA’s by definition, yet are caple of deciding a much wider class
of languages. This suggests the need to examine other sub-computing paradigms other than
those that restrict memory access; hence the recent interest in algebraic models of computation.
1
Figure 1:
δ a transition function δ that, given the current state and the tape symbol being read, determines
the machine’s next state, the next tape symbol to be written, and the direction for the tape
head to move. In other words,
δ : Q × Γ → Q × Γ × {L, R}.
It helps to think of a Turing machine as consisting of a one-way infinite tape (i.e. array) of symbols
from Γ, where at the beginning of the computation the tape consists of input symbols w1 · · · wn ,
followed by an infinite sequence of t symbols. The machine head reads one tape cell and moves
either right or left according to δ. Before moving, it first writes a new symbol on the cell being read.
2
Example 1. The following is a state diagram for a Turing machine that halts in the accept state on
some input iff the input has the form w#w, where w ∈ {0, 1}∗ .
q1
1
R →
x,
#→R
x,
→ R
0
0, 1 → R q2 q8 x→R q3 0, 1 → R
t→R
#→R #→R
x→R q4 qa q5 x→R
0 L
→
x, x,
L →
1
q6 0, 1, x → L
#→L
q7 0, 1 → L
x→R
3
q1 : x-out the next bit of the left word, or move to q8 if there are no remaining bits
q8 : check if there is a remaining bit to the right of #, and accept iff there are no remaining bits
q4 ,q5 : look for the next bit to the right of #, and continue if it matches the previous one x’d out to
the left of #
Simplifying conventions
1. If δ(q, s) is undefined, then we take it to mean δ(q, s) = (qr , s, R) which results in a rejecting
computation.
2. We assume the tape has a buffer symbol $ to the left of the first cell, and that helps indicate
when the head has run off the left side of the tape. In this case the next step is always for the
head to move right to the first tape cell.
4
Given Turing machine M , a configuration for M is a vector ~κ which represents the current state
of the machine, along with its tape contents and tape-head location. Moreover, ~κ has the form
~κ = $c1 · · · cj−1 qcj · · · ck , and is interpreted as follows.
• M is in state q.
• Either k = j or ck is the last cell of the tape that contains a non-blank symbol.
5
Example 2. Given the two Turing-machine tapes below, provide configuration vectors for each tape.
Assume in both cases the machine is in state q3 .
↓
$ t 0 1 t t 1 t ···
↓
$ 1 0 1 t t t t ···
6
Special Turing machine configurations
Initial Configuration has the form ~κ = $q0 w1 · · · wn , where w is the input word
Recursive case Assume that ~κi = $c1 · · · cj−1 qcj · · · ck has been defined, q 6∈ {qa , qr }, and δ(q, cj ) =
(q̂, a, D).
Moreover, the computation of M on input w is said to be a finite computation if and only if |S(M, w)|
is finite. In this case we say that M halts on input w. Notice also that in this case the final
configuration of S(M, w) must either be accepting or rejecting, in which case we either call S(M, w)
an accepting computation, or a rejecting computation, and say that M accepts or rejects the
input. The language L accepted by M , denoted L(M ), consists of all words w from Σ∗ for which
M accepts w. Such a language is said to be Turing recognizable or recursively enumerable.
Moreover, if M halts on all of its inputs, then L(M ) is said to be Turing decidable or recursive.
7
Example 3. Provide the state diagram for a Turing machine M that accepts all binary words having
an equal number of zeros and ones. Show the computation of M on input 0110.
Solution.
x→R
t→L qa
a
1
R →
x, x,
→ R
0
0, x → R b $→R c 1, x → R
1 L
→
x, x,
L →
0
0, 1, x → L
8
Example 3 Continued.
1. $a0110
2. $xb110
3. $dxx10
4. d$xx10
5. $axx10
6. $xax10
7. $xxa10
8. $xxxc0
9. $xxdxx
10. $xdxxx
11. $dxxxx
12. d$xxxx
13. $axxxx
14. $xaxxx
15. $xxaxx
16. $xxxax
17. $xxxxat
18. $xxxqa x
9
Special Kinds of Turing Machines
Decider A Turing machine is a decider iff it halts on all inputs.
Recognizer A Turing machine is a recognizer iff it halts on all inputs that it accepts.
Multitape A multitape Turing machine has more than one tape along with a head for each
tape. Moreover, its transition function simultaneously controls each of its heads. Indeed, if
M has k > 0 tapes, then its transition function δ accepts k + 1 inputs (one state and k read
symbols) and provides a (2k + 1)-tuple output (one next state, k write symbols, and k head
directions).
Enumerator An enumerator Turing machine M starts with a blank tape, and has an extra
write-only tape on which it is capable of writing a potentially infinite set L of words. In this
case we say that L is enumerated by M .
Universal A Turing machine U is said to be universal iff for any input hM, wi, where M is a
Turing machine and w is some input word for M , then U (w) = M (w). Note: here we are
restricting M so that its input alphabet is the same as U ’s. Examples of universal Turing
machines include a computer operating system and a human who is capable of following a
Turing-machine computation using pencil and paper.
10
Example 4. Provide a program for a Turing machine that starts with a blank input tape and
proceeds to generate eight different configurations, with each configuration having the form wq3 t,
where w ∈ {0, 1}3 and no two configurations have the same binary word.
11
Church-Turing Thesis
The Church-Turing Thesis states that any problem that can be solved via some step-by-step
algorithm can be solved by a Turing machine.
Because of the Church-Turing thesis, we may use other algorithmic means besides the Turing machine
to describe an algorithm. With that said, there are occasions when we will need to work with Turing
machines. One such occasion occurs when we need to be more precise about how many computation
steps or how much memory is being used by the algorithm. Such quantities can be readily computed
for a Turing machine. Another occasion occurs when we need to provde something about an arbitrary
program or algorithm. In this case we may assume that the program is described by a Turing machine.
12
Exercises
1. Provide the state diagram for a Turing machine M that accepts all binary palindromes. Provide
the sequence of configurations that comprises the computation of M on input 01110.
2. Provide the state diagram for a Turing machine that accepts all inputs of the form x#y, where
x, y ∈ {0, 1}+ , |x| = |y|, and x ≥ y when x and y are viewed as binary numbers.
3. Provide the state diagram for a Turing machine that accepts the language
4. Provide the state diagram for a Turing machine that accepts the language
5. Provide the state diagram for a Turing machine that, on input x ∈ {0, 1}+ , replaces x with x
1’s. Here, we are thinking of x as a binary number. For example, $1001 would be replaced with
$111111111, while $00 is replaced with $.
6. For the Turing machine M with state diagram shown below, draw the computation tree
T (M, 001). Is this an accepting computation? Explain.
0 → 1, L
0 → 1, R
0→R
a b c
0 → 1, L
L 1
1 → 0, R
1, →
t→L
→ R 1→R
0
1→R
d e f
0→R
1 → 0, L
13