turing machines
play

Turing Machines Wen-Guey Tzeng Computer Science Department - PowerPoint PPT Presentation

Turing Machines Wen-Guey Tzeng Computer Science Department National Chiao Tung University Alan Turing One of the first to conceive a machine that can run computation mechanically without human intervention. We call algorithmic


  1. Turing Machines Wen-Guey Tzeng Computer Science Department National Chiao Tung University

  2. Alan Turing • One of the first to conceive a machine that can run computation mechanically without human intervention. We call “ algorithmic computation ” now. • The first to conceive a universal 1912-1954 machine – that can run programs • Break German Enigma Machine (encryption) in WWII • Turing Award: the most prestigious award in CS • Bio movie: The Imitation Game, 2015 2017 Spring 2

  3. TM Model 2017 Spring 3

  4. Definition • A Turing machine (TM) M is defined by M=(Q,  ,  ,  , q 0 , ฀ , F) – Q: the set of internal states –  : the input alphabet –  : the tape alphabet –  : Q   Q  {L,R}, the transition function – ฀ : blank symbol – q 0  Q: the initial state – F  Q: the set of final states • Note: this TM is deterministic. 2017 Spring 4

  5. Transition function  •  (q 0 , a)=(q 1 , d, R) 2017 Spring 5

  6. Example: • M=({q 0 , q 1 }, {a,b}, {a, b, ฀ },  , q 0 , ฀ , {q 1 }) –  (q 0 , a)=(q 0 , b, R) –  (q 0 , b)=(q 0 , b, R) –  (q 0 , ฀ )=(q 1 , ฀ , L) 2017 Spring 6

  7. Transition graph –  (q 0 , a)=(q 0 , b, R) –  (q 0 , b)=(q 0 , b, R) –  (q 0 , ฀ )=(q 1 , ฀ , L) 2017 Spring 7

  8. TM runs forever • Check TM on input aab 2017 Spring 8

  9. Instantaneous description • x 1 qx 2 = a 1 a 2 …a k-1 q a k a k+1 …a n • Also, called “configuration” 2017 Spring 9

  10. Example: • M=({q 0 , q 1 }, {a,b}, {a, b, ฀ },  , q 0 , ฀ , {q 1 }) –  (q 0 , a)=(q 0 , b, R) –  (q 0 , b)=(q 0 , b, R) –  (q 0 , ฀ )=(q 1 , ฀ , L) • ID: q 0 aa, bq 0 a , bbq 0 ฀ , bq 1 b • Move: – q 0 aa ├ bq 0 a ├ bbq 0 ฀ ├ bq 1 b (halt) 2017 Spring 10

  11. TM halts • A TM on input w “halts” if q 0 w reaches a configuration that  is not defined. – A TM on an input w may not halt. (Run forever) • Halting configuration: x 1 qx 2 (halt) – Halting does not imply acceptance • Accepting configuration: x 1 q f x 2 ( halt ) – Must halt and enter a final state q f – Acceptance implies halting • Infinite loop (non-stop): x 1 qx 2 ├ *  2017 Spring 11

  12. A computation • A computation is a sequence of configurations that leads to a halt state. • q 0 aa ├ bq 1 b ├ bbq 1 ฀ ├ bq 1 b (halt) 2017 Spring 12

  13. Standard TM • It is deterministic. • There is only one tape. • The tape is unbounded in both directions. • All other cells are filled with blanks. • No output devices. • The input is on the tape in the beginning. • The left string on the tape can be viewed as output. 2017 Spring 13

  14. TM as • Language acceptors • Transducers 2017 Spring 14

  15. TM as language acceptors • A string w is accepted by M if – M on input w enters a final state and halts. – Note: no need to read the entire input • The language accepted by M L(M)={w  + : q 0 w ├ * x 1 q f x 2 (halt), q f  F, x 1 , x 2  * } – x 1 q f x 2 (halt) is a halt configuration. • A language accepted by some TM is called a “ recursively enumerable (r.e.) ” set. 2017 Spring 15

  16. Example: • Design a TM to accept the strings of form 00* • The transition function –  (q 0 , 0)=(q 1 , 0, R) –  (q 1 , 0)=(q 1 , 0, R) –  (q 1 , ฀ )=(q 2 , ฀ , R) • F={q 2 } 2017 Spring 16

  17. Example: • Design a TM to accept L={a n b n : n  1} • Idea: – Loop • Mark leftmost ‘a’ as ‘x’ in the tape • Move all the way right to mark ‘b’ as ‘y’ – After marking all a’s, move all the way right to find ฀ 2017 Spring 17

  18. • Example, w=aabb • Mark leftmost ‘a’ as ‘x’ in the tape –  (q 0 , a)=(q 1 , x, R) • Move all the way right to mark ‘b’ as ‘y’ –  (q 1 , a)=(q 1 , a, R) –  (q 1 , y)=(q 1 , y, R) –  (q 1 , b)=(q 2 , y, L) ฀ ฀ . . . a a b b . . . 2017 Spring 18

  19. • Move back to find leftmost ‘a’ –  (q 2 , y)=(q 2 , y, L) –  (q 2 , a)=(q 2 , a, L) –  (q 2 , x)=(q 0 , x, R) • Repeat until all a’s are marked as x’s ฀ ฀ . . . x a y b . . . 2017 Spring 19

  20. • After marking all a’s as x’s, move all the way right to find ฀ –  (q 0 , y)=(q 3 , y, R) –  (q 3 , y)=(q 3 , y, R) –  (q 3 , ฀ )=(q 4 , ฀ , R) – If ‘b’ is encountered during the action of moving right, TM halts on a non-final state. ฀ ฀ . . . x x y y . . . 2017 Spring 20

  21. Example: • Design a TM to accept L={w  {a,b} + : n a (w)=n b (w)} • Idea: – Loop • Pose at the beginning of the string • Mark leftmost ‘a’ as ‘x’ in the tape • Move all the way right to find the first b and mark it as – After marking all symbols as X, enter the final state 2017 Spring 21

  22. TM as transducers • To compute a function f(w)=w’, where w, w’ are strings – q 0 w ├ * q f w’ (halt) • A function f:D  R is TM-computable if there is a TM M=(Q,  ,  ,  , q 0 , ฀ , F) such that q 0 w ├ * q f f(w) (halt) for all w  D • We will show in the following that TM can compute complicated functions 2017 Spring 22

  23. Example: (integer adder) • Given two positive integer x and y, compute x+y – x and y are unary-represented • Eg. X=3, w(x)=111 – Input: w(x) 0 w(y) – Output: w(x+y) 0 – That is, q 0 w(x)0w(y) ├ q f w(x+y)0 2017 Spring 23

  24. • The transition function •  (q 0 , 1)=(q 0 , 1, R) •  (q 0 , 0)=(q 1 , 1, R) •  (q 1 , 1)=(q 1 , 1, R) •  (q 1 , ฀ )=(q 2 , ฀ , L) •  (q 2 , 1)=(q 3 , 0, L) •  (q 3 , 1)=(q 3 , 1, L) •  (q 3 , ฀ )=(q 4 , ฀ , R) • Run q 0 111011 2017 Spring 24

  25. Example: (string copier) • Design a TM to compute q 0 w ├ * q f ww, w=1 + • Steps 1. Replace every 1 by x 2. Find the rightmost x and replace it with 1 3. Travel to the right end and create 1 (in replace of ฀ ) 4. Repeat 2 and 3 until there are no x’s 2017 Spring 25

  26. Run q 0 11 2017 Spring 26

  27. Examples: (comparer) • Design a TM to compute q 0 w(x)0w(y) ├ * q Y w(x)0w(y) if x  y q 0 w(x)0w(y) ├ * q N w(x)0w(y) if x<y 2017 Spring 27

  28. Combining TM for complicated tasks • Design a TM to compute f(x,y)=x+y if x  y, and f(x,y)=0 if x<y 2017 Spring 28

  29. • q C,0 w(x)0w(y) ├ * q A,0 w(x)0w(y) if x  y ├ * q E,0 w(x)0w(y) if x<y • q A,0 w(x)0w(y) ├ * q A,f w(x+y)0 • q E,0 w(x)0w(y) ├ * q E,f 0 2017 Spring 29

  30. Example: (if-then-else) • if a then q j else q k –  (q i , a)=(q j0 , a, R), for q i  Q –  (q j0 , c)=(q j , c, L), for all c  –  (q i , b)=(q k0 , b, R) for b  -{a} –  (q k0 , c)=(q k , c, L), for all c  2017 Spring 30

  31. Example: (integer multiplier) • Design a TM for q 0 w(x)0w(y) ├ * q f w(xy) • Steps – Loop until x contains no more 1’s • Find a 1 in x and replace it with another a • Replace leftmost 0 by 0y – Replace all a’s with 1’s 2017 Spring 31

  32. 2017 Spring 32

  33. Macroinstructions  subprogram • A calls B 2017 Spring 33

  34. Turing’s Thesis • Mechanical computation – Computation without human intervention • Turing Thesis: any computation that can be carried out by mechanical means can be carried out by some Turing machine. • Also called “Church-Turing Thesis” 2017 Spring 34

  35. • Reasoning: – Anything that can be done by an existing digital computer can be done by a TM – No one has yet been able to suggest a problem, solvable by algorithms, but cannot be solved by some TM – Other models are proposed. But, they are no more powerful than TM’s. • Even quantum computers are no more powerful than TM’s in terms of the power language acceptance 2017 Spring 35

  36. Algorithms • An algorithm for a functin f:D  R is a TM such that q 0 d ├ * q f f(d) for all d  D 2017 Spring 36

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend