TOC SY Unit-3
TOC SY Unit-3
TOC SY Unit-3
OPERANDS: are characters from the alphabet over which the regular expression is defined.
OPERATORS:
+= Matches the character before the + one or more times Eg: a+c -> ac, aac, aaac
*=Matches anything in the place of the *, or a "greedy" match : Eg : ab*c -> abc, abbcc, abcdc
. = Matches any character as a wildcard Eg: a.c -> abc, asc, a123c
In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx, xxxx, .....}
In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx, xxx, xxxx, .....}
b
(a+b)*
=
(a+b)0 = ɛ
(a+b)1 = {a,b}
b (a+b)2 = {aa,ab,ba,bb}
(a+b)3 = {aaa,aab,abb,bbb}
(a+b)n = {an,bn,............}
Formal Definition
The class of regular expressions over Σ is defined recursively as follows
1. Regular expressions over Σ (include letters ∅ (empty set) and ε (empty
string of length 0) i.e L(r)={ε} and L(r)= { } for ∅
2. Every symbol a ∈ Σ is a RE over Σ.
3. If R1 & R2 are RE over Σ then so are (R1+R2), (R1.R2) & (R1)*, where
‘+’ indicates alternative path (parallel path),
The operation ‘.’ denotes concatenation (series connection) and “*” denotes
iteration (closure)
4. RE are only those that are obtained using rules 1 to 3
● If ‘r’ is a regular expression, then the language represented by ‘r ‘ is denoted by
L(r).
● e.g.
1) if r =a + b i.e. union, a or b
L (r) = { a,b}
2) if r= a.b i.e concatenation
L (r) = { ab}
3) if r = a* i.e. kleene closure
L (r) = {ε,a, aa,aaa, aaaa,......}
● Thus, we say that set of regular language is closed under union, concatenation
and kleene closure.
● R1+R2 means ORing of two regular expression i.e. R1 or R2
● R1.R2- means R1 followed by R2 i.e. R1R2
● R1* = Zero and more occurance of R, (iterative operation)
● R1+ =( Transitive closure)- Atleast one and more occurance of R1
● R+ = R.R*
Regular Set
Any set that represents the value of the Regular Expression is called a Regular Set
And …….
Algebraic Laws of Regular expressions over ∑
● Ø is a RE denotes the empty set { }
● ε is a RE denotes {ε}
● a is a RE, a ∈ ∑ denotes {a}
● let R1 and R2 be two REs on ∑ then
● R1 + R2 is RE
● R1 . R2 is RE
● R1* is RE
Quick test: Match the following
1 L = {a,b,c} a 0(0+1)*1
2 L = {abb,ab} b (ab)*
3 L = {ɛ,a,aa,ab,ba,bb,aab,abb....} c (a+b)*
4 L = {ɛ ,ab,abab,..} d (0+1)*
5 L = {01,011,001,00110,0111….} e (a+b+c)
6 L = {ɛ,0,1,01,10,11,00,001,111....} f (ab+a).b
Quick test: Complete the table by finding RE or RL of the following
R = (1* 0*)
Language.
L2 is a regular language.
R = a*
Examples
1. Write the Regular Expression for language accepting all combinations of a’s over the
set ∑={a} Ans: RE = a*
2. Write the Regular Expression for language accepting all strings except Null string over
the set ∑={a} Ans: RE = a+
3. Write the Regular Expression for language accepting all strings containing any no. of
a’s and b’s Ans: RE = (a+b)*
4. Write the Regular Expression for language accepting all the strings starting with 1 and
ending with 0 over ∑={0,1} Ans: RE = 1(0+1)*0
5. Write the Regular Expression for language accepting all the strings starting with a but
not having consecutive b’s Ans: L = {a, aba, aab, aba, aaa, abab, .....} RE= (a+ab)*
Examples
6. Write the Regular Expression for language consisting of all strings over ∑={0,1}
with at least two consecutive 0’s.
L(r1) = {ε,ab,abab,ababab,....} -1
L (r2) = {ε,a,aa,aaa,aaaa,..} . {ε,b,bb,bbb,bbbb,...}
= {ε,a,b,aa,bb,aaa,bbb,.....} -2
From 1 & 2
● (a.b) * ≠ a*.b*
For Practice:
If L(r) = Set of all strings over Σ = {0,1,2} such that at least one ‘0’ followed by at least one ‘1’
followed by at least one ‘2’ is there, Find RE ‘r’ representing this language
Ans- r= 0.0*.1.1*.2.2*
Ans -
L(r)= {aa,aba,abba,abbba,abbbba,.....}
If L(r) = {a,c,ab,cb,abb,cbb,abbb,....} What is r ?
Ans : r= (a+c).b*
Represent the language over Σ = {a,b} containing at least one ‘a’ & at least one ‘b’
Ans
10. L(r)= set of all strings over Σ = {0,1} ending with 011
(b + c)* a (b + c)*
Write the regular expression for the language accepting all the string in which any number of a's is followed by any number of b's
is followed by any number of c's.
As we know, any number of a's means a* any number of b's means b*, any number of c's means c*. Since as given in problem
statement, b's appear after a's and c's appear after b's. So the regular expression could be:
1. R = a* b* c*
The language can be predicted from the regular expression by finding the meaning of it. We will first split the regular expression
as:
L = {The language consists of the string in which a's appear triples, there is no restriction on the number of b's}
Write the regular expression for the language containing the string over {0, 1} in which there are at least two occurrences of 1's
between any two occurrences of 1's between any two occurrences of 0's.
At least two 1's between two occurrences of 0's can be denoted by (0111*0)*.
Similarly, if there is no occurrence of 0's, then any number of 1's are also allowed. Hence the r.e. for required language is:
1. R = (1 + (0111*0))*
Let L(r) = set of all strings over ∑={a,b} in which the string either contain all b’s or else there is
an an ‘a’ followed by some b’s , the set also contain ε. Find Regular Language for above
language
R.E.= b* + ab* = ( ε + a) b*
Let L is subset of {0,1}* be the language of all strings of even length. Find RE
Ans
Input= {0,1}
L= {00,01,10,11}
L(r) = (00+01+10+11)*
Or
((0+1).(0+1))*
➢ Find RE for the language consisting of all strings of a’s and b’s without
any combination of double letters.
Ans- (ε+b) (ab)* (ε+a)
0 1, 3, 4, 5, 7, 8, 9, 11
0 1, 3, 4, 5, 7, 8, 9, 11
A
0
0 1, 3, 4, 5, 7, 8, 9, 11 2 1, 3, 4, 5, 7, 8, 9, 11 B
1
2
Step 3: find input(i.e. 0 1 2 ) transition here for State A
A
0
0 1, 3, 4, 5, 7, 8, 9, 11 2 1, 3, 4, 5, 7, 8, 9, 11 B
1
2
C
D 6 5, 7, 8, 9, 11
10 9, 11
Step 3: find input(i.e. 0 1 2 ) transition here for State A
A
0
0 1, 3, 4, 5, 7, 8, 9, 11 2 1, 3, 4, 5, 7, 8, 9, 11 B
1
2
C
D 6 5, 7, 8, 9, 11
10 9, 11
Step 2:
It can be converted to DFA using direct method
•Construct DFA that accepts language represented
by
• r= (ab/ba)*.aa.(ab/ba)*
• = (ab+ba)*.aa.(ab+ba)*
Convert to DFA a. (a+b)*
Find RE for DFA
R.E. = (0+1).(0+1)*
DFA to RE: Arden’s Theorem
R = Q + RP
= Q + (Q + RP)P
= Q+QP+RP2
= Q+QP+ (Q + RP)P2
= Q+QP+QP2+RP3
= Q+QP+QP2+(Q+RP)P3
= Q+QP+QP2+QP3+RP4
= Q+QP+QP2……+QPn +RPn+1
= Q(ε+P+P2+....+Pn) +RPn+1
.....
= QP*
Arden’s Theorem Examples
Find regular expression for the following DFA using Arden’s Theorem-
Solution-
Step-01:
Form a equation for each state-
A = B.1 => A = ∈ + B.1 ……(1) to write equation in Arden’s Thm format use ∈
B = A.0 ……(2)
Step-02:
Step-02:
Q1 =1*.0 +(0 +1) Q1 Using Arden’s Theorem in (3), we get- R=Q1; Q=1*.0; P=(1.0)
Q1 =1*.0(0 +1)*
Thus, Regular Expression for the given DFA = 0(10)*
Home Work
Find regular expression for the following DFA using Arden’s Theorem-
Find regular expression for the following DFA using Arden’s Theorem-
Solution-
Step-01:
1. Lexical Analyser
2. Text Editor
3. Grep Command