1 / 101

Lecture 5: Turning Machine

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.

dmitri
Télécharger la présentation

Lecture 5: Turning Machine

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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 5: Turning Machine 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. Lecture 5: Turning Machine The Definition of Turing Machine 大同大學資工所 智慧型多媒體研究室

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

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

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

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

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

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

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

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

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

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

  29. Head Head Example # 1 1 1 1 1 1 1 1 1 # Y # #

  30. Head Head Example # 1 1 1 1 1 1 1 1 1 # 1 N # #

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

  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 / Write the state transition table. Exercise

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

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

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

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

  37. > > > ?/? ?/? ?/? 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

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

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

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

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

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

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

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

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

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

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

  48. ├ 1. 2. Exercises

  49. Lecture 5: Turning Machine Extensions of the TM 大同大學資工所 智慧型多媒體研究室

  50. Extensions of the TM 1-way TM Standard TM Deterministic TM’s 2-way TM k-tape (1-way) TM Nondeterministic TM

More Related