220 likes | 493 Views
Turing Machines. Reading: 9.1. The next level of Machine…. PDAs improved on FSAs by adding memory. We make the memory more flexible to do more complicated tasks. Turing Machine. Control Unit. Read-Write Head. Input/Output Tape. Turing Machine Formal Definition.
E N D
Turing Machines Reading: 9.1
The next level of Machine… • PDAs improved on FSAs by adding memory. • We make the memory more flexible to do more complicated tasks.
Turing Machine Control Unit Read-Write Head Input/Output Tape
Turing Machine Formal Definition • Turing Machine M = (Q,Σ, Γ, δ, q0, □, F) • Q is the set of states • Σ is the input alphabet, subset of the tape alphabet • Γ is the tape alphabet • δ is the transition function • □ is the blank, special character in the tape alphabet • q0 is the initial state • F is the set of final states
Computing with a TM • Read-write head starts somewhere on the tape, and control unit is in the initial state. • transition function takes state, tape symbol, and transitions to new state, writing a symbol on the tape, and moving one space left or right. • δ(q0,a) = (q1, d, R) State = q0 a b c State = q1 d b c
Stopping the computation • Since the tape (and therefore the input) is now unbounded, when do you stop? • Stop in a halt state: any machine configuration for which delta function is not defined. • Assume that all final states are also halt states.
What does it do? • q0 initial, q1 final. • Transition Rules: δ(q0,a) =(q0,b,R) δ(q0,b) =(q0,b,R) δ(q0,□) =(q1, □,L)
Standard TM • The Standard Turing Machine that: • Has an unbounded tape in both directions • Is deterministic • Has no special input or output. The tape takes care of both.
Instantaneous Description of a TM • xqy is an instantaneous description of a turing machine. q is the current state, and the tape is y x
Descriptions and Moves • Suppose there is a transition δ(q1,c) = (q2,e,R) • Then xq1cy ┝ xeq2y State = q1 □□ a b c d □□□ State = q2 □□ a b e d □□□
Notation • xqy ┝* wq’z means there is some sequence of moves that puts the machine from the first description to the second. • Any sequence of moves leading to a halt state is called a computation. • xqy ┝* ∞ means the configuration leads to an infinite loop.
Turing Machines as Acceptors • A turing machine accepts a string if the machine starts in q0 with the head at the start of the input, and ends in a final state. • Formally, L(M) = {w Σ+ : q0w┝* x1 qf x2 for some qf in F and x1, x2 in Γ }
Design a Turing machine that accepts 00* (lambda not included in any TM language) δ(q0,0) = (q0,0,R) δ(q0,□) = (qf,□,R)
Turing Machine that accepts anbn : n>0 • Idea: read an “a”, and replace it with “x” • Then look for a “b” - replace the first “b” with a “y” • Once a successful pair is made, go to next state. • Go back to the next “a” and return to first state. • If there aren’t any more a’s, check that there are also no more b’s. • If that’s true, accept.
Turing Machines as Transducers • Input = initial tape that isn’t blank • Output = final tape that isn’t blank • A function is Turing-computable if there is a Turing machine that computes it. • What kind of functions do you think are Turing-computable?
Computing x + y • Suppose x and y are represented by some number of ones, and they are separated by a 0. RW head is at the start of x. • At end, RW head is at the start of x+y. x+y is represented with ones, and there is a zero at the end of the input. • How would you do it?
Design a TM that copies a string • Start with the RW head at the beginning of a string of 1’s. • Replace every 1 with an x. • Replace the rightmost x with a 1. • Go to the first blank and write a 1. • Repeat 2 & 3 until there are no more x’s.
Design a Turing Machine that computes x >= y • Start with unary notation, with 0 in between. • Halt in qx if x >=y and qy if y >x. • Use same idea as anbn, but check if there are more on one side than another.