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. Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org. At last we reach: TURING MACHINES 2 Turing Machine Model Draw a picture here 3 PDA’s vs. Turing Machines PDA • 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 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 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) A current state, a character read, and whether we came from the left or right b) A current state, a character read c) A current state, a character to write d) A destination state, a character read e) None of the above or more than one of the above 6 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) A current state, a character read, and whether we came from the left or right b) A current state, a character to write, and whether we should next go left or right c) A destination state, a character read, and whether we should write ‘L’ or ‘R’ d) A destination state, a character to write, and whether we should next go left or right e) None of the above or more than one of the above 7 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? a) The TM is in state q1, the tape contains “xbay”, and the tape head is on the “b”. b) The TM is in state q1, the tape contains “xbay”, and the tape head is on the “a”. c) The TM is in state q1, the tape contains “xbq1ay”, and we don’t know where the tape head is. 8 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? a) b) c) d) e) xq3bay xbbq3y xbaq3by xq3aay None of the above or more than one of the above 9 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? a) b) c) d) e) xq3ddy xcdq3y xq3ccy xq3ccdy None of the above or more than one of the above 10 More Transition Function • (a) TRUE • (b) FALSE x0qrej11y yields x01q11y can never happen in any Turing Machine 11 Turing machines give you these: DECIDABLE AND TURINGRECOGNIZABLE LANGUAGES 12 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? Context-Free Regular What about this stuff??? 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? a) Check to see if it’s even b) Keep on dividing by 2; if you get an odd number, it’s not a power of 2 c) Keep on dividing by 2; if you get an odd number > 2, it’s not a power of 2 d) 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: a) b) c) d) Decidable Turing-recognizable Decidable AND Turing-recognizable Neither decidable nor Turing-recognizable So a language is not context-free. What is it? • 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. Regular Context-Free Decidable Turing-recognizable What’s out here…? After Exam 2.