Upload
theresapainter
View
220
Download
0
Embed Size (px)
Citation preview
8/13/2019 re-auto
1/21
Lecture 5: REs, DFAs, NDFAs. 1
Regular Expressions
Let = {a, b}. The regular expressions over arecertain strings over the alphabet {a, b, (, ),,, }
Construction Rules:1., a and b are regular expressions2. If and are REs, then so are ( ), ( ), and
.
Examples:(ab)(((ab)c) (ba))
8/13/2019 re-auto
2/21
Lecture 5: REs, DFAs, NDFAs. 2
What REs Do
Regular expressions (which are strings) represent languag(which are sets of strings), via the function L:
(1) L(a) = {a}(2) L(b) = {b}
(3) L() = (4) L(( )) = L()L( )(5) L(( )) = L() L( )(6) L( ) = L()
Example:
L((ab)) = L(a)L(b) (4)= L(a)L(b) (6)= {a}{b} (1, 2)
L is called the semantics .
8/13/2019 re-auto
3/21
Lecture 5: REs, DFAs, NDFAs. 3
Syntactic Shorthand
Union and concatenation of languages are associativei.e., for any languages L1 , L2 , L3 :
(L1 L2 )L3 = L1(L2 L3 )(L1 L2 ) L3 = L1 (L2 L3 )
Thus, we can leave out many parentheses when writingREs, without changing the meaning [semantics]
For example, the following are all equivalent:((ab)c)(a(bc))abc
even though only the rst two are official REs
8/13/2019 re-auto
4/21
Lecture 5: REs, DFAs, NDFAs. 4
Regular Languages
A language is regular iff there is a regular expressionthat represents it.
Examples:
Strings ending in a = (a b)a
Strings of even length = (aa abbabb)
Strings with even # of as = (baba)
= b(abab)
Strings with two as = b bab babab
= b(e a(b(e ab)))
Decimal numerals in standard form, no leading zeroes= 0 ((1 . . . 9)(0 . . . 9))
[Where + = and e = ]
8/13/2019 re-auto
5/21
Lecture 5: REs, DFAs, NDFAs. 5
A more interesting regular language
L = All strings with an even # of as and an even #of bs
= (baba) (a bab)
but this isnt a regular expression
= ( aabb)
((abba)(aabb)
(abba)(aabb)
)
=
Claim: x L() iff x L( ) Clear that each member of L() has an even # of
as and even # of bs( ) If x has an even # of as and an even # of bs, then
x L()Pf: x = 1 1 . . . n n , i , i , n 0Each pair i i is either:
An equal pair aa or bb An unequal pair ab or baEach unequal pair must be matched with a subseque
unequal pair
8/13/2019 re-auto
6/21
Lecture 5: REs, DFAs, NDFAs. 6
Deterministic Finite Automata (DFAs)
a b b a b a
1
23
4
Input tape
Start state marked with