8/10/2019 Lesson 03.ppt
1/18
1
Recap Lecture-2
Kleene Star Closure, Plus operation, recursivedefinition of languages, INTEGER, EVEN,
factorial, PALINDROME, {a
n
b
n
}, languages ofstrings (i) ending in a, (ii) beginning and endingin same letters, (iii) containing aa or bb(iv)containing exactly aa,
8/10/2019 Lesson 03.ppt
2/18
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 thatS* T* But S*T*
Solution: Since ST , so every string belongingto S* , also belongs to T* but bbb is a stringbelongs to T*but does not belong to S*.
8/10/2019 Lesson 03.ppt
3/18
3
3) Let S={a, bb, bab, abaab} be a set of strings. Areabbabaabab and baabbbabbaabb in S*? Does any wordin S*have odd number of bs?
Solution: since abbabaabab can be grouped as(a)(bb)(abaab)ab , which shows that the last member ofthe group does not belong to S, so abbabaabab is not inS*, while baabbbabbaabb can not be grouped as
members of S, hence baabbbabbaabb is not in S*
. Sinceeach string in S has even number of bs so there is nopossiblity of any string with odd number of bs to be inS*.
8/10/2019 Lesson 03.ppt
4/18
4
Task
Q1)Is there any case when S+ contains? Ifyes then justify your answer.
Solution: consider S={,a} thenS+ ={, a, aa, aaa, }Hereis in S+ as member of S. Thuswillbe in S+ , in this case.
8/10/2019 Lesson 03.ppt
5/18
5
Q2) Prove that for any set of strings S
i. (S+)*=(S*)*
Solution: In generalis not in S+ , whiledoes belong to S*. Obviouslywill now be
in (S+
)*
, while (S*
)*
and S*
generate thesame set of strings. Hence (S+)*=(S*)*.
8/10/2019 Lesson 03.ppt
6/18
6
Q2) continued
ii) (S+)+=S+
Solution: since S+ generates all possible
strings that can be obtained byconcatenating the strings of S, so (S+)+generates all possible strings that can beobtained by concatenating the strings ofS+ , will not generate any new string.
Hence (S+)+=S+
8/10/2019 Lesson 03.ppt
7/18
7
Q2) continued
iii) Is (S*)+=(S+)*
Solution: sincebelongs to S* ,sowill
belong to (S*
)+
as member of S*
.Moreovermay not belong to S+, in general, whilewill automatically belong to (S+)*.
Hence (S
*
)
+
=(S
+
)
*
8/10/2019 Lesson 03.ppt
8/18
8
Regular Expression
As discussed earlier that a*generates
, a, aa, aaa,
and a+
generates a, aa, aaa, aaaa, , so thelanguage L1= {, a, aa, aaa, } andL2= {a, aa, aaa, aaaa, } can simply beexpressed by a*and a+, respectively.
a*and a+ are called the regular expressions(RE) for L1 and L2respectively.
Note:a+, aa* and a*a generate L2.
8/10/2019 Lesson 03.ppt
9/18
9
Recursive definition of Regular
Expression RE)
Step 1: Every letter of includingis aregular expression.
Step 2: If r1and r2 are regular expressions then
1.(r1)
2.r1r2
3.r1+ r2and
4.r1*
are also regular expressions.
Step 3: Nothing else is a regular expression.
8/10/2019 Lesson 03.ppt
10/18
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 starclosure 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 bythe regular expression x+.
8/10/2019 Lesson 03.ppt
11/18
11
Now consider another language L, consistingof 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 stringshaving exactly double a, defined over= {a, b}, then its regular expression maybe
b*aab*
8/10/2019 Lesson 03.ppt
12/18
12
Now consider another language L, of evenlength, defined over = {a, b}, then itsregular expression may be
((a+b)(a+b))*
Now consider another language L, of oddlength, defined over = {a, b}, then itsregular expression may be
(a+b)((a+b)(a+b))* or
((a+b)(a+b))*(a+b)
8/10/2019 Lesson 03.ppt
13/18
13
Remark
It may be noted that a language may beexpressed by more than one regularexpressions, while given a regular expressionthere exist a unique language generated by thatregular expression.
8/10/2019 Lesson 03.ppt
14/18
8/10/2019 Lesson 03.ppt
15/18
15
Consider the language, defined over
={a, b}, of words starting with double aand ending in double b then its regular
expression may be aa(a+b)*bbConsider the language, defined over
={a, b} of words starting with a and
ending in b OR starting with b and endingin a, then its regular expression may bea(a+b)*b+b(a+b)*a
8/10/2019 Lesson 03.ppt
16/18
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 endingin same letter, then its regular expressionmay be (a+b)+a(a+b)*a+b(a+b)*b
8/10/2019 Lesson 03.ppt
17/18
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 itsregular expression may be (a+b)*b +. It is to
be noted that this language may also beexpressed by ((a+b)*b)*.
8/10/2019 Lesson 03.ppt
18/18
18
SummingUP Lecture 3
RE, Recursive definition of RE, defininglanguages by RE, { x}*, { x}+, {a+b}*,Language of strings having exactly one aa,
Language of strings of even length, Languageof strings of odd length, RE defines uniquelanguage (as Remark), Language of stringshaving at least one a, Language of strings
havgin at least one a and one b, Language ofstrings starting with aa and ending in bb,Language of stringsstarting with and endingin different letters.