Turing Machines (TM) : Model of Computation
Turing Machines (TM) : Model of Computation
Turing Machines (TM) : Model of Computation
Model of Computation
Outlines
• Structure of Turing machines
• Deterministic Turing machines (DTM)
– Accepting a language
– Computing a function
• Composite Turing machines
• Multitape Turing machines
• Nondeterministic Turing machines (NTM)
• Universal Turing machines (UTM)
TAPE
/1,L
/,L
0/,L
p3 h
Jaruloj Chongstitvatana 2301379 Turing Machines 9
How a DTM works
s
/,L
/@,R
1/,R
p1 q1
@ 1
0 0
0 1 0 0
0
/,R
0/0,L 0/,R
@/,R
1/1,L
0/0,R
p4 p2 1/1,R q2
/1,L
/,L
0/,L
On the input 0001000,
p3 h the TM halts.
Jaruloj Chongstitvatana 2301379 Turing Machines 10
How a DTM works
s
/,L
/@,R
1/,R
p1 q1
@ 0 0
0 0 0 0
0
/,R
0/0,L 0/,R
@/,R
1/1,L
0/0,R
p4 p2 1/1,R q2
/1,L
/,L
0/,L
p3 h
Jaruloj Chongstitvatana 2301379 Turing Machines 17
TM computing a function
• Definition
Let T=(Q, , , , s) be a TM, and f be a
function from * to *.
T computes f if, for any string w in *,
(s, , , w) |-T* (h, , , f(w)).
1/1,R 1/1,L
1/1,R
/,R /1,R /,L 1/,L
s p1 p2 p3 p4
/,R
• Definition
Let T = (Q, , , , s) be an NTM.
Let w* and f be a function from * to *.
T accepts w if (s, , , w) |-T* (h, , , 1).
The language accepted by a TM T, denoted by L(T),
is the set of strings accepted by T.
T computes f if, for any string w in *, (s, , , w) |-T*
(h, , , f(w)).
/@,R
0/0,L
1/1,L
q0 t0
/@,L
v p /,R
u
@/,L
h
0/0,R
1/1,R
q1 t1
0/0,L
1/1,L
/,L 0/0,R
r1 1/1,R
Jaruloj Chongstitvatana 2301379 Turing Machines 29
Multitape TM
• TM with more than one tape.
• Each tape has its own tape head.
• Each tape is independent.
CONTROL
UNIT
TAPE
TAPE
Jaruloj Chongstitvatana 2301379 Turing Machines 30
2-Tape Turing Machine
• a quintuple (Q, , , , s), where
– the set of states Q is finite, and does not contain the halt
state h,
– the input alphabet is a finite set of symbols, not
including the blank symbol ,
– the tape alphabet is a finite set of symbols containing ,
but not including the blank symbol ,
– the start state s is in Q, and
– the transition function is a partial function from
Q ({})2 Q{h} ({})2 {L, R, S}2 .
Jaruloj Chongstitvatana 2301379 Turing Machines 31
Example of 2-Tape Turing Machine
,/(,),(R,S) ,/(,),(L,R) ,/(,),(R,S)
s p1 p2 p3
0,/(0,),(R,S) 0,/(0,0),(L,R) 0,/(0,),(R,S)
1,/(1,),(R,S) 1,/(1,1),(L,R) 1,/(1,),(R,S)
,/(,),(L,L)
,/(1,),(L,L) ,/(,),(R,R)
h q2 p4
0,0/(,),(L, L)
1,1/(,),(L, L)
Theorem:
For any 2-tape TM T, there exists a single-
tape TM M such that for any string in *:
– if T halts on with on its tape, then M halts
on with on its tape, and
– if T does not halt on , then M does not halt on
.
0 1 1 1 0
0 1 1 1 0
seperator
p
a1,a2/(b1,b2),(d1,d2)
q
c(a1,a2)
p T_tape1 (a1,b1,d1)
T_tape2 (a2,b2,d2) q
c(?,?)/c(?,?),R
S
not #/not #,L
#/#,R
c(0,?)/c(1,?),d c(1,x)/c(1,x),L
c(0,?)/c(1,?),d 1/c(1,),L #/#,L c(?,x)/c(1,x),R
h
It is
Remember
not possible
symbol
that #/#,L
c(1,?)
under
is found
tape head
because
in
c(0,?) is wriiten
tape 1in cell 1.
not #/not #,L
Jaruloj Chongstitvatana 2301379 Turing Machines 39
Tcleanup
|, L
p1
0|0,L
?| , R
1|1,L
|,R
#/,R
/,L
c(,)|, S
c(0,)|0, S
c(1,)|1, S
|, L
pn
|, R |, R h
0/0,R
/,L
1/1.R
/,R
/,R
/,L
Proof:
Let T = (Q, , , , s) be a 2-tape TM.
We construct a 1-tape TM M=(K, , ’, ’, s’) such that
– ’ = {c(a,b)| a,b are in {}} {c(a,b)| a,b
are in {}} {c(a,b)|a,b are in {}}
{c(a,b)|a,b are in {}} {#}
We need to prove that:
– if T halts on with output , then M halts on with
output , and
– if T does not halt on , then M does not halt on
FindStateinCurrentConfiguration EraseCurrentConfiguration
h WriteAllPossibleNextConfiguration
FindStateinCurrentConfiguration EraseCurrentConfiguration
Current
Current state:
state: ssq
h WriteAllPossibleNextConfiguration
Tape 2
*
- - s
- -
0 -
1 - 0
1 - -
- *
# - 0
- -
q -
1 - 0
1 - - #
*
# @ s 0 1 1 0 # 0 1 q 1 0 #
*
/@,S /,R 0/0,R
s q
Jaruloj Chongstitvatana 2301379 Turing Machines 47
WriteAllPossibleNextConfiguration
a/b1,d1 a/bn,dn
q1 p qn
a/b2,d2
q2
a,p
Writeq1b1d1 Writeq2b2d2 Writeqnbndn
/@,S 0/0,R
/,R
s q
,s
WriteqR Writes@R
Writeq0R Nondeterministic
move
… Deterministic
move
Jaruloj Chongstitvatana 2301379 Turing Machines 49
if Mn halts on input with output
– How to simulate T
CopyInputToTape2 CopyStartStateToTape3
UpdateTape2 FindRightMove
0
(halt)
UpdateStateOnTape3 CopyTape2ToTape1
Tape 1
# 0 0 , 0 0 , 0 0 0 , 0 0 0 , 0 0 0
# 0 0 0 , 0 , 0 , 0 , 0 # ... # |
Tape 2
1 0 0 1
0 0
1 1
0 1 CopyInputToTape2 CopyStartStateToTape3
UpdateStateOnTape3 CopyTape2ToTape1
0 0 0 halt