Presentation is loading. Please wait.

Presentation is loading. Please wait.

Turing Machines CS 130 Theory of Computation HMU Textbook: Chap 8.

Similar presentations


Presentation on theme: "Turing Machines CS 130 Theory of Computation HMU Textbook: Chap 8."— Presentation transcript:

1 Turing Machines CS 130 Theory of Computation HMU Textbook: Chap 8

2 Models of computation Finite automata and regular expressions Represent regular languages Can’t “count” Grammars and pushdown automata Represent context free languages Can count and remember symbols once Turing machines Represent recursive and recursively enumerable languages Model contemporary programs

3 Turing Machine Model Input tape surrounded by infinitely many blanks Tape head can move back and forth the tape and replace current symbol TM BBBBBBB000111BBBBB ……

4 TM definition A Turing Machine M is a tuple M = (Q, , , , q 0, B, F), where: Q is a set of states  is the input alphabet  is the tape alphabet =   {B}  other tape symbols  : Q    Q    D is the state transition function mapping (state, symbol) to (state, symbol, direction); D = { ,  };  may be undefined for some pairs q 0 is the start state of M B is the blank symbol (default symbol on input tape) F  Q is the set of accepting states or final states of M (if applicable)

5 TM that accepts 0 n 1 n Q={q 0,q 1,q 2,q 3,q 4 },  ={0,1},  ={0,1,B,Y}  defined as follows:  (q 0,0) = (q 1,B,  )erase leftmost 0  (q 1,0) = (q 1,0,  )move to right until a 1  (q 1,Y) = (q 1,Y,  )is encountered, replace  (q 1,1) = (q 2,Y,  )that 1 with Y  (q 2,Y) = (q 2,Y,  )move to left until a blank  (q 2,0) = (q 2,0,  )is encountered, then go  (q 2,B) = (q 0,B,  )back to initial state  (q 0,Y) = (q 3,Y,  )if Y on tape go to state 3  (q 3,Y) = (q 3,Y,  )ensure only Y’s remain on tape  (q 3,B) = (q 4,B,  )accept once B is seen (F={q 4 })

6 TM that accepts 0 n 1 n q0q0 q4q4 q3q3 q2q2 q1q1 0,B,  Y,Y,  0,0,  1,Y,  Y,Y,  0,0,  B,B,  Y,Y,  B,B, 

7 TM that increments a bit-string Q={q 0,q 1,q 2,q 3 },  ={0,1},  ={0,1,B,X}  defined as follows:  (q 0,0) = (q 0,0,  )go to rightmost  (q 0,1) = (q 0,1,  )non-blank  (q 0,B) = (q 1,B,  )  (q 1,1) = (q 1,0,  )replace 1’s with 0’s  (q 1,0) = (q 2,1,  )until 0/B is encountered,  (q 1,B) = (q 2,1,  )replace that 0/B with a 1 No applicable transitions from q 2 means the turing machine halts

8 TM that increments a bit-string q0q0 q2q2 q1q1 0,0,  B,B,  B,1,  0,1,  1,1,  1,0,  go to the rightmost non-blank move to the left, replacing 1s with 0s once a B or 0 is encountered, replace it with a 1

9 Instantaneous descriptions Instantaneous description (ID): depicts the characteristics of the machine as transitions are carried out For finite automata, the state of the machine and the remaining input is sufficient For TM’s, the following are needed for an ID: State Symbols on the tape Position of the tape head Can be expressed as X 1 X 2 …X i-1 qX i X i+1 …X n which means the TM is in state q, the tape contains X 1 X 2 …X n and the tape head is at X i

10 ID example Suppose for the first TM example, the input is 0011 The initial ID is q 0 0011 After applying the transition  (q 0,0) = (q 1,B,  ), ID: q 1 011 Depict this as a move: q 0 0011 |  q 1 011 Next 3 transitions:  (q 1,0) = (q 1,0,  ), ID: 0q 1 11  (q 1,1) = (q 2,Y,  ), ID: q 2 0Y1  (q 2,0) = (q 2,0,  ), ID: q 2 B0Y1 Eventually, ID will be YYBq 4 (TM accepts)

11 TM as recognizer A TM accepts a string w if there exists a sequence of moves from ID q 0 w to ID uq f v (u,v   *, q f  F) q 0 w |  * uq f v In the previous example, q 0 0011 |  * YYBq 4 Given a TM M, L(M) is the set of all strings that M accepts A language recognized by a TM is called a recursively enumerable language

12 TM halting on input TMs are also useful for computation In this case, what is important is the machine halts on input w (and leaves the appropriate output on the tape) A TM halts on input w if there exists a sequence of moves from ID q 0 w to ID uq i xv (u,v  *, x , q i  Q) &  (q i,x) is undefined (no transition applies) The TM can be viewed as a function; f(w) = uxv

13 TM as decider It could be arranged so that the TM either leaves a YES or a NO on the input tape after processing an input string YES means accept, NO means reject The TM decides whether a string is acceptable The TM in this case defines a corresponding language, in a stronger sense than a TM recognizer, because it also halts for rejected strings The language in this case is called a recursive language (different from recursively enumerable)

14 Hierarchy of languages regular recursive recursively enumerable context-free context-sensitive type 0 type 1 type 2 type 3 TM recognizer TM decider

15 About TMs Church-Turing Thesis: TMs represent what can be solved by a computer program (a mathematically unprovable statement) Some problems cannot be solved/decided by a TM (e.g., the Halting Problem) TMs can be deterministic or nondeterministic; the variation helps in modeling problem complexity classes (P and NP)


Download ppt "Turing Machines CS 130 Theory of Computation HMU Textbook: Chap 8."

Similar presentations


Ads by Google