190 likes | 357 Views
Module 20. NFA’s with l -transitions NFA- l ’s Formal definition Simplifies construction LNFA- l Showing LNFA -l is a subset of LNFA (extra credit) and therefore a subset of LFSA. Defining NFA- l ’s. Change: l -transitions. We now allow an NFA M to change state without reading input
E N D
Module 20 • NFA’s with l-transitions • NFA-l’s • Formal definition • Simplifies construction • LNFA-l • Showing LNFA-l is a subset of LNFA (extra credit) • and therefore a subset of LFSA
Change: l-transitions • We now allow an NFA M to change state without reading input • That is, we add the following categories of transitions to d • d(q,l) is allowed
a,b a,b a a b a l b a a b l a,b a,b Example *
M accepts string x if one of the configurations reached is an accepting configuration (q0, x) |-* (f, l),f e 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-l Language L is in language class LNFA-l iff Defining L(M) and LNFA-l *
LNFA-l 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-l • There exists an algorithm A2 which constructs an FSA M’ such that L(M’) = L(M)
A2 Visualization • Goal • Let M be any NFA-l • There exists an algorithm A2 which constructs an FSA M’ such that L(M’) = L(M) NFA-l M FSA M’
NFA M1 NFA-l M A2 FSA M’ A2’ A1 NFA-l M FSA M’ Algorithm A2 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-l M A2’ NFA M1 New Goal (extra credit) • Difficulty • NFA-l M can make transitions on l • How can the NFA M1 simulate these l-transitions? a l b l l b 1 2 3 4 5 6
NFA-l M A2’ NFA M1 b b b Basic Idea • For each state q of M and each character a of S, figure out which states are reachable from q taking any number of l-transitions and exactly one transition on that character a. • In the NFA-d M1, directly connect q to each of these states using an arc labeled with a. a l b l l b 1 2 3 4 5 6 1 2 3 4 5 6
NFA-d M1 NFA-l M A2’ b b b b b b Process State 2 a l b l l b 1 2 3 4 5 6 1 2 3 4 5 6
NFA-d M1 NFA-l M A2’ b a b b a b b b b Process State 3 a l b l l b 1 2 3 4 5 6 1 2 3 4 5 6
a l b l l b 1 2 3 4 5 6 NFA-d M1 NFA-l M A2’ b b b b b b Final Picture a a a a b 1 2 3 4 5 6 b b
Input NFA-l M = (Q, S, q0, d, A) Output NFA M1 = (Q1, S1, q1, d1, A1) What is Q1? Q1 = Q In this case, Q1 = {1,2,3,4,5,6} What is S1? S1 = S In this case, S1 = S = {a,b} What is q1? We always make q1 = q0 In this case q1 = 1 a l b l l b 1 2 3 4 5 6 Construction
Input NFA-l M = (Q, S, q0, d, A) Output NFA M1 = (Q1, S1, q1, d1, A1) What is d1? d1(q,a) = the set of states reachable from state q in M taking any number of l-transitions and exactly one transition on the character a More on this later In this case d1(1,a) = {} d1(1,b) = {3,4,5} What is A1? A1 = A with one minor change If an accepting state is reachable from q0 using only l-transitions, then we make q1 an element of A1 In this case, using only l-transitions, no accepting state is reachable from q0, so A1 = A a l b l l b 1 2 3 4 5 6 Construction
d1(q,a) = the set of states reachable from state q in M taking 0 or more l-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 l-transitions We call this set of states L(q) Next, compute all states reachable from any element of L(q) using the character a We can denote these states as d(L(q),a) Finally, compute all states reachable from states in d(L(q),a) using 0 or more l-transitions We denote these states as L(d(L(q),a)) This is the desired answer a l b l l b 1 2 3 4 5 6 Computing d1(q,a)
d1(1,b) = {3,4,5} Compute L(1), all states reachable from state 1 using 0 or more l-transitions L(1) = {1,2} Compute d(L(q),b), all states reachable from any element L(1) of using the character b: d(L(q),b) = d({1,2},b) = d(1,b) U d(2,b) = {} U {3} = {3} Compute L(d(L(q),a)), all states reachable from states in d(L(q),a) using 0 or more l-transitions L(d(L(q),a)) = L(3) = {3,4,5} a l b l l b 1 2 3 4 5 6 Example
Comments • For extra credit, you should be able to execute this algorithm • Convert any NFA-l 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-l into an equivalent FSA
LNFA-l = 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-l M s.t. L(M) = L