NFA/DFA: Closure Properties, Relation to Regular Languages Lecture 5 1
Today NFAs recap : Determinizing an NFA Closure Properties of class of languages accepted by NFAs/DFAs Towards proving equivalence of regular languages and languages accepted by NFAs (and hence DFAs) More closure Properties of regular languages CS 374 2
NFA : Formally N = ( Σ , Q , δ , s , F ) Σ : alphabet Q : state space s : start state F : set of accepting states " By default, NFA δ : Q × { Σ ∪ ε } → � ( Q ) can have ε -moves w We say q � N p if ∃ a 1 , …, a t ∈ Σ ∪ { ε } and q 1 ,…, q t +1 ∈ Q , such that w = a 1 … a t , q 1 = q, q t +1 = p, and ∀ i ∈ [ 1, t ], q i +1 ∈ δ ( q i ,a i ) w s � N p L ( N ) = { w | for some p ∈ F } ε -closure C ε ({ 1 }) = { 1 , 2 , 3 , 0 } e.g., δ ( 1 , o ) = { 2 }, δ ( 1 , x )=Ø, δ ( 1 , ε )={ 2 } . CS 374 ε a-z ε 0 1 3 4 6 2 5 c o l o u r ε ε ε 3
ε -Moves is Syntactic Sugar Can modify any NFA N , to get an NFA N new without ε -moves N new = ( Σ , Q , δ new , s , F new) ! a ∈ Σ a { p | q � N p } δ new ( q , a ) = C ε ( δ ( C ε ({ q }), a )) $ ε q � N p ⇔ p ∈ C ε ({ q} ) , { 0 , 2 , 3 , 4 , 5 } e.g. : δ new ( 1 , o ) = ? . ε q � N new p ⇔ p=q, w w For | w | ≥ 1, q � N p ⇔ q � N new p Prove! { F , if C ε ({ s }) ∩ F = Ø F new = F ∪ { s }, otherwise. Theorem : L ( N ) = L ( N new ) CS 374 ε a-z ε 0 1 3 4 6 2 5 c o l o u r ε ε ε 4
ε -Moves is Syntactic Sugar Can modify any NFA N , to get an NFA N new without ε -moves N new = ( Σ , Q , δ new , s , F new) ! δ new ( q , a ) = C ε ( δ ( C ε ({ q }), a )) δ q C a δ c 0 0 0 1, ε 0 { a, b, c } { a, b, c, d } 1 a b a { a, b, d } 1 { b, d } { b, d } ε 1 d 0 { b, c } { b, c, d } b { b, d } 1 { d } { d } 0 Ø Ø CS 374 c { c } 1 { d } { d } 0 Ø Ø d { d } 1 { d } { d } 5
ε -Moves is Syntactic Sugar Can modify any NFA N , to get an NFA N new without ε -moves N new = ( Σ , Q , δ new , s , F new) ! δ new ( q , a ) = C ε ( δ ( C ε ({ q }), a )) δ q a c 0 0 0 1, ε 0 { a, b, c, d } 1 a b a 1 { b, d } ε 1 d { 0 { b, c, d } F , if C ε ({ s }) ∩ F = Ø F new = b 0 F ∪ { s }, otherwise. 1 { d } c 0 0 0 0 Ø 0 ,1 CS 374 c 1 a b 1 { d } 0 ,1 1 0 Ø d d 0 ,1 1 { d } 6
NFA to DFA Can modify any NFA N , to get an equivalent DFA M To avoid errors, first, Remember to δ T a remove ε -moves specify final states 0 0 { a,b,c,d } 0 0,1 {a} bcd bd δ q a 1 { b,d } 1 0 { a,b,c,d } 1 1 1 0 { a, b, c, d } Ø a {a,b,c,d} 0 a 1 { b,d } 1 { b, d } 0 0 0 { b,c,d } abcd d {b,d} 1 0 { b, c, d } 1 { d } b 0 1 { d } { b,c,d } 0 {b,c,d} c 0 0 { d } 1 0 0 Ø 0 ,1 CS 374 c 0 Ø 1 a b 1 { d } {d} 1 { d } 0 ,1 1 0 Ø d 0 Ø d Ø 0 ,1 1 { d } 1 Ø 7
NFA to DFA: Formally DFA: M N = ( Σ , � ( Q ), δ † , s † , F † ) NFA: N = ( Σ , Q , δ , s , F ) δ : Q × Σ → � ( Q ) δ † : � ( Q ) × Σ → � ( Q ) δ † ( T , a ) = ∪ q ∈ T δ ( q , a ) ε -moves already s † = { s }, F † = { T | T ∩ F ≠ Ø } removed Theorem : L ( N ) = L ( M N ) Proof? Recall definitions of L ( DFA ), L ( NFA ) CS 374 8
Language Accepted by a DFA DFA: M = ( Σ , Q M , δ M , s M , F M ) Two ways to define the state that an input w leads to starting from a state w q � p if w = a 1 … a t and ∃ q 1 ,…, q t +1 , δ * ( q, ε ) = q such that q 1 = q, q t +1 = p, and δ * ( q,au ) = δ * ( δ M ( q,a ) , u ) ∀ i ∈ [ 1, t ], q i +1 = δ M ( q i ,a i ) w Theorem : q � p ⇔ p = δ *( q , w ) Prove! CS 374 w L ( M ) = { w | ∃ p ∈ F M , s M � p } = { w | δ * ( s M ,w ) ∈ F M } 9
Language Accepted by an NFA NFA: N = ( Σ , Q N , δ N , s N , F N ) Two ways to define the set of states that an input w leads to starting from a set of states w q � p δ † ( T , a ) = ∪ q ∈ T δ N ( q , a ) if ∃ a 1 … a t and q 1 ,…, q t +1 , such δ † * ( T , ε ) = T that w = a 1 … a t , q 1 = q, q t +1 = p, δ † * ( T , au ) = δ † *( δ † ( T , a ), u ) and ∀ i ∈ [ 1, t ], q i +1 ∈ δ N ( q i ,a i ) s † = { s N }, F † = { T | T ∩ F N ≠ Ø } w Theorem : q � p ⇔ p ∈ δ † *({ q }, w ) Prove! CS 374 w L ( N ) = { w | ∃ p ∈ F N , s N � p } = { w | δ † * ({ s N } ,w ) ∩ F N ≠ Ø } = { w | δ † * ( s † ,w ) ∈ F † } 10
Side-by-Side DFA: M = ( Σ , Q M , δ M , s M , F M ) NFA: N = ( Σ , Q N , δ N , s N , F N ) δ N : Q N × Σ → � ( Q N ) δ † : � ( Q N ) × Σ → � ( Q N ) δ M : Q M × Σ → Q M δ † ( T , a ) = ∪ q ∈ T δ N ( q , a ) δ † * ( T , ε ) = T δ * ( q, ε ) = q δ * ( q,au ) = δ * ( δ M ( q,a ) , u ) δ † * ( T , au ) = δ † *( δ † ( T , a ), u ) s † = { s N }, F † = { T | T ∩ F N ≠ Ø } CS 374 L ( M ) ={ w | δ * ( s M ,w ) ∈ F M } L ( N ) = { w | δ † * ( s † ,w ) ∈ F † } If Q M = � ( Q N ) , δ M = δ † , s M = s † , F M = F † , then L ( M )= L ( N ) ✓ 11
Closure Properties for NFAs If L has an NFA, then op ( L ) has an NFA where op can be complement or Kleene star If L 1 and L 2 each has an NFA, then L 1 op L 2 has an NFA where op can be a binary set operation (e.g., union, intersection, difference etc.) or concatenation Complement and Binary set operations Consider the equivalent DFA CS 374 Union can be seen directly too… 12
Closure Under Union ε ε CS 374 13
Closure Properties for NFAs If L has an NFA, then op ( L ) has an NFA where op can be complement or Kleene star If L 1 and L 2 each has an NFA, then L 1 op L 2 has an NFA where op can be a binary set operation (e.g., union, intersection, difference etc.) or concatenation Complement and Binary set operations Consider the equivalent DFA CS 374 (Union can be seen directly too…) Now: concatenation and Kleene star 14
Single Final State Form Can compile a given NFA so that there is only one final state (and there is no transition out of that state) ε ε CS 374 15
Closure Under Concatenation ε CS 374 16
Closure Under Kleene Star ε ε CS 374 17
NFAs & Regular Languages Theorem : For any language L, the following are equivalent: (a) L is accepted by an NFA (b) L is accepted by a DFA (c) L is regular Saw : (a) ⇒ (b) Later : (b) ⇒ (c) Now : (c) ⇒ (a) CS 374 Proof of (c) ⇒ (a) : By induction on the least number of operators in a regular expression for the language 18
NFAs & Regular Languages Theorem : L regular ⇒ L is accepted by an NFA Proof : To prove that if L = L ( r ) for some regex r , then L = L ( N ) for some NFA N . By induction on the number of operators in the regex. Base case: L has a regular expression with 0 operators. Then the regex should be one of Ø, ε , a ∈ Σ . In each case, ∃ N s.t. L = L ( N ) . ✓ Inductive step: Let n > 0 . Assume that every language which has a regex with k operators has an NFA, where 0 ≤ k < n . CS 374 If L has a regex with n operators, it must be of the form r 1 r 2 , r 1 + r 2 , or r 1 * , and hence L = L 1 L 2 , or L 1 ∪ L 2 or ( L 1 )* , where L 1 = L ( r 1 ) and L 2 = L ( r 2 ) . Since r 1 and r 2 must have < n operators, by IH L 1 , L 2 have NFAs. By closure of NFAs under these operations , so does L . ✓ 19
NFAs & Regular Languages Example : L given by regular expression (10+1)* ε 1 ε 0 ε ε ε ε ε 1 CS 374 20
Closure Properties for Regular Languages Theorem : If L i are regular then, so is: From the definition of regular languages L 1 ∪ L 2 , L 1 *, L 1 L 2 $ (or from NFA closure properties) ̅ 1 $ By considering DFAs for the languages and L using the complement construction for DFAs L 1 ∩ L 2 $ By De Morgan’s Law (or by the cross-product construction for DFAs) formula( L 1 , L 2 , …, L k ) $ suffix( L 1 ) $ CS 374 h ( L 1 ) and h -1 ( L 1 ) , where h is a homomorphism Skipped from this course … 21
More Closure Properties formula f ( L 1 , …, L k ) = { w | f ( b 1 ,…, b k ) holds, where b i ≡ ( w ∈ L i ) } $ e.g., f ( b 1 , b 2 , b 3 ) = majority ( b 1 , b 2 , b 3 ) Theorem : If L 1 , …, L k are regular, then for any boolean formula f , formula f ( L 1 , …, L k ) is regular Proof : Any boolean formula can be written using operators ∧ , ∨ and ¬ (AND, OR, NOT). formula f ∧ g ( L 1 , …, L k ) = formula f ( L 1 , …, L k ) ∩ formula g ( L 1 , …, L k ) formula f ∨ g ( L 1 , …, L k ) = formula f ( L 1 , …, L k ) ∪ formula g ( L 1 , …, L k ) formula ¬ f ( L 1 , …, L k ) = Σ * — formula f ( L 1 , …, L k ) CS 374 Complete the proof by induction on the number of operators in f . 22
Recommend
More recommend