1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class...

19
1 • FSA’s – Defining FSA’s – Computing with FSA’s • Defining L(M) – Defining language class LFSA – Comparing LFSA to set of solvable languages (REC)

Transcript of 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class...

Page 1: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

1

• FSA’s– Defining FSA’s– Computing with FSA’s

• Defining L(M)

– Defining language class LFSA– Comparing LFSA to set of solvable languages

(REC)

Page 2: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

2

Finite State Automata

New Computational Model

Page 3: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

3

Tape

• We assume that you have already seen FSA’s in CSE 260– If not, review material in reference textbook

• Only data structure is a tape– Input appears on tape followed by a B character

marking the end of the input– Tape is scanned by a tape head that starts at

leftmost cell and always scans to the right

Page 4: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

4

Data type/States

• The only data type for an FSA is char

• The instructions in an FSA are referred to as states

• Each instruction can be thought of as a switch statement with several cases based on the char being scanned by the tape head

Page 5: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

5

Example program

1 switch(current tape cell) {case a: goto 2case b: goto 2case B: return yes

}2 switch (current tape cell) {

case a: goto 1case b: goto 1case B: return no;

}

Page 6: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

6

New model of computation

• FSA M=(Q,,q0,A,)– Q = set of states = {1,2}

– = character set = {a,b}• don’t need B as we see below

– q0 = initial state = 1

– A = set of accepting (final) states = {1}

• A is the set of states where we return yes on B

• Q-A is set of states that return no on B

– = state transition function

1 switch(current tape cell) {case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {case a: goto 1

case b: goto 1

case B: return no;

}

Page 7: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

7

Textual representations of *

1 switch(current tape cell) {case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {case a: goto 1

case b: goto 1

case B: return no;

}

1

2

a b

1 1

2 2

(1,a) = 2, (1,b)=2, (2,a)=1, (2,b) = 1

{(1,a,2), (1,b,2), (2,a,1), (2,b,1)}

Page 8: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

8

Transition diagrams

1 2

a,b

a,b1 switch(current tape cell) {case a: goto 2

case b: goto 2

case B: return yes

}

2 switch (current tape cell) {case a: goto 1

case b: goto 1

case B: return no;

}

Note, this transition diagramrepresents all 5 components of an FSA, not just the transition function

Page 9: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

9

Exercise

• FSA M = (Q, , q0, A, )

– Q = {1, 2, 3}– = {a, b}

– q0 = 1

– A = {2,3}– : {(1,a) = 1, (1,b) = 2, (2,a)= 2, (2,b) = 3,

(3,a) = 3, (3,b) = 1}

• Draw this FSA as a transition diagram

Page 10: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

10

Transition Diagram

1

2

3

a

a

a

b

b

b

Page 11: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

11

Computing with FSA’s

Page 12: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

12

Computation Example *

1

2

3

a

a

a

b

b

b

Input: aabbaa

Page 13: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

13

Computation of FSA’s in detail

• A computation of an FSA M on an input x is a complete sequence of configurations

• We need to define– Initial configuration of the computation– How to determine the next configuration given

the current configuration– Halting or final configurations of the

computation

Page 14: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

14

• Given an FSA M and an input string x, what is the initial configuration of the computation of M on x?– (q0,x)

– Examples• x = aabbaa

• (1, aabbaa)

• x = abab

• (1, abab)

• x = • (1, )

Initial Configuration

1

2

3

a

a

a

b

b

b

FSA M

Page 15: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

15

• (1, aabbaa) ├M (1, abbaa)– config 1 “yields” config 2 in

one step using FSA M• (1,aabbaa) ├ M (2, baa)

– config 1 “yields” config 2 in 3 steps using FSA M

• (1, aabbaa) ├ M (2, baa)– config 1 “yields” config 2 in 0

or more steps using FSA M• Comment:

– ├ M determined by transition function

– There must always be one and only one next configuration

• If not, M is not an FSA

Definition of ├M

1

2

3

a

a

a

b

b

b

3

FSA M

*

Page 16: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

16

• Halting configuration– (q, )

– Examples• (1, )

• (3, )

• Accepting Configuration– State in halting configuration

is in A

• Rejecting Configuration– State in halting configuration

is not in A

Halting Configurations *

1

2

3

a

a

a

b

b

b

FSA M

Page 17: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

17

• Two possibilities for M running on x– M accepts x

• M accepts x iff the computation of M on x ends up in an accepting configuration

• (q0, x) ├M (q, ) where q is in A

– M rejects x• M rejects x iff the computation of M on x ends up in a

rejecting configuration• (q0, x) ├M (q, ) where q is not in A

– M does not loop or crash on x• Why?

FSA M on xb

bb

aa

a

FSA M

*

*

Page 18: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

18

– For the following input strings, does M accept or reject?• • aa• aabba• aab• babbb

Examplesb

bb

aa

a

FSA M

Page 19: 1 FSA’s –Defining FSA’s –Computing with FSA’s Defining L(M) –Defining language class LFSA –Comparing LFSA to set of solvable languages (REC)

19

• Notation from the book

• (q, c) = p

• k(q, x) = p– k is the length of x

• *(q, x) = p

• Examples– (1, a) = 1

– (1, b) = 2

– 4(1, abbb) = 1

– *(1, abbb) = 1

– (2, baaaaa) = 3

Definition of *(q, x)

1

2

3

a

a

a

b

b

b

FSA M