AT Module 2
AT Module 2
Regular expressions
The language accepted by DFA or NFA and ε-NFA is called regular
language.
A regular language can be described using regular expressions
consisting of the symbols such as alphabet in Σ, the operators such as
‘.’, ’+’ and ‘*’.
The three operators used to obtain a regular expression are:
+ :union operator (least precedence)
. : concatenation operator (next least precedence)
* : closure operator (highest precedence)
Regular expression
Definition: A regular expression is recursively defined as
follows.
1.ϕ is a regular expression denoting an empty language.
2. ε-(epsilon) is a regular expression indicates the language containing an
empty string.
3. a is a regular expression which indicates the language containing only
{a}
4. If R is a regular expression denoting the language LR and S is a regular
expression denoting the language LS, then
a. R+S is a regular expression corresponding to the language
LRULS.
b. R.S is a regular expression corresponding to the language LR.LS..
c. R* is a regular expression corresponding to the language LR*.
5. The expressions obtained by applying any of the rules from 1-4 are
regular expressions.
• L={Ɛ,a,b,aa,ab,ba,bb,aaa,bbb,aba,abb,bba,}
• L={abb, aabb,ababbababb, aaaaaabb,}
• L={aa,aabab,bbbbaab, bababaabaabb,}
• L={Ɛ,a,b,c,ab,ac,bc,aaaabc,bbbb,cccc,bc,}
• L={a,bb,ababa,abbabbabb,}
The table shows examples of regular expressions and the language corresponding to
these regular expressions.
Regular
Meaning
expressions
Set of strings of a’s and b’s of any length including the NULL
(a+b)*
string.
(a+b)*abb Set of strings of a’s and b’s ending with the string abb
ab(a+b)* Set of strings of a’s and b’s starting with the string ab.
(a+b)*aa(a+b)* Set of strings of a’s and b’s having a sub string aa.
(aa)*(bb)*b Set of strings consisting of even number of a’s followed by odd number of b’s
(0+1)*000 Set of strings of 0’s and 1’s ending with three consecutive zeros(or ending with 000)
R.E=(Ɛ+b)(ab)*(Ɛ+a)
13. Third symbol from right is ‘a’ and fourth symbol from the right is ‘b’.
L={abaaa, bbabb,aaabaaa,…….}
R.E=(a+b)*ba(a+b)(a+b)
14. Two or more letters but beginning and ending with the same letter where
Σ={a,b}.
L={abbbba, baaaab, abababa, bbbb, aaaa,……}
R.E=a(a+b)*a+b(a+b)*b
15. Length is either even or multiple of 3 or both.
L={Ɛ, ab,aa,abab,aba, abbabb, abbbabaaabbb,……}
R.E= ((a+b)(a+b))* + ((a+b) (a+b) (a+b))*
19. L={an bm | n ≥ 4, m ≤ 3}
R.E=0*+ 0*11*
=0*(Ɛ+11*)
=0*(Ɛ+1*)
=0*1*
Properties of regular
language
1. Closure properties of regular languages
⚫ Used to build recognizers for languages that are
constructed from other languages by certain operations.
⚫ Ex. Automata for intersection of two regular languages
2. Decision properties of regular languages
– Used to find whether two automata define the same
language
– Used to minimize the states of DFA
-Eg. Design of switching circuits.
closure properties of regular
languages
1. The union of two regular languages is regular.
2. The intersection of two regular languages is regular.
3. The complement of a regular language is regular.
4. The difference of two regular languages is regular.
5. The reversal of a regular language is regular.
6. The closure (star) of a regular language is regular.
7. The concatenation of regular languages is regular.
8. A homomorphism (substitution of strings for
symbols) of a regular language is regular.
9. The inverse homomorphism of a regular language
is regular
Closure of regular languages under
Boolean operations
🞆Ex1.
▪ L1={a,a3,a5,-----}
▪ L2={a2,a4,a6,-----}
▪ L1 ᴜ L2 = {a,a2,a3,a4,----}
▪ RE=a(a)*
🞆Ex2.
▪ L1={ ab,a2 b2, a3b3, a4b4,-----}
▪ L2={ab,a3 b3,a5b5,-----}
▪ L1 ᴜ L2 = {ab,a2b2, a3b3, a4b4, a5b5----}
▪ RE=ab(ab)*
Closure of regular languages under
Boolean operations
🞆Closure Under Complementation
🞆Theorem : If L is a regular language over alphabet S,
then L = Σ* - L is also a regular language.
🞆Proof: - Let L =L(A) for some DFA. A=(Q, Σ, δ, q0, F).
🞆Then L = L(B), where B is the DFA (Q, Σ, δ, q0, Q-F).
🞆That is, B is exactly like A, but the accepting states of A
have become non-accepting states of B, and vice
versa, then w is in L(B) if and only if δ*( q0, w) is in Q-F,
which occurs if and only if w is not in L(A).
🞆Ex1. L1={a,a3,a5,-----}
Σ* -L1={e,a2,a4,a6,-----}
RE=(aa)*
🞆 Ex2. Consider a DFA, A that accepts all and only the strings of 0’s
and 1’s that end in 01. i.e L(A) = (0+1)*01. The complement of L(A)
is therefore all string of 0’s and 1’s that do not end in 01
🞆Closure Under Intersection
🞆 Theorem : If L and M are regular languages, then so is L ∩ M.
🞆 Proof :Let L and M be the language of automata AL =(QL, Σ, δL, qL, FL) and
AM =(QM, Σ, δM, qM , FM).
🞆 Assume the alphabets of both automata are the same; i.e., Σ is the
union of the alphabets of L and M. AL and AM are DFA’s.
🞆 For L ∩ M, we shall construct an automata A that simulate both AL and
AM . Formally, we define
A =(QL x QM, Σ, δ, (qL , qM ) , FL xFM )
where δ ((p,q),a)=(δL (p,a), δM(q,a)).
🞆 “w” string is accepted by A if and only if both AL and AM
accept w.
i.e δL*(qL,w) ϵ FL and δM*(qM,w) ϵ FM
🞆 Thus , A accepts the intersection of L and M.
Closure of regular languages
under Boolean operations
🞆Ex1.
▪ L1={a,a2,a3,a4,a5,a6,-----}
▪ L2={a2,a4,a6,-----}
▪ L1∩L2 = {a2,a4,a6,----}
▪ RE=aa(aa)*
🞆Ex2
▪ L1={ab,a3b3,a5b5,a7b7-----}
▪ L2={a2 b2, a4b4, a6b6,-----}
▪ L1∩L2 = ϕ
▪ RE= ϕ
Closure of regular languages under
Boolean operations
🞆Ex3.
🞆 Consider a DFA that accepts all those strings that have a 0.
🞆 The FA for LR can be derived from FA for L by swapping initial and final
states and changing the direction of each edge. It is shown in the above
right figure.
Closure under Reversal
🞆Proof based on regular expression:
🞆 Let L is the language corresponding to regular expression E.
🞆 It is required to P.T there is another regular expression ER such that
L(ER)=(L(E))R .
🞆 Which is read as “language of ER is the reversal of language of E”.
🞆 Basis: By definition of R.E, we have ϕ, ε and a are R.E.
🞆 So, the reversal of regular expression ER is given by:
⚫{ε}R={ε}
⚫{ϕ}R = ϕ
⚫{a}R={a}
Closure under Reversal
🞆 Induction: Again, by definition of R.E, if E1 and E2 are regular
expressions, then: E1+E2 , E1.E2 and E1* regular expressions.
🞆 Case 1: E=E1+E2 is a R.E, then
ER=E1R+E2R
Is a R.E denoting the languages:
L(ER)=L(E1R) ᴜ L(E2R)
🞆 Case 2: E=E1.E2 is a R.E, then
ER=E1R.E2R
Is a R.E denoting the languages:
L(ER)=L(E1R).L(E2R)
🞆 Case 3: E=E1* is a R.E, then
ER=E1R
Is a R.E denoting the languages:
L(ER)=L(E1R)
Closure under Homomorphism
🞆Homomorphism:
🞆 Definition : A string homomorphism is a function on strings that works by substituting
a particular string for each symbol.
OR
🞆 Definition: Let Σ and Г are set of alphabets. The homomorphic
function
h: Σ Г*
🞆 is called Homomorphism i.e., a substitute where a single letter is
replaced by a string. If w=a1a2a3…..an, then h(w)=h(a1)h(a2)
…….h(an).
🞆 If L is made of alphabets from Σ, then h(L)={ h(w) | w ϵ L} is called
homomorphic image.
Closure under Homomorphism
🞆 Example 1: Let Σ={0,1} , Г ={0,1,2} and h(0)=01, h(1)=112. what is h(010)? If L={00,010}.
What is homomorphic image of L?
🞆 Soln: By definition, h(w)=h(a1)h(a2)…….h(an).
So,
h(010)=h(0)h(1)h(0)
h(010)=0111201
🞆L(00,010)=L ( h(00),h(010) )
=L( h(0)h(0), h(0)h(1)h(0) )
L(00,010)=L( 0101 , 0111201 )
Closure under Homomorphism
• where |u| = n-1 and lv| = 1 so that |uv| = |u| + |v| = n-1+1 = n which is true.
According to the pumping lemma, uviw ∈ L for i = 0, 1, 2,...
• Step 3: According to the pumping lemma, uviw ∈ L for i = 0, 1, 2,...
• If i is 0, i.e., v does not appear and so the number of 1's on the left of x will be less
than the number of 1's on the right of x and so the string is not of the form wwR.
• So, uviw ∉ L. when i = 0.
• This is a contradiction to the assumption that the language is regular. So, the
language L = ( wwR I w e (0+11*) is not regular.
Show that L = {anbn |n≥1) is not
regular.
• Step 1:
• Let L is regular and n be the number of states in FA. Consider the string:
x =aaaabbbb.
• Since Ixl=2n≥n, we can split the string x into uvw such that |uv|≤n and |
v| ≥1 as shown below:
• where |u| = n-1 and lv| = 1 so that |uv| = |u| + |v| = n-1+1 = n which is
true.
• Step 3: According to the pumping lemma, uviw ∈ L for i = 0, 1, 2,...
• If i is 0, i.e., v does not appear and so the number of a’s will be less than
the number of b's and so the string is not of the form ‘n’ number a’s
followed by ‘n’ number of b’s
• So, uviw ∉ L. when i = 0.
• This is a contradiction to the assumption that the language is regular.
• So, the language L = {anbn |n≥1) is not regular.
Show that L = {aibj |i>j) is not
regular.
• Step 1:
• Let L is regular and n be the number of states in FA. Consider the
string: x =an+1bn.
• Since Ixl=2n+1≥n, we can split the string x into uvw such that |uv|≤n
and |v| ≥1 as shown below:
• x= an+1bn = am ak abn
u v w
where |u| = m and lv| = k>1 so that |uv| = |u| + |v| = m+k ≤ n which is
true. According to the pumping lemma, uviw ∈ L for i = 0, 1, 2,...
• Step 3: According to the pumping lemma, uviw ∈ L for i = 0, 1, 2,...
• i.e., am ( ak)i abn ∈ L for i ≥0
• If i is 0, i.e., number of a’s in string u will not be more than the
number of b’s in w.
• So, uviw ∉ L. when i = 0.
• This is a contradiction to the assumption that the language is regular.
• So, the language L = {aibj |i>j) is not regular.