19
1 Module 20 • NFA’s with -transitions – NFA-’s • Formal definition • Simplifies construction – LNFA- – Showing LNFA is a subset of LNFA (extra credit) • and therefore a subset of LFSA

1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA is a subset of LNFA (extra credit) and therefore

Embed Size (px)

Citation preview

Page 1: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

1

Module 20

• NFA’s with -transitions– NFA-’s

• Formal definition

• Simplifies construction

– LNFA- – Showing LNFA is a subset of LNFA (extra

credit)• and therefore a subset of LFSA

Page 2: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

2

Defining NFA-’s

Page 3: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

3

Change:-transitions

• We now allow an NFA M to change state without reading input

• That is, we add the following categories of transitions to – (q is allowed

Page 4: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

4

Example *

a,b

a

a,b

a b a

b

a,b a,b

a a b

Page 5: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

5

Defining L(M) and LNFA-*

• M accepts string x if one of the configurations reached is an accepting configuration

– (q0, x) |-* (f, ),f A

• M rejects string x if all configurations reached are either not halting configurations or are rejecting configurations

• L(M) or Y(M)

• N(M)

• LNFA-– Language L is in

language class LNFA- iff

Page 6: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

6

LNFA- subset LFSA

• Recap of what we already know– Let M be any NFA

– There exists an algorithm A1 which constructs an FSA M’ such that L(M’) = L(M)

• New goal– Let M be any NFA-– There exists an algorithm A2 which constructs an FSA

M’ such that L(M’) = L(M)

Page 7: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

7

Visualization

• Goal– Let M be any NFA-– There exists an algorithm A2 which constructs an FSA

M’ such that L(M’) = L(M)

NFA- M FSA M’A2

Page 8: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

8

Modified Goal

• Question– Can we use any existing algorithms to simplify the task

of developing algorithm A2?

• Yes, we can use algorithm A1 which converts an NFA M1 into an FSA M’ such that L(M’) = L(M1)

NFA- M FSA M’A2

NFA- M FSA M’

Algorithm A2

NFA M1

A1A2’

Page 9: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

9

New Goal (extra credit)• Difficulty

– NFA- M can make transitions on – How can the NFA M1 simulate these -transitions?

NFA- M NFA M1A2’

a

bb 2 3 4 5 61

Page 10: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

10

Basic Idea

• For each state q of M and each character of , figure out which states are reachable from q taking any number of -transitions and exactly one transition on that character .

• In the NFA- M1, directly connect q to each of these states using an arc labeled with .

NFA- M NFA M1A2’

a

bb 2 3 4 5 61

2 3 4 5 61

bb

b

Page 11: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

11

Process State 2 NFA- M NFA- M1A2’

a

bb 2 3 4 5 61

2 3 4 5 61

bb

b

b b

b

Page 12: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

12

Process State 3 NFA- M NFA- M1A2’

a

bb 2 3 4 5 61

2 3 4 5 61

bb

b

b b

ba

a

b

Page 13: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

13

Final Picture NFA- M NFA- M1A2’

a

bb 2 3 4 5 61

2 3 4 5 61

bb

b

b b

ba

a

b

b

b

a

a

Page 14: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

14

Construction

• Input NFA- M = (Q, , q0, , A)

• Output NFA M1 = (Q1, 1, q1, 1, A1)

– What is Q1?

• Q1 = Q

• In this case, Q1 = {1,2,3,4,5,6}

– What is 1?

• 1 =

• In this case, 1 = = {a,b}

– What is q1?

• We always make q1 = q0

• In this case q1 = 1

a

bb 2 3 4 5 61

Page 15: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

15

Construction

• Input NFA- M = (Q, , q0, , A)

• Output NFA M1 = (Q1, 1, q1, 1, A1)

– What is 1?

• 1(q,a) = the set of states reachable from state q in M taking any number of -transitions and exactly one transition on the character a

– More on this later

• In this case – 1(1,a) = {}

– 1(1,b) = {3,4,5}

– What is A1?

• A1 = A with one minor change

– If an accepting state is reachable from q0 using only-transitions, then we make q1 an element of A1

• In this case, using only -transitions, no accepting state is reachable from q0, so A1 = A

a

bb 2 3 4 5 61

Page 16: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

16

Computing 1(q,a)

• 1(q,a) = the set of states reachable from state q in M taking 0 or more -transitions and exactly one transition on the character a– Break this down into three steps

• First compute all states reachable from q using 0 or more -transitions– We call this set of states (q)

• Next, compute all states reachable from any element of (q) using the character a

– We can denote these states as ((q),a)

• Finally, compute all states reachable from states in ((q),a) using 0 or more -transitions

– We denote these states as (((q),a))

– This is the desired answer

a

bb 2 3 4 5 61

Page 17: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

17

Example

• 1(1,b) = {3,4,5}– Compute (1), all states reachable from state 1 using 0 or more -

transitions• (1) = {1,2}

– Compute ((q),b), all states reachable from any element (1) of using the character b:

• ((q),b) = ({1,2},b)• = (1,b) U (2,b)• = {} U {3} = {3}

– Compute (((q),a)), all states reachable from states in ((q),a) using 0 or more -transitions

• (((q),a)) = (3)• = {3,4,5}

a

bb 2 3 4 5 61

Page 18: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

18

Comments

• For extra credit, you should be able to execute this algorithm – Convert any NFA- into an equivalent NFA.

• For extra credit, you should understand the idea behind this algorithm– Why the transition function is computed the way it is– Why A1 may need to include q1 in some cases

• You should understand the importance of this algorithm– Compiler role again– Use in combination with previous algorithm for converting any

NFA into an equivalent FSA to create a new algorithm for converting any NFA- into an equivalent FSA

Page 19: 1 Module 20 NFA’s with -transitions –NFA- ’s Formal definition Simplifies construction –LNFA- –Showing LNFA  is a subset of LNFA (extra credit) and therefore

19

LNFA- = LFSA

• Implications– Let us primarily use the term LFSA to refer to

this language class– Given a language L is in LFSA

• We know there exists an FSA M s.t. L(M) = L

• We know there exists an NFA M s.t. L(M) = L

– To show a language L is in LFSA• Show there exists an FSA M s.t. L(M) = L

• Show there exists an NFA- M s.t. L(M) = L