F all 1998 F ormal Language Theory Dr. R. Bo y er W eek - - PDF document

f all 1998 f ormal language theory dr r bo y er w eek f
SMART_READER_LITE
LIVE PREVIEW

F all 1998 F ormal Language Theory Dr. R. Bo y er W eek - - PDF document

F all 1998 F ormal Language Theory Dr. R. Bo y er W eek F our: Equiv alence b et w een Finite Automata and Regular Expressions e -mo 1. Example of Con v ersion of NF A with v es with a DF A W e consider


slide-1
SLIDE 1 F all 1998 F
  • rmal
Language Theory Dr. R. Bo y er W eek F
  • ur:
Equiv alence b et w een Finite Automata and Regular Expressions 1. Example
  • f
Con v ersion
  • f
NF A with e-mo v es with a DF A W e consider the NF A M = (Q; ; ; q ; fq 3 g); where Q = fq ; q 1 ; q 2 ; q 3 ; q 4 g; with t w
  • letter
alphab et
  • =
fa; bg; and with
  • ne
accepting state fq 3 g and
  • is
giv en b y the follo wing table: NF A T ransitions state a b e 1
  • 2
1
  • 3
2 4
  • 1
3
  • 4
  • 4
1
  • 3
Computation
  • f
e-closures states e-closure q fq ; q 1 ; q 2 ; q 3 g q 1 fq 1 ; q 3 g q 2 fq 1 ; q 2 ; q 3 g q 3 fq 3 g q 4 fq 3 ; q 4 g Computation
  • f
the states and transitions
  • f
the equiv alen t DF A: Since the
  • riginal
NF A has initial state f0g; the corresp
  • nding
DF A has initial state whic h is its e-closure: E (0) = f0; 1; 2; 3g 1
slide-2
SLIDE 2 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions DF A T ransitions set
  • f
states a b f0; 1; 2; 3g E (1) [ E (2) = f1; 3; 4g E (4) = f3; 4g f1; 3; 4g E (1) = f1; 3g E (4) = f3; 4g f3; 4g E (1) = f1; 3g E (4) = f3; 4g f1; 3g ; E (4) = f3; 4g ; ; ; The accepting states are an y sets
  • f
states that con tain an accepting state
  • f
the
  • riginal
NF A. So, the accepting sets
  • f
the equiv alen t DF A are f0; 1; 2; 3g; f1; 3; 4g; f3; 4g and f1; 3g: 2. Prop
  • sition.
Let r b e a regular expression. Then there exists a NF A that accepts L(r ): The construction using induction
  • n
the n um b er
  • f
  • p
erators in r : It is con v enien t to normalize the t yp e
  • f
NF A used in the construction. W e require that the NF A has
  • ne
nal state and no transitions
  • ut
  • f
this unique nal state. It is easy to v erify that this do es not restrict the languages that will b e recognized. Base Case: r con tains zero
  • p
erators. Then either r = ;
  • r
r =
  • 2
: F
  • r
r = ;; the NF A has t w
  • states
q and q f ; where q is the start state and q f 2
slide-3
SLIDE 3 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions is the accepting state. There is no edge connecting them. F
  • r
r =
  • ;
again there are t w
  • states
q and q f as b efore. There is
  • ne
edge connecting them lab eled with the letter
  • :
The induction h yp
  • thesis
is that the result holds for all regular expressions with k
  • p
erators
  • r
less. No w, assume r is a regular expression con taining k + 1
  • p
erators. There are three cases to consider. Case One: r = r 1 [ r 2 : W e rst state the construction informally . Then r 1 = L(M 1 ), where M 1 has initial state q 1 and unique accepting state f 1 ; and r 2 = L(M 2 ), where M 2 has initial state q 2 and unique accepting state f 2 : Then NF A that accepts the union r will ha v e initial state q and unique accepting state f ; further there are e-transitions from q to b
  • th
initial states q 1 and q 2 and e-transitions from the nal states f 1 and f 2 to f : In detail, let the NF A's b e giv en as M 1 = (Q 1 ;
  • 1
;
  • 1
; q 1 ; ff 1 g) and M 2 = (Q 2 ;
  • 2
;
  • 2
; q 2 ; ff 2 g) where Q 1 \ Q 2 = ;: W e create a new initial state q and a new nal state f : T ak e M = (Q 1 [ Q 2 [ fq ; f g;
  • 1
[ S 2 ; ; q ; ff g); where (q ; e) = fq 1 ; q 2 g; (q ; a) =
  • 1
(q ; a); q 2 Q 1 n ff 1 g; a 2
  • 1
[ feg; (q ; a) =
  • 2
(q ; a); q 2 Q 2 n ff 1 g; a 2
  • 2
[ feg; (f 1 ; e) = (f 2 ; e) = ff g 3
slide-4
SLIDE 4 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions Case Tw
  • :
r = r 1
  • r
2 : Let M 1 and M 2 b e as ab
  • v
e. Informally , the NF A that accepts r is
  • btained
b y connecting the nal state
  • f
M 1 to the initial state
  • f
M 2 : More precisely , M = (Q 1 [ Q 2 ;
  • 1
[ S 2 ; ; q 1 ; ff 2 g); where (q ; a) =
  • 1
(q ; a); q 2 Q 1 n ff 1 g; a 2
  • 1
[ feg; (f 1 ; e) = fq 2 g; (q ; a) =
  • 2
(q ; a); q 2 Q 2 n ff 2 g; a 2
  • 2
[ feg; Case Three: r = (r 1 )
  • :
Let the NF A M = (Q 1 [ fq ; f g; ; ; q ; ff g); where (q ; e) = fq 1 ; f g; (f 1 ; e) = fq 1 ; f g; (q ; a) =
  • 1
(q ; a); q 2 Q 1 ; a 2
  • 1
3. Example. W e apply the ab
  • v
e construction to r =
  • 1
  • [
1: 4. Prop
  • sition.
The class
  • f
languages accepted b y DF A's are closed under the follo wing
  • p
erations: (1) union, concatenation, Kleene star; (2) complemen tation; 4
slide-5
SLIDE 5 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions (3) in tersection. Note: w e shall presen t t w
  • dieren
t constructions for in tersection. The rst will b e somewhat implicit and mak es use
  • f
(2) while the second construction will use the cross pro duct
  • f
automata. Let M 1 = (Q 1 ; ;
  • 1
; s 1 ; F 1 ) and M 2 = (Q 2 ; ;
  • 2
; s 2 ; F 2 ): Then w e let M = (Q 1
  • Q
2 ; ;
  • ;
(s 1 ; s 2 ); F ) where
  • ((q
; q ); a) = ( 1 (q ; a);
  • (q
; a)); q 2 Q 1 ; q 2 Q 2 ; a 2 ; F = F 1
  • F
2 = f(f ; f ) : f 2 F 1 ; f 2 F 2 g: The idea
  • f
the cross pro duct construction is that a computation in M actu- ally will trace
  • ut
the computation in the t w
  • mac
hines M 1 and M 2 sim ulta- neously . Note: if the collection
  • f
accepting states is c hanged to (F 1
  • Q
2 ) [ (Q 1
  • F
2 ); then M w
  • uld
accept the union L(M 1 ) [ L(M 2 ): So, this construction will pro duce a DF A that accepts the union rather than a NF A. 5. There are algorithms to answ er the follo wing questions ab
  • ut
DF A's: (1) giv en w 2
  • ;
is w 2 L(M )? (2) Is L(M ) = ;? 5
slide-6
SLIDE 6 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions (3) Is L(M ) =
  • ?
(4) Giv en t w
  • DF
A's M 1 and M 2 ; is L(M 1 )
  • L(M
2 )? (5) Giv en t w
  • DF
A's M 1 and M 2 ; is L(M 1 ) = L(M 2 )? Pro
  • f.
6. Prop
  • sition.
If L = L(M ); where M is a DF A, then L is a regular language; that is, there is a regular expression r suc h that L = L(r ): W e shall study t w
  • constructions
for this corresp
  • ndence.
The rst is a graph based algorithm that builds up the regular expression as no des are deleted from the state diagram. The second is a metho d analogous to solving a linear system
  • f
equations. T
  • presen
t the graph
  • rien
ted algorithm, w e need to in tro duce an ev en more general notion
  • f
NF A. It will ha v e the expanded prop ert y that its edges ma y b e lab eled b y regular expressions, not simply b y a 2
  • r
e: W e will denote this new class
  • f
automata b y GNF A. Next, w e describ e ho w a string w is accepted. No w, in an usual NF A, the mac hine matc hes an input sym b
  • l
with an edge lab el in
  • rder
to mak e a mo v e. F
  • r
a GNF A, the automaton will consume, p erhaps, more than
  • ne
sym b
  • l
in
  • rder
to mak e the next mo v e. It will consume a substring that b elongs to the regular language whic h is denoted b y the edge lab el. F
  • r
a tec hnical normalization reason, w e shall assume that the GNF A M has a start state s that has NO edge coming in to it and that M has a unique 6
slide-7
SLIDE 7 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions nal state ff g with NO edges lea ving it. F urther, assume f 6= s: F
  • r
completeness, w e giv e a detailed explanation
  • f
acceptance. Let M b e a GNF A, and let w 2
  • :
If w 2 L(M ); then w = w 1 w 2 : : : w k and there is a sequence
  • f
states q = s; q 1 ; : : : ; q k = f ; suc h that w i 2 L(R i ); where
  • (q
i1 ; q i ) = R i ; where R i is the regular expression lab el. Finally , w e can describ e the con v ersion pro cess
  • f
a DF A in to an equiv alen t regular expression. Step 1: Con v ert the giv en DF A M in to a GNF A M b y in tro ducing a new start state, new nal state, and the necessary transitions. Supp
  • se
M has k states. Step 2: If k = 2; then M has just the start state and the unique nal state. It is clear that L(M ) = L(R); where R =
  • (s;
f ): Step 3: "No de Reduction Step" If k > 2; w e remo v e a no de to pro duce an equiv alen t automaton M 00 : In particular, select a no de q 00 6= s; f : Then dene M 00 = (Q n fq 00 g; ;
  • 00
; s; ff g) where
  • 00
(q i ; q j ) =
  • (q
i ; q j ); if either
  • (q
i ; q 00 ) = ;
  • r
  • (q
00 ; q i ) = ;;
  • therwise,
  • 00
(q i ; q j ) = R 1
  • (R
2 )
  • R
3 [ R 4 ; where R 1 =
  • (q
i ; q 00 ); R 2 =
  • (q
00 ; q 00 ); R 3 =
  • (q
00 ; q j ); R 4 =
  • (q
i ; q j ): 7
slide-8
SLIDE 8 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions Step 4: Rep eat Step 3 un til M 00 has t w
  • states:
s and f : Note: This construction is also v alid for an y NF A. I w
  • rded
it for DF A's to emphasize the new automaton
  • f
t yp e GNF A. W e need to v erify that Step 3 do es indeed pro duce an equiv alen t automaton. W e can argue b y visualizing paths through the state diagram
  • f
the GNF A. W e next compare the ab
  • v
e graph algorithm with the approac h tak en in the textb
  • k.
As usual, the language L is accepted b y the DF A M = (fq 1 ; : : : ; q n g; ;
  • ;
q 1 ; F ): W e let R k ij denote the set
  • f
all strings that tak e the automaton M from state q i to state q j without going through an y state n um b ered k
  • r
larger; that is,
  • nly
strings are allo w ed that start at q i and end at q j and
  • nly
use states q 1 ; : : : ; q k 1 as in termediate states. Suc h sets
  • f
strings satisfy an imp
  • rtan
t inductiv e iden tit y: R k +1 ij = R k ij [ R k ik (R k k k )
  • R
k k j : T
  • understand
this iden tit y , consider the follo wing. An y string w that is con tained in R k +1 ij either uses state q k
  • r
not. If w do es not use state q k ; then it m ust lie in R k ij : So, w e m ust examine ho w state q k is used b y the string w : Of course, q k m ust b e used as some in termediate state. So, w uses a path 8
slide-9
SLIDE 9 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions from state q i to q k and from q k to q j ; suc h that
  • nly
states q 1 ; : : : ; q k are used as in termediate states. So, it seems that w e m ust add the set R k ik R k k j : In fact, there is a further p
  • ssibilit
y . W e can also use paths that cycle through state q k : So, the set
  • f
strings that use state q k is: R k ik (R k k k )
  • R
k k j : One detail to consider is that (R k k k )
  • is
prop erly larger than R k ij itself, b ecause q k is not allo w ed as an in termediate state for strings from R k ij : W e can easily describ e the set
  • f
strings R 1 ij : F
  • r
i 6= j; R 1 ij = fa :
  • (q
i ; a) = q j g; while for i = j; R 1 ii = fa :
  • (q
i ; a) = q i g [ feg: W e sho w b y induction that R k ij is denoted b y a regular expression r k ij : F
  • r
k = 1; w e let, for i 6= j; r 1 ij = a 1 [ : : : [ a p ; for i = j; r 1 ii = e [ a 1 [ : : : [ a p ; where
  • (q
i ; a ` ) = q j ; 1
  • `
  • p:
If this set is empt y , then r 1 ij = ;; for i 6= j ; while for i = j; r 1 ii = e: W e conclude that R 1 ij = L(r 1 ij ): W e no w assume that the result holds for v alue k : That is, for an y set R k `m ; there exists a regular expression r k `m suc h that R k `m = L(r k `m : W e need to sho w that an y set R k +1 ij is giv en b y a regular expression. By the inductiv e prop ert y
  • f
the set R k +1 ij ; w e kno w that R k +1 ij = R k ij [ R k ik (R k k k )
  • R
k k j : By the induction h yp
  • thesis,
w e ha v e: R k ij [ R k ik (R k k k )
  • R
k k j = L(r k ij ) [ L(r k ik )L((r k k k )
  • L(r
k k j ) = L(r k ij [ r k ik ((r k k k )
  • r
k k j ): This nishes the induction. 9
slide-10
SLIDE 10 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions Finally , w e
  • bserv
e that L(M ) = S fR n+1 1j : q j 2 F g: Example
  • f
con v erting a DF A in to a regular expression. Giv e a regular expression for the deterministic nite automaton M with states fq 1 ; q 2 ; q 3 g; with transitions: State a b 1 3 2 2 1 1 3 1 1 The accepting states are fq 2 ; q 3 g and the initial state is fq 1 g: W e compute the regular expressions r k ij ; for k = 1; 2; 3; 4: Recall: r k +1 ij = r k ij [ r k ik (r k k k )
  • r
k k j : F
  • r
k = 1; w e are in the base case. r 1 11 = e; r 1 12 = a; r 1 13 = b; r 1 21 = a; r 2 22 = e; r 2 23 = b; r 1 31 = ;; r 1 32 = a [ b; r 1 33 = e: 10
slide-11
SLIDE 11 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions F
  • r
the remaining sets, w e need to use the inductiv e set iden tit y . r 2 11 = r 1 11 [ r 1 11 (r 1 11 )
  • r
1 11 = e r 2 12 = r 1 12 [ r 1 11 (r 1 11 )
  • r
1 12 = a [ ae
  • e
= a r 2 13 = r 1 13 [ r 1 11 (r 1 11 )
  • r
1 13 = b [ ee
  • b
= b r 2 21 = r 1 21 [ r 1 21 (r 1 11 )
  • r
1 11 = a [ ae
  • e
= a r 2 22 = r 1 22 [ r 1 21 (r 1 11 )
  • r
1 12 = e [ ae
  • a
= e [ aa r 2 23 = r 1 23 [ r 1 21 (r 1 11 )
  • r
1 13 = b [ ae
  • b
= b [ ab r 2 31 = r 1 31 [ r 1 31 (r 1 11 )
  • r
1 11 = ; [ ;e
  • e
= ; r 2 32 = r 1 32 [ r 1 31 (r 1 11 )
  • r
1 12 = (a [ b) [ ;e
  • e
= ; r 2 33 = r 1 33 [ r 1 31 (r 1 11 )
  • r
1 13 = (a [ b) [ ;e
  • a
= a [ b r 3 11 = r 2 11 [ r 2 12 (r 2 22 )
  • r
2 21 = e [ a(e [ aa)
  • a
= (aa)
  • r
3 12 = r 2 12 [ r 2 12 (r 2 22 )
  • r
2 22 = a [ a(e [ aa)
  • (e
[ aa) = a(aa)
  • r
3 13 = r 2 13 [ r 2 12 (r 2 22 )
  • r
2 23 = (b [ ab) [ a(e [ aa)
  • (b
[ ab) = a
  • b
r 3 21 = r 2 21 [ r 2 22 (r 2 22 )
  • r
2 21 = a [ (e [ aa)(e [ aa)
  • a
= a(aa)
  • r
3 22 = r 2 22 [ r 2 22 (r 2 22 )
  • r
2 22 = (e [ aa) [ (e [ aa)(e [ aa)
  • (e
[ aa) = (aa)
  • r
3 23 = r 2 23 [ r 2 22 (r 2 22 )
  • r
2 23 = (b [ ab) [ (e [ aa)(e [ aa)
  • (b
[ ab) = a
  • 11
slide-12
SLIDE 12 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions r 3 31 = r 2 31 [ r 2 32 (r 2 22 )
  • r
2 21 = ; [ (a [ b)(e [ aa)
  • a
= (a [ b)(aa)
  • a
r 3 32 = r 2 32 [ r 2 32 (r 2 22 )
  • r
2 22 = (a [ b) [ (a [ b)(e [ aa)
  • (e
[ aa) = (a [ b)(aa)
  • r
3 33 = r 2 33 [ r 2 32 (r 2 22 )
  • r
2 23 = e [ (a [ b)(e [ aa)
  • (b
[ ab) = e [ (a [ b)a
  • b
Finally , w e
  • nly
need to compute r 4 12 and r 4 13 : r 4 12 = r 3 12 [ r 3 13 (r 3 33 )
  • r
3 32 = a(aa)
  • [
a
  • [e
[ (a [ b)a
  • b]
  • (a
[ b)(aa)
  • =
a(aa)
  • [
a
  • b[(a
[ b)a
  • b]
  • (a
[ b)(aa)
  • r
4 13 = r 3 13 [ r 3 13 (r 3 33 )
  • r
3 33 = a
  • b
[ a
  • b[(a
[ b)a
  • b]
  • a
  • b
= a
  • b[(a
[ b)a
  • b]
  • F
  • r
the second metho d, w e rst presen t a result that is kno wn as Arden's Lemma: Arden's Lemma: Let A; B
  • with
e = 2 A: Then the equation: X = A
  • X
[ B has the unique solution X = A
  • B
: Step 1: If X is a solution, then A
  • B
  • X
: 12
slide-13
SLIDE 13 We ek F
  • ur
: : : : : Equivalenc e b etwe en A utomata and R e gular Expr essions T
  • see
this, note that A
  • B
= (A + [ e)B = A + B [ B = A(A
  • B
) [ B : Step 2: X
  • A
  • B
: By Step 1, X = A
  • B
[ C ; since A
  • B
  • X
with C \ A
  • B
= ;: W e w an t to sho w that C = ;: No w X = AX [ B ; so A
  • B
[ C = A(A
  • B
[ C ) [ B = A + B [ AC [ B = A + B [ B [ AC = (A + [ e)B [ AC = A
  • B
[ AC : Next, consider the relation: (A
  • B
[ C ) \ C = (A
  • B
[ AC ) \ C : Then C = AC \ C ; so C
  • AC
: Since e 6= A; the shortest string in AC m ust b e longer than the shortest string in C : Hence, AC = C = ;: W e conclude: A
  • B
is the unique solution. Note: If e 2 A; then the solution A
  • B
is no longer unique but it is the smallest solution. 13