Lecture 6
Lecture 6
and a+ generates a, aa, aaa, aaaa, …, so the language L = {Λ, a, aa, aaa, …} and L = {a,
aa, aaa, aaaa, …} can simply be expressed by a* and +a 1, 2
respectively.
a* and a+ are called the regular expressions (RE) for L and L respectively.
1 2
+ * *
Note: a , aa and a a generate L .
2
4
Recursive definition of Regular
Expression(RE)
Step 1: Every letter of Σ including Λ is a regular expression. {a, b}
Step 2: If r1 and r2 are regular expressions then
1. (r1)
2. r1 r2, r2r1
3. r1 + r2 and
4. *
r1
5. R1+
► Now consider another language L, of strings having exactly double a, defined over Σ =
{a, b}, then it’s regular expression may be
b*aab*
► 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.
15
Example
► Consider the language, defined over Σ={a , b} of words having at least one a,
may be expressed by a regular expression
► 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
► 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)*
► Consider the language, defined over Σ={a, b}, of words starting with double a
and ending in double b then its regular expression may be
20
Cont..
► 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 bOR starting with b and ending in a, then its regular expression may
be
► Consider the language, defined over Σ={a, b} of words starting with a and
ending in bOR starting with b and ending in a, then its regular expression may
be
a(a+b)*b+b(a+b)*a
{aab, abb, baa, bba}=> R.E=(aab+abb+baa+bba)
R.E=a(a+b)b+b(a+b)a
► Write the regular expression for the language defined over Σ={a, b} of all
the words beginning with a.
► Write a regular expression for the language, defined over Σ={a, b} of
words beginning and ending in same letter.
► Write a regular expression for the language, defined over Σ={a, b} of
words ending in b.
► Write a regular expression for the language, defined over Σ={a, b} of words
not ending in a.
r2=(a+b)* =>L(r2)={^, a, b, aa, ab, ba, bb, aaa, bbb, abb, aab, bab, aba, …}
Here r1 does not generate any string of concatenation of a and b, while r2 generates
such strings.
► 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 L 1*, of strings obtained by concatenating the strings of L, including
the null string.
► 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)*
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.
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).
Q&A