Lecture 3
Lecture 3
Lecture 3
Theory of Automata
Regular Expressions
Lecture 03: Theory of Automata:2011
Regular Expressions
• Defining Languages by Another New Method
• Introducing EVEN-EVEN
Theory Of Automata 3
Lecture 03: Theory of Automata:2011
Language-Defining Symbols
Theory Of Automata 4
Lecture 03: Theory of Automata:2011
Plus Sign
• Let us introduce another use of the plus sign. By
the expression
x+y
where x and y are strings of characters from an
alphabet, we mean either x or y.
Theory Of Automata 5
Lecture 03: Theory of Automata:2011
Example
• Consider the language L={Λ, x, xx, xxx,…} of strings,
defined over Σ = {x}.
Theory Of Automata 6
Lecture 03: Theory of Automata:2011
Example
Theory Of Automata 7
Lecture 03: Theory of Automata:2011
Example
Example
Or
((a+b)(a+b))*(a+b).
Theory Of Automata 9
Lecture 03: Theory of Automata:2011
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)*.
(a+b)*a(a+b)*b(a+b)*+ (a+b)*b(a+b)*a(a+b)*.
Theory Of Automata 10
Lecture 03: Theory of Automata:2011
Example
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
a(a+b)*b+b(a+b)*a
Theory Of Automata 11
Lecture 03: Theory of Automata:2011
Remark
12
Lecture 03: Theory of Automata:2011
Note
• It is important to be clear about the difference of
the following regular expressions:
• r1 = a*+b*
• r2 = (a+b)*
13
Lecture 03: Theory of Automata:2011
• From now on, for convenience, we will simply say some b’s to
mean some or no b’s. When we want to mean some positive
number of b’s, we will explicitly say so.
Theory Of Automata 14
Lecture 03: Theory of Automata:2011
Example
• Consider the language T over the alphabet
Σ = {a; b; c}:
• T = {a; c; ab; cb; abb; cbb; abbb; cbbb; abbbb;
cbbbb; …}
• In other words, all the words in T begin with
either an a or a c and then are followed by some
number of b’s.
• Using the above plus sign notation, we may
write this as
T = language((a+ c)b*)
Theory Of Automata 15
Lecture 03: Theory of Automata:2011
Example
• Consider a finite language L that contains all the
strings of a’s and b’s of length three exactly:
L = {aaa, aab, aba, abb, baa, bab, bba, bbb}
• Note that the first letter of each word in L is
either an a or a b; so are the second letter and
third letter of each word in L.
• Thus, we may write
L = language((a+ b)(a + b)(a + b))
• or for short,
L = language((a+ b)3)
Theory Of Automata 16
Lecture 03: Theory of Automata:2011
Example
• In general, if we want to refer to the set of all possible
strings of a’s and b’s of any length whatsoever, we could
write
language((a+ b)*)
18
Lecture 03: Theory of Automata:2011
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.
(aa+bb+(ab+ba)(aa+bb)*(ab+ba))*
19
Lecture 03: Theory of Automata:2011
20
Lecture 03: Theory of Automata:2011
21
Lecture 03: Theory of Automata:2011
Example
• The language of all words that have at least two a’s can
be defined by the expression:
(a + b)*a(a + b)*a(a + b)*
Example
• Let V be the language of all strings of a’s and b’s in
which either the strings are all b’s, or else an a followed
by some b’s. Let V also contain the word Λ. Hence,
V = {Λ, a, b, ab, bb, abb, bbb, abbb, bbbb, …}
• We can define V by the expression
b* + ab*
where Λ is included in b*.
• Alternatively, we could define V by
(Λ + a)b*
which means that in front of the string of some b’s, we have
either an a or nothing.
Theory Of Automata 23
Lecture 03: Theory of Automata:2011
Example contd.
• Hence,
(Λ + a)b* = b* + ab*
Theory Of Automata 24