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

Lecture 6

1) The document discusses regular expressions and regular languages. It defines the Kleene star and plus operations and how they are used to define languages. 2) Regular expressions are constructed recursively using letters, concatenation, union, Kleene star and plus operations. They can be used to concisely define various languages. 3) Examples of regular expressions are provided to define languages containing strings of a certain form over an alphabet.

Uploaded by

Faizan Asif045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Lecture 6

1) The document discusses regular expressions and regular languages. It defines the Kleene star and plus operations and how they are used to define languages. 2) Regular expressions are constructed recursively using letters, concatenation, union, Kleene star and plus operations. They can be used to concisely define various languages. 3) Examples of regular expressions are provided to define languages containing strings of a certain form over an alphabet.

Uploaded by

Faizan Asif045
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

1

Lahore Garrison University


CSC353-Theory of Automata
Week-3 Lecture-6
Semester-4 Fall 2022
2
Preamble of lecture

► Kleene Star Closure


► Plus operation
► Recursive definition of languages
► Examples

Lahore Garrison University


3
Regular Expression

► As discussed earlier that a* generates


Λ, a, aa, aaa, …

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+

are also regular expressions.


Step 3: Nothing else is a regular expression.
5
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+.

Lahore Garrison University


6
Cont..

► Now consider another language L, consisting of all possible


strings, defined over Σ = {a, b}. This language can also be
expressed by the regular expression
7
Cont..

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

Lahore Garrison University


8
Cont..

Now consider another language L, of strings having exactly double


a, defined over Σ = {a, b}, then it’s regular expression may be

Lahore Garrison University


9

► Now consider another language L, of strings having exactly double a, defined over Σ =
{a, b}, then it’s regular expression may be
b*aab*

Lahore Garrison University


10
Cont..

► Language L, of even length, defined over Σ = {a, b}, then it’s


regular expression

Lahore Garrison University


11
Cont..

► Language L, of even length, defined over Σ = {a, b}, then it’s


regular expression
((a+b)(a+b))*

Lahore Garrison University


12
Cont..

► Language L, of odd length, defined over Σ = {a, b}, then it’s


regular expression may be

Lahore Garrison University


13
Cont..

► Language L, of odd length, defined over Σ = {a, b}, then it’s


regular expression may be
► L={a, b , aaa, abb, bab, bba, aab, baa, bbb, …}
(a+b)((a+b)(a+b))* or ((a+b)(a+b))*(a+b)

Lahore Garrison University


14
Cont..

► 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

Lahore Garrison University


16
Cont..

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

Lahore Garrison University


17
Example

► Consider the language, defined over Σ = {a, b} of words having at least one a
and one b, may be expressed by a regular expression

Lahore Garrison University


18
Cont..

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

Lahore Garrison University


19
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
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

Lahore Garrison University


21
Example

► 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

Lahore Garrison University


22
Cont..

► 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

Lahore Garrison University


23
Task

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

Lahore Garrison University


24
Note

► It is important to be clear about the difference of the following regular


expressions r1=a*+b* => L(r1)={^, a, b, aa, bb, aaa, bbb, aaaa, bbbb, ….}

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.

Lahore Garrison University


25
Cont..

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


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

Lahore Garrison University


26
Regular Languages

► The language generated by any regular expression is called regular language.


► It is to be noted that if r1, r2 are regular expressions, corresponding to the languages L1, L2
then the languages generated by r1 + r2, r1r2 (or r2r1) and r1* (or r2*) are also regular
languages.

Lahore Garrison University


27
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 L 1*, of strings obtained by concatenating the strings of L, including
the null string.

Lahore Garrison University


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

Lahore Garrison University


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

Lahore Garrison University


30
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).

Lahore Garrison University


31

Q&A

Lahore Garrison University


32
References

Lahore Garrison University

You might also like