0% found this document useful (0 votes)
33 views16 pages

Turing

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)
33 views16 pages

Turing

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/ 16

Turing Machines

Last Updated March 22nd, 2024

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:

1.1 Turing machine definition

A Turing machine consists of a 7-tuple (Q, Σ, Γ, δ, q0 , qa , qr ) where

Q a finite set of states

Σ the finite input alphabet, not including the blank symbol ⊔

Γ the finite tape alphabet, where Σ ⊂ Γ and ⊔ ∈ Γ

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

q0 ∈ Q the initial state

qa the accepting state

qr the rejecting state

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

q2 ,q3 ,q6 : look for the pound symbol

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 #

q7 : search for the nearest x 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.

ˆ The tape head is reading cell cj .

ˆ The i th tape cell contains symbol ci ∈ Γ, for all 1 ≤ i ≤ k.

ˆ 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

Initial Configuration has the form ⃗κ = q0 w1 · · · wn , where w is the input word

Final Configuration any configuration ⃗κ = c1 · · · cj−1 qcj · · · ck , where q is either qa or qr . In the


former case we call it an accepting configuration, while in the latter case we call it a
rejecting configuration.

Turing machine computation

Let M = (Q, Σ, Γ, δ, q0 , qa , qr ) be a Turing machine. Then the Turing machine computation of


M on input w consists of a (possibly infinite) sequence S(M, w) of configurations ⃗κ0⃗κ1 , . . . which is
recursively defined as follows.

Base case ⃗κ0 = q0 w1 · · · wn is the initial configuration.

Recursive case Assume that ⃗κi = c1 · · · cj−1 qcj · · · ck has been defined, q ̸∈ {qa , qr }, and δ(q, cj ) =
(q̂, a, D).

Case 1: D=R. Then


⃗κi+1 = c1 · · · cj−1 aq̂cj+1 · · · ck
if j < k, and
⃗κi+1 = c1 · · · ck−1 aq̂⊔
if j = k
Case 2: D=L. Then
⃗κi+1 = c1 · · · q̂cj−1 acj+1 · · · ck
if j > 1, and
⃗κi+1 = q̂ac2 · · · ck
if j = 1.

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

Nondeterministic A nondeterministic Turing machine (NTM) is one whose δ-transition


function is now defined as
δ : Q × Γ → P(Q × Γ × {L, R}),
meaning that, for a given configuration, there could be more than one next configuration.

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.

Transducer A Turing machine T is called a transducer if it serves the purpose of computing a


function f : Σ∗ → Σ∗ , where Σ is the machine’s input alphabet. The main difference between
a transducer and a decider is that, instead of having accept and reject states qa and qr , T has
a single halt state qh . Similar to a decider, on input w ∈ Σ∗ , the computation begins with
an initial configuration and produces a sequence of configurations by folllowing T ’s transition
function. If the halt state is never reached, then f (w) is undefined. Otherwise, f (w) is defined
by examining the final halting configuration, and setting f (w) equal to the longest tape prefix
in Σ∗ . For example, if the final configuration has tape contents 01100010⊔⊔01101⊔ · · · , then
f (w) = 01100010, since ⊔ ̸∈ Σ. In other words, the output ends with the first instance of a
blank cell.

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 × Σ)

2. its transition function is


δ : Q × Γ → Q × Γ × {L, R},
.

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

1. the current state,

2. the tape head location, and

3. the contents of each of the first t cells.

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.

Defining the variables.

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.

3. ⃗c0j = xj , 0 ≤ j < m, encodes the jth bit of x.

4. ⃗c0m = #.

5. ⃗c0(m+1+j) = yj , 0 ≤ j < n, encodes the jth bit of y.

6. ⃗c0j = ⊔, m + n + 1 < j < t.

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.

Next State For all i = 1, . . . , t − 1,

[(⃗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′ )].

Cell Values For all i = 1, . . . , t − 1 and for all j = 0, . . . , t − 1,

(⃗cij = ⃗c(i−1)j ∧ h(i−1)j )∨

h(i−1)j ∧ [(⃗si−1 = q1 ∧ ⃗c(i−1)j = α1 ∧ ⃗cij = β1 ) ∨ · · · ∨ (⃗si−1 = qr ∧ ⃗c(i−1)j = αr ∧ ⃗cij = βr )].

Head Location For all i = 1, . . . , t − 1, there exists a j = 0, . . . , t − 1, such that

h(i−1)j ∧ [(⃗si−1 = q1 ∧ ⃗c(i−1)j = α1 ∧ ((hi(j−1) ∧ d1 = L) ∨ (hi(j+1) ∧ d1 = R)) ∨ · · ·

∨(⃗si−1 = qr ∧ ⃗c(i−1)j = αr ∧ ((hi(j−1) ∧ dr = L) ∨ (hi(j+1) ∧ dr = R))].

Head in Single Location For all i = 0, . . . , t − 1 and for all j, k = 0, . . . , t − 1, j ̸= k,

hij → hik .

Final State is Accepting


⃗st−1 = qa .

14
Finishing the Proof.

1. Boolean formula Fx (y0 , . . . , yn−1 ) is the conjunction of the total of

t(t + 2) = O(t2 ) = O(q 2 (m))

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.

3. Therefore, L ≤pm SAT.

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

L = {x = y + z|x, y, z ∈ {0, 1}+ and x = y + z}.

For example 101 = 11 + 10 ∈ L since

(5)2 = (3)2 + (2)2 .

4. Provide the state diagram for a Turing machine that accepts the language

L = {x = y + z|x, y, z ∈ {0, 1}+ and x = y − z}.

For example 11 = 101 − 10 ∈ L since

(3)2 = (5)2 + (2)2 .

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

You might also like