Section 3 Non-Determinism, Regular Expressions, and Kleene’s Theorem Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem 109 / 289
Chapter Non-Determinism, Regular Expressions, and Kleene’s 2 Theorem Examples Allowing Λ -transitions Definitions Making the automaton deterministic Regular languages Kleene Brzozowski et McCluskey Other Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem 110 / 289
Regular languages Definition (REG) – ∅ is in REG. – { a } in REG, for every a ∈ Σ – if L 1 and L 2 in REG, then so are L 1 ∪ L 2 , L 1 · L 2 , and L ∗ 1 . [M] D. 3.1 R Smallest set[family] of languages that – contains ∅ and { a } for a ∈ Σ , and basis – is closed under union, concatenation and star. induction [M] cf. E 1.20 Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 148 / 289
From elementary components { ab , bab } ∗ { Λ , bb } ( ( { a } · { b } ) ∪ ( { b } · { a } · { b } ) ) ∗ · ( ∅ ∗ ∪ ( { b } · { b } ) ) · ∗ ∪ ∪ ∗ · · · { b } { b } ∅ { a } { b } { b } · { a } { b } Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 149 / 289
Regular expressions – ∅ , Λ , and a are RegEx (for all a ∈ Σ ) – if E 1 and E 2 are RegEx, then so are E ∗ 1 , ( E 1 + E 2 ) , and ( E 1 E 2 ) expression [syntax] vs its language [semantics] E string L ( E ) language ∅ ∅ { Λ } Λ a { a } ( E 1 + E 2 ) L ( E 1 ) ∪ L ( E 2 ) ( E 1 E 2 ) L ( E 1 ) · L ( E 2 ) E ∗ L ( E 1 ) ∗ 1 we say E 1 = E 2 iff L ( E 1 ) = L ( E 2 ) w ∈ E iff w ∈ L ( E ) Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 150 / 289
Examples – Odd number of a bba 0 ba 1 bbba 2 bba 1 a 2 bb b ∗ ab ∗ ( ab ∗ a ) ∗ b ∗ not correct b ∗ ab ∗ ( ab ∗ ab ∗ ) ∗ b ∗ ab ∗ ( ab ∗ ab ∗ )( ab ∗ ab ∗ ) b ∗ a ( b ∗ ab ∗ ab ∗ ) ∗ not correct b ∗ a ( b ∗ ab ∗ a ) ∗ b ∗ b ∗ a ( b ∗ ab ∗ a )( b ∗ ab ∗ a ) b ∗ b ∗ a ( b + ab ∗ a ) ∗ b ∗ ab ∗ ( ab ∗ a ) b ∗ ( ab ∗ a ) b ∗ [M] E 3.2 Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 151 / 289
Examples – Ending with b , no aa bb ( ab ) bbb ( ab )( ab ) b ( b + ab ) ∗ ( b + ab ) at least once [M] cf. E 3.3, see ֒ → E. 2.3 – No aa may also end in a ( b + ab ) ∗ ( Λ + a ) Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 152 / 289
Examples – Even number of both a and b two letters together aa and bb keep both numbers even [odd] ab and ba switch between even and odd, for both numbers Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 153 / 289
Examples – Even number of both a and b two letters together aa and bb keep both numbers even [odd] ab and ba switch between even and odd, for both numbers ( aa + bb + ( ab + ba )( aa + bb ) ∗ ( ab + ba ) ) ∗ [M] E 3.4, see ֒ → Brzozowski et McCluskey aa a ee oe ee oe a ab + ba aa bb ab + ba b b b b a eo oo eo oo a bb Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 154 / 289
Kleene’s theorem Theorem (Kleene) Finite automata and regular expressions specify the same familiy of languages. from RegEx to FAA → Thompson’s construction ֒ from FA to RegEx → McNaughton and Yamada ֒ State elimination ֒ → Brzozowski et McCluskey Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 155 / 289
Thompson’s construction Theorem If L is a regular language, then there exists an NFA that accepts L. q 1 M 1 f 1 q 0 q 0 q 2 M 2 f 2 a q 0 f q 1 q 2 M 1 f 1 M 2 f 2 NFA for L ∗ . . . [M] Th 3.25 [L] Th 3.1 Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 156 / 289
Thompson’s construction Theorem If L is a regular language, then there exists an NFA that accepts L. q 1 M 1 f 1 q 0 q 0 q 2 M 2 f 2 a q 0 f q 0 q 1 M 1 f 1 q 1 q 2 M 1 f 1 M 2 f 2 [M] Th 3.25 [L] Th 3.1 Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 157 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ Step 1 ♠ ♠ ❥ ♠ ♠ ❥ ✲ ✲ ✲ ✲ a a ♠ ❥ ♠ ✲ ✲ b ♠ ❥ ♠ ♠ ♠ ❥ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a a b ♠ ♠ ❥ ♠ ❥ ♠ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a b b Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 158 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ Step 2 ♠ ♠ ♠ ♠ ❥ ✲ ✲ ✲ ✲ a Λ a ♠ ❥ ♠ ✲ ✲ b ♠ ♠ ♠ ♠ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a a Λ Λ b ♠ ♠ ♠ ♠ ♠ ♠ ❥ ✲ ✲ ✲ ✲ ✲ ✲ a Λ Λ b b Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 159 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ Step 3 ♠ ♠ ♠ ❥ ♠ ✲ ✲ ✲ a Λ a ✟ ✯ ✟✟✟ Λ ♠ ✲ ❍❍❍ ♠ ❥ ♠ ❥ ❍ Λ ✲ b ♠ ♠ ♠ ♠ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a a Λ Λ b ♠ ♠ ♠ ♠ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a Λ Λ b b Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 160 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ ✤ ✜ Step 4 Λ ♠ ♠ ♠ ♠ ✲ ✲ ✲ a Λ a ✟ ✯ ✟✟✟ Λ ❄ ♠ ❥ ♠ ✲ ✲ Λ ❍❍❍ ✻ ♠ ♠ ❥ ❍ Λ ✲ b ✣ ✢ Λ ✤ ✜ Λ ❥ ♠ ❄ ♠ ♠ ♠ ♠ ♠ ♠ ✲ ✲ ✲ ✲ ✲ ✲ ✲ a a Λ Λ Λ b ♠ ♠ ♠ ♠ ♠ ❥ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a Λ Λ b b Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 161 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ ✤ ✜ Step 5 Λ ♠ ♠ ♠ ♠ ✲ ✲ ✲ a Λ a ✯ ✟ ✟✟✟ Λ ♠ ❄ ♠ ✲ ✲ Λ ❍❍❍ ✻ ♠ ♠ ❍ ❥ Λ ✲ b ✣ ✢ Λ Λ ✤ ✜ Λ ❄ ♠ ❄ ♠ ♠ ♠ ♠ ♠ ♠ ✲ ✲ ✲ ✲ ✲ ✲ a a Λ Λ Λ b ❩❩❩ ♠ ♠ ♠ ♠ ♠ ❥ ♠ Λ ⑦ ❩ ✲ ✲ ✲ ✲ ✲ a Λ Λ b b Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 162 / 289
Example 3.28. An NFA Corresponding to (( aa + b ) ∗ ( aba ) ∗ bab ) ∗ ✤ ✜ Step 6 Λ ♠ ♠ ♠ ♠ ✲ ✲ ✲ a a Λ ✯ ✟ ✟✟✟ Λ ❄ ♠ ♠ ✲ Λ ❍❍❍ ✒ � ♠ ♠ ✻ ❥ ❍ � Λ ✲ Λ b � ♣ ♠ ❥ � ✣ ✢ ✲ Λ Λ ✤ ✜ ✻ Λ ❄ ♠ ❄ ♠ ♠ ♠ ♠ ♠ ♠ ✲ ✲ ✲ ✲ ✲ ✲ Λ a Λ Λ a b ❩❩❩ ♠ ♠ ♠ ♠ ♠ ♠ Λ ❩ ⑦ ✲ ✲ ✲ ✲ ✲ Λ a Λ b b ✣ ✢ Λ Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 163 / 289
Intro: finding a regular expression b a b a a a a a q 0 q 1 q 2 q 0 q 1 q 2 b b b b ( b + ab ) ∗ b [( b + ab ) ∗ a ] a + a a � �� � � �� � loop on q 0 single loop on q 2 [( b + ab ) ∗ aa ] [ b ( b + ab ) ∗ aa + a ] ∗ � �� � � �� � from q 0 to q 2 loop on q 2 short answer ( a + b ) ∗ aa see ֒ → FA example Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Regular languages 164 / 289
above It is possible to construct an expression for a small automaton “by hand” by starting with a restricted version of the automaton, and slowly adding nodes and edges. below Next a formal proof how this can be done generally, referred to as the McNaughtonYamada algorithm. The expression is built iteratively. First we consider only paths in the automaton that can not pass any node: we only consider single edges. Then we add the nodes one by one. Regular expression R ( k ) ( i , j ) includes all strings from paths from i to j where only the paths visiting nodes from 1 to k . (We always may exit or enter any other node, but only as first or last node of the path.) later The method of Brzozowski below “implements” this proof, using a generalized automaton. It features graphs with edges that carry regular expressions.
Theorem If M is an FA , then L ( M ) is regular. PROOF M = ( Q , Σ , q 0 , A , δ ) assume Q = { 1, 2, . . . , n } q 0 = 1 L ( k ) ( i , j ) only paths i , p 1 , . . . , p ℓ , j with 1 � p ℓ � k [M] Th 3.30 cf. Floyd’s algorithm for all-pairs shortest path problem Automata Theory Non-Determinism, Regular Expressions, and Kleene’s Theorem Kleene 165 / 289
Recommend
More recommend