Properties of Regular Languages
Standard Representations of Regular Languages
A language L over an alphabet S is regular
iff
• It is accepted by FA (DFA, NFA, or NFA-e).
• It is described by a regular expression.
• It is generated by regular grammar (Left-linear or Right-linear).
Standard Representations of Regular Languages
Regular Languages
Regular
Expressions
Regular Grammars (Left/Right Linear) FA
(DFA/NFA/NFA- e)
When we say: We are given a Regular Language
We mean:
L
Language is in a standard Representation (FA/RE/RG)
L
Standard Representations of Regular Languages
Closure Properties
• Recall a closure property is a statement that a certain operation on languages, when applied to languages in a class, produces a result that is also in that class.
• For regular languages, we can use any of its representations to prove a closure property.
Given two regular languages L
1and L
2, is their union is also regular ? If it is true for all regular
languages, then family of regular
languages is closed under union.
L 1 L 2
Are regular Languages For regular languages and
we will prove that:
Properties of RLs
We say: The family of Regular languages are
closed under
L 1 Regular language
( ) M 1 L 1
L = M 1
Single final state
NFA M 2
L 2
Single final state
( ) M 2 L 2
L =
Regular language
NFA
Example
a
b
M 1
{ } ba
L 2 = b a
M 2
L
1={a
nb :n≥0}
Union
NFA for
M 1
M 2
!
"∪ !
$l l l
l
Example
a
b
b a
l l l
l
}
1 { a b L = n
}
2 { ba L =
} {
}
2 {
1 L a b ba
L È = n È
NFA for
Concatenation
NFA for L 1 L 2
M 1 M 2
l l
Example
NFA for
a
b b a
}
1 { a b L = n
}
2 { ba L =
} {
} }{
2 {
1 L a b ba a bba
L = n = n
l l
³ 0
n
Star Operation
NFA for L 1 *
M 1
l
l
1 * Î L
l
l l
Example
The string in L
1* is w NFA for
* } {
1 * a b L = n
a
b
}
1 { a b L = n l
l
l
l
1 2 1
L w
w w
w w
i
k
Î
= !
Reversal
L 1 R
M 1
NFA for 1 ¢ M
1. Reverse all transitions
2. Mark initial state as final state and vice versa
L 1
Example
}
1 { a b L = n
a
b
M 1
}
1 R { ba n
L =
a
b
1 ¢
M
Complement
1. Take the DFA that accepts L 1
M 1
L 1 ¢
M 1
L 1
2. Make final states non-final,
and vice-versa
Example
}
1 { a b L = n
a
b
M 1
b a,
b a,
} {
* } ,
1 { a b a b
L = - n a
b
1 ¢ M
b a,
b
a,
Intersection
DeMorgan’s Law: L 1 Ç L 2 = L 1 È L 2
2 1
, L
L regular
2 1
, L
L regular
2
1
L
L È regular
2
1
L
L È regular
2
1
L
L Ç regular
Example
}
1 { a b L = n
} ,
2 { ab ba L =
regular regular
}
2 {
1 L ab
L Ç =
regular
Example
a b
b a
b a,
b
} a,
2 {
1 L ab
L Ç =
Intersection (Product)
L1 = L(M1), M1 = (Q, S, d1, q0, F1), Q = {q0, q1…... qm,} L2 = L(M2), M2 = (P, S, d2, p0, F2), Q = {p0, p1…... pn,} M1 and M2 are DFAs.
Define new automation, M’ = (Q’, S, d’, (q0, p0), F’) Q’ = QXP = {(qi, pj): qi Q, pj P}
Define transition function d’ s.t.
d’( (qi, pj), a ) = (qk, pl) If d1(qi, a ) = qk
AND d2(pj, a ) = pl
Define transition for all states.
The initial state is (q0, p0),
F’ is the set of all states s.t. (qi, pj) s.t.
qi, F1, pj F2
Example-1
Example-2
Find product
DIFFERENCE
L1 = L(M1), M1 = (Q, S, d1, q0, F1), Q = {q0, q1…... qm,} L2 = L(M2), M2 = (P, S, d2, p0, F2), Q = {p0, p1…... pn,} M1 and M2 are DFAs
!
"− !
$= !
"∩ !
$2 1
, L
L regular
regular regular
!
", !
$!
"∩ !
$DIFFERENCE
If L1 and L2 are regular languages, then So is L1 - L2 L1 - L2 consists of strings in L1 but not L2 i.e.
!
"− !
$= !
"∩ !
$Let M1 and M2 be DFA’s whose languages are L1 and L2, respectively.
Construct C, the product automaton of M1 and M2. Make the final states of C be the pairs where M1-state is final but M2-state is not.
Example
Exercise
L
1= L ( (a+b)a*) L
2= L( baa*)
For given languages L
1and L
2, construct the FAs.
• Union
• Star closure
• Concatenation
• Complement
• Reversal
• Intersection
• Difference
Exercise
L1 = L ( (a+b)a*) L2 = L( baa*)
!
"⊝ !
$= {': ' ∈ !
"*+ ' ∈
!
$,-. ' /0 1*. /1 ,*.ℎ !
"314 !
$} 1*+ (!
", !
$) = {': ' ∉ !
"314 ' ∉ !
$}
:*+ (!
", !
$) = {' ∶ ' ∈ !
"*+ ' ∈ !
$}
! = {-<: - ∈ !, < ∈ !
=}
Exercise
L1 = {w ε {0, 1 }* : w consists of 0’s in multiple of 3}
L2 = {w ε {0, 1 }* : w consists of odd number of 0’s}
!
"⊝ !
$= {': ' ∈ !
"*+ ' ∈
!
$,-. ' /0 1*. /1 ,*.ℎ !
"314 !
$} 1*+ (!
", !
$) = {': ' ∉ !
"314 ' ∉ !
$}
:*+ (!
", !
$) = {' ∶ ' ∈ !
"*+ ' ∈ !
$}
! = {-<: - ∈ !, < ∈ !
=}
Exercise
L
1= {w ε {0, 1 }* : w consists of 0’s in multiple of 3}
L
2= {w ε {0, 1 }* : w consists of odd number of 0’s}
For given languages L
1and L
2, find FA for
• Union
• Star closure
• Concatenation
• Complement
• Reversal
• Intersection
• Difference
Reversal of Regular Expression
Basis: If r is a primitive RE (∅, λ or a ε ∑ ), then rR= r.
Induction: If r1 and r2 are two REs (r1 + r2)R = (r1)R + (r2)R
(r1r2)R = (r2)R.(r1)R (r1*)R = ((r1)R)*
Reversal of Regular Expression: Example
Let r1 = 01* , r2 =10*.
(r1 + r2)R = (01* + 10*)R = (01*)R+ (10*)R
= (1*)R0R + (0*)R1R
= (1R)*0 + (0R)*1
= 1*0+ 0*1
Homomorphism
A homomorphism on an alphabet is a function that gives a string for each symbol in that alphabet.
h : ∑ Γ*
Where ∑ and Γ are alphabets.
Rules: h(a1a2 … an-1an) = h(a1)h(a2) …… h(an-1)h(an) h(a1+ a2) = h(a1) + h(a2)
h( (a1)* ) = (h(a1))*
Example: h(0) = ab; h(1) = λ
∑ = {0, 1} Γ ={a, b}
h(01010) = h(0)h(1)h(0)h(1)h(0)
= (ab)(λ)(ab)(λ)(ab)(λ)(ab) = ababab
Closure Under Homomorphism
If L is a regular language, and h is a homomorphism on the alphabet of language L.
Then h(L) = {h(w) | w εL} is also a regular language.
Proof: Let r be a regular expression for L.
Apply h to each symbol in r to form a new RE r’
The new RE r’ generates language h(L).
Closure Under Homomorphism : Example
Let h(0) =ab; h(1) = λ.
∑ = {0, 1} Γ ={a, b}
If L is the RL with regular expression 01* + 10*.
Then, h(L) is the homomorphism on the alphabet of language L.
The regular expression of language h(L) is r’ = h(01* +10*)
= h(0)(h(1))* + h(1) (h(0)*
= (ab)(λ)* + (λ)(ab)*
= (ab)λ + λ (ab)*
= (ab) + (ab)*
= (ab)*
Closure Under Homomorphism : Example
Let h(a) =dbcc; h(b) = bdc.
∑ = {a, b} Γ ={b, c, d}
If L is the regular language denoted by RE r = (a + b*) (aa*).
Show that h(L) is also regular language.
Right Quotient of Languages
Let L
1and L
2be languages on the same alphabet.
Then the right quotient of L
1with L
2is
L
1/ L
2= {x: xy L
1for some y L
2}
In other words, if the string in L
1has a
suffix from L
2, remove the suffix and the
resulting string is in L
1/L
2Right Quotient of Languages: Example
L1 = {anbm : n ≥ 1, m ≥ 0} ∪ {ba}
L1 = {ba, a, aa, aaa, …. ab, abb, …… aab, aabb……}
L2 = {bm : m ≥ 1}
L2 = {b, bb, bbb, ….. }
Then the right quotient of L1 with L2 is L1 / L2 = {anbm : n ≥ 1, m ≥ 0}
Closure under right quotient
If L
1, L
2are regular then L
1/L
2is regular.
L
1is regular so it has a FA.
For each node in the FA of L
1, check if there is a walk from that node to a final node using a string in L
2.
If so, mark that node final.
So L
1/L
2is regular.
Example
L
1= L(a*baa*); L
2= L(ab*) DFA for L
1:
q0 q1 q2
q3
a
b a
a
a, b
b b
Example
L
1= L(a*baa*); L
2= L(ab*) DFA for L
2:
L
2= {a, ab, abb … }
p0 p1
p2
b a
a
a, b
b
Example
L
1= L(a*baa*); L
2= L(ab*)
Remove final marking, remember final state is q2.
q0 q1 q2
q3
a
b a a
a, b b b
L
2= {a, ab, abb … }
Example
L
1= L(a*baa*); L
2= L(ab*)
For each node, look for a walk on element of L2 to q2.
q0 q1 q2
q3
a
b a a
a, b b b
L
2= {a, ab, abb … }
Example
L
1= L(a*baa*); L
2= L(ab*) DFA for L
1/L
2:
q0 q1 q2
q3
a
b a a
a,b
b b
Find Right Quotient
L
1= {a
nb
m: n ≥1, m ≥0} ∪ {ba}
L
2= {b
m: m ≥ 1 }
L
1/L
2= ?
Exercise
L
1=L(a*baa*) L
2=L(aba*)
• Find L
1/L
2• If head of a language is defined as head(L) = {x : xy L for some y
∑*}
Find head(L
1) and head(L
2)
Elementary Questions about
Regular Languages
Membership Question
Question: Given regular language and string
how can we check if ?
L
L w Î
w
Answer: Take the DFA that accepts and check if is accepted
L
w
DFA
L w Î
DFA
L w Ï w
w
If there is a path from initial state to final state with labeled w; Accepted
If there is no path from initial state to final state with labeled w; Rejected
Given regular language how can we check
if is empty: ?
L L
Take the DFA that accepts
Check if there is any path from the initial state to a final state
L )
( L = Æ
Question:
Answer:
DFA
Æ
¹ L
DFA
Æ
=
L
Given regular language how can we check
if is finite?
L L
Take the DFA that accepts
Check if there is a walk with cycle from the initial state to a final state
L
Question:
Answer:
DFA
L is infinite
DFA
L is finite
Given regular languages and
how can we check if ? L 1 L 2
2
1 L
L =
Question:
Æ
= Ç
È
Ç ) ( ) ( L 1 L 2 L 1 L 2
Find if
Answer:
Æ
= Ç
È
Ç ) ( ) ( L 1 L 2 L 1 L 2
Æ
= Ç 2
1 L
L and L 1 Ç L 2 = Æ
2
1 L
L = L 1
L 2 L 2 L 1
2
1 L
L Í L 2 Í L 1
L 2 L 1
Æ
¹ Ç
È
Ç ) ( ) ( L 1 L 2 L 1 L 2
Æ
¹ Ç 2
1 L
L or L 1 Ç L 2 ¹ Æ L 1
L 2 L 2 L 1
2
1 L
L Ë L 2 Ë L 1
2
1 L
L ¹
Non-regular languages
Regular Languages
Every finite language is regular.
Some infinite languages are regular L
1={a
nb : n >=0}
Regularity:
The language is regular if, in processing any string, the information that has to be
remembered at any stage is strictly limited.
Some infinite languages are not regular
L
2= {a
nb
n: n >=0}
How can we prove that a language L is regular?
Prove that there is DFA M that accepts L
Prove that there is RE r that generates L
Prove that there is RG G that generates L
Regular languages
b
a * b * c + a
...
etc
* ) ( a b c
b + +
Non-regular languages { a n b n : n ³ 0 }
}*}
, { :
{ vv R v Î a b
How can we prove that a language is not regular?
L
Prove that there is no DFA that accepts L
Problem: this is not easy to prove
Solution: the Pumping Lemma !!!
The pumping Lemma uses pigeonhole principle.
The Pigeonhole Principle
pigeons
pigeonholes
4
3
A pigeonhole must
contain at least two pigeons
...
...
pigeons
pigeonholes
n
m n > m
The Pigeonhole Principle
...
pigeons
pigeonholes
n m
m
n > There is a pigeonhole
with at least 2 pigeons
The Pigeonhole Principle
If we put n objects into m boxes and if n > m
• then at least one box must have more than
one object in it.
The Pigeonhole Principle and
DFAs
DFA with 4 states
q 1 a q 2 q 3 b
q 4
b
b b
b
a a
aab
q 1 a q 2 q 3 b
q 4
b
b
b
a a
a
In walks of strings: no state
is repeated
abab aabb aabbb abbabb
In walks of strings:
q 1 a q 2 q 3 b
q 4
b
b
b
a a
a
a state
is repeated
If string has length :
q 1 a q 2 q 3 b
q 4
b
b
b
a a
a
w | w | ³ 4
Thus, a state must be repeated Then the transitions of string
are more than the states of the DFA
w
In general, for any DFA:
String has length number of states w ³
A state must be repeated in the walk of q w
... q ...
walk of w
Repeated state
In other words for a string : transitions are pigeons states are pigeonholes
q a
w
... q ...
walk of w
Repeated state
The Pumping Lemma
Take an infinite regular language L
There exists a DFA that accepts L
states m
Take string with w w Î L
There is a walk with label : w
...
walk w
If string has length w | w | ³ m
(numberof states of DFA)