Turing Machines Hopcroft Motawi Ullman Chap 8 Models

  • Slides: 11
Download presentation
Turing Machines Hopcroft, Motawi, Ullman, Chap 8

Turing Machines Hopcroft, Motawi, Ullman, Chap 8

Models of computation n Finite automata and regular expressions n n n Grammars and

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

Turing Machine Model n n Input tape surrounded by infinitely many blanks Tape head

Turing Machine Model n n Input tape surrounded by infinitely many blanks Tape head can move back and forth the tape and replace current symbol … BBBBBBB 000111 BBBBB … TM

TM definition n A Turing Machine M is a tuple M = (Q, ,

TM definition n A Turing Machine M is a tuple M = (Q, , q 0, B, F), where: n n n n 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)

TM that accepts 0 n 1 n n n Q={q 0, q 1 ,

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

TM that increments a bit-string n n Q={q 0, q 1 , q 2,

TM that increments a bit-string n n Q={q 0, q 1 , q 2, q 3}, ={0, 1, B, X} defined as follows: n n n (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

Instantaneous descriptions n Instantaneous description (ID): depicts the characteristics of the machine as transitions

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

ID example n Suppose for the first TM example, the input is 0011 n

ID example n Suppose for the first TM example, the input is 0011 n n After applying the transition (q 0, 0) = (q 1, B, ), ID: q 1011 n n n The initial ID is q 00011 Depict this as a move: q 00011 | q 1011 Next 3 transitions: (q 1, 0) = (q 1, 0, ), ID: 0 q 111 (q 1, 1) = (q 2, Y, ), ID: q 20 Y 1 (q 2, 0) = (q 2, 0, ), ID: q 2 B 0 Y 1 Eventually, ID will be YYBq 4 (TM accepts)

TM as recognizer n A TM accepts a string w if there exists a

TM as recognizer n A TM accepts a string w if there exists a sequence of moves from ID q 0 w to ID uqfv (u, v *, qf F) n n q 0 w | * uqfv In the previous example, q 00011 | * 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

TM halting on input n n n TMs are also useful for computation In

TM halting on input n n n 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 uqixv (u, v *, x , qi Q) & (qi, x) is undefined (no transition applies) n The TM can be viewed as a function; f(w) = uxv

About TMs n n n Church-Turing Thesis: TMs represent what can be solved by

About TMs n n n Church-Turing Thesis: TMs represent what can be solved by a computer program (a mathematically unprovable statement) Some problems cannot be solved 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)