comp20121 the implementation and power of computer
play

COMP20121 The Implementation and Power of Computer Languages Power - PowerPoint PPT Presentation

COMP20121 The Implementation and Power of Computer Languages Power Part http://www.cs.man.ac.uk/ petera/2121/index.html . Peter Aczel room: CS2.52, tel: 56155 petera@cs.man.ac.uk email: School of Computer Science, University of


  1. Transition function Therefore the transition function will take • the current state from Q , • the content of the current cell from T , • and will return • a new state from Q , • a symbol to write onto the tape from T , • a direction from { L, R, N } . A move is one step in that direction. • Alternatively, the machine might stop. COMP20121 - Section 3 – p.149/307

  2. Turing machine Definition 14 A Turing machine or TM over ∈ T ⊇ Σ consists of the tape alphabet • a finite set of states Q ; COMP20121 - Section 3 – p.150/307

  3. Turing machine Definition 14 A Turing machine or TM over ∈ T ⊇ Σ consists of the tape alphabet • a finite set of states Q ; • a start state q • ∈ Q ; COMP20121 - Section 3 – p.150/307

  4. Turing machine Definition 14 A Turing machine or TM over ∈ T ⊇ Σ consists of the tape alphabet • a finite set of states Q ; • a start state q • ∈ Q ; • a set F ⊆ Q of accepting states ; COMP20121 - Section 3 – p.150/307

  5. Turing machine Definition 14 A Turing machine or TM over ∈ T ⊇ Σ consists of the tape alphabet • a finite set of states Q ; • a start state q • ∈ Q ; • a set F ⊆ Q of accepting states ; • a transition function that maps Q × T to ( Q × T × { L, R, N } ) ∪ { stop } . COMP20121 - Section 3 – p.150/307

  6. Comparison: TMs versus PDAs Unlike a pushdown automaton, a Turing machine can • manipulate the input string; COMP20121 - Section 3 – p.151/307

  7. Comparison: TMs versus PDAs Unlike a pushdown automaton, a Turing machine can • manipulate the input string; • process the input string several times; COMP20121 - Section 3 – p.151/307

  8. Comparison: TMs versus PDAs Unlike a pushdown automaton, a Turing machine can • manipulate the input string; • process the input string several times; • write to a random-access memory. COMP20121 - Section 3 – p.151/307

  9. Comparison: TMs versus PDAs Unlike a pushdown automaton, a Turing machine can • manipulate the input string; • process the input string several times; • write to a random-access memory. Like a pushdown automaton, a Turing machine may run forever (on some input strings). COMP20121 - Section 3 – p.151/307

  10. Example We typically give a Turing machine via its transition table. COMP20121 - Section 3 – p.152/307

  11. Example We typically give a Turing machine via its transition table. δ a b For example: 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop COMP20121 - Section 3 – p.152/307

  12. Example We typically give a Turing machine via its transition table. δ a b For example: 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop To see what this machine does with an input string, we first have to define what it means for a TM to accept an input string. COMP20121 - Section 3 – p.152/307

  13. Acceptance of a string by a TM. Definition 15 We say that a string α is accepted by a Turing machine if, when • started in the initial state • with the head positioned on the first (left-most) character of α and • the tape otherwise empty the Turing machine halts and the state at that time is an accepting state. COMP20121 - Section 3 – p.153/307

  14. Example–II Assume that the Turing machine given by the transition table δ a b 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop has only one accepting state, namely 0. COMP20121 - Section 3 – p.154/307

  15. Example–II δ a b 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop Then the language accepted by the machine is COMP20121 - Section 3 – p.155/307

  16. Example–II δ a b 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop Then the language accepted by the machine is the language of all words consisting entirely of a s. COMP20121 - Section 3 – p.155/307

  17. Example–II δ a b 0 (0 , a, R ) (1 , b, R ) stop 1 stop stop stop Then the language accepted by the machine is the language of all words consisting entirely of a s. At the end of the calculation, the input string is untouched. COMP20121 - Section 3 – p.155/307

  18. Example–III Assume that the Turing machine given by the transition table δ a b 0 (0 , , R ) (1 , , R ) stop 1 stop stop stop has only one accepting state, namely 0. COMP20121 - Section 3 – p.156/307

  19. Example–III δ a b 0 (0 , , R ) (1 , , R ) stop 1 stop stop stop Then the language accepted by the machine is COMP20121 - Section 3 – p.157/307

  20. Example–III δ a b 0 (0 , , R ) (1 , , R ) stop 1 stop stop stop Then the language accepted by the machine is the language of all words consisting entirely of a s. COMP20121 - Section 3 – p.157/307

  21. Example–III δ a b 0 (0 , , R ) (1 , , R ) stop 1 stop stop stop Then the language accepted by the machine is the language of all words consisting entirely of a s. At the end of the calculation, the input string has been destroyed. COMP20121 - Section 3 – p.157/307

  22. A more sophisticated example Consider the following Turing machine with only accepting state 0. δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 COMP20121 - Section 3 – p.158/307

  23. A more sophisticated example Consider the following Turing machine with only accepting state 0. δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 What is the language accepted by this Turing machine? COMP20121 - Section 3 – p.158/307

  24. A more sophisticated example Consider the following Turing machine with only accepting state 0. δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 What is the language accepted by this Turing machine? Not so easy! COMP20121 - Section 3 – p.158/307

  25. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a b a b a . . . COMP20121 - Section 3 – p.159/307

  26. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  27. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  28. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  29. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  30. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  31. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b a . . . COMP20121 - Section 3 – p.159/307

  32. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b . . . COMP20121 - Section 3 – p.159/307

  33. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b . . . COMP20121 - Section 3 – p.159/307

  34. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b . . . COMP20121 - Section 3 – p.159/307

  35. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b . . . COMP20121 - Section 3 – p.159/307

  36. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . b a b . . . COMP20121 - Section 3 – p.159/307

  37. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a b . . . COMP20121 - Section 3 – p.159/307

  38. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a b . . . COMP20121 - Section 3 – p.159/307

  39. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a b . . . COMP20121 - Section 3 – p.159/307

  40. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a b . . . COMP20121 - Section 3 – p.159/307

  41. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a . . . COMP20121 - Section 3 – p.159/307

  42. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a . . . COMP20121 - Section 3 – p.159/307

  43. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . a . . . COMP20121 - Section 3 – p.159/307

  44. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . . . . COMP20121 - Section 3 – p.159/307

  45. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . . . . COMP20121 - Section 3 – p.159/307

  46. Running a Turing machine δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 . . . . . . Hence the word ababa is accepted by the machine. COMP20121 - Section 3 – p.159/307

  47. Configurations We use a configuration x 1 x 2 · · · x i qx i +1 · · · x n to describe a situation where COMP20121 - Section 3 – p.160/307

  48. Configurations We use a configuration x 1 x 2 · · · x i qx i +1 · · · x n to describe a situation where • the content of the tape is x 1 · · · x n (where the x j are from T ), and all cells to the left of x 1 and to the right of x n are blank; COMP20121 - Section 3 – p.160/307

  49. Configurations We use a configuration x 1 x 2 · · · x i qx i +1 · · · x n to describe a situation where • the current state is q ; • the head currently points at the cell holding x i +1 . COMP20121 - Section 3 – p.160/307

  50. Configurations We use a configuration x 1 x 2 · · · x i qx i +1 · · · x n to describe a situation where Control unit State: q · · · · · · · · · · · · x 1 x 2 x i x i +1 x n COMP20121 - Section 3 – p.160/307

  51. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 0 ababa . . . a b a b a . . . COMP20121 - Section 3 – p.161/307

  52. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 1 baba . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  53. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 b 1 aba . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  54. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 ba 1 ba . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  55. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 bab 1 a . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  56. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 baba 1 . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  57. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 bab 3 a . . . b a b a . . . COMP20121 - Section 3 – p.161/307

  58. Running a Turing machine–II δ a b (1 , , R ) (2 , , R ) 0 stop (1 , a, R ) (1 , b, R ) (3 , , L ) 1 (2 , a, R ) (2 , b, R ) (4 , , L ) 2 (5 , , L ) (0 , , N ) 3 stop (5 , , L ) (0 , , N ) 4 stop (5 , a, L ) (5 , b, L ) (0 , , R ) 5 ba 5 b . . . b a b . . . COMP20121 - Section 3 – p.161/307

Recommend


More recommend