0% found this document useful (0 votes)
219 views

Theory of Automata Chapter 4

The document discusses regular expressions and regular languages. It defines regular expressions, provides examples of regular expressions like a*, a+ that generate specific languages, and explains how regular expressions can be used to define languages consisting of strings of certain lengths or containing certain patterns of letters. The key concepts are that regular expressions are used to define regular languages, and operations on regular expressions preserve regularity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
219 views

Theory of Automata Chapter 4

The document discusses regular expressions and regular languages. It defines regular expressions, provides examples of regular expressions like a*, a+ that generate specific languages, and explains how regular expressions can be used to define languages consisting of strings of certain lengths or containing certain patterns of letters. The key concepts are that regular expressions are used to define regular languages, and operations on regular expressions preserve regularity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

AUTOMATA THEORY

Ms. Shaista Shabbir


University of KOTLI AJK
Department of CS & IT

Automata Theory
Lec# 5, 6

REGULAR EXPRESSIONS

Automata Theory Ms Shaista Shabbir TOA UOKAJK 2


Regular Expression

Definition:
 The language defining symbols we are about to create are
called Regular Expressions.
 The languages associated with these regular expressions are
called Regular Languages.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 3


Examples

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).
Automata Theory Ms Shaista Shabbir TOA UOKAJK 4
More Examples

These RE’s define the language:

a+ = { }
aa* = { }
a*a = { }
a* = { }
Does they define the same language ???????
Automata Theory Ms Shaista Shabbir TOA UOKAJK 5
Recursive Definition of Regular Expression

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
Automata Theory Ms Shaista Shabbir TOA UOKAJK 6
More Examples

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+.
Automata Theory Ms Shaista Shabbir TOA UOKAJK 7
Note

Important
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”.
This means that x+y offers a choice, much the same
way that x*.

Care should be taken so as not to confuse this with + as an exponent.


Automata Theory Ms Shaista Shabbir TOA UOKAJK 8
More Examples

Consider another language L,


“consisting of all possible strings”,
defined over Σ = {a, b}.
This language can also be expressed by the Regular Expression
(a + b)*
(a + b)*={Λ a b aa ab ba bb aaa aba baa abb bab bba
bbb ……………}
All possible strings Upto length 3
Automata Theory Ms Shaista Shabbir TOA UOKAJK 9
More Examples

Consider languages L, defined over Σ = {a, b},


then their RE’s may be:
“of strings having exactly one ‘a’”
RE = b*ab*
“of even length”
RE = ((a+b)(a+b))*.
“of odd length”
RE = (a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b).
Automata Theory Ms Shaista Shabbir TOA UOKAJK 10
Remarks

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.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 11


More Examples
Consider the languages, defined over Σ = {a , b}
“words having at least one a”
R.E = (a+b)*a(a+b)*
“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)*
“words starting with double a and ending in double b”
R.E = aa(a+b)*bb
“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
Automata Theory Ms Shaista Shabbir TOA UOKAJK 12
More Examples

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 a c and then are followed by
some number of b’s”.
RE = ((a+c)b*) = language(either a or c then some b’s)
So far we learn that a language can be expressed in three forms.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 13


More Examples

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)]*

Automata Theory Ms Shaista Shabbir TOA UOKAJK 14


Finite Languages

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


Automata Theory Ms Shaista Shabbir TOA UOKAJK 15
Finite Languages

Consider another language L over Σ = {a, b},


L = {abba baaa bbbb}
We can represent L by symbolic expression
L= language (abba+baaa+bbbb)
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)
Automata Theory Ms Shaista Shabbir TOA UOKAJK 16
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.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 17


Equivalent Regular Expressions

Definition
Two regular expressions are said to be equivalent if they
generate the same language.

Example
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.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 18


Note

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

then

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

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

(r1)* = (aa + bb)*

Automata Theory Ms Shaista Shabbir TOA UOKAJK 19


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+b)*
(a+b)* = a (a+b)*+b (a+b)* + Λ
(a+b)* = (a+b)*ab (a+b)* + b*a*
Automata Theory Ms Shaista Shabbir TOA UOKAJK 20
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.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 21


Note

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.

Automata Theory Ms Shaista Shabbir TOA UOKAJK 22


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)*

Automata Theory Ms Shaista Shabbir TOA UOKAJK 23


Summary

RE, Recursive definition of RE, defining languages by RE, { x}*,


{ x}+, {a+b}*, Language of strings
having exactly one ‘a’, Language of strings of ‘even length’,
Language of strings of ‘odd length’, RE defines unique
language (as Remark), Language of strings having at least one
‘a’, Language of strings having at least one ‘a’ and one ‘b’,
Language of strings starting with ‘aa’ and ending in ‘bb’,
Language of strings starting with and ending in different letters.
Automata Theory Ms Shaista Shabbir TOA UOKAJK 24

You might also like