Download
lecture 7 turning machines n.
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 7: Turning Machines PowerPoint Presentation
Download Presentation
Lecture 7: Turning Machines

Lecture 7: Turning Machines

291 Vues Download Presentation
Télécharger la présentation

Lecture 7: Turning Machines

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture 7: Turning Machines 虞台文 大同大學資工所 智慧型多媒體研究室

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

  3. Lecture 7: Turning Machines An Overview on Finite State Machine 大同大學資工所 智慧型多媒體研究室

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

  5. 0 q0 q1 0 1 1 1 1 0 q2 q3 0 Finite State Machine Examples: 00100011<CR> 01101011<CR> 001010101<CR> 0010010101<CR>

  6. symbol (event) 0 0 1 <CR> q0 q1 0 q0 1 1 1 1 q1 0 state q2 q2 q3 0 q3 Finite State Machine q1 q2 ok q0 q3 err q3 q0 err err q2 q1 The Parser

  7. symbol (event) 0 1 <CR> q0 q1 q2 ok q1 q0 q3 err state q2 q3 q0 err err q3 q2 q1 The Parser Implementation (I) #define q0 0 #define q1 1 #define q2 2 #define q3 3 #define fini 4

  8. symbol (event) 0 1 <CR> q0 q1 q2 ok q1 q0 q3 err state q2 q3 q0 err err q3 q2 q1 The Parser Implementation (I) int parser[4][3]={ q1, q2, fini, q0, q3, fini, q3, q0, fini, q2, q1, fini }; int state=q0; int event; char* str;

  9. Implementation (I) void ToEvent(char c) { if(c == ’0’) event = 0; else if(c == ’1’) event = 1; else event = 2; } Event (or Message) Encoding

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

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

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

  13. 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();

  14. 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; }

  15. 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; }

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

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

  18. Exercise • 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.

  19. Lecture 7: Turning Machines The Definition of Turing Machine 大同大學資工所 智慧型多媒體研究室

  20. Hang Head # # Definition A Turing machine is a quadruple K: finite set of states, hK. : alphabet, #, L, R. : transition function s: sK, initial state.

  21. The Transition Function • Change state from q to p. • b  printb; • b{L, R}  Move head in the direction of b.

  22. a  . . . . . . . . . . . . . . . . . . . q K . . . . . The Transition Function

  23. Head  # w a u # Memory Configuration or The configuration of a Turing machine is a member of

  24. Head  # w a u # Halt Configuration or The configuration of a Turing machine is a member of

  25. Lecture 7: Turning Machines Computing with Turing Machine 大同大學資工所 智慧型多媒體研究室

  26. ├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

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

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

  29. Head w # # Head Head u # # Turing Computable Functions

  30. Head Head Example # 1 1 1 1 1 1 1 1 1 # Y # #

  31. Head Head Example # 1 1 1 1 1 1 1 1 1 # 1 N # #

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

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

  34. Discussion • Three main usages of machines: • Compute • Decision • Accept • See textbooks for the definitions of • Turing decidability • Turing acceptability

  35. Lecture 7: Turning Machines Turing-Machine Programming 大同大學資工所 智慧型多媒體研究室

  36. RYR RNR # # # >L #L # #L 1 1 1 0 0 0 0 0 Simplified Notation

  37. > > > a/ L/ R/ q0 q0 q0 h h h Basic Turing-Machines • ||symbol-writing machines: • Head-moving machines

  38. > > > ?/? ?/? ?/? q10 q20 q10 q1m q2n q1m h h q1h > ?/? q30 q3p h a 2. b a/a ?/? q20 q2n h > ?/? ?/? q10 q1m q20 q2n h b/b ?/? q30 q3p Combining Rules >M1 >M3 >M2 1. >M1 M2 >M1M2

  39. Lecture 7: Turning Machines Some Example of Powerful TMs 大同大學資工所 智慧型多媒體研究室

  40. 1. 3. >R >L 2. 4. >R >L Some Powerful TMs

  41. a b >R R >R R a, b, c, # c # Abbreviation >RR

  42. Head # a b c # Head # # a b c # a b c Example: (Copier)

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

  44. Head # a b c # Head a b c # Example: (Shift-Left)

  45. >L# R LsR # L# Example: (Shift-Left) # 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 # …

  46. Head ├ # a b b # a Head # Y # Example: (Palindrome)

  47. Head ├ # a b a # a Head # N # Example: (Palindrome)

  48. >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 # # …

  49. 4. Exercises

  50. 5. 6. Exercises where w and v are strings of decimal numbers such that