notes to closure properties

Notes to Closure Properties Simpli fi cation of the automata design L - PowerPoint PPT Presentation

Notes to Closure Properties Simpli fi cation of the automata design L . = . L = { } . L = L . { } = L ( L ) L = 1 ) = L ( L 1 L 2 ) L 1 ( L 2 . L 2 ( L 1 . L 2 ) = ( L 1 . L 2 ) R L


  1. Notes to Closure Properties Simpli fi cation of the automata design L . ∅ = ∅ . L = ∅ { λ } . L = L . { λ } = L ( L ∗ ) ∗ L ∗ = 1 ) ∗ = L ∗ ( L 1 ∪ L 2 ) ∗ L ∗ 1 ( L 2 . L ∗ 2 ( L 1 . L ∗ 2 ) ∗ = ( L 1 . L 2 ) R L R 2 . L R = 1 ∂ w ( L 1 ∪ L 2 ) ∂ w ( L 1 ) ∪ ∂ w ( L 2 ) = ∂ w ( Σ ∗ − L ) Σ ∗ − ∂ w L = Proof of non–regularity L = { w | w ∈ { 0 , 1 } ∗ , | w | 1 = | w | 2 } is not regular since L ∩ { 0 i 1 j | i , j ≥ 0 } = { 0 i 1 i | i ≥ 0 } is not regular (pumping lemma). Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 75 / 75 - 95

  2. Regular Expressions (RegE) De fi nition 4.1 (Regular Expression (RegE), value of a RegE L ( α )) Regular expressions α , β ∈ RegE ( Σ ) over a fi nite non–empty alphabet Σ = { x 1 , x 2 , . . . , x n } and their value L ( α ) is de fi ned by induction: value L ( α ) ≡ [ α ] expression α for ∅ empty expression L ( ∅ ) = {} ≡ ∅ Basis: empty string L ( λ ) = { λ } λ a a ∈ Σ L ( a ) = { a } . Induction: expression value remark α + β L ( α + β ) = L ( α ) ∪ L ( β ) L ( αβ ) = L ( α ) L ( β ) . may be used αβ α ∗ L ( α ∗ ) = L ( α ) ∗ ( α ) L (( α )) = L ( α ) brackets do not change the value. The class of regular expressions over Σ : RegE ( Σ ) is the smallest class closed under operations above. Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 76 / 75 - 95

  3. Examples, Precedence Example 4.1 (Regular Expressions) The language of alternating 0’s and 1’s may be written: either ( 01 ) ∗ + ( 10 ) ∗ + 1 ( 01 ) ∗ + 0 ( 10 ) ∗ or ( λ + 1 )( 01 ) ∗ ( λ + 0 ). The language L (( 0 ∗ 10 ∗ 10 ∗ 1 ) ∗ 0 ∗ ) = { w | w ∈ { 0 , 1 } ∗ , | w | 1 = 3 k , k ≥ 0 } . De fi nition 4.2 (Precedence) The star ∗ is the operator with highest precedence, then concatenation . , the lowest precedence has the union +. Theorem 4.1 (RegE and DFA ! Kleene theorem (a variant)) Any language recognizable by a DFA can be expressed by a regular expression. Any language of a regular expression can be recognized by a λ -NFA (therefore also a DFA). Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 77 / 75 - 95

  4. Example 0,1 1 R (2) 12 = 1 ∗ 0 ( 0 + 1 ) ∗ 0 1 2 R (0) λ + 1 = 11 R (0) 0 = 12 R (0) ∅ = 21 R (0) ( λ + 0 + 1 ) = 22 R (1) λ + 1 + ( λ + 1 )( λ + 1 ) ∗ ( λ + 1 ) = 1 ∗ 11 R (1) 0 + ( λ + 1 )( λ + 1 ) ∗ 0 = 1 ∗ 0 12 R (1) ∅ + ∅ ( λ + 1 ) ∗ ( λ + 1 ) = ∅ 21 R (1) λ + 0 + 1 + ∅ ( λ + 1 ) ∗ 0 = λ + 0 + 1 22 1 ∗ + 1 ∗ 0 ( λ + 0 + 1 ) ∗ ∅ R (2) = 1 ∗ 11 R (2) 1 ∗ 0 + 1 ∗ 0 ( λ + 0 + 1 ) ∗ ( λ + 0 + 1 ) = 1 ∗ 0 ( 0 + 1 ) ∗ 12 R (2) ∅ + ( λ + 0 + 1 )( λ + 0 + 1 ) ∗ ∅ = ∅ 21 R (2) λ + 0 + 1 + ( λ + 0 + 1 )( λ + 0 + 1 ) ∗ ( λ + 0 + 1 )=( 0 + 1 ) ∗ 22 Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 78 / 75 - 95

  5. From a DFA to RegE From a DFA to RegE Let us have a DFA A , Q A = { 1 , . . . , n } with n states. Let R ( k ) be a regular expression, L ( R ( k ) ij ) = { w | δ ∗ ≤ k ( i , w ) = j } the set of ij words transferring the state i into j in A where no state with an index higher than k is on the path. We iteratively construct R ( k ) pro k = 0 , . . . , n . ij k = 0, i � = j : R (0) = a 1 + a 2 + . . . + a m where a 1 , a 2 , . . . , a m are symbols on ij edges i into j (or R (0) = ∅ or R (0) = a for m = 0 , 1). ij ij k = 0, i = j : loops, R (0) = λ + a 1 + a 2 + . . . + a m where a 1 , a 2 , . . . , a m are ii symbols on loops in i . Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 79 / 75 - 95

  6. Induction. We have ∀ i , j ∈ Q R ( k ) ij . We construct R ( k +1) . ij R ( k ) ( k +1) , ( k +1) R ( k ) R ( k ) i , ( k +1) ( k +1) , j j k+1 i R ( k ) i , j R ( k +1) = R ( k ) + R ( k ) i ( k +1) ( R ( k ) ( k +1)( k +1) ) ∗ R ( k ) ij ij ( k +1) j Paths from i into j not meeting ( k + 1) are already in R ( k ) ij . Paths from i into j through ( k + 1) with possible loops can be expressed R ( k ) i ( k +1) ( R ( k ) ( k +1)( k +1) ) ∗ R ( k ) ( k +1) j . Finally RegE = ⊕ j ∈ F A R ( n ) the union over all accepting states j . 1 j Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 80 / 75 - 95

  7. DFA to RegE by Successive State Elimination Previous method may generate up to 4 n symbols. Following algorithm sometimes avoids duplicity. We allow regular expressions to anotate the graph (a transformation of the automaton). State s selected for elimination After s is eliminated. R 11 + Q 1 S ∗ P 1 R 11 q 1 p 1 q 1 p 1 S Q 1 P 1 R 21 + Q 2 S ∗ P 1 R 1 m + Q 1 S ∗ P m s R k 1 + Q k S ∗ P 1 R 21 Q 2 R 1 m P m R 31 q 2 q 2 R 2 m + Q 2 S ∗ P m Q k p m p m R 2 m R km + Q k S ∗ P m R 3 m q k q k Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 81 / 75 - 95

  8. A RegE from a DFA For every accepting state q ∈ F we eliminate all states p ∈ Q \ { q , q 0 } . U R For q � = q 0 we take S RegE ( q ) = ( R + SU ∗ T ) ∗ SU ∗ . T R For q = q 0 we take RegE ( q ) = R ∗ . And take the union (addition) over all accepting states: RegE ( DFA ) = ⊕ q ∈ F RegE ( q ). Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 82 / 75 - 95

  9. Example Example 4.2 DFA that accepts 1 at the second last or the third-last position. 0,1 0,1 0,1 1 the original automaton A B C D 0 + 1 0 + 1 0 + 1 1 We replace strings by a RegE. A B C D 0 + 1 1 ( 0 + 1 ) 0 + 1 We eliminate B . A C D 0 + 1 1 ( 0 + 1 )( 0 + 1 ) We eliminate C . A D We get RegE: ( 0 + 1 ) ∗ 1 ( 0 + 1 ) + ( 0 + 1 ) ∗ 1 ( 0 + 1 )( 0 + 1 ). [Elimination Order] We start by non-accepting nor initial nodes q / ∈ F , q � = q 0 . Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 83 / 75 - 95

  10. From a RegE to λ –NFA From a RegE to λ –NFA Basis: By induction by the structure of R . In each step we construct λ -NFA E that λ Empty string λ recognizes the same language L ( R ) = L ( E ) with three additional properties: Empty set ∅ 1. Exactly one accepting state. 2. No edges into the inital state. a A single string a 3. No edges from the accepting state. λ λ Addition R + S : R λ λ S INDUCTION: λ Concatenation RS : R S λ Iteration R ∗ : λ λ R λ Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 84 / 75 - 95

  11. Pattern search in the text Static text: we create indexes rather than using RegE. RegE are useful in the dynamic text (like news). Example 4.3 (Search for streets in addresses on the web) Street identi fi cation Streen|St \ .|Avenue|Ave \ .|Road|Rd \ the name before ’[A-Z][a-z]*( [A-Z][a-z]*)*’ house number [0-9]+[A-Z]? ’[0-9]+[A-Z]? [A-Z][a-z]*( [A-Z][a-z]*)* all together Streen|St \ .|Avenue|Ave \ .|Road|Rd \ . ’ We are missing: Bouleward, Place, Way Streets without any identi fi er (almost all Czech streets) Street names with numbers. . . . Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 85 / 75 - 95

  12. Converting Among Representations Converting NFA to DFA λ − NFA NFA λ closure in O ( n 3 ). Search O ( n ) n states multiplied by n 2 O ( n 3 2 n ) arcs for λ transitions. O ( n ) O ( n 3 2 n ) Subset construction, DFA O ( n ) with possibly 2 n states. For each state, O ( n 3 ) time to RegE DFA O ( n 3 4 n ) compute transitions. Converting DFA to NFA Just modify transition table by putting set-brackets around states and adding column for λ in the case of λ − NFA. Automaton to Regular Expression Conversion O ( n 3 4 n ) RegE to Automaton Conversion λ − NFA in the time O ( n ). Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 86 / 75 - 95

  13. String Substitution, (String) Homomorphism De fi nition 4.3 (String Substitution, (String) Homomorphism) We have a fi nite alphabet Σ . For each x ∈ Σ we have σ ( x ) a language over the alphabet Y x . Further, we de fi ne: σ ( λ ) = { λ } σ ( u . v ) = σ ( u ) . σ ( v ) The mapping σ : Σ ∗ → P ( Y ∗ ) where Y = � x ∈ Σ Y x is substitution . σ ( L ) = � w ∈ L σ ( w ) e–free, λ –free substitution is a substitution where none σ ( x ) contains λ . For w = a 1 . . . a n ∈ Σ n σ ( w ) = σ ( a 1 ) . . . σ ( a n ). Example 4.4 (substitution) σ (0) = { a i b j , i , j ≥ 0 } , σ (1) = { cd } σ (010) = { a i b j cda k b l , i , j , k , l ≥ 0 } Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 87 / 75 - 95

  14. (String) Homomorphism De fi nition 4.4 ((String) Homomorphism) Homomorphism h is a special case of a substitution where h ( x ) = w x ∀ x ∈ Σ . If ∀ x : w x � = λ is is e–free ( λ –free) homomorphism . Inverse homomorphism h − 1 ( L ) = { w | h ( w ) ∈ L } . Example 4.5 (homomorphism) The function h de fi ned by: h (0) = ab , and h (1) = λ is a homomorphism. For example, h (0011) = abab . For L = 10 ∗ 1 is h ( L ) = ( ab ) ∗ . Theorem (Closure under homomorphism) If language L and all ∀ x ∈ Σ σ ( x ) are regular, so is also σ ( L ) , h ( L ) , h − 1 ( L ) . Automata and Grammars Regular Expressions,Kleene Theorem, Subst., Homom. 4 August 9, 2019 88 / 75 - 95

Recommend


More recommend