250 likes | 491 Views
CSE 105 Theory of Computation. Alexander Tsiatas Spring 2012. Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution- NonCommercial - ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org.
E N D
CSE 105Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at http://peerinstruction4cs.org. Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org.
At last we reach: Turing Machines
Turing Machine Model Draw a picture here
PDA’s vs. Turing Machines PDA Turing Machine Processes input string in any order; it starts out on the tape Can move tape head to any point on the tape Deterministic Halts whenever q_accept or q_reject is reached “Blank” symbol included • Processes input string left to right • Only memory access is the top of the stack • Non-deterministic • Halts when all input is read • No “blank” symbol Both models: infinite memory
Important Turing Machine detail • There is ONE way for a Turing Machine to accept a string. • Visit state qaccept; the machine halts and accepts. • There are TWO ways for a Turing Machine to not accept a string. • Visit state qreject; the machine halts and rejects. • Infinite loop. • The LANGUAGE of a Turing machine is: the set of strings that are accepted by a Turing machine. • All strings that are NOT accepted are NOT in the language.
Turing Machine Formal Description • In the TM transition function δ: Q x Γ -> Q x Γ x {L,R}, a given input of the transition function is: • A current state, a character read, and whether we came from the left or right • A current state, a character read • A current state, a character to write • A destination state, a character read • None of the above or more than one of the above
Turing Machine Formal Description • In the TM transition function δ: Q x Γ -> Q x Γ x {L,R}, a given output of the transition function is: • A current state, a character read, and whether we came from the left or right • A current state, a character to write, and whether we should next go left or right • A destination state, a character read, and whether we should write ‘L’ or ‘R’ • A destination state, a character to write, and whether we should next go left or right • None of the above or more than one of the above
Turing Machine configurations • Suppose we have at TM s.t. Γ={a,b,c,d,_}, Q = {qx | 1≤x≤10} U {qacc,qrej}. Suppose the current configuration is xbq1ay. What does this mean? • The TM is in state q1, the tape contains “xbay”, and the tape head is on the “b”. • The TM is in state q1, the tape contains “xbay”, and the tape head is on the “a”. • The TM is in state q1, the tape contains “xbq1ay”, and we don’t know where the tape head is.
Executing a Transition, “yields” • Suppose we have at TM s.t. Γ={a,b,c,d,_}, Q = {qx | 1≤x≤10} U {qacc,qrej}, and the transition function includes rules δ(q1,a) = (q3,b,R) and δ(q1,b) = (q3,a,L). We also have strings x,y in Γ*. Which configuration does the current configuration, xbq1ay, yield? • xq3bay • xbbq3y • xbaq3by • xq3aay • None of the above or more than one of the above
Executing a Transition, “yields” • Suppose we have at TM s.t. Γ={a,b,c,d,_}, Q = {q1, q2, q3, q4,qacc,qrej}, and the transition function includes rules δ(q2,c) = (q3,d,R) and δ(q2,d) = (q3,c,L). We also have strings u,v,x,y in Γ*. Which configuration does the current configuration, xcq2dy, yield? • xq3ddy • xcdq3y • xq3ccy • xq3ccdy • None of the above or more than one of the above
More Transition Function • (a) TRUE • (b) FALSE x0qrej11y yields x01q11y can never happen in any Turing Machine
Turing machines give you these: DECIDABLE AND TURING-RECOGNIZABLE LANGUAGES
So a language is not context-free. What is it? • L = {1^{2n} | n ≥ 0}. • Not context-free. • Exercise: prove it! • So there is no PDA or CFG with L as its language. • What about Turing Machines? What about this stuff??? Context-Free Regular
L = {1^{2n} | n ≥ 0} WHOA, that looks complicated. Let’s break this down.
L = {1^{2n} | n ≥ 0} • How could you check to see if a number is a power of 2? • Check to see if it’s even • Keep on dividing by 2; if you get an odd number, it’s not a power of 2 • Keep on dividing by 2; if you get an odd number > 2, it’s not a power of 2 • Keep on dividing by 2; if you get down to 0, it’s a power of 2
L = {1^{2n} | n ≥ 0} No 1’s Even 1’s One 1 Odd 1’s STEP 1: Scan the tape left to right, cross off every other 1, keep track if the number of 1’s is even, odd, or equal to 1.
L = {1^{2n} | n ≥ 0} No 1’s Even 1’s One 1 Odd 1’s STEP 2: If you’re left with just one 1, halt and accept!
L = {1^{2n} | n ≥ 0} No 1’s Even 1’s One 1 Odd 1’s STEP 3: If you’re left with an odd number of 1’s, but more than one, halt and reject!
L = {1^{2n} | n ≥ 0} No 1’s Even 1’s One 1 Odd 1’s STEP 4: Send the tape head back to the left end of the tape.
L = {1^{2n} | n ≥ 0} No 1’s Even 1’s One 1 Odd 1’s STEP 5: Go back to STEP 1.
L = {1^{2n} | n ≥ 0} • This is a “high-level” description of a Turing Machine: • STEP 1: Scan the tape left to right, cross off every other 1, keep track if the number of 1’s is even, odd, or equal to 1. • STEP 2: If you’re left with just one 1, halt and accept! • STEP 3: If you’re left with an odd number of 1’s, but more than one, halt and reject! • STEP 4: Send the tape head back to the left end of the tape. • STEP 5: Go back to STEP 1. • On Homework and Exams: give high-level descriptions. • This should be easier than drawing the diagram, specifying the transition details, etc.
L = {1^{2n} | n ≥ 0} • This language L is: • Decidable • Turing-recognizable • Decidable AND Turing-recognizable • Neither decidable nor Turing-recognizable
So a language is not context-free. What is it? What’s out here…? After Exam 2. • Decidable: there is a TM that always halts on all inputs. • Turing-recognizable: there is a TM that always halts for accepted strings, but MAY NOT HALT on rejected strings. Turing-recognizable Decidable Context-Free Regular