Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

Closure Properties of Regular

Languages
• Union
• Concatenation
• Kleene Closure
• Intersection
• Difference
• Complement
• Reversal
• Homomorphism
• Inverse Homomorphism
Closure Properties
• A closure property ascertains that “an operation on
languages that belong to a class (e.g., Regular
languages), produces a result that is also in that same
class”

• For regular languages, we can use any of its


representations (FA or RE) to prove a closure property.
Closure under UNION
Statement: If L and M are regular languages, so will be L  M.

Proof
Let L be regular language represented by regular expressions R

Let M be regular language represented by regular expressions S

R+S is a regular expression whose language is L  M.

Since L  M can be represented with a regular expression, it


is also a regular language.
Closure under CONCATENATION
Statement: If L and M are regular languages, so will be L.M

Proof
Let L be regular language represented by regular expressions R

Let M be regular language represented by regular expressions S

R.S is a regular expression whose language is L.M.


Since L.M can be represented with a regular
expression, it is also a regular language.
Closure under KLEENE CLOSURE
Statement: If L is a regular language, so will be L*.

Proof
Let L be a regular language represented by regular expression R

R* is a regular expression whose language is L*.

Since L* can be represented with a regular expression,


it is also a regular language.
Closure under INTERSECTION
Statement: If L and M are regular languages, so will be L  M

Proof
Let A be DFA whose language is L
Let B be DFA whose languages is M

We can construct a DFA C whose language is both L and M, by


building a product of A and B

Final states of C will be the pairs consisting of final states of both A


and B.
Example: Product DFA for Intersection
0
0
1 0
A B [A,C] [A,D]

0, 1 1
1 1
0
0
1 [B,C] [B,D]
0
1
0
C D

1
Closure under DIFFERENCE
Statement: If L and M are regular languages, so will be L - M

Proof
Let A be DFA whose language is L
Let B be DFA whose languages is M

We can construct a DFA C whose language is both L and M, by building a


product of A and B

Final states of C will be the pairs be the pairs where A-state is final but B-
state is not.
Example: Product DFA for Difference

0
0
1 0
A B [A,C] [A,D]

0, 1 1
1 1
0
0
1 [B,C] [B,D]
0
1
0
C D

1
Closure under COMPLEMENT
Statement:If L is a regular language, so will be 𝐿ത .

Proof
Complement of a language w.r.t. alphabet Σ is Σ* - L.

Since Σ* is a regular expression, it is a regular


language.

We have seen that regular languages are closed under


difference, therefore, Σ* - L is also a regular language.
Closure under REVERSAL
Statement: If L is a regular language, so will be LR.

Example: L = {0, 01, 100}; then LR = {0, 10, 001}.

Proof
Let E be the regular expression of L.

We have to show ER is the RE of LR.

If E is a single symbol (a, ε, or φ) then ER = E.


If E = R+S, then ER = RR + SR.
If E = R.S, then ER = SR.RR.
If E = R*, then ER = (RR)*
Closure under REVERSAL

• Let E = 01* + 10*


• Then ER = (01* + 10*)R
= (01*)R + (10*)R
= (1*)R.0R + (0*)R.1R
= (1R)*.0R + (0R)*.1R
= 1*0 + 0*1
Language of ER is the reverse of L
⇒ LR is a regular language.
HOMOMORPHISM
Homomorphism on an alphabet is function that gives a
string for each symbol in that alphabet.

Example: h(0) = ab; h(1) = ε;

Extend to strings by h(a1…an) =h(a1)…h(an)


i.e., h(01010) = ababab.

Or
h(a) = 0; h(b) = 11;
h(abbab) = 01111011.
Closure under HOMOMORPHISM
Statement: If L is a regular language, and h is a
homomorphism on its alphabet, then
h(L) = {h(w) | w ∊ L} is also a regular language.

Proof
Let A be an automata that accepts L.
Construct A’ such that:
- Every transition of A is replaced by h(a).
- Introduce intermediate states wherever
|h(a)| > 1.
- Start and final states of A and A’ are same
Example of homomorphism
Let h(0) = ab; h(1) = ε.
Let L be the language of regular expression 01* + 10*.

Then h(L) is the language of regular expression is


(ab)ε*+ ε(ab)*
Note: use parentheses to enforce the proper grouping.

(ab)ε*+ ε(ab)* can be simplified as ab + (ab)*


Since L(ab) is contained in L((ab)*), we can further simplify it as
(ab)*
Therefore the language of h(L) is (ab)*.
Inverse homomorphism
Let h be a homomorphism and L a language whose alphabet
is the output language of h.
h-1(L) = {w | h(w) is in L}
Example:
Let h(0) = ab; h(1) = ε.
Let L = {abab, baba}.
h-1(L) = the language with two 0’s and any number of 1’s =
L(1*01*01*).
Note: no string maps to baba; any string with exactly two 0’s
maps to abab.
Closure under Inverse Homomorphism
• Start with a DFA A for L
• Construct a DFA B for h-1(L) with:
– The same set of states.
– The same start state.
– The same set of final states.
• Input alphabet = the symbols to which
homomorphism h applies.
• The transitions for B are computed by applying h
to an input symbol a and seeing where A would go
on sequence of input symbolsa h(a).
• Formally, δB(q, a) = δA(q, h(a)).
Example:

a 1 Since
B B h(1) = ε
1
a
A b A 0
b
b 0 Since
C C h(0) = ab
a
1, 0
h(0) = ab
h(1) = ε
Decision Properties
A language can be represented in two ways:
i. Formal – with a RE or DFA.
ii. Informal – with a prose statement
e.g. L = {w | w starts with ‘aba’} over Σ = {a,b}
Or L contains strings that have even no. of 0’s
and odd no. of 1’s.

A decision property for a class of languages is an algorithm


that takes a formal description of a language (e.g., DFA) and
tells whether or not some property holds true.
Example: Is language L empty?
Why decision properties?
A language may be defined formally or informally.
How do you know if:
 Two languages are the same or different?
 Two representations are of the same
language or not?
 The given language is finite?
 The given language is not empty?
 Is this really the smallest representation i.e,
minimum DFA or smallest Regular Expression?
Converting among representations
NFA to DFA
• To find ɛ-closures of n states takes O(n3) time.
(Warshall’s algorithm can be used to compute
the ɛ-closure of all states at a time)
• Using subset construction method, we can
compute the equivalent DFA
Worst-case cost of conversion
• ɛ -NFA to NFA: O(n3), where n is the number of
states
• NFA to DFA: O(2n)
• DFA to NFA: O(n)
• DFA to RE: O(n34n), since there are n3 REs to
be constructed and each of the rounds can
quadruple the size.
• RE to ɛ-NFA: O(n), where n is the length of the
RE.
Testing emptiness of Regular Languages
• Start state is reachable always.
• From start, make a set of reachable states.
i.e. p is reachable from q, if there is an arc from q to p
with any label (ɛ / a).
• If any of the reachable states is an accepting state,
then the language is not empty.
• Reachability can be computed in O(n2) for
n-states DFA.
• If L is represented as a RE, then convert it to an ɛ-
NFA in O(n) time, for n symbols in RE, then check
reachability. Total time = O(n).
Direct emptiness test on RE’s
• Atomic RE’s
– Empty (ɸ) = true
– Empty (ɛ) = false
– Empty (a) = false
• Compound RE’s
– Empty (R + S) = Empty (R) ∧ Empty (S)
( True ∧ False )
– Empty (R.S) = Empty (R) ∨ Empty (S)
( True ∨ False )
– Empty (R*) = false
Testing membership of a Regular
Language
• Given a string w and a language L, does
w∈L?
Note: w is enumerated, while L is
represented by a DFA or RE.
• If L is represented by a DFA, simulate it for w. If
DFA stops at an accepting state, w ∈ L. Else w ∉ L.
• Simulates in O(n) time, for | w | = n.
• If L is represented in any other way (ɛ-NFA, NFA
or RE), first convert it to a DFA.
Test membership after conversion
• If w is of length n, and NFA has m states, then
we need to maintain a set of states the NFA
can be in, computed in time O(nm2).
• If NFA has ɛ-transitions, then we need O(m2)
time to first compute the ɛ-closure of each
state, and then simulate w.
• If L is given as a RE with m symbols, convert it
to ɛ-NFA with at most 2m states in O(m) time,
and then simulate w in O(nm2).

You might also like