0% found this document useful (0 votes)
6 views24 pages

TOA Lecture03

Theory of automata lecture slide

Uploaded by

Hamza Anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

TOA Lecture03

Theory of automata lecture slide

Uploaded by

Hamza Anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Lecture No 3

Dr. Nazir Ahmad Zafar 1


Topics Covered

• Regular Expressions (RE)


• Recursive Definition of RE
• Defining Languages by RE
• Language of Strings

Dr. Nazir Ahmad Zafar 2


Regular Expressions

• The language defining symbols


• We are about to create are called Regular
Expressions.
• The languages associated with these regular
expressions are called Regular Languages.

Dr. Nazir Ahmad Zafar 3


* and + notations

a* generates language
L1= {Λ, a, aa, aaa, aaaa…}
a+ generates language
L2={a, aa, aaa, aaaa, …}
So,
The languages L1 & L2 can be expressed as a*,
a+ respectively and are called Regular
expressions (RE’s).
Dr. Nazir Ahmad Zafar 4
Different REs and same Languages

These RE’s define the language:

a+ = { }
aa* = { }
a*a = { }
a* = { }

Do they define the same language ???????


Dr. Nazir Ahmad Zafar 5
Recursive Definition of RE
Step 1: Every letter of Σ including Λ is a regular
expression.
Step 2: If r1 and r2 are regular expressions then
(r1)
r1 r2
r1 + r2 and
r1*
are also regular expressions.
Step 3: Nothing else is a regular expression

Dr. Nazir Ahmad Zafar 6


Kleene Star Closure

Consider the language,


L={Λ, x, xx, xxx,…} of strings, defined over Σ = {x}.
We can write this language as the Kleene star closure of
alphabet, Σ or L=Σ*={x}* .
This language can also be expressed by the regular
expression x*.
Similarly the language,
L={x, xx, xxx,…}, defined over Σ = {x}, can be
expressed by the RE x+.

Dr. Nazir Ahmad Zafar 7


Important Note

We now introduce another use for the plus ‘+’ sign. By


The expression x+y where x & y are strings of
characters from an alphabet, we mean “either x or y”.

Dr. Nazir Ahmad Zafar 8


Example 1 & 2
Example 1
Σ = {a, b}. Consider language L “consisting of all
possible strings”, over Σ
Regular Expression: (a + b)*
(a + b)* = {Λ a b aa ab ba bb aaa aba baa abb
bab bba bbb ……………}
Example 2
All possible strings of (a + b)* upto length 3
= {Λ a b aa ab ba bb aaa aba baa abb bab bba bbb}
Dr. Nazir Ahmad Zafar 9
Example 3, 4, 5

Consider Σ = {a, b}
Example 3
Languages “of strings having exactly one “a”
RE = b*ab*
Example 4
“of even length” RE = ((a+b)(a+b))*.
Example 5 “of odd length”
RE = (a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b)
Dr. Nazir Ahmad Zafar 10
Remark

• It may be noted that a language may be


expressed by more than one regular
expression
• While given a regular expression there exist a
unique language generated by that regular
expression.

Dr. Nazir Ahmad Zafar 11


More Examples
Σ = {a , b}
Example 6: “words having at least one a”
R.E = (a+b)*a(a+b)*
Example 7: “words having at least one a and one b”
R.E = (a+b)*a(a+b)*b(a+b)*+ (a+b)*b(a+b)*a(a+b)*
Example 8: “words starting with double a and ending in
double b”
R.E = aa(a+b)*bb
Example 9: “words starting with a and ending in b OR
starting with b and ending in a”
R.E = a(a+b)*b+b(a+b)*a
Dr. Nazir Ahmad Zafar 12
Various Ways representing Regular Languages
• Tabular
• Descriptive
• Regular Expressions

Dr. Nazir Ahmad Zafar 13


Example 10: Ways to represent languages
Consider language T defined over alphabet
Σ = {a,b,c}, & we have to write RE
T = {a c ab cb abb cbb abbb cbbb abbbb cbbbb . . . . . .}

Can be expressed in words as,


“All the words in T begin with an a or c and then are
followed by some number of b’s”.

RE = ((a+c)b*) = language(either a or c then some b’s)

Dr. Nazir Ahmad Zafar 14


Example 11

Another important language i.e. EVEN-EVEN


“All possible words having even number of a’s
and b’s”

E = [aa+bb+(ab+ba)(aa+bb)*(ab+ba)]*

Dr. Nazir Ahmad Zafar 15


Example 12: Finite Languages

Now consider a finite language L over Σ = {a,


b},
“all the strings of a’s and b’s of length exactly
three.”
L = {aaa aab aba abb baa bab bba bbb}
So what would be the Regular expression ?

R.E = (a+b) (a+b) (a+b) or (a+b)3

Dr. Nazir Ahmad Zafar 16


Example 13 & 14
Consider another language L over Σ = {a, b},
Example 13: L = {abba, baaa, bbbb}
We can represent L by symbolic expression
L= language (abba+baaa+bbbb)
Example 14: If L is a finite language that includes
that null word Λ , then how can we represent L
through symbolic expression ?
L = {Λ, a aa, bbb}
We can represent L by symbolic expression
L = language (Λ+a+aa+bbb)
Dr. Nazir Ahmad Zafar 17
Note

It may be noted that if a language contains


even thousand words, its RE may be
expressed, placing ‘+’ between all the
words.

• Here the special structure of RE is not


important.

Dr. Nazir Ahmad Zafar 18


Equivalent Regular Expressions
Definition
Two regular expressions are said to be equivalent if
they generate the same language.
Example 15
Consider the following regular expressions
r1 = (a + b)* (aa + bb)
r2 = (a + b)*aa + ( a + b)*bb then both regular
expressions define the language of strings
ending in aa or bb.

Dr. Nazir Ahmad Zafar 19


Operators on Regular Expressions

If r1 = (aa + bb) and r2 = ( a + b) then


Union
r1+r2 = (aa + bb) + (a + b)

Concatenation
r1r2 = (aa + bb) (a + b) = (aaa + aab + bba + bbb)

Closure
(r1)* = (aa + bb)*
Dr. Nazir Ahmad Zafar 20
Guess Equivalences ?

aa*=a+
a* = (a*)*
(a+b)* = a*b*
(a+b)* = (a+b)* + (a+b)*
(a+b)* = (a+b)* (a+b)*
(a+b)* = a (a+b)*+b (a+b)* + Λ

Dr. Nazir Ahmad Zafar 21


Regular Languages
• Languages generated by Regular Expressions are
called Regular Languages.
• It is to be noted that 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.

Dr. Nazir Ahmad Zafar 22


Union, Concatenation and Closure of Languages
It is to be noted that if L1 and L2 are expressed
by r1and r2, respectively then the language
expressed by
• r1+ r2, is the language L1 + L2 or L1  L2
• r1r2, is the language L1L2, of strings
obtained by prefixing every string of L1
with every string of L2
• r1*, is the language L1*, of strings obtained
by concatenating the strings of L, including
the null string.
Dr. Nazir Ahmad Zafar 23
Examples
Example
1. If r1 = (aa+bb) and r2 = (a+b) then the language
of strings generated by r1+r2, is also a regular
language, expressed by (aa+bb) + (a+b)
2. If r1 = (aa+bb) and r2 = (a+b) then the language
of strings generated by r1r2, is also a regular
language, expressed by (aa+bb)(a+b)
3. If r = (aa+bb) then the language of strings
generated by r*, is also a regular language,
expressed by (aa+bb)*
Dr. Nazir Ahmad Zafar 24

You might also like