CSCI 2670 Introduction to Theory of Computing October 7, 2004.

26
CSCI 2670 Introduction to Theory of Computing October 7, 2004

description

October 7, Announcements Homework due Wednesday –3.2 b,d 3.5 all, 3.7, 3.8 a,c (high-level descriptions) Reminder: tutorial sessions are suspended until further notice –Extended office hours while tutorials are suspended Monday 11:00 – 12:00 Tuesday 3:00 – 4:00 Wednesday 3:00 – 5:00

Transcript of CSCI 2670 Introduction to Theory of Computing October 7, 2004.

Page 1: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

CSCI 2670Introduction to Theory of

Computing

October 7, 2004

Page 2: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 2

Agenda• Yesterday

– Test• Today

– Continue Turing Machines

Page 3: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 3

Announcements• Homework due Wednesday

– 3.2 b,d 3.5 all, 3.7, 3.8 a,c (high-level descriptions)

• Reminder: tutorial sessions are suspended until further notice– Extended office hours while tutorials

are suspended• Monday 11:00 – 12:00• Tuesday 3:00 – 4:00• Wednesday 3:00 – 5:00

Page 4: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 4

Formal definition of a TMDefinition: A Turing machine is a 7-

tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and

1. Q is the set of states,2. is the input alphabet not

containing the special blank symbol ~

3. is the tape alphabet, where ~ and ,

4. : QQ{L,R} is the transition function,

Page 5: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 5

Formal definition of a TMDefinition: A Turing machine is a 7-

tuple (Q,,,,q0,qaccept,qreject), where Q, , and are finite sets and

5. q0Q is the start state,6. qacceptQ is the accept state, and7. qrejectQ is the reject state, where

qrejectqaccept

Page 6: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 6

Computing with a TM• M receives input w = w1w2…wn*

on leftmost n squares of tape– Rest of tape is blank (all ~ symbols)

• Head position begins at leftmost square of tape

• Computation follows rules of • Head never moves left of leftmost

square of the tape– If says to move L, head stays put!

Page 7: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 7

Completing computation• Continue following transition

rules until M reaches qaccept or qreject– Halt at these states

• May never halt if the machine never transitions to one of these states!

Page 8: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 8

TM configurations• The configuration of a Turing

machine is the current setting– Current state– Current tape contents– Current tape location

• Notation uqv– Current state = q– Current tape contents = uv

• Only ~ symbols after last symbol of v– Current tape location = first symbol of v

Page 9: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 9

Configuration C1 yields C2

• C1 yields C2 if the TM can legally go from C1 to C2 in one step– Assume a, b and u, v *

– uaqibv yields uqkacv if (qi,b)=(qk,c,L)– uaqibv yields uacqkv if (qi,b)=(qk,c,R)

Page 10: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 10

Configuration C1 yields C2

• Special cases if head is at beginning or end of tape– qibv yields qkcv if (qi,b)=(qk,c,L)– qibv yields cqkv if (qi,b)=(qk,c,R)– uaqi is the same as uaqi~

• “handle this case as before”• uaqi~ yields uqkac~ if (qi,b)=(qk,c,L)• uaqi~ yields uacqk~ if (qi,b)=(qk,c,R)

Page 11: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 11

Special configurations• Start configuration

– q0w• Halting configurations

– Accepting configuration: uqacceptv– Rejecting configuration: uqrejectv

• u, v *

Page 12: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 12

Strings accepted by a TM• A Turing machine M accepts input

sequence w if a sequence of configurations C1, C2, …, Ck exist, where

1. C1 is the start configuration of M on input w

2. each Ci yields Ci+1 for i = 1, 2, …, k-13. Ck is an accepting configuration

Page 13: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 13

Language of a TM• The language of M, denoted L(M),

is– L(M) = {w | M accepts w}

• A language is called Turing-recognizable if some Turing machine recognizes it

Page 14: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 14

Deciders• A Turing machine is called a

decider if every string in * is either accepted or rejected

• A language is called Turing-decidable if some Turing machine decides it– These languages are often just called

decidable

Page 15: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 15

Turing machine notation(qi,b)=(qk,c,D), where D = L or R,

is represented by the following transition

qi qkb c, D

• In the special case where (qi,b)=(qk,b,D), i.e., the tape is unchanged, the right-hand side will just display the direction

Page 16: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 16

Example• Write a TM that accepts all strings

of the form 101001000100001 …– Start with a 1– End with a 1– Progressively more 0’s between

consecutive 1’s

Page 17: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 17

Design• Check first symbol is a 1

– If not reject• Move right and check if second

symbol is a 0– If not reject– If so, replace with X and begin

recursion

Page 18: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 18

Recursion (high level)• Go back and forth on either side of

each 1– Replace 0’s on right side of 1 with an X– Replace X’s on left side of 1 with a Y

• After all X’s on left side of 1 are replaced with Y’s, there should be exactly one on the right side that has not been X’ed– If not, reject– If so, repeat process (recursion step)

Page 19: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 19

Exit condition• If you begin to look for the next

group of 0’s and reach a ~ then accept

Page 20: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 20

Page 21: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 21

Group project 1• Design a Turing machine to accept

any string in {a,b}* after making a copy of it on the tape– The tape will start with w – After TM processes the string, the

tape should read ww

Page 22: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 22

Group project 2• Write a Turing machine that

accepts the language {w {a,b}* | |w| is even}

Page 23: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 23

Group project 3• Write a Turing machine that

accepts the language {anbm | nm and nm}

Page 24: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 24

Group project 4• Write a Turing machine that

accepts the language {anbman+m | n0 and m1}

Page 25: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 25

Group project 5• Write a Turing machine that

accepts the language {wwR | w{a,b}*}

Page 26: CSCI 2670 Introduction to Theory of Computing October 7, 2004.

October 7, 2004 26

Group project 6• Design a Turing machine that

accepts the language {w{a,b}* | w has more a’s than

b’s}