Transcript Lecture 21

Lecture 21
• 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
• That is, we add the following categories of
transitions to d
– d(q,l) is allowed
Example
a,b
l
l
a,b
a,b
a
a
b
a
b
a
a
b
a,b
Defining L(M) and LNFA-l
• 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)
– The set of strings accepted
by M
• N(M)
– The set of strings rejected
by M
• LNFA-l
– Language L is in language
class LNFA-l iff there
exists an NFA-l M such
that L(M) = 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)
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
A2
FSA M’
Modified Goal
NFA-l M
A2
FSA M’
• 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
Algorithm A2
A1
FSA M’
Answer-Preserving Input
Transformation Sidebar
NFA-l M
A2’
NFA
M1
A1
FSA M’
Algorithm A2
• Example of real-life answer-preserving input transformation
– Problem P2 that algorithm A2 solves: Converting NFA-l M into FSA
M’ s.t. L(M’) = L(M)
– Problem P1 that algorithm A1 solves: Converting NFA M1 into FSA M’
s.t. L(M’) = L(M1)
– Input Transformation Algorithm A2’: converts an NFA-l M into an
NFA M1 s.t. L(M1) = L(M)
• A2’ maps input for problem P2 into an input for problem P1.
– Essentially, P2 <= P1
New Goal
(extra credit)
A2’
NFA-l M
NFA M1
• Difficulty
– NFA-l M can make transitions on l
– How can the NFA M1 simulate these l-transitions?
a
1
l
2
b
3
l
4
l
5
b
6
Basic Idea
A2’
NFA-l M
NFA M1
• 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
1
l
2
b
3
l
4
b
2
3
5
b
6
b
b
1
l
4
5
6
Process State 2
NFA-d M1
A2’
NFA-l M
a
1
l
2
b
3
l
4
b
1
2
b
b
5
b
6
b
b
3
l
4
5
b
6
Process State 3
NFA-d M1
A2’
NFA-l M
a
1
l
2
b
3
l
4
b
1
2
b
a
b
5
b
6
b
a
b
3
l
4
5
b
b
6
Final Picture
NFA-d M1
A2’
NFA-l M
a
1
l
2
b
3
l
4
b
1
l
a
2
b
b
3
a
b
4
a
5
b
a
5
b
6
b
6
b
b
b
a
Construction
1
l
• 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
2
b
3
l
4
l
5
b
6
a
Construction
1
l
2
b
3
l
4
l
5
b
6
• 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
Computing
d1(q,a)
•
a
1
l
2
b
3
l
4
l
5
b
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
6
a
Example
•
1
l
2
b
3
l
4
l
5
b
d1(1,b) = {3,4,5}
– Compute L(1), all states reachable from state 1 using 0 or more ltransitions
• 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}
6
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