# CS 461 – Oct. 21 Begin chapter 3 We need a better (more encompassing) model of computation. Ex. { 1 n 2 n 3 n } couldn’t be accepted by PDA. –How could.

## Presentation on theme: "CS 461 – Oct. 21 Begin chapter 3 We need a better (more encompassing) model of computation. Ex. { 1 n 2 n 3 n } couldn’t be accepted by PDA. –How could."— Presentation transcript:

CS 461 – Oct. 21 Begin chapter 3 We need a better (more encompassing) model of computation. Ex. { 1 n 2 n 3 n } couldn’t be accepted by PDA. –How could any machine accept this language? –Somehow need to check 1s, 2s and 3s at same time. –We should also be able to handle 1 n 2 n 3 n 4 n, etc.

Turing Machine 3 rd model of computation –Alan Turing, 1936 –Use “tape” instead of stack –Can go left or right over the input! Every TM has: –Set of states, including 1 start and 1 accept state –Input alphabet –Tape alphabet, including special “blank” symbol –Transition function δ (state, input) = (state, output, direction)

The tape and δ Tape is infinite in both directions –Blanks straddle the input on the tape. Begin reading at leftmost input symbol. As soon as you enter accept state, halt. –You don’t have to read all the input. δ (state, input) = (state, output, direction) –You may change state. –You may change the symbol that’s on the tape. –The “direction” is either L or R.

States A TM has at least 3 states –One accept state –One reject state –Ordinary states that we describe in our transition table, beginning with a start state. We don’t need transitions for the accept or reject states. Sometimes a transition “doesn’t matter” because we can’t be in that situation. –Ex. If the leftmost symbol isn’t blank, then the rightmost symbol can’t be blank. You can just go to reject state.

Example A TM to accept the language 0(0+1)*1. –Make sure first symbol is 0. Else reject. –Keep moving right until you see blank. –After blank, go left. If 1, accept. Else reject. StateInput 0Input 1Input _ s1s2, 0, Rreject s2s2, 0, Rs2, 1, Rs3, _, L s3reject Doesn’t matter

Let’s trace 011 StateInput 0Input 1Input _ s1s2, 0, Rreject s2s2, 0, Rs2, 1, Rs3, _, L s3reject Doesn’t matter TapeTransitionEffect [s1]011s2,0,R0[s2]11 0[s2]11s2,1,R01[s2]1 01[s2]1s2,1,R011[s2] 011[s2]_s3,_,L01[s3]1_ 01[s3]1

Input  output TMs can easily modify the input on the tape. Thus we can have useful output! Example: let’s flip the bits of our binary input, and automatically accept. –Note: the reject state is unreachable. StateInput 0Input 1Input _ s1s1, 1, Rs1, 0, R

Infinite loop It’s possible for a TM to have an infinite loop. We say that the TM “loops.” In this case, it doesn’t accept or reject its input. Simple example: From start state, go left on any input! StateInput 0Input 1Input _ s1s1, 0, Ls1, 1, Ls1, _, L

Mystery #1 What does this TM do? Assume s1 is the start state, and unspecified transitions are crash. StateInput 0Input 1Input _ s1s2, 1, R s2s1, 0, R Hint: notice we never move left. This means it doesn’t matter what we write on tape.

Mystery #2 Can you figure out what this machine does? –See something wrong? StateInput 0Input 1Input _ s1s1, 0, Rs2, 1, Rs1, _, R s2 s2, 1, Rs2, _, R

Download ppt "CS 461 – Oct. 21 Begin chapter 3 We need a better (more encompassing) model of computation. Ex. { 1 n 2 n 3 n } couldn’t be accepted by PDA. –How could."

Similar presentations