Lecture 7: Turning Machines
description
Transcript of Lecture 7: Turning Machines
Lecture 7: Turning Machines
虞台文大同大學資工所智慧型多媒體研究室
Content
An Overview on Finite State Machine The Definition of Turing Machine Computing with Turing Machine Turing-Machine Programming Some Examples of Powerful TMs Extensions of the TM Nondeterministic Turing Machine
Lecture 7: Turning Machines
An Overview on Finite State Machine
大同大學資工所智慧型多媒體研究室
Example Input a 0/1 sting. If the numbers of 0 and 1 in the
string are both even, then it is legal; otherwise, it is illegal.– 0011001001(legal)– 11001001001(illegal)
Writing a C program to do so.
q0 q1
q2 q3
0
0
0
0
1 1 1 1
Examples:
00100011<CR>
01101011<CR>
001010101<CR>
0010010101<CR>
Finite State Machine
Finite State Machine
q0 q1
q2 q3
0
0
0
0
1 1 1 1
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>q1
q0
q3
q2
q2
q3
q0
q1
ok
err
err
err
The ParserThe Parser
Implementation (I)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>q1
q0
q3
q2
q2
q3
q0
q1
ok
err
err
err
The ParserThe Parser
#define q0 0#define q1 1#define q2 2#define q3 3#define fini4
#define q0 0#define q1 1#define q2 2#define q3 3#define fini4
Implementation (I)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>q1
q0
q3
q2
q2
q3
q0
q1
ok
err
err
err
The ParserThe Parser
int parser[4][3]={q1, q2, fini,q0, q3, fini,q3, q0, fini,q2, q1, fini
};
int state=q0;int event;char* str;
int parser[4][3]={q1, q2, fini,q0, q3, fini,q3, q0, fini,q2, q1, fini
};
int state=q0;int event;char* str;
Implementation (I)
void ToEvent(char c){
if(c == ’0’) event = 0;else if(c == ’1’) event = 1;else event = 2;
}
void ToEvent(char c){
if(c == ’0’) event = 0;else if(c == ’1’) event = 1;else event = 2;
}
Event (or Message) EncodingEvent (or Message) Encoding
Implementation (I)
void main(){
// Ask user to input a 0/1 string// Store the string into strstate = q0; //initializationwhile(state!=fini){
ToEvent(*str++);EventHandler(event);
}}
void main(){
// Ask user to input a 0/1 string// Store the string into strstate = q0; //initializationwhile(state!=fini){
ToEvent(*str++);EventHandler(event);
}} Event (or Message) LoopEvent (or Message) Loop
Implementation (I)
void EventHandler(int event){
int next_state = parser[state][event];switch(next_state){ case fini:
printf(”%s\n”, state==q0 ? ”ok” : ”err”); default:
state = next_state; //change state}
}
void EventHandler(int event){
int next_state = parser[state][event];switch(next_state){ case fini:
printf(”%s\n”, state==q0 ? ”ok” : ”err”); default:
state = next_state; //change state}
}
Event HandlerEvent Handler
Implementation (II)
q0 q1
q2 q3
0
0
0
0
1 1 1 1
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>pq1
pq0
pq3
pq2
pq2
pq3
pq0
pq1
ok
err
err
err
The ParserThe Parser
Implementation (II)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>pq1
pq0
pq3
pq2
pq2
pq3
pq0
pq1
ok
err
err
err
The ParserThe Parser
#define q0 0#define q1 1#define q2 2#define q3 3#define fini4
#define q0 0#define q1 1#define q2 2#define q3 3#define fini4
void pq0(), pq1(), pq2(), pq3();void ok(), err();void pq0(), pq1(), pq2(), pq3();void ok(), err();
Implementation (II)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>pq1
pq0
pq3
pq2
pq2
pq3
pq0
pq1
ok
err
err
err
The ParserThe Parser
void pq0(){
state = q0;}
void pq1(){
state = q1;}
void pq0(){
state = q0;}
void pq1(){
state = q1;}
void pq2(){
state = q2;}
void pq3(){
state = q3;}
void pq2(){
state = q2;}
void pq3(){
state = q3;}
Implementation (II)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>pq1
pq0
pq3
pq2
pq2
pq3
pq0
pq1
ok
err
err
err
The ParserThe Parser
void ok(){
printf(”ok\n”);state = fini;
}
void err(){
printf(”error\n”);state = fini;
}
void ok(){
printf(”ok\n”);state = fini;
}
void err(){
printf(”error\n”);state = fini;
}
Implementation (II)
stat
e
q0
q1
q2
q3
symbol(event)
0 1 <CR>pq1
pq0
pq3
pq2
pq2
pq3
pq0
pq1
ok
err
err
err
The ParserThe Parser
typedef void (*FUNCTION)();
FUNCTION parser[4][3]={pq1, pq2, ok,pq0, pq3, err,pq3, pq0, err,pq2, pq1, err
};
typedef void (*FUNCTION)();
FUNCTION parser[4][3]={pq1, pq2, ok,pq0, pq3, err,pq3, pq0, err,pq2, pq1, err
};
Implementation (II)
void main(){
// Ask user to input a 0/1 string// Store the string into strstate = q0; //initializationwhile(state!=fini){
ToEvent(*str++);(*parser[state][event])();
}}
void main(){
// Ask user to input a 0/1 string// Store the string into strstate = q0; //initializationwhile(state!=fini){
ToEvent(*str++);(*parser[state][event])();
}} Event (or Message) LoopEvent (or Message) Loop
Exercise
1. Write a C Program to recognize floating-point string. The syntax of the floating-point string is defined the same as that defined in C language.
Lecture 7: Turning Machines
The Definition of Turing Machine
大同大學資工所智慧型多媒體研究室
Definition
# #
Head
A Turing machine is a quadruple( , , , )K sK: finite set of states, hK. : alphabet, #, L, R.
s: sK, initial state.: transition function
Ne
ScannedSymbol
CurrentState Action
Takenw
State
: , }{ {}K Rh LK
Hang
The Transition Function
( , ) ( , )q a p b
,q K a
1. Change state from q to p.
2. b print b;b{L, R} Move head in the direction of b.
Ne
ScannedSymbol
CurrentState Action
Takenw
State
: , }{ {}K Rh LK
The Transition Function
( , ) ( , )q a p b
,q K a K
. . . . . . . . . . . . . .a
. . . . .
. . . . .
q ( , )p b
Ne
ScannedSymbol
CurrentState Action
Takenw
State
: , }{ {}K Rh LK
Memory Configuration
w a #
Head
u #
( , , , )q w a u or ( , )q wau
The configuration of a Turing machineis a member of
( , , , )M K s
* #*w
q ua
K h
Halt Configuration
w a #
Head
u #
( , , , )wh a u or ( , )h wau
The configuration of a Turing machineis a member of
( , , , )M K s
* #*w
q ua
K h
Lecture 7: Turning Machines
Computing with Turing Machine
大同大學資工所智慧型多媒體研究室
Yields in One Step├M
( , , , ).M K s Let
Then, 1 1 1 1 2 2 2 2( , , , ) ( , , , )q w a u q w a u├M
if and only if 1 1 2( , ) ( , )q a q b , where { , }b L R
such that
bw1 a1 u1
w2=w1 a2 u2=u1
b Lw1=w2a2 a1 u1
w2 a2 u2=a1u1
b Rw1 a1 u1=a2u2
w2=w1a1 a2 u2
Used to trace the computation sequence.
Yields*M├
where Ci denotes the configuration of M. We say that co
mputation sequence (1) is of length n or has n steps.
0 1 nC C C
( , , , ).M K s Let is the reflexive, transitive
closure of ├M , i.e., if, for some n 0,
*M├
├M
0 nC C*M├
(1)├M ├M
Turing Computable Functions
Let 0, 1 {#}, and let .
f is said to be a Turing computable function
if
such that, for any ,
* *0 1:f
( , , , )M K s *0w
( )f w u ( , # #) ( , # #)s w h u*M
├
M is, then, said to compute f.
Turing Computable Functions
w
Head
# #
u
Head
# #
Head
( )f w u
( , # #)s w
( , # #)h u
Example
31
( ) 1 , 3
n
m
Y w
f w N w m n
otherwise
Head
# 1 1 1 1 1 1 1 1 1 #
Head
# Y #
Example
31
( ) 1 , 3
n
m
Y w
f w N w m n
otherwise
Head
# 1 1 1 1 1 1 1 1 1 #
Head
# N #
1
Example
31
( ) 1 , 3
n
m
Y w
f w N w m n
otherwise
q0 q1 q11 q2 q21 q3 q31
q7
q6q4
q5
h
> L / # / 1 L / # / 1 L / # / 1
R / #
Y /
R / #
R / #
N /
R /
0 / 00 / 0
0 / 0
0 / 0
L /
HeadHead
# 1 1 1 1 1 1 1 1 1 #1
Exercise
q0 q1 q11 q2 q21 q3 q31
q7
q6q4
q5
h
> L / # / 1 L / # / 1 L / # / 1
R / #
Y /
R / #
R / #
N /
R /
0 / 00 / 0
0 / 0
0 / 0
L /
2. Write the state transition table.
Discussion
Three main usages of machines:– Compute– Decision– Accept
See textbooks for the definitions of– Turing decidability– Turing acceptability
Lecture 7: Turning Machines
Turing-Machine Programming
大同大學資工所智慧型多媒體研究室
Simplified Notation
q0 q1 q11 q2 q21 q3 q31
q2
q6q4
q5
h
> L / # / 1 L / # / 1 L / # / 1
R / #
Y /
R / #
R / #
N /
# /
0 / 00 / 0
0 / 0
0 / 0
L /
q0 q1 q11 q2 q21 q3 q31
q2
q6q4
q5
h
> L / # / 1 L / # / 1 L / # / 1
R / #
Y /
R / #
R / #
N /
# /
0 / 00 / 0
0 / 0
0 / 0
L /
>L #L1 #L1 #1
RYR
#
RNR
# #
0
00 0
0
Basic Turing-Machines
1. || symbol-writing machines:
2. Head-moving machines
Print a q0 h> a/
Move Left
RMove ight
q0 h> L/
q0 h> R/
>a
>L
>R
Combining Rules
>M1
>M2
>M3
q10 h?/?q1m>q30 h> ?/?q3p
1. >M1 M2 >M1M2
q20 h?/?q2nq10
?/?q1m>
q20 h?/?q2n>
2. 1>M 2M
3M
a
b q10 q1h?/?q1m> q20 h?/?q2n
a/a
q30
?/?
q3p
b/b
Lecture 7: Turning Machines
Some Example of Powerful TMs
大同大學資工所智慧型多媒體研究室
Some Powerful TMs
>R #
>R #
>L #
>L #
#>R1.
#>R2.
#>L3.
#>L4.
Abbreviation
={a,b,c,#}
>R R
ab
c
#
>R Ra, b, c, # >RR
Example: (Copier)
: # # # # #Copy w w w*M├
Head
# a b c #
Head
# #a b c a b c#
Example: (Copier)
: # # # # #Copy w w w*M├
# a b c #
# a b c #
# a b c #
# # b c #
# # b c # a
# # b c # a
# a b c # a
# a b c # a
# # b c # # >L# R #R# R#sL# L#s
R#
s #
#
Example: (Shift-Left)
- : # # #Left Shift w w*M├
Head
# a b c #
Head
a b c #
Example: (Shift-Left)
- : # # #Left Shift w w*M├
# a b c #
# a b c #
# a b c #
# a b c #
a a b c #
a a b c #
a b b c #
a a b c #
…
>L# R LsR
L#
s #
#
Example: (Palindrome)
# #: # #
# #
Y w LPalindrome w
N w L
*M├
*0 : RL w w w
Head
# a b b #a
Head
Y ##
Example: (Palindrome)
# #: # #
# #
Y w LPalindrome w
N w L
*M├
*0 : RL w w w
Head
# a b a #a
Head
N ##
Example: (Palindrome)
# #: # #
# #
R
R
Y w wPalindrome w
N w w
*M├
# a b b a ## # a b b a #
# # a b b a #
a # a b b a #
a # a b b a #
a # # b b a #
a # # b b a #
a # # b b a #
a # # b b # #
a # # b b # #
a # a b b a #
…
(SR)
>SRL# LaRR #R# L #L#
L# #RYR
L# #RNR
#L
# # , #t s
#s s
#
Exercises
- : # # ## #Shift Right w w3.
: # # # # #RMirror w w w4.
Exercises
Y: # #
N
n n n
n n n
w a b cTrinity w
w a b c
5.
: # # # #Increase w v6.where w and v are strings of decimal numbers such that
( ) ( ) 1val v val w
Lecture 7: Turning Machines
Extensions of the TM
大同大學資工所智慧型多媒體研究室
Extensions of the TM
Standard TM
2-way TM
k-tape (1-way) TM
Nondeterministic TM
1-way TM
Deterministic TM’s
( , ) ( , )q a p b
Two-Way Infinite Tape
w a u
Head ##
or( , , , ) ( , )q w a u q wau
Memory Configuration
Lemma
1 1 1 1 1, , ,M K s a two-way TM
one-way TM that simulates
M1 as follows:
2 2 2 2 2, , ,M K s
1( , #) ( , )s w h uav1.1
*M├ 2( , # #) ( , # )s w h uav*
M├
2. M1 does not halt M2 does not halt.
#
Proof
simulates
1 1 1 1 1, , ,M K s
2 2 2 2 2, , ,M K s
3 2 1 0 1 2 3
$0
11
22
33
4
##M1
M2
Proof
simulates
1 1 1 1 1, , ,M K s
2 2 2 2 2, , ,M K s
###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
2 ?K
2 ? 2 ?
2 ?s
Proof
simulates
1 1 1 1 1, , ,M K s
2 2 2 2 2, , ,M K s
###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
2 1 { } 1,2K K h
E.g., 1 0 1 2, ,K q q q
0 0
1 12
2 2
,1 , 2
,1 ,2
,1 ,2
,1 ,2
q q
q qK
q q
h h
Proof
simulates
1 1 1 1 1, , ,M K s
2 2 2 2 2, , ,M K s
###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
2 1 1 1 1 1 1 1$
Mark left end
Final
Operations
Head onlower track
Head onupper track
Mark halt configuration
Proof
simulates
1 1 1 1 1, , ,M K s
2 2 2 2 2, , ,M K s
###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
2 1 1 1 1 1 1 1$
1 0,1,# 2
(0,0), (0,1), (0,#),
(1,0), (1,1)
(0, 0), (0, 1), (0, #),
(1, 0), (1
(0,0), (0,1), (0, #),
(1,0), (1,1), (1,#),
(#,
, (1, #),
(#,0), (#,1), (#,
, 1), (1, #),
(#, 00), (#,1), ), (#, 1), (
$,0,1, #
#, #)(
,
#, #) ,# , )
E.g.,
Proof ###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
1. M2 simulates the input for M1 into M2 in the following way:
a b c b b c bM1#
Head
$a#
M2b#
c#
b#
b#
c#
b#
#
#
Headg
1 1: ( , #) ,1 , $ (#,#)#
wg s w s
s 2
Proof ###
3 2 1 0 1 2 3 3 2 1 0 1 2 3
$0
1
1
2
2
3
3
4 0
1
1
2
2
3
3
4
##M1
M2
1. M2 simulates the input for M1 into M2 in the following way:
2. Simulate the operations of M1 on M2.3. When M2 would halt, restore the tape to “single track”
format by M1.
a b c b b c bM1#
Head
$a#
M2b#
c#
b#
b#
c#
b#
#
#
Headg
Proof
1 0 1 1 0 0 1M1#
Head
0 1 2 3 412
$1
0M2
1
1
0
#
0
#
1
#
Head
#
1. Simulate M1 on upper track:
1 1, ,q a p b
Simulate the operations of M1 on M2.
2Determine
2 1
2 1 2
,1 , ,
,1 , , ,1 ,
,1 ,
p b a b
q a a p L b L
p R b R
Proof
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2. Simulate M1 on lower track:
1 2, ,q a p b
Simulate the operations of M1 on M2.
2Determine
1 1
2 1 2
, 2 , ,
, 2 , , , 2 ,
, 2 ,
p a b b
q a a p R b L
p L b R
1 0 1 1 0 0 1M1#
Head
0 1 2 3 41213
Proof
$1
0M2
1
1
0
1
0
#
1
#
Head
#
3. Change track:
Simulate the operations of M1 on M2.
2Determine
2 ,1 ,$ ,2 ,q q R
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2 , 2 ,$ ,1 ,q q R
Proof
4. Extend the tape to the right:
Simulate the operations of M1 on M2.
2Determine
2 ,1 , # ,1 , (#,#)q q
$1
0M2
1
1
0
1
0
#
1
#
Head
#
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2 , 2 , # ,2 , (#,#)q q
Proof
4. Extend the tape to the right:
Simulate the operations of M1 on M2.
2Determine
2 ,1 , # ,1 , (#,#)q q
$1
0M2
1
1
0
1
0
#
1
#
Head
#
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2 , 2 , # ,2 , (#,#)q q
#
#
#
#
Proof
5. Halt and record head position:
Simulate the operations of M1 on M2.
2Determine
2 1 2 1 2,1 , ( , ) ,1 , ( , )h a a h a a
$1
0M2
1
1
0
1
0
#
1
#
Head
#
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2 1 2 1 2, 2 , ( , ) , 2 , ( , )h a a h a a
Proof
5. Halt and record head position:
Simulate the operations of M1 on M2.
2Determine
2 1 2 1 2,1 , ( , ) ,1 , ( , )h a a h a a
$1
0M2
1
1
0
1
0
#
1
#
Head
#
$1
0M2
1
1
0
1
0
#
1
#
Head
#
2 1 2 1 2, 2 , ( , ) , 2 , ( , )h a a h a a
Proof1. M2 simulates the input for M1 into M2 in the following
way:
2. Simulate the operations of M1 on M2.3. When M2 would halt, restore the tape to “single track”
format by M1.
a b c b b c bM1#
Head
$a#
M2b#
c#
b#
b#
c#
b#
#
#
Headg
Proof1. M2 simulates the input for M1 into M2 in the following
way:
2. Simulate the operations of M1 on M2.3. When M2 would halt, restore the tape to “single track”
format by M1.
a b c b b c bM1#
Head
$a#
M2b#
c#
b#
b#
c#
b#
#
#
Headg
$1
0M2
1
1
0
1
0
#
1
#
Head
#
#M2 #1 1 0 1 1 0 0 1
Head
Lemma
1 1 1 1 1, , ,M K s a two-way TM
one-way TM that simulates
M1 as follows:
2 2 2 2 2, , ,M K s
1( , #) ( , )s w h uav1.*M├ 2( , # #) ( , # )s w h uav*
M├
2. M1 does not halt M2 does not halt.
Theorem
Any function that is computed or
language that is decided or accepted by
a two-way Turing Machine is also
computed, decided or accepted by a
standard Turing Machine.
k-Tape TM
Usually for I/O
Usually for working memory
Head
Head
Head
. . .
MemoryConfiguration 1 1 1 2 2 2, , , , k k kq w a u w a u w a u
Example (Duplicate)
: # # # # #Duplicate w w w
w# #
#
w# #
#
w# #
# w #
w# #
# w #
w# #
# w #
w #
(1)#L (2)# (1) (2)R R (2)s
(2)#L (2)R (1) (1)s R
(1) #s
(2) #s
(1)#
LemmaM1: k-tape TM, k > 0
: alphabet of M1
s1: initial state
Standard TM 2 2 2 2, , ,K s
such that
1. M1 halts on input w, i.e., 1, # #, #, , #s w 1
*M├ 1 1 1, , , k k kh w a u w a u
Then, for M2, 2 , # #s w2
*M├ 1 1 1,h w a u
2. M1 hangs on w M2 too.
3. M1 neither halts nor hangs on w M2 too.
Theorem
Any function that is computed or
language that is decided or accepted by
a k-tape Turing machine is also
computed, decided or accepted by a
standard Turing machine.
Lecture 7: Turning Machines
Nondeterministic Turing Machine
大同大學資工所智慧型多媒體研究室
NTM Definition
A Turing machine is a quadruple( , , , )K s K: finite set of states, hK.
: alphabet, #, L, R.
s: sK, initial state.
: transition function
{ { , }}K h L RK
The same as standard TM.
Transition Function
{ { , }}K h L RK
E.g.,
1 1 2 2( , ) ( , ), ( , ), , ( , )r rq a p b p b p b
K
. . . . . . . . . . . . . .a
. . . . .
. . . . .
q1 1
2 2
( , )
( , )
( , )r r
p b
p b
p b
p1
p2
pr
aa
a
q
Language Acceptance by an NTM
NTM is usually used as a language acceptor.
A language, say, L can be accepted by an NTM if, given any input w L, there exists a computation sequence which can lead the NTM to a halt state.
Example
*{ , } contains substring L w a a bb w bba a regular language
Head
# a b #b a b
Head
# a b #a a a
There is a terminating path.
There is no a terminating path.
Example
*{ , } contains substring L w a a bb w bba a regular language
Head
# a b #b a b
HeadHead
# a b #b a b
L
a, b
L L L L ab a b b a
#
# b, # a, # a, # b, #
Example
is a composite numbernL I n
n is a composite number iff
2 such that
2
pn pq
q
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPEGenerate p 2
Generate q 2
Compute m = pq
Compare m and n
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
G: generate a random number larger than 2.
>RIR IR ##
#
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
G: generate a random number larger than 2.
I I #
p = 2
>RIR IR ##
#
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
G: generate a random number larger than 2.
I I # I I I I I #
p = 2 q = 5
>RIR IR ##
#
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
P: product
I I # I I I I I #
p = 2 q = 5
: # # # # #p q pqP I I I
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
P: product
I I #
m = pq = 10
: # # # # #p q pqP I I I
I I I I I I I I
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
P: product
I I #
m = pq = 10
: # # # # #p q pqP I I I
I I I I I I I I
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
E: equivalence
I I #
m = pq = 10
: # # #m n halt m nE I I
m n
I I I I I I I I
Example
is a composite numbernL I n
L can be accepted by the NTM
>GGPE# I I I I I I I I I I #
Head
n = 10
I I #
m = pq = 10
I I I I I I I I
n is a composite number iff2
such that 2
pn pq
q
Lemma
For every NTM , we can
construct a standard TM such that for any
1 1 1 1( , , , )M K s
2M *
1 #w
1. if M1 halts on w, then M2 is also so;
2. if M1 does not halts on w, then M2 is also not.
Proof1 1 1 1( , , , )M K s
2 ?M
K1
1
. . . . . . . . . . . . . .a
. . . . .
. . . . .
q1 1
2 2( , )
( , )
( , )
( , )
q a
k k
p b
p bA
p b
1 { , }L R
1 { }K h
( , ) 1 11 2q aA K r ( , ) 1 11 2q aA K r
Numbering:
p1
p2
p3
a
a
a
q
( , ) 3, 10q aA r
1
2
3, 4, …,10
Proof1 1 1 1( , , , )M K s
2 ?M
Computation path indexing
>
d1
d2
d3
d1
d2
d1
d2
d3
d4
Proof1 1 1 1( , , , )M K s
2 ?M
An computation path (#d2d1d4#)
>
d1
d2
d3
d1
d2
d1
d2
d3
d4
Proof1 1 1 1( , , , )M K s
2 ?M
G : computation path generation
## #d1#
#d2#
#dr#
…
#d1d1#
#d1d2#
#d1dr#
…#drdr#
…#d2d1#
#d1d1d1#
#d1d1d2#
#d1drdr#…
#drdrdr#
…#d2d1d1#
#d1d1d1d1#
#d1d1d1d2#
#d1drdrdr#
…
#drdrdrdr#
…#d2d1d1d1#
……
……
…
Proof1 1 1 1( , , , )M K s
2 ?M
# w
Head
#1M
1st tape: never changed.
2nd tape: simulate the computation of M1.
3rd tape: computation path.
# w
Head
#
$ w
Head
#
#
Head
2M #
Proof# w
Head
#1M
# w
Head
#
$ w
Head
#
#
HeadHead
2M 2M #
Copy tape1 to tape 2.
>$(2)R(2)R(3)C M1’ G#(3)
Proof
>$(2)R(2)R(3)C M1’ G#(3)
# w
Head
#1M
# w
Head
#
$ w
Head
#
#
HeadHead
2M 2M #
Copy tape1 to tape 2.
Simulate M1 on tape
2 according to the computation path
depicted on tape 3.
Generate computation
path.
# w’
Head
#1M
# w
Head
#
$ w’
Head
#
#
HeadHead
2M 2M #
d1 d5 d2 d3 d1 d2 #
halt
# w’
Head
#1M
# w
Head
#
$ w’
Head
#
#
HeadHead
2M 2M #
d1 d5 d2 d3 d1 d2 #
Lemma
For every NTM , we can
construct a standard TM such that for any
1 1 1 1( , , , )M K s
2M *
1 #w
1. if M1 halts on w, then M2 is also so;
2. if M1 does not halts on w, then M2 is also not.