Turing
Turing
1 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 pushdown automaton since the former is equipped with
an infinite stack memory while the Turing machine has a memory consisting of an infinite array of
cells that can be accessed in any order. Turing machines are equivalent in power to other models of
computation, including the URM model and most modern programming languages.
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 acccess to an infinite array of memory cells that may be accessed in any order.
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 ⊔ symbols. The tape 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
#→R
→
x,
→
x,
R
0
0, 1 → R q2 q8 x→R q3 0, 1 → R
⊔→R
#→R #→R
x→R q4 qa q5 x→R
0
L
→
x,
→
x,
L
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. If the tape head is reading the first tape cell and is instructed to move left, then we assume the
head moves to a “buffer” blank cell and that the next instruction must force the head to move
back to the first tape cell without writing on the buffer cell.
3. The tape head never writes a blank symbol. Thus, a blank cell that borders a non-blank cell
serves as a left or right delimiter for a word w ∈ (Γ − {⊔})∗ , called the tape word which
consists only of non-blank cells.
4. If the tape head is reading a blank and it moves right, then it must write a non-blank symbol.
Thus, such a move increases the tape word’s length by one.
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 ck is the last cell of the tape that contains a non-blank symbol or ck = ⊔ the tape head
is reading ck .
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 .
↓
⊔ 0 1 ⊔ ⊔ 1 ⊔ ···
↓
1 0 1 ⊔ ⊔ ⊔ ⊔ ···
6
Special Turing machine configurations
Recursive case Assume that ⃗κi = c1 · · · cj−1 qcj · · · ck has been defined, q ̸∈ {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 ∈ Σ∗ for which
M accepts w. Such a language is said to be Turing recognizable or recursively enumerable.
Moreover, if M halts on all 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
⊔→L qa
a
1
R
→
x,
→
x,
R
0
0, x → R b ⊔→R c 1, x → R
1
L
→
x,
→
x,
L
0, 1, x → L
8
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 ⟨M, w⟩, 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.
9
For the NTM machine N with state diagram shown below, draw the computation tree T (N, 10); i.e.
the computation tree of N on input 10. Is this an accepting computation?
0 → 1, L
0 → 1, R
0→R
a b c
0 → 1, L
1 → 0, R
⊔→L
1
1,
→
1→R
→
R
0
1→R
d e f
0→R
1 → 0, L
Solution.
10
Example 4. Provide a state diagram for a nondeterministic Turing machine M that starts with
a blank input tape and proceeds to generate eight different configurations, with each configuration
having the form wq3 ⊔, where w ∈ {0, 1}3 and no two configurations have the same binary word.
11
2 Cook’s Theorem
We now provide an example of why Turing machines are considered the computing model of choice
in the study of computational complexity theory.
Theorem 1. (Cook’s Theorem) SAT is NP-complete.
Proof.
Let L be a decision problem in NP via verifier v(x, y), where v(x, y) is computable in O(q(|x|))
steps and variable y can be encoded using O(q(|x|)) bits, for some polynomial q. We describe how
to compute a Boolean formula Fx (y) whose size is bounded by a polynomial in |x|, and which is
satisfiable iff x is a positive instance of L. Thus, Fx (y) depends on x and its variables are the
Boolean variables that encode y.
To accomplish this, we assume the Turing-machine model of computation. Let M = (Q, δ, {0, 1}, Γ, q0 , qa )
be a Turing machine that decides v(x, y), where
1. Q is its set of machine states, including the respective initial and acccepting states q0 and qa
(a rejecting state is implied in case δ(q, s) is undefined for some pair (q, s) ∈ Q × Σ)
We may assume that x is encoded with m bits, y with n bits, m + n + 1 ≤ t, where t = O(q(m)) is
a bound on the number of configurations needed for the computation M (x, y). Note also that the
computation requires at most the first t tape cells. Thus, we may define a polynomial (with respect
to t) number of Boolean variables that capture each configuration of the computation of M (x, y).
And for each of the t configurations, the variables must indicate
It then follows that we need at most ⌈log |Q|⌉ variables to describe M ’s state. Also, we may use t
variables to encode the head location. Finally, we need at most t⌈log |Σ|⌉ variables to encode the
contents of each of the first t cells. Thus we need a total of O(t2 ) = O(q 2 (m)) variables to describe all
of M ’s configurations. These variables are defined as follows. Note: for simplicity, instead of defining
individual Boolean variables that encode each bit of the encoding of the machine state, we instead
12
define a vector ⃗s of Boolean variables. We also define a vector of Boolean variables to represent the
current symbol stored in a cell.
1. ⃗si , 0 ≤ i < t, is a ⌈log |Q|⌉-bit vector of variables that encodes the state of the i th configuration
of M (x, y).
2. hij equals 1 iff, for the i th configuration, the head is located at cell j, 0 ≤ i, j < t.
3. ⃗cij , 0 ≤ i, j < t, is a ⌈log |Γ|⌉-bit vector of variables that encodes the symbol stored in cell j in
the i th configuration of M (x, y).
13
Then the following equations completely define each of the Boolean variables. Reminder: we assume
|x| = m and |y| = n.
Base Cases.
1. ⃗s0 = q0 .
2. h00 = 1.
4. ⃗c0m = #.
In what follows, for simplicity we assume the head never moves (left) off the tape. We may also think
of δ as the list of 5-tuples
(q1 , α1 , q1′ , β1 , d1 ), . . . , (qr , αr , qr′ , βr , dr ),
where, for all u = 1, . . . , r, qu , qu′ ∈ Q, αu , βu ∈ Γ, and du ∈ {L, R}.
Recursive Cases.
[(⃗si−1 = q1 ∧ h(i−1)1 ∧ ⃗c(i−1)1 = α1 ∧ ⃗si = q1′ ) ∨ · · · ∨ (⃗si−1 = qr ∧ h(i−1)1 ∧ ⃗c(i−1)1 = αr ∧ ⃗si = qr′ )]
∨ · · ·∨[(⃗si−1 = q1 ∧h(i−1)(t−1) ∧⃗c(i−1)(t−1) = α1 ∧⃗si = q1′ )∨· · ·∨(⃗si−1 = qr ∧h(i−1)(t−1) ∧⃗c(i−1)1 = αr ∧⃗si = qr′ )].
hij → hik .
14
Finishing the Proof.
number of Boolean formulas defined in both the base and recursive cases. Moreover, since each
formula has size O(1), it follows that F may be constructed in a polynomial number of steps
with respect to |x| = m.
2. By completely adhering to M ’s program from the initial state to the final state, we see that
Fx (y0 , . . . , yn−1 ) is satisfiable iff there is some certificate y for which v(x, y) = 1, iff x is a
positive instance of L.
15
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
1 → 0, R
⊔→L
1
1,
1→R
→
R
0
1→R
d e f
0→R
1 → 0, L
16