0% found this document useful (0 votes)
86 views41 pages

CS273 Theory of Automata & Fomal Languages: (WEEK-2) Lecture-3 & 4

The document summarizes key concepts from Lectures 3 and 4 of the course CS273 on Theory of Automata and Formal Languages. It discusses regular expressions and their recursive definition. Examples are provided of using regular expressions to define various languages, including languages with a certain number of a's and b's, languages starting or ending in certain patterns. It also discusses equivalent regular expressions and operations on regular expressions like union, concatenation and kleene star.

Uploaded by

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

CS273 Theory of Automata & Fomal Languages: (WEEK-2) Lecture-3 & 4

The document summarizes key concepts from Lectures 3 and 4 of the course CS273 on Theory of Automata and Formal Languages. It discusses regular expressions and their recursive definition. Examples are provided of using regular expressions to define various languages, including languages with a certain number of a's and b's, languages starting or ending in certain patterns. It also discusses equivalent regular expressions and operations on regular expressions like union, concatenation and kleene star.

Uploaded by

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

CS273

Theory of Automata & Fomal


Languages
(WEEK-2)
LECTURE-3 & 4

Regular expressions
Lecturer
Azka Aziz
[email protected]
Recap Lecture-2

 Kleene Star Closure, Plus operation, recursive


definition of languages, INTEGER, EVEN,
factorial, PALINDROME, {anbn}, languages of
strings (i) ending in a, (ii) beginning and ending
in same letters, (iii) containing aa or bb
(iv)containing exactly aa,

2
Task
 Q)
1) Let S={ab, bb} and T={ab, bb, bbbb} Show
that S* = T* [Hint S*  T* and T*  S*]
2) Let S={ab, bb} and T={ab, bb, bbb} Show that
S* ≠ T* But S*  T*
Solution: Since S  T , so every string belonging
to S* , also belongs to T* but bbb is a string
belongs to T* but does not belong to S*.

3
 3) Let S={a, bb, bab, abaab} be a set of strings. Are
abbabaabab and baabbbabbaabb in S*? Does any word
in S* have odd number of b’s?
Solution: since abbabaabab can be grouped as (a)(bb)
(abaab)ab , which shows that the last member of the
group does not belong to S, so abbabaabab is not in S *,
while baabbbabbaabb can not be grouped as members
of S, hence baabbbabbaabb is not in S*. Since each
string in S has even number of b’s so there is no
possiblity of any string with odd number of b’s to be in
S*.

4
Task

Q1)Is there any case when S+ contains Λ? If


yes then justify your answer.
Solution: consider S={Λ,a} then
S+ ={Λ, a, aa, aaa, …}
Here Λ is in S+ as member of S. Thus Λ will
be in S+ , in this case.

5
Q2) Prove that for any set of strings S

i. (S+)*=(S*)*
Solution: In general Λ is not in S+ , while Λ
does belong to S*. Obviously Λ will now be
in (S+)*, while (S*)* and S* generate the
same set of strings. Hence (S+)*=(S*)*.

6
Q2) continued…

ii) (S+)+=S+
Solution: since S+ generates all possible
strings that can be obtained by
concatenating the strings of S, so (S+)+
generates all possible strings that can be
obtained by concatenating the strings of S+
, will not generate any new string.
Hence (S+)+=S+

7
Q2) continued…

iii) Is (S*)+=(S+)*
Solution: since Λ belongs to S* ,so Λ will
belong to (S*)+ as member of S* .Moreover
Λ may not belong to S+, in general, while Λ
will automatically belong to (S+)*.
Hence (S*)+=(S+)*

8
Regular Expression

 As discussed earlier that a* generates


Λ, a, aa, aaa, …
and a+ generates a, aa, aaa, aaaa, …, so the
language L1 = {Λ, a, aa, aaa, …} and L2 =
{a, aa, aaa, aaaa, …} can simply be expressed
by a* and a+, respectively.
a* and a+ are called the regular expressions
(RE) for L1 and L2 respectively.
Note: a+, aa* and a*a generate L2.
9
Recursive definition of Regular
Expression(RE)

Step 1: Every letter of Σ including Λ is a regular expression.


Step 2: If r1 and r2 are regular expressions then
1.(r1)

2.r1 r2

3.r1 + r2 and

4. r1*
are also regular expressions.
Step 3: Nothing else is a regular expression.

10
Defining Languages (continued)…

 Method 3 (Regular Expressions)


 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 regular
expression x+.

11
 Now 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)*.
 Now consider another language L, of strings
having exactly double a, defined over Σ
= {a, b}, then it’s regular expression may be
b*aab*

12
 Now consider another language L, of even
length, defined over Σ = {a, b}, then it’s
regular expression may be
((a+b)(a+b))*
 Now consider another language L, of odd
length, defined over Σ = {a, b}, then it’s
regular expression may be
(a+b)((a+b)(a+b))* or
((a+b)(a+b))*(a+b)

13
Remark

 It may be noted that a language may be


expressed by more than one regular
expressions, while given a regular expression
there exist a unique language generated by that
regular expression.

14
 Example:
 Consider the language, defined over
Σ={a , b} of words having at least one a,
may be expressed by a regular expression
(a+b)*a(a+b)*.
 Consider the language, defined over
Σ = {a, b} of words having at least one a
and one b, may be expressed by a regular
expression
(a+b)*a(a+b)*b(a+b)*+ (a+b)*b(a+b)*a(a+b)*. 15
 Consider the language, defined over
Σ={a, b}, of words starting with double a
and ending in double b then its regular
expression may be aa(a+b)*bb
 Consider the language, defined over
Σ={a, b} of words starting with a and
ending in b OR starting with b and
ending in a, then its regular expression
may be a(a+b)*b+b(a+b)*a

16
TASK

 Consider the language, defined over


Σ={a, b} of words beginning with a, then
its regular expression may be a(a+b)*

 Consider the language, defined over


Σ={a, b} of words beginning and ending
in same letter, then its regular expression
may be (a+b)+a(a+b)*a+b(a+b)*b

17
TASK

 Consider the language, defined over


Σ={a, b} of words ending in b, then its
regular expression may be (a+b)*b.
 Consider the language, defined over
Σ={a, b} of words not ending in a, then its
regular expression may be (a+b)*b + Λ. It is to
be noted that this language may also be
expressed by ((a+b)*b)*.

18
CS273
Theory of Automata & Fomal
Languages
(WEEK-2)
LECTURE # 4

Regular Languages
Lecturer
Azka Aziz
[email protected]
SummingUP Lecture 3

RE, Recursive definition of RE, defining languages


by RE, { x}*, { x}+, {a+b}*, Language of strings
having exactly one aa, 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 havgin 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.

20
Recap Lecture 3

RE, Recursive definition of RE, defining languages


by RE, { x}*, { x}+, {a+b}*, Language of strings
having exactly one aa, 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 havgin 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.

21
Task

 Determine the RE of the language, defined over


Σ={a, b} of words beginning with a.
Solution:
The required RE may be a(a+b)*
 Determine the RE of the language, defined over
Σ={a, b} of words beginning with and ending in
same letter.
Solution:
The required RE may be (a+b)+a(a+b)*a+b(a+b)*b

22
Task Continued …

 Determine the RE of the language, defined over


Σ={a, b} of words ending in b.
Solution:
The required RE may be
(a+b)*b.
 Determine the RE of the language, defined over
Σ={a, b} of words not ending in a.
Solution: The required RE may be
(a+b)*b + Λ Or ((a+b)*b)*

23
An important example

The Language EVEN-EVEN :


Language of strings, defined over Σ={a, b}
having even number of a’s and even
number of b’s. i.e.
EVEN-EVEN = {Λ, aa, bb, aaaa,aabb,abab,
abba, baab, baba, bbaa, bbbb,…} ,
its regular expression can be written as
(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*

24
Note

 It is important to be clear about the difference


of the following regular expressions
r1=a*+b*
r2=(a+b)*
Here r1 does not generate any string of
concatenation of a and b, while r2 generates
such strings.

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

26
Note

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


1. r1+r2 =(aa + bb) + (a + b)
2. r1r2 =(aa + bb) (a + b)
=(aaa + aab + bba + bbb)
3. (r1)* =(aa + bb)*

27
Regular Languages

 Definition:
The language generated by any regular
expression is called a regular language.
It is to be noted that if r1, r2 are regular
expressions, corresponding to the languages L 1
and L2 then the languages generated by r 1+ r2,
r1r2( or r2r1) and r1*( or r2*) are also regular
languages.

28
Note

 It is to be noted that if L1 and L2 are expressed by r1and


r2, respectively then the language expressed by
1) r1+ r2, is the language L1 + L2 or L1 U L2
2) r1r2, , is the language L1L2, of strings obtained by
prefixing every string of L1 with every string of L2
3) r1*, is the language L1*, of strings obtained by
concatenating the strings of L, including the null string.

29
Example

 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)
 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)
 If r=(aa+bb) then the language of strings generated by
r*, is also a regular language, expressed by (aa+bb) *

30
All finite languages are regular.

Example:
Consider the language L, defined over Σ={a,b},
of strings of length 2, starting with a, then
L={aa, ab}, may be expressed by the regular
expression aa+ab. Hence L, by definition, is a
regular language.

31
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.
Consider the language L={aaa, aab, aba, abb,
baa, bab, bba, bbb}, that may be expressed by
a RE aaa+aab+aba+abb+baa+bab+bba+bbb,
which is equivalent to (a+b)(a+b)(a+b).

32
Introduction to Finite
Automaton
 Consider the following game board that contains
64 boxes

33
Finite Automaton Continued …

There are some pieces of paper. Some are of


white colour while others are of black color. The
number of pieces of paper are 64 or less. The
possible arrangements under which these pieces
of paper can be placed in the boxes, are finite.
To start the game, one of the arrangements is
supposed to be initial arrangement. There is a
pair of dice that can generate the numbers
2,3,4,…12 . For each number generated, a
unique arrangement is associated among the
possible arrangements.
34
Finite Automaton Continued …

It shows that the total number of transition


rules of arrangement are finite. One and more
arrangements can be supposed to be the
winning arrangement. It can be observed that
the winning of the game depends on the
sequence in which the numbers are generated.
This structure of game can be considered to be
a finite automaton.

35
Defining Languages (continued)…
 Method 4 (Finite Automaton)
Definition:
A Finite automaton (FA), is a collection of the
followings
1) Finite number of states, having one initial and some
(maybe none) final states.
2) Finite set of input letters (Σ) from which input
strings are formed.
3) Finite set of transitions i.e. for each state and for
each input letter there is a transition showing how
to move from one state to another.

36
Example

 Σ = {a,b}
 States: x, y, z where x is an initial state and z is final
state.
 Transitions:
1. At state x reading a go to state z,
2. At state x reading b go to state y,
3. At state y reading a, b go to state y
4. At state z reading a, b go to state z

37
Example Continued …

 These transitions can be expressed by the


following table called transition table

Old States New States

Reading a Reading b
x- z y
y y y
z+ z z
38
Note

 It may be noted that the information of an FA,


given in the previous table, can also be depicted
by the following diagram, called the transition
diagram, of the given FA
a,b

y
b

x–
a,b
a
Z+ 39
Remark

 The previous transition diagram is an FA


accepting the language of strings, defined over
Σ={a, b}, starting with a. It may be noted
that this language may be expressed by the
regular expression
a (a + b)*

40
Summing Up

 Regular expression of EVEN-EVEN language,


Difference between a* + b* and (a+b)*,
Equivalent regular expressions; sum, product
and closure of regular expressions; regular
languages, finite languages are regular,
introduction to finite automaton, definition of
FA, transition table, transition diagram

41

You might also like