Lecture 07: Theory of Automata:08 Properties of Regular Languages.
Properties of Regular Languages
-
Upload
linda-welch -
Category
Documents
-
view
244 -
download
18
description
Transcript of Properties of Regular Languages
Properties of Regular Languages Closure property : New recognizers for
languages that are constructed from other languages by certain operations can be built.
Decision Property: This property gives algorithms for answering important questions about automata.
Proving a language to be Regular A language L is regular if there exists a DFA
which accepts the strings of L Example: Is L={01,0011,000111,…}regular?
Try constructing a DFA for given L={0n1n|n>=1}
q0 q1
0
1
•Think of all strings 00001, 0001 etc which are not in L. These are also accepted by the DFA
•Try any other DFA
L={0n1n|n>=1} is not regular The language contains strings containing
equal number of zeroes followed by equal number of ones.
If L is regular, then L should be the language of some DFA
Before learning the proof, we understand an important principle.
Pigeonhole Principle If there are more pigeons than the
pigeonholes, then there must be at least one hole that has more than one pigeon.
Pigeonhole Principle The Pigeonhole Principle depends on the
number of pigeonholes being finite. Therefore this principle works for finite state
automata with the states as pigeonholes and the symbols in a string w as pigeons
This principle does not work for other kinds of automata that have an infinite number of states
Pigeonhole Principle If we put n objects into m boxes, and if n>m,
then at least one box must have more than one item in it
DFA and Pigeonhole Principle
q0 q1q2 q3 q4q4
1.Total states: 5
2.Minimum size of acceptable input string: 1(direct)
3.Minimum size of acceptable input string that passes through all the states : 4
4.What if a string is of size 5? Say 01110
0 1 1 0
DFA and Pigeonhole Principle
q0 q1q2 q3 q4q4
1.What if a string is of size 5? Say 01110
2.Certainly there is an arc that repeats at least one state.
3.This also means that the DFA also accepts even bigger strings e.g. 01111110, 011110
0 1 1 0
1
Proving another language to be regular using Pigeonhole Principle This gives us an idea of extending our
knowledge about the regular language that is accepted by the DFA
It states that now any language which is having a regular expression 0111*0 is also regular as there is a DFA that accepts all the strings in this language
Example We had considered 5 states and a string of 5
inputs say 01110, and observed that there is certainly a loop at 4th state.
In a transition graph with n vertices (states), any walk of length n or longer must repeat some vertex, that is contain a cycle.
Pumping Lemma Let L be a regular language . Then there
exists a constant n (which depends on L) such that every string w in L such that |w|>=n, we can break w into three strings, w=xyz, such that
1. y≠є2. |xy|<=n3. For all k>=0, the string xykz is also in L
Use Pumping Lemma to understand previous example
Number of states :5 String 01110 can be written as xyz where x=011
y=1z=0
We can now easily see that the string 01111110 is of the form 011140 for k=4 and is accepted by the DFA, hence is in L
Pumping Lemma This way we have seen that if any string in
a language is of larger size than the total number of states, then we can always find a nonempty string y that can be ‘pumped’, that is repeating y any number of times, or deleting it keeps the resulting string in the language L
Proof of Pumping Lemma Let L be regular. Then L=L(A) for some
DFA A. Let A has n states Consider any string of length n or more,
say m
w=a1a2….. anan+1an+2 ….. Am
where m>=n
Proof of Pumping Lemma For i=0,1,2,……n define state pi to be
qa1a2….. aiwhereis the transition function of A. then p0 =q
By the pigeonhole principle, it is not possible for the n+1 different pi for i=0,1,2,….n to be distinct since there are only n states
Proof of Pumping Lemma This indicates a repetition of some state
and we can find two integers i and j, with 0<=i<j<=n such that pi=pj.
We can break w=xyz as follows
1. x=a1a2….. ai
2. y= ai+1ai+2….. aj
3. z= aj+1aj+2….. am
L={0n1n|n>=1} is not regular: Proving by the Pumping Lemma Let L be regular So Pumping lemma must hold (as L is
infinite and a DFA has finite number of states)
Let the number of states in the DFA be ‘m’ let us consider a string 0m1m
qmq0 q1 q2 qm
1.0m is accepted by the DFA
2. Consider a string 0m 1m , which means there is a y
such that 0m 1m can be written as xyz (Pumping Lemma)
0 0 0 0 0 0
1
• Let x= 00000..000(m times)
• y=1
• z=111 …..1111(m-1 times)
• But here |xy|>m (states) Contradiction
Hence L is not regular
Closure Properties of Regular Languages Closure properties express the idea that any
language L formed from any regular language by certain operations, then L is also regular.
Closure Properties Union (of two regular language is regular) Intersection Complement Difference Reversal Star closure Concatenation Homomorphism Inverse homomorphism
Closure under Union Let L and M are regular Then these languages have regular
expressions R and S i.e. L=L(R) and M=L(S) LUM = L(R) U L(S) = L(R+S) Since R and S are the regular expressions then
R+S is also regular This implies LUM is also regular (Union is
Closed)
Closure under complementation If L is regular then to prove that its
complement Ľ (L bar), which is defined as - L, is also regular.
If there exists any DFA that accepts Ľ, then we say that the complement of L is also regular.
For this we learn to construct such DFA
Constructing a DFA to accept L complement Since L is regular, there exists a DFA that
accepts it. Let L=L(R ). Convert the regular expression R to an є-
NFA. Convert the є-NFA to a DFA by the subset
construction.
Constructing a DFA to accept L complement Complement the accepting states of that
DFA i.e. now the accepting states of this new DFA are the states other than the accepting states of previous one (i.e. Q-F)
Turn the complement DFA into a regular expression
Proving that the complement of a regular language is also regular Let L=L(A) for some DFA A Where A= (Q, , q0,F) Then Ľ=L(B) where B=(Q, , q0,Q-F) Then A and B are same other than the fact
that their accepting states are different Then any string w is in L(B) if and only if
q0,w) is in Q-F which occurs only if w is not in L(A). Hence Ľ is regular.
Example :Class assignment Prove that L(A) = (0+1)*01 is regular. Prove that the language consisting of all
strings that do not end in 01 is regular. If this language is regular, draw a DFA
accepting the language.
Closure under Intersection Intersection of two regular languages L and
M is written as L ∩ M Demorgan’s Law
__ __ ________
_______ _ ______
L ∩ M = L U M
ML L ∩ M
Closure under Intersection If L is regular, then complement of L is
also regular. If M is regular, then complement of M is
also regular. Also union of two regular languages is
proved to be regular Hence intersection of two regular
languages is also regular.
Special DFA construct for intersection of two regular languages
Let L and M be the languages of automata
AL=(QL, ,L, qL,FL) and
AM=(QM, ,M, qM,FM)
Construct an automaton
A = (QL XQM, ,, qLXqM,FLXFM)
Where the states are the pairs of type (p,q) such that p is in QL and q is in QM
Special DFA construct for intersection of two regular languages The alphabet is assumed to be the same. The transition function LXM such that
p,q),a)= an intermediate state of A which is a pair of states obtained by transition of state p (in AL) and of state q (in AM)
p,q),a)=(Lp,a) ,M q,a))
Special DFA construct for intersection of two regular languages The start state of the new DFA =(qL ,qM) Final states of the new DFA = cross
products of FL and FM
Now to prove that L ∩ M is regular Prove that there is a DFA that accepts all
strings of L ∩ M Let us assume that the newly constructed
DFA is the required one
Special DFA construct for intersection of two regular languages
Let a string w ∈ L ∩ M This means w ∈ L and w ∈ M Since L and M are regular, w is accepted by the
corresponding automata i.e.
LqL,w) ∈FL and M qM,w) ∈ FM
This indicates that qL, qM),w) ∈(FL,FM) Hence L ∩ M is Regular
Closure under Difference L-M = set of all strings that are in L and
not in M i.e. L-M = L ∩ M Since Complement of M is regular as M is
regular, Intersection of L and M is also regular
Hence the difference of two regular languages is regular
q
Example Let L=L(A) and M= L(B) where automata
A and B are described by the following transition diagrams
q
p q
r s
Reversal of a regular language is regular Reversal of a string w = a1a2……an is the
string anan-1……a1 denoted as wR.
Reversal of string 110101 is 101011 Reversal of string abaaa is aaaba Reversal of a language L is the language
consisting of the reversals of all its strings LR= {wR | w∈ L}
Proving reversal of a regular language is regular: through DFA construct Construct an automaton for LR
Reverse all arcs in the transition diagram for A
Make the start state of A the only accepting state for the new automaton
Create a new start state P0 with transitions on є to all the accepting states of A
q
Example : L=1*0(0+1)* L={100,1100,…101,1101,…} LR = {001,0011,….101,1011,…} First we draw a DFA for this language L
p q
1
0
0,1
p q
Example : drawing a new automaton for LR= (0+1)*01* Reverse the arcs and make p as accepting state Introduce a new start state p0 and draw an arc
with symbol є from p0 to the final state of A
p
1
0
0,1
p0
є
Homomorphism A string homomorphism is a function on
strings that works by substituting a particular string for each symbol.
Example : Let = {0,1}; w=0011then function h(0)=ab
h(1)=є Then h(w)= h(0)h(0)h(1)h(1)=ababєє h(w)=abab
Homomorphism to a language Homomorphism to a language is applied
by applying it to each of the strings in the language
h(L) = {h(w) | w is in L} Let L= 10*1
i.e. L={11,101,1001,…} Then h(L) = {єє, єabє, єababє,…} or
(ab)*
If L is regular then h(L) is also regular Let
L=L( R) for regular expression R Let E be an expression over Then let h(E) be an expression obtained by
replacing each symbol a of in E by h(a)
Then h(R) defines the language h(L).
Equivalence and Minimization of Automata Testing whether two descriptors for regular
languages are equivalent, in the sense that they define the same languages.
This gives a method to minimize a DFA
Definition: Equivalent states Two states p and q are said to be equivalent
if for all input strings w, p,w) is an accepting state if and only if q,w) is an accepting state
If two states are not equivalent then we say they are distinguishable (i.e. if they are not equivalent for at least one w)
Table filling algorithmB x
C x x
D x x x
E x x x
F x x x x
G x x x x x x
H x x x x x x
A B C D E F G