190 likes | 293 Views
Conversions. Regular Expression to FA FA to Regular Expression. Language Representing Regular Expressions. We define a mapping from a regular expression to a language L() as follows: Step 0: L() = L( e ) = L() = for each Inductive step: L(( )) = L(()) = L(*) =.
E N D
Conversions Regular Expression to FA FA to Regular Expression
Language Representing Regular Expressions • We define a mapping from a regular expression to a language L() as follows: • Step 0: • L() = • L(e) = • L() = for each • Inductive step: • L(( )) = • L(()) = • L(*) = {} {e} {} L() L() L()L() L()*
Regular Languages Definition. A language is regular if there exists a regular expression that describes all its strings
Examples Example 1. Find L((ab*)a) L(ab*a) = L(a)L(b)*L(a) = {w : w is of the form abna with n = 0, 1, 2,…} Example 2. Find L((a(a b)*)). L(a(a b)*) = L(a)(L(a) L(b))* = {aw : w is a word in }
Example Find the regular expression for the language L in the alphabet {a,b} such that the words in L contains the substring aaa Find the regular expression for the language L in the alphabet {a,b} such that the words in L contains the substring aaa or bbb
Main Theorem About Finite Automata (Kleene) (1) Given a finite automata A, there is a regular expression expr such that L(A) = L(expr) (2) Given a regular expression expr, there is a finite automata A such that L(A) = L(expr)
Algorithm A (from text) Input: a regular expression expr Output: a finite automaton accepting L(expr) • Convert any step-0 element (any of the characters in , or e) occurring in expr to a finite automaton accepting this element • Apply the theorem about closure under set operations to every • Union • Concatenation • Kleene star
Recall: Construction on NFA-ls l l M(R1) l l M(R) M(R2) l l M(R*) M(R1 U R2) l l l M(R1) M(R2) M(R1 R2)
Exercise • Obtain a finite automaton accepting a regular expression: • One or two in class • How about: • (a a*b) a (ba*) • (a* b*) a*b+a • Make up several! • Use the union, concatenation, and * operations
Algorithm B (from text) Input: a finite automaton A Output: a regular expression expr such that L(expr) = L(A) • Assumptions about the automaton A: • A has a single favorable state • If it doesn’t, can this be taken care of ? • There are no transitions directed to the initial state • If there is one, can this be taken care of ? • There are no transitions starting at the favorable state Definition. An expression diagram is a labeled directed graph like a FSA, but with transitions labeled by regular expressions. as opposed to single elements of .
Algorithm B – States to RE Unions For every pair of nodes such that there is more than one transition from one to the other one: expr1 expr2 … exprn expr1 expr2 … exprn
expr1 (expr2)* expr3 Algorithm B – States to RE Kleene * • For every pair of nodes such that there is an intermediate node connecting them: expr3 expr1 expr2
b q0 q1 a a q2 b Simple Example
q0 a q2 b Delete node q1 b q1 a ab
q0 Delete node q2 (ab*ab)* a ab q2 b
b q0 q1 a b a b a q2 q3 b Detailed Example
b q0 q1 a bb b a ab b a q2 q3 b Delete node q1
q0 b bb a a q2 q3 b Delete node q2 ab*ab ab
q0 b bb a q3 Finally ab*ab (ab*ab)*a ((b bb) (ab*ab)*a)*