cse 105 theory of computation
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
CSE 105Theory of
Computation
Alexander TsiatasSpring 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.
2
TURING MACHINESAt last we reach:
3
Turing Machine ModelDraw a picture here
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.
6
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 rightb) A current state, a character readc) A current state, a character to writed) A destination state, a character reade) None of the above or more than one of the above
7
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 rightb) A current state, a character to write, and whether we should
next go left or rightc) 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 righte) None of the above or more than one of the above
8
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.
9
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) xq3bayb) xbbq3yc) xbaq3byd) xq3aaye) None of the above or more than one of the above
10
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) xq3ddyb) xcdq3yc) xq3ccyd) xq3ccdye) None of the above or more than one of the above
11
More Transition Function
• (a) TRUE• (b) FALSE
x0qrej11y yields x01q11y can never happen in any Turing Machine
12
DECIDABLE AND TURING-RECOGNIZABLE LANGUAGES
Turing machines give you these:
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?
Regular
Context-Free
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 evenb) Keep on dividing by 2; if you get an odd number, it’s
not a power of 2c) Keep on dividing by 2; if you get an odd number > 2, it’s
not a power of 2d) Keep on dividing by 2; if you get down to 0, it’s a power
of 2
L = {1^{2n} | n ≥ 0}
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.
No 1’s
One 1
Even 1’s
Odd 1’s
L = {1^{2n} | n ≥ 0}
STEP 2: If you’re left with just one 1, halt and accept!
No 1’s
One 1
Even 1’s
Odd 1’s
L = {1^{2n} | n ≥ 0}
STEP 3: If you’re left with an odd number of 1’s, but more than one, halt and reject!
No 1’s
One 1
Even 1’s
Odd 1’s
L = {1^{2n} | n ≥ 0}
STEP 4: Send the tape head back to the left end of the tape.
No 1’s
One 1
Even 1’s
Odd 1’s
L = {1^{2n} | n ≥ 0}
STEP 5: Go back to STEP 1.
No 1’s
One 1
Even 1’s
Odd 1’s
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) Decidableb) Turing-recognizablec) Decidable AND Turing-recognizabled) 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
What’s out here…? After Exam 2.
Decidable
Turing-recognizable