Professional Documents
Culture Documents
TOA - Lec5 Regular Expressions Cont
TOA - Lec5 Regular Expressions Cont
Lecture # 5
Chapter # 4 Cont…
Definition
For regular expressions r1 and r2
2
Example
Regular expression: a b a *
La b a * La b La *
La b La *
La Lb La *
a b a*
a, b , a, aa, aaa,...
a, aa, aaa,..., b, ba, baa,...
3
Example
Regular expression r a b * a bb
Lr a, bb, aa, abb, ba, bbb,...
4
Example
r (0 1) * 00 (0 1) *
L(r ) = { all strings with at least
two consecutive 0 }
5
Regular Languages
Definition: The language generated by any
regular expression is called a regular
language.
Note: If r1, r2 are regular expressions,
corresponding to the languages L1 and L2
then the languages generated by r1+ r2, r1r2
(or r2r1) and r1*( or r2*) are also regular
languages.
6
Languages
Generated by
Regular Expressions
Regular
Languages
7
Note: All finite languages are regular whereas some
infinite languages are regular & some are non-regular.
In order to write RE for finite languages just include
+’s between the words of finite languages.
Consider the alphabet Σ={a,b}. The words of length 1
are two. Its RE will be a+b.
Similarly the words of length 2 will be aa,ab,ba,bb. Its
RE will be aa+ab+ba+bb or (a+b)(b+a).
Similary the languages of all words whose length is 3
will be aaa,aab,aba,abb,bbb,bba,bab,baa.
Thus we can conclude that all words of a’s and b’s of
any length can be defined by (a+b)*.
8
EVEN-EVEN Language
EVEN-EVEN = { aa bb aaaa aabb abab abba baab
baba bbaa bbbb aaaaaa …}
In this language we have following three types of
strings
type1 = aa
type2 = bb
type3 = (ab+ba)(aa+bb)*(ab+ba)
9
Equivalent Regular Expressions
Definition:
10
Check Equality
1. (a+)* = (a*)+ = a*
2. (a*+b)* = (a+b)*
3. (a+b)*ab(a+b)* = (a+b)*a(a+b)*b(a+b)*
4. (a+b)*= (a*+b*)*
5. (a+b)*= (a*b*+b*a*)*
6. (a+b)*= a(a+b)*+b(a+b)*+
7. (a+b)*= a(a+b)*ab(a+b)*+b*a*
8. (aa+ab*)* = (aa+ab)*
9. a*a* = (aa)*
10.(a+b)*= (a*b*)*
11
Check Equality
1. (a+)* = (a*)+ = a*
Yes
2. (a*+b)* = (a+b)* Yes
3. (a+b)*ab(a+b)* = (a+b)*a(a+b)*b(a+b)* Yes
4. (a+b)*= (a*+b*)* Yes
5. (a+b)*= (a*b*+b*a*)* Yes
6. (aa+ab*)* = (aa+ab)* No – what is missing
7. (a+b)*= a(a+b)*+b(a+b)*+ Yes
8. (a+b)*= a(a+b)*ab(a+b)*+b*a* No
9. a*a* = (aa)* No
10.(a+b)*= (a*b*)* Yes
12
Practice Questions
13