1.73k likes | 1.95k Views
CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 4 School of Innovation, Design and Engineering Mälardalen University 2012. 1. Content.
E N D
CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 4 School of Innovation, Design and Engineering Mälardalen University 2012 1
Content Regular Expressions and Regular LanguagesNFADFA Subset Construction (Delmängdskonstruktion)FA RE State Elimination (Tillståndseliminering)Minimizing DFA by Set Partitioning (Särskiljandealgoritmen)Grammar: Lineargrammar. Regulargrammar. Application: Compiler. LexicalAnalysis.
Two Basic Theoremsabout Finite State Automata Based on C Busch, RPI, Models of Computation
1: KleeneTheoremNFADFA Let M be NFA accepting L. Then there exists DFA M´ that accepts L as well.For each NFA there exists corresponding DFA that accepts the same language.
II: Finite Language TheoremAny finite language is regular.Any finite language is FSA-acceptable. Proof: every finite language is a union of single strings which are regular because described by regular expressions Example L = {abba, abb, abab} L is expressed by the regular expression “abba|abb|abab“ FSA = Finite State Automaton = DFA/NFA
Union: Concatenation: Are Regular Languages Star: Properties For regular languages and we will prove that:
Union: Concatenation: Star: Regular languages are closed under
Regular language Regular language NFA NFA Single final state Single final state
Union (Thompson’s construction) • NFA for
NFA for Example
Concatenation (Thompson’s construction) • NFA for
Example • NFA for
Star Operation (Thompson’s construction) • NFA for
Example • NFA for
Theorem The reverse of a regular language is a regular language Proof idea Construct NFA that accepts : invert the transitions of the NFA that accepts
Proof Since is regular, there is NFA that accepts Example:
Make old initial state a final state and vice versa
is regular Resulting machine accepts
Theorem: Regular expressions are representation of regular languages and they are equivalent. Regular expressions describe regular languages in formal language theory. They have the same expressive power as regular grammars.
1. For any regular expression the language is regular Theorem - Part 1 Languages Generated by Regular Expressions Regular Languages
2. For any regular language there is a regular expression with Theorem - Part 2 Languages Generated by Regular Expressions Regular Languages
Proof - Part 1 For any regular expression the language is regular Proof by induction on the size of
NFAs Induction Basis • Primitive Regular Expressions: (where ) Regular Languages
Assume for regular expressions and Inductive Hypothesis that and are regular languages
Inductive Step • We will prove: regular languages
By inductive hypothesis we know: and are regular languages Regular languages are closed under union concatenation star
Therefore regular languages is a regular language And trivially
Proof – Part 2 For any regular language there is a regular expression with Proof by construction of regular expression
Since is regular take the NFA that accepts it Single final state
From construct the equivalent • Generalized Transition Graph • transition labels are regular expressions Example QED
Summary: Operations on Regular Expressions • RE Regular language description • a+b {a,b} • (a+b)(a+b) {aa, ab, ba, bb} • a* {, a, aa, aaa, …} • a*b {b,ab, aab, aaab, …} • (a+b)* {, a, b, aa, ab, ba, aaa, bbb…}
Operator Precedence • 1. Kleene star • 2. Concatenation • 3. Union • allows dropping unnecessary parentheses.
6 Example: From a Regular Expression to an NFA Example : (a+b)*abb step by step construction (a+b) a 3 2 1 4 5 b
7 Example: From a Regular Expression to an NFA Example : (a+b)*abb (a+b)* a 3 2 0 1 6 4 5 b
Example: From a Regular Expression to an NFA Example : (a+b)*abb (a+b)*abb a 3 2 0 1 6 a 7 8 4 5 b b 9 b 10
Converting FA to a Regular ExpressionState Eliminationhttp://www.math.uu.se/~salling/Movies/FA_to_RegExpression.mov
, 2 1 3 Example • Add a new start (s) and a new final (f) state: • From s to the ex-starting state (1) • From each ex-final state (1,3) to f
s ; ; , ; , ; , 2 1 The original: 3 f Let’s remove state 1! Each combination of input/output to 1 will generate a new path once state 1 is gone
s ( ) , ; When state 1 is gone we must be able to make all those transitions! , 2 1 Previous: 3 , f
s ( ) ; , 2 1 3 f
s ( ( ) ) ; , , 2 1 3 f