Closure Properties Summary Inf2A: Closure Properties of Regular Languages Stuart Anderson School of Informatics University of Edinburgh October 19, 2007 university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Summary Outline Closure Properties 1 Demonstrating Closure under various operators Closure: Example Summary 2 university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Regular expressions R L ( R ) ε { ε } ∅ ∅ { a } (for any a ∈ Σ ) a L ( R 1 ) ∪ L ( R 2 ) R 1 + R 2 � � R 1 R 2 xy | x ∈ L ( R 1 ) , y ∈ L ( R 2 ) R ∗ � x 1 . . . x n | n ∈ N 0 , x 1 , . . . , x n ∈ L ( R 1 ) � . 1 university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Closure under union and concatenation Theorem: If L 1 and L 2 are regular languages, then the following two languages are also regular: L 1 ∪ L 2 , 1 � L 1 L 2 = xy | x ∈ L 1 , y ∈ L 2 } . 2 Proof: Let R 1 , R 2 be regular expressions such that L ( R 1 ) = L 1 , L ( R 2 ) = L 2 . Then L 1 ∪ L 2 = L ( R 1 ) ∪ L ( R 2 ) = L ( R 1 + R 2 ) and L 1 L 2 = L ( R 1 ) L ( R 2 ) = L ( R 1 R 2 ) . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Closure under complementation Theorem: If L ⊆ Σ ∗ is a regular language, then the following language is also regular: ∼ L = { x ∈ Σ ∗ | x �∈ L } . Proof: Let M be a DFA that recognises L . Let M ′ be the DFA obtained from M by making all states that are not final states of M final states of M ′ and vice versa. Then M ′ recognises ∼ L : M ′ accepts string x running M ′ on input x ends in a final state of M ′ ⇐ ⇒ running M ′ on input x does not end in a final state of M ⇐ ⇒ ⇐ ⇒ running M on input x does not end in a final state of M ⇐ ⇒ M does not accept x ⇐ ⇒ x ∈∼ L . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example a b a a a b b b A DFA for the language L = { x aba | x ∈ { a , b } ∗ } . a b a a a b b b A DFA for ∼ L . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Closure under intersection and difference Theorem: If L 1 and L 2 are regular languages, then the following two languages are also regular: L 1 ∩ L 2 , 1 � L 1 \ L 2 = x | x ∈ L 1 and x �∈ L 2 } . 2 Proof: We use the facts that � � L 1 ∩ L 2 = ∼ ∼ L 1 ∪ ∼ L 2 (by DeMorgan’s rule) and � � L 1 \ L 2 = L 1 ∩ ∼ L 2 = ∼ ∼ L 1 ∪ L 2 . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Constructions Problem: Suppose we are given DFAs for L 1 and L 2 . How do we construct DFAs for ∼ L 1 , L 1 ∪ L 2 , L 1 ∩ L 2 , L 1 \ L 2 ? university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Complementation We have already seen a construction. Union Compute an NFA with ε -transitions. 1 Convert it to a DFA. 2 Intersection and difference Combine the constructions for complementation and union. university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example a,b a b a a a a b a b p0 p1 p2 p3 q1 q2 q3 q0 b a b b b q4 a,b M 1 M 2 Construct a DFA for � � L ( M 1 ) ∩ L ( M 2 ) = ∼ ∼ L ( M 1 ) ∪ ∼ L ( M 2 ) . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example (cont’d) Step 1: Construct DFAs for ∼ L ( M 1 ) and ∼ L ( M 2 ) . a,b a b a a b a a b a p0 p1 p2 p3 q0 q1 q2 q3 b a b b b q4 a,b university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example (cont’d) Step 2: Construct an NFA with ε -transitions for ∼ L ( M 1 ) ∪ ∼ L ( M 2 ) . a b a a a b p0 p1 p2 p3 ε b b 0 a,b ε a a b q0 q2 q3 q1 b a b q4 a,b university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example (cont’d) Step 3: Convert the NFA with ε -transitions for ∼ L ( M 1 ) ∪ ∼ L ( M 2 ) to a DFA. δ a b { 0 , p 0 , q 0 } { p 1 , q 1 } { p 0 , q 4 } { p 1 , q 1 } { p 1 , q 4 } { p 2 , q 2 } { p 0 , q 4 } { p 1 , q 4 } { p 0 , q 4 } { p 1 , q 4 } { p 1 , q 4 } { p 2 , q 4 } { p 2 , q 2 } { p 3 , q 3 } { p 0 , q 4 } { p 2 , q 4 } { p 3 , q 4 } { p 0 , q 4 } { p 3 , q 3 } { p 1 , q 3 } { p 2 , q 3 } { p 3 , q 4 } { p 1 , q 4 } { p 2 , q 4 } { p 1 , q 3 } { p 1 , q 3 } { p 2 , q 3 } { p 2 , q 3 } { p 3 , q 3 } { p 0 , q 3 } { p 0 , q 3 } { p 1 , q 3 } { p 0 , q 3 } university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Example (cont’d) Step 4: Complement the DFA for ∼ L ( M 1 ) ∪ ∼ L ( M 2 ) . Result: � � � � Q , Σ , { 0 , p 0 , q 0 } , { p 3 , q 3 } , δ , where � Q = { 0 , p 0 , q 0 } , { p 1 , q 1 } , { p 0 , q 4 } , { p 1 , q 4 } , { p 2 , q 2 } , { p 2 , q 4 } , � { p 3 , q 3 } , { p 3 , q 4 } , { p 1 , q 3 } , { p 2 , q 3 } , { p 0 , q 3 } , university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Demonstrating Closure under various operators Summary Closure: Example Union vs. Intersection vs. Difference The automata we construct for L ( M 1 ) ∩ L ( M 2 ) , L ( M 1 ) ∪ L ( M 2 ) , and L ( M 1 ) \ L ( M 2 ) only differ in their final states: Intersection: Final states (of the powerset automaton) are states that contain a final state of M 1 and a final state of M 2 . Union: Final states (of the powerset automaton) are states that contain a final state of M 1 or a final state of M 2 . Difference: Final states (of the powerset automaton) are states that contain a final state of M 1 but not a final state of M 2 . university-logo Stuart Anderson Regular Languages Lecture 9A
Closure Properties Summary Summary Kleene’s theorem tell us that regular expressions and FSAs describe the same class of languages. NFA/DFA equivalence tells us that in this case nondeterminism doe not change the class of languages recognised (see later). Closure results tell us we can augment regular expressions with many operaors that allow us to express regular sets succinctly without going outside languages recognisable by FSMs. university-logo Stuart Anderson Regular Languages Lecture 9A
Recommend
More recommend