You are on page 1of 5

Turing Machine

CS154 FINITE
STATE
q10
CONTROL

Turing Machines
AI N P U T 

INFINITE TAPE

read write move read write move

0 → 0, R  → , R 0 → 0, R  → , R
qaccept qaccept

0 → 0, R 0 → 0, R
 → , R  → , R
qreject 0 → 0, R 0 → 0, R
 → , L  → , L
Language = {0}

This Turing machine recognizes the


language {0}

Deciding the language L = { w#w | w ∈ {0,1}* }


Turing Machines versus DFAs STATE
q1,#FIND # q#, FIND
q0, FIND q1,FIND  qGO LEFT
q0,FIND
TM can both write to and read from the tape

The head can move left and right

The input doesn’t have to be read entirely, 0 1


0
X 1
X #
1 0
# 0
X
1 1 1
and the computation can continue further
(even, forever) after all input has been read 1. If there’s no # on the tape, reject.
2. While there is a bit to the left of #,
Replace the first bit with X, and check if the first bit
Accept and Reject take immediate effect to the right of the # is identical. (If not, reject.)
Replace that bit with an X too.
3. If there’s a bit to the right of #, then reject else accept

1
Definition: A Turing Machine is a 7-tuple
T = (Q, Σ, Γ, δ, q0, qaccept, qreject), where: Turing Machine Configurations
Q is a finite set of states
q7
Σ is the input alphabet, where  ∉ Σ
Γ is the tape alphabet, where  ∈ Γ and Σ ⊆ Γ
δ : Q × Γ → Q × Γ × {L, R}
1 1 0 1 0 0 0 1 1 0
q0 ∈ Q is the start state
qaccept ∈ Q is the accept state corresponds to the configuration:
qreject ∈ Q is the reject state, and qreject ≠ qaccept
11010q700110

Defining Acceptance and Rejection A TM M recognizes a language L iff M accepts


Let C1 and C2 be configurations of M all and only those strings in L
We say C1 yields C2 if, after running M in C1
for one step, M is then in configuration C2 A language L is called recognizable or
recursively enumerable (r.e.)
Suppose δ(q1, b) = (q2, c, L) iff some TM recognizes L
Then aaq1bb yields aq2acb
Suppose δ(q1, a) = (q2, c, R)
Then cabq1a yields cabcq2 A TM M decides a language L iff M accepts all
strings in L and rejects all strings not in L
Let w ∈ Σ* and M be a Turing machine
M accepts w if there are configs C0, C1, ..., Ck, s.t.
A language L is called decidable or recursive
• C 0 = q0 w
iff some TM decides L
• Ci yields Ci+1 for i = 0, ..., k-1, and
• Ck contains the accepting state qaccept

A language is called recognizable n


(recursively enumerable) if some TM { 02 | n ≥ 0 }
recognizes it
PSEUDOCODE:
A language is called decidable (recursive) if
some TM decides it 1. Sweep from left to right, cross out every other 0
2. If in stage 1, the tape had only one 0, accept
3. If in stage 1, the tape had an odd number of 0’s,
reject
4. Move the head back to the first input symbol.
recognizable decidable 5. Go to stage 1.
languages languages
Why does this work?
Idea: Every time we return to stage 1, the
number of 0’s on the tape is halved.

2
x → x, L
n C = {aibjck | k = i*j, and i, j, k ≥ 1}
{ 02 | n ≥ 0 } 0 → 0, L
q2
PSEUDOCODE:
 → , R
 → , L
x → x, R 1. If the input doesn’t match a*b*c*, reject.
x → x, R 2. Move the head back to the leftmost symbol.
q0 q1 q3 3. Cross off an a, scan to the right until b.
0 → , R 0 → x, R Sweep between b’s and c’s, crossing off one of
x → x, R each until all b’s are crossed off.
 → , R 0 → 0, R If all c’s get crossed off while doing this, reject.
 → , R 0 → x, R
4. Uncross all the b’s.
If there’s another a left, then repeat stage 3.
qreject qaccept q4
If all a’s are crossed out,
x → x, R Check if all c’s are crossed off.
 → , R If yes, then accept, else reject.

C = {aibjck | k = i*j, and i, j, k ≥ 1} Multitape Turing Machines

aabbbcccccc
xabbbcccccc FINITE
STATE
k
xayyyzzzccc CONTROL

xabbbzzzccc
xxyyyzzzzzz
δ : Q × Γk → Q × Γk × {L,R}k

Theorem: Every Multitape Turing Machine can be Theorem: Every Multitape Turing Machine can be
transformed into a single tape Turing Machine transformed into a single tape Turing Machine

1 0 0 1 0 0

FINITE FINITE
STATE STATE
CONTROL CONTROL

FINITE FINITE
STATE . . . STATE . . .
1 0 0 # # # 1 0 0 # # #
CONTROL CONTROL

3
Theorem: Every Multitape Turing Machine can be Theorem: Every Multitape Turing Machine can be
transformed into a single tape Turing Machine transformed into a single tape Turing Machine

1 0 0 1 0 0

FINITE FINITE
STATE STATE
CONTROL CONTROL

FINITE FINITE
STATE . . . STATE . . .
1 0 0 # # # 1 0 0 # # #
CONTROL CONTROL

Nondeterministic TMs We can encode a TM as a bit string.


start reject
Theorem: Every nondeterministic Turing
n states state state
machine N can be transformed into a single
tape Turing Machine M that recognizes the
same language. 0n10m10k10s10t10r10u1
Proof Idea (more details in Sipser): m tape symbols
M(w): blank
(first k are input accept
For all strings C ∈ {Q ∪ Γ ∪ #}* in lex. order, symbol
symbols) state
Check if C = C0# < #Ck where
C0, < ,Ck is some accepting computation
history for N on w. If so, accept. ( (p, a), (q, b, L) ) = 0p10a10q10b10
( (p, a), (q, b, R) ) = 0p10a10q10b11

Similarly, we can encode DFAs and NFAs ADFA = { (D, w) | D is a DFA that accepts string w }
as bit strings. Theorem: ADFA is decidable
Proof Idea: Directly simulate D on w!
So we can define the following languages:
ANFA = { (N, w) | N is an NFA that accepts string w }
ADFA = { (B, w) | B is a DFA that accepts string w }
Theorem: ANFA is decidable. (Why?)
ANFA = { (B, w) | B is an NFA that accepts string w }

ATM = { (C, w) | C is a TM that accepts string w } ATM = { (M, w) | M is a TM that accepts string w }

ATM is recognizable but not decidable


(Can define (x, y) := 0|x|1xy)

4
Universality of Turing Machines
Theorem: There is a universal Turing machine U The Church-Turing Thesis
that can take as input
- the code of an arbitrary TM M
- an input string w, Everyone’s
such that U(M, w) accepts iff M(w) accepts. Intuitive Notion = Turing Machines
of Algorithms
This is a fundamental property:
Turing machines can run their own code!
This thesis is tested every time you write
Note that DFAs/NFAs do not have this property. a program that does something!
That is, ADFA is not regular.

A TM recognizes a language if it accepts all w ∈ Σ* w ∈ Σ*


and only those strings in the language

A language is called recognizable or TM w∈L? TM w∈L?


recursively enumerable, (or r.e.)
if some TM recognizes it yes no yes no

accept reject accept reject or no output


A TM decides a language if it accepts all
strings in the language and rejects all strings L is decidable L is recognizable
not in the language (recursive) (recursively enumerable)
A language is called decidable (or recursive)
if some TM decides it Theorem: L is decidable if both L and ¬L
are recursively enumerable

Recall: Given L ⊆ Σ *, define ¬L := Σ * - L There are languages over {0,1}


Theorem: L is decidable
that are not decidable
iff both L and ¬L are recognizable Assuming the Church-Turing Thesis,
this means there are problems that
Given: NO computing device can solve
a TM M1 that recognizes A and
a TM M2 that recognizes ¬A, We can prove this using a counting argument.
we can build a new machine M that decides A We will show there is no onto function from
the set of all Turing Machines to the set of all
How? Any ideas? languages over {0,1}. (But it works for any Σ)
M1 always accepts x, when x is in A
M2 always accepts x, when x is not in A That is, every mapping from Turing machines to
languages must “miss” some language.

You might also like