Lecture 5: Turning Machine. 虞台文. 大同大學資工所 智慧型多媒體研究室. 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.
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
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
Example • Input a 0/1 sting. • If the numbers of 0 and 1 in the string are botheven, then it is legal; otherwise, it is illegal. • 0011001001(legal) • 11001001001(illegal) • Writing a C program to do so.
Implementation (I) void main() { // Ask user to input a 0/1 string // Store the string into str state = q0; //initialization while(state!=fini){ ToEvent(*str++); EventHandler(event); } } Event (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 } } Event Handler
symbol (event) 0 0 1 <CR> q0 q1 0 q0 1 1 1 1 q1 0 state q2 q2 q3 0 q3 Implementation (II) pq1 pq2 ok pq0 pq3 err pq3 pq0 err err pq2 pq1 The Parser
symbol (event) 0 1 <CR> q0 pq1 pq2 ok q1 pq0 pq3 err state q2 pq3 pq0 err err q3 pq2 pq1 The Parser Implementation (II) #define q0 0 #define q1 1 #define q2 2 #define q3 3 #define fini 4 void pq0(), pq1(), pq2(), pq3(); void ok(), err();
symbol (event) 0 1 <CR> q0 pq1 pq2 ok q1 pq0 pq3 err state q2 pq3 pq0 err err q3 pq2 pq1 The Parser Implementation (II) void pq0() { state = q0; } void pq1() { state = q1; } void pq2() { state = q2; } void pq3() { state = q3; }
symbol (event) 0 1 <CR> q0 pq1 pq2 ok q1 pq0 pq3 err state q2 pq3 pq0 err err q3 pq2 pq1 The Parser Implementation (II) void ok() { printf(”ok\n”); state = fini; } void err() { printf(”error\n”); state = fini; }
symbol (event) 0 1 <CR> q0 pq1 pq2 ok q1 pq0 pq3 err state q2 pq3 pq0 err err q3 pq2 pq1 The Parser typedef void (*FUNCTION)(); FUNCTION parser[4][3]={ pq1, pq2, ok, pq0, pq3, err, pq3, pq0, err, pq2, pq1, err }; Implementation (II)
Implementation (II) void main() { // Ask user to input a 0/1 string // Store the string into str state = q0; //initialization while(state!=fini){ ToEvent(*str++); (*parser[state][event])(); } } Event (or Message) Loop
Hang Head # # Definition A Turing machine is a quadruple K: finite set of states, hK. : alphabet, #, L, R. : transition function s: sK, initial state.
The Transition Function • Change state from q to p. • b printb; • b{L, R} Move head in the direction of b.
a . . . . . . . . . . . . . . . . . . . q K . . . . . The Transition Function
Head # w a u # Memory Configuration or The configuration of a Turing machine is a member of
Head # w a u # Halt Configuration or The configuration of a Turing machine is a member of
├M w1 a1 u1 w1=w2a2 a1 u1 w1 a1 u1=a2u2 w2=w1 a2 u2=u1 w2 a2 u2=a1u1 w2=w1a1 a2 u2 Used to trace the computation sequence. Yields in One Step├M Let Then, if and only if , where such that
├ Let is the reflexive, transitive closure of ├M , i.e., if, for some n 0, ├ ├ ├M ├M ├M (1) Yields where Ci denotes the configuration of M. We say that computation sequence (1) is of length n or has n steps.
Let 0, 1 {#}, and let . f is said to be a Turing computable function if such that, for any , ├ Turing Computable Functions M is, then, said to compute f.
Head w # # Head Head u # # Turing Computable Functions
h R / q5 Y / N / q6 q4 R / # R / # R / # > L / # / 1 L / # / 1 L / # / 1 q0 q1 q11 q2 q21 q3 q31 0 / 0 0 / 0 0 / 0 q7 0 / 0 L / Example
h R / q5 Y / N / q6 q4 R / # R / # R / # > L / # / 1 L / # / 1 L / # / 1 q0 q1 q11 q2 q21 q3 q31 0 / 0 0 / 0 0 / 0 q7 0 / 0 L / Write the state transition table. Exercise
Discussion • Three main usages of machines: • Compute • Decision • Accept • See textbooks for the definitions of • Turing decidability • Turing acceptability
├ Head # a b c # Head # # a b c # a b c Example: (Copier)
├ >L# R #R# R#sL# L#s # R# Example: (Copier) # a b c # # a b c # # a b c # # # b c # # # b c # # # # b c # a # # b c # a # a b c # a # a b c # a
├ Head # a b c # Head a b c # Example: (Left-Shift)
├ >L# R LsR # L# Example: (Left-Shift) # a b c # # a b c # # a b c # # a b c # a a b c # a a b c # a a b c # a b b c # …
Head ├ # a b b # a Head # Y # Example: (Palindrome)
Head ├ # a b a # a Head # N # Example: (Palindrome)
├ >SRL# LaRR #R# L #L# # # #L L# #RNR L# #RYR Example: (Palindrome) # a b b a # # # a b b a # (SR) # # a b b a # 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 # # …