1 / 50

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.

linda-welch
Download Presentation

Properties of Regular Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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?

  3. Try constructing a DFA for given L={0n1n|n>=1} 0 q0 1 q1 • Think of all strings 00001, 0001 etc which are not in L. These are also accepted by the DFA • Try any other DFA

  4. 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.

  5. Pigeonhole Principle • If there are more pigeons than the pigeonholes, then there must be at least one hole that has more than one pigeon.

  6. 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

  7. 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

  8. DFA and Pigeonhole Principle q2 q3 q4 q0 0 q1 1 1 0 q4 • Total states: 5 • Minimum size of acceptable input string: 1(direct) • Minimum size of acceptable input string that passes through all the states : 4 • What if a string is of size 5? Say 01110

  9. DFA and Pigeonhole Principle 1 q2 q3 q4 q0 0 q1 1 1 0 q4 • What if a string is of size 5? Say 01110 • Certainly there is an arc that repeats at least one state. • This also means that the DFA also accepts even bigger strings e.g. 01111110, 011110

  10. 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

  11. 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.

  12. 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 • y≠є • |xy|<=n • For all k>=0, the string xykz is also in L

  13. Use Pumping Lemma to understand previous example • Number of states :5 • String 01110 can be written as xyz where x=011 y=1 z=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

  14. 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

  15. 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

  16. Proof of Pumping Lemma • For i=0,1,2,……n define state pi to be d(q0,a1a2….. ai) where d is the transition function of A. then p0 =q0 • 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

  17. 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 • x=a1a2….. ai • y= ai+1ai+2….. aj • z= aj+1aj+2….. am

  18. Proof of Pumping Lemma y=ai+1ai+2….. aj x=a1a2….. ai pi p0 z=aj+1aj+2….. am

  19. 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

  20. 0m is accepted by the DFA • Consider a string0m 1m, which means there is a y such that 0m 1mcan be written as xyz (Pumping Lemma) 0 q0 q1 0 q2 0 0 0 0 qm qm • Let x= 00000..000(m times) • y=1 • z=111 …..1111(m-1 times) • But here |xy|>m (states) Contradiction 1 Hence L is not regular

  21. 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.

  22. Closure Properties • Union (of two regular language is regular) • Intersection • Complement • Difference • Reversal • Star closure • Concatenation • Homomorphism • Inverse homomorphism

  23. 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)

  24. Closure under complementation • If L is regular then to prove that its complement Ľ (L bar), which is defined as S*- 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

  25. 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.

  26. 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

  27. Proving that the complement of a regular language is also regular • Let L=L(A) for some DFA A • Where A= (Q, S,d, q0,F) • Then Ľ=L(B) where B=(Q, S,d, 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 d*(q0,w) is in Q-F which occurs only if w is not in L(A). Hence Ľ is regular.

  28. 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.

  29. DFA accepting language that does not end with 01 1 0 {q0 ,q2 } {q0 ,q1 } {q0} 0 {q0 ,q1 } 1 0 1

  30. Closure under Intersection • Intersection of two regular languages L and M is written as L ∩ M • Demorgan’s Law __ __ ________ _______ _ ______ L ∩ M = L U M M L L ∩ M

  31. 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.

  32. Special DFA construct for intersection of two regular languages • Let L and M be the languages of automata AL=(QL, S,dL, qL,FL) and AM=(QM, S,dM, qM,FM) • Construct an automaton A = (QL XQM, S,d, qLXqM,FLXFM) Where the states are the pairs of type (p,q) such that p is in QL and q is in QM

  33. Special DFA construct for intersection of two regular languages • The alphabet S is assumed to be the same. • The transition function d = dLXdM such that d((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) • d((p,q),a)=(dL(p,a) ,dM (q,a))

  34. 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 • Letus assume that the newly constructed DFAis the required one

  35. Special DFA construct for intersection of two regular languages • Let a stringw ∈L ∩ M • This meansw ∈ L andw ∈M • Since L and M are regular, w is accepted by the corresponding automata i.e. dL(qL,w)∈FL anddM (qM,w) ∈ FM • This indicates that • d(( qL, qM),w)∈(FL,FM) • HenceL ∩ M is Regular

  36. 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 Mis also regular • Hence the difference of two regular languages is regular

  37. p q Example • Let L=L(A) and M= L(B) where automata A and B are described by the following transition diagrams 0,1 1 q 0 0 0,1 q r s 1

  38. 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}

  39. Example : reversal of a language • Let L= {001,10,111} then LR = {100,01,111}

  40. Proving reversal of a regular language is regular: through DFA construct • Construct an automaton forLR • 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

  41. 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 1 0,1 q p 0 q

  42. 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 1 0,1 p є p 0 q p0

  43. Homomorphism • A string homomorphism is a function on strings that works by substituting a particular string for each symbol. • Example : Let S= {0,1}; w=0011 then function h(0)=ab h(1)=є • Then h(w)= h(0)h(0)h(1)h(1)=ababєє • h(w)=abab

  44. 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)*

  45. If L is regular then h(L) is also regular • Let L=L( R) for regular expressionR • Let E be an expression over S • Then let h(E) be an expression obtained by replacing each symbol a of S in E by h(a) Then h(R) defines the language h(L).

  46. 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

  47. Definition: Equivalent states • Two states p and q are said to be equivalent if for all input strings w, d(p,w) is an accepting state if and only if d(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)

  48. Example 1 0 0 1 C A B 0 D C 1 0 1 1 0 1 1 0 H E F G 0 1 0

  49. Table filling algorithm B 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

  50. Minimum state DFA equivalent to given DFA G 1 D,F 1 1 A,E 0 0 0 0 1 C B,H C 1 0

More Related