Presentation is loading. Please wait.

Presentation is loading. Please wait.

Properties of Regular Languages

Similar presentations


Presentation on theme: "Properties of Regular Languages"— Presentation transcript:

1 Properties of Regular Languages
Engineered for Tomorrow Properties of Regular Languages Draw DFA for L={e} for a regular language, L={e, 01} for the r.l., L={e, 01, 0011} for the r.l., L={e, 01, 0011, } now, try for the r.l., L={0k1k | 0≤k ≤ infinity}

2 {0n1n | 0=<n} is not regular, but
Engineered for Tomorrow Example: {0n1n | 0=<n} is not regular, but {0n1n | 0nk, for some fixed k} is regular, for any fixed k. For k=3: L = {ε, 01, 0011, }

3 Pumping Lemma for Regular Languages
Engineered for Tomorrow Pumping Lemma for Regular Languages Pumping Lemma relates the size of string accepted with the number of states in a DFA What is the largest string accepted by a DFA with n states, presuming there is no loop? Now, if there is a loop, what type of strings are accepted via the loop(s)?

4 Pumping Lemma for Regular Languages
Engineered for Tomorrow Pumping Lemma for Regular Languages Lemma: (the pumping lemma) Let M be a DFA with |Q| = n states. If there exists a string x in L(M), such that |x|  n, then there exists a way to write it as x = uvw, where u,v, and w are all in Σ* and: 1 |uv|  n |v|  1 AND, all the strings uviw are also in L(M), for all i  0

5 Pumping Lemma for Regular Languages
Engineered for Tomorrow Pumping Lemma for Regular Languages Proof: Let x = a1a2 … am where m  n, x is in L(M), and δ(q0, a1a2 … ap) = qjp a1 a2 a3 … am qj0 qj1 qj2 qj3… qjm m  n and qj0 is q0 Consider the first n symbols, and first n+1 states on the above path: a1 a2 a3 … an qj0 qj1 qj2 qj3… qjn Since |Q| = n, it follows from the pigeon-hole principle that js = jt for some 0  s<t  n, i.e., some state appears on this path twice (perhaps many states appear more than once, but at least one does).

6 Since 0  s<t  n and uv = a1…at it follows that:
Engineered for Tomorrow Let: u = a1…as v = as+1…at Since 0  s<t  n and uv = a1…at it follows that: 1  |v| and therefore 1  |uv| |uv|  n and therefore 1  |uv|  n In addition, let: w = at+1…am It follows that uviw = a1…as(as+1…at)iat+1…am is in L(M), for all i  0.  In other words, when processing the accepted string x, the loop was traversed once, but could have been traversed as many times as desired, and the corresponding strings would be accepted. AND, “as many times” >= 0

7 Non-Regular Language: Example
Engineered for Tomorrow Non-Regular Language: Example Theorem: The language: L = {0k1k | k  0} (1) is not regular. Proof: (by contradiction) Suppose that L is regular. Then there exists a DFA M such that: L = L(M) (2) We will show that M accepts some strings not in L, contradicting (2). Suppose that M has n states, and consider a string x=0m1m, where m>>n. By (1), x is in L. By (2), x is also in L(M), note that the machine accepts a language not just a string

8 Since |x| = m >> n, it follows from the pumping lemma that:
Engineered for Tomorrow Since |x| = m >> n, it follows from the pumping lemma that: x = uvw 1  |uv|  n 1  |v|, and uviw is in L(M), for all i  0 Since 1  |uv|  n and n<<m, it follows that 1  |uv| < m. Also, since x = 0m1m it follows that uv is a substring of 0m. In other words v=0j, for some j  1. Since uviw is in L(M), for all i  0, it follows that 0m+cj1m is in L(M), for all c  1 (no. of loops), and j  1 (length of the loop) But by (1) and (2), 0m+cj1m is not in L(M), for any c  1, i.e., m+cj > m, a contradiction.  Note that L basically corresponds to balanced parenthesis.

9 Non-Regularity Example
Engineered for Tomorrow Non-Regularity Example Theorem: The language: L = {0k1k2k | k  0} (1) is not regular. Proof: (by contradiction) Suppose that L is regular. Then there exists a DFA M such that: L = L(M) (2) We will show that M accepts some strings not in L, contradicting (2). Suppose that M has n states, and consider a string x=0m1m2m, where m>>n. By (1), x is in L. By (2), x is also in L(M), note that the machine accepts a language not just a string

10 Since |x| = m >> n, it follows from the pumping lemma that:
Engineered for Tomorrow Since |x| = m >> n, it follows from the pumping lemma that: x = uvw 1  |uv|  n 1  |v|, and uviw is in L(M), for all i  0 Since 1  |uv|  n and n<<m, it follows that 1  |uv|  m. Also, since x = 0m1m2m it follows that uv is a substring of 0m. In other words v=0j, for some j  1. Since uviw is in L(M), for all i  0, it follows that 0m+cj1m2m is in L(M), for all c  1 and j  1. But by (1) and (2), 0m+cj1m2m is not in L(M), for any c  1, a contradiction.  Note that the above proof is almost identical to the previous proof.

11 NonRegularity Example
Engineered for Tomorrow NonRegularity Example Theorem: The language: L = {0m1n2m+n | m,n  0} (1) is not regular. Proof: (by contradiction) Suppose that L is regular. Then there exists a DFA M such that: L = L(M) (2) We will show that M accepts some strings not in L, contradicting (2). Suppose that M has n states, and consider a string x=0m1n2m+n, where m>>n. By (1), x is in L. By (2), x is also in L(M).

12 Since |x| = m >> n, it follows from the pumping lemma that:
Engineered for Tomorrow Since |x| = m >> n, it follows from the pumping lemma that: x = uvw 1  |uv|  n 1  |v|, and uviw is in L(M), for all i  0 Since 1  |uv|  n and n<<m, it follows that 1  |uv|  m. Also, since x = 0m1n2m+n it follows that uv is a substring of 0m. In other words v=0j, for some j  1. Since uviw is in L(M), for all i  0, it follows that 0m+cj1m2m+n is in L(M), for all c  1. In other words v can be “pumped” as many times as we like, and we still get a string in L(M). But by (1) and (2), 0m+cj1n2m+n is not in L(M), for any c  1, because the acceptable expression should be 0m+cj1n2m+cj+n, a contradiction.  What about {0m1n | m, n  0}?

13 Engineered for Tomorrow
Closure Properties Certain operations on regular languages are guaranteed to produce regular languages Union: L  M Intersection: L  M Complement: L Difference: L - M Reversal: LR = {wR | wL} Closure: L* Concatenation: LM Homomorphism: h(L) = {h(w) | wL, h is a homomorphism} Inverse homomorphism: h-1(L) = {w | h(w)L, h is a homomorphism}

14 Corollary: L+ too: it is LL*
Engineered for Tomorrow Theorem: The regular languages are closed with respect to union, concatenation and Kleene closure. Proof: Let L1 and L2 be regular languages. By definition there exist regular expressions r1 and r2 such that L(r1) = L1 and L(r2) = L2. But then r1 + r2 is a regular expression representing Similarly for concatenation and Kleene closure. Corollary: L+ too: it is LL*

15 A direct construction of a DFA M such that : Let:
Engineered for Tomorrow A direct construction of a DFA M such that : Let: M1 = (Q1, Σ, δ1,p0,F1), where Q1 = {p0, p1,…} M2 = (Q2, Σ, δ2,q0,F2), where Q2 = {q0, q1,…} where L(M1) = L1 and L(M2) = L2. Construct M where: Q = Q1 x Q2 Note that M has a state for each = {[p0, q0], [p0, q1], [p0, q2],…} pair of states in M1 and M2 Σ = as with M1 and M2 F = F1 x F2 start state = [p0, q0] δ([pi, qj], a) = [δ1(pi, a), δ2(qj, a)] for all [pi, qj] in Q and a in Σ

16 Closure under Regular Operators
Engineered for Tomorrow Closure under Regular Operators L = L(R1), M = L(R2), then by definition LM = L(R1+R2) LM = L(R1R2) L* = L(R*)

17 Example L is recognized by Then L is recognized by q1 1 q0 q2 q1 1 q0
Engineered for Tomorrow Example L is recognized by Then L is recognized by q1 1 q0 q2 q1 1 q0 q2

18 Closure under Intersection
Engineered for Tomorrow Closure under Intersection If L and M are regular languages, so is LM Proof 1. By DeMorgan’s Law, LM = LM. we already know that regular languages are closed under complement and union.

19 Closure under Intersection
Engineered for Tomorrow Closure under Intersection Proof 2. Let L be recognized by an DFA AL = (QL, , L, qL, FL) And M be recognized by an DFA AM = (QM, , M, qM, FM) We can cross product the two DFAs as: ALM = (QLxQM, , LM, (qL, qM), FLxFM) Where LM((p, q), a) = (L(p, a), M(q, a)) Then LM is recognized by ALM.

20 Engineered for Tomorrow
Example L: M: LM: p q 1 0,1 r s 0,1 1

21 Closure under Difference
Engineered for Tomorrow Closure under Difference If L and M are regular languages, then so is L - M Proof. Observe that L - M = LM. We already know that regular languages are closed under complement and intersection.

22 Closure under Reversal
Engineered for Tomorrow Closure under Reversal If L is a regular language, so is LR Proof 1. Let L be recognized by an FA A, turn A into an FA recognizing LR, by Reversing all arcs Making the old start state the new sole accepting state Creating a new start state q0, with (q0, )=F (the old accepting states)

23 Closure under Reversal
Engineered for Tomorrow Closure under Reversal Proof 2. Let L be described by a regex E. We shall construct a regex ER such that L(ER) = LR. We proceed by a structural induction on E. E is , , a, then ER = E E = F + G, then ER = FR + GR E = FG, then ER = GR FR E = (F)*, then ER = (FR)*

24 Engineered for Tomorrow
Homomorphism A homomorphism on 1 is a function h: 1*2*, where 1 and 2 are alphabets. Let w = a1a2…an, then h(w) = h(a1)h(a2)…h(an) and h(L) = {h(w) | wL} Example: Let h: {0,1}*{a,b}* be defined by h(0)=ab, h(1)=. Then h(0011) = abab h(L(10*1)) = L((ab)*)

25 Closure under Homomorphism
Engineered for Tomorrow Closure under Homomorphism If L is a regular language over , and h is a homomorphism on , then h(L) is regular Proof. Let L be described by a regex E. We claim that L(h(E)) = h(L) E is , , then h(E)=E, L(h(E)) = L(E) = h(L(E)) E is a, then L(E)={a}, L(h(E)) = {h(E)} = {h(a)} = h(L(E)) E = F+G, then L(h(E)) = L(h(F+G)) = L(h(F)+h(G)) = L(h(F))L(h(G)) = h(L(F))h(L(G)) = h(L(F)L(G)) = h(L(F+G)) = h(L(E)) E = FG, then L(h(E)) = L(h(FG)) = L(h(F)h(G)) = L(h(F))L(h(G)) = h(L(F))h(L(G)) = h(L(F)L(G)) = h(L(FG)) = h(L(E)) E = F*, then L(h(E)) = L(h(F*)) = L(h(F)*) = L(h(F))* = h(L(F))* = h(L(F)*) = h(L(F*)) = h(L(E))

26 Engineered for Tomorrow
Inverse Homomorphism Let h: 1*2* be a homomorphism, and L2*, then define h-1(L) = {w1* | h(w)L}

27 Engineered for Tomorrow
Example Let h: {a,b}*{0,1}* be defined by h(a)=01, h(b)=10. If L = L((00+1)*), then h-1(L) = L((ba)*). Claim: h(w)L if and only if w=(ba)n Proof. If w=(ba)n, then h(w)=(1001)nL; if h(w)L, and assume w not in L((ba)*), then four possible cases for w. w begins with a. Then h(w) begins with 01, not in L w ends with b. Then h(w) ends with 10, not in L w = xaay. Then h(w) = u0101v, not in L w = xbby. Then h(w) = u1010v, not in L

28 Example 1 = {a, b}, 2 = {0, 1} h(a) = 01, h(b) = 10 L: h-1(L): p q p
Engineered for Tomorrow Example 1 = {a, b}, 2 = {0, 1} h(a) = 01, h(b) = 10 L: h-1(L): p q 1 p q b a

29 Engineered for Tomorrow
Decision Properties Given a representation (e.g. RE, FA) of a regular language, what can we tell about L? Membership: Is string w in L? Emptiness: Is L = ? Finiteness: Is L a finite language? Note that every finite language is regular (why?), but a regular language is not necessarily finite.

30 Engineered for Tomorrow
Emptiness Given an FA for L, L is not empty if and only if at least one final state is reachable from the start state in FA. Alternatively, given a regex E for L, we can use the following to test if L(E) = : E=F+G, L(E)= if and only if L(F) and L(G) are empty E=FG, L(E)= if and only if either L(F) or L(G) is empty E=F*, L(E) is not empty

31 Engineered for Tomorrow
Finiteness Given a DFA for L, eliminate all states that are not reachable from the start state and all states that do not reach an accepting state. Test if there are any cycles in the remaining DFA; if so, L is infinite, if not, then L is finite.

32 Equivalence of States Let A = (Q, , , q0, F), and p, qQ. We define
Engineered for Tomorrow Equivalence of States Let A = (Q, , , q0, F), and p, qQ. We define p≡q (p and q are equivalent)  w*, *(p,w)F iff *(q,w)F Otherwise, p and q are distinguishable  w*, *(p,w)F and *(q,w)F, or vice versa “≡” is an equivalence relation

33 Compute Equivalence of States
Engineered for Tomorrow Compute Equivalence of States Initially, all pairs of states are in relation “≡”; remove the pairs of distinguishable states inductively as the following Basis: any non-accepting state is distinguishable from any accepting state. (w=) Induction: p and q are distinguishable if there is some input symbol a such that (p, a) is distinguishable from (q, a).

34 Engineered for Tomorrow
Example A ≡ E B ≡ H D ≡ F

35 Equivalence of Reg. Languages
Engineered for Tomorrow Equivalence of Reg. Languages Let L and M be two regular languages, to test if L = M? Convert L and M to DFA representations Compute the equivalence relation “≡” on all the states of the two DFAs together. If the two start states are equivalent, then L = M, else L  M.

36 Engineered for Tomorrow
Example A ≡ C B ≡ E D ≡ C

37 Engineered for Tomorrow
Minimization of DFAs Equivalence relation “≡” partitions the states into groups, where all the states in one group are equivalent. We can minimize the DFA by merging all equivalent states into one state, and merging the transitions between the states into the transitions between groups.

38 Engineered for Tomorrow
Example ({A, E}, {B, H}, {C}, {D, F}, {G})

39 Why the Minimization Can’t Be Beaten?
Engineered for Tomorrow Why the Minimization Can’t Be Beaten? Suppose we have a DFA A, and we minimize it to construct a DFA M. Yet there is another DFA N with fewer states than M and L(N)=L(M)=L(A). Proof by contradiction that this can't happen: Compute the equivalence relation “” on the states of M and N together. Start states of M and N are equivalent because L(M)=L(N). If p, q are equivalent, then their successors on any one input symbol are also equivalent. Since neither M not N could have an inaccessible state, every state of M is equivalent to at least one state of N.

40 Why the Minimization Can’t Be Beaten? (Cont’d)
Engineered for Tomorrow Why the Minimization Can’t Be Beaten? (Cont’d) Since N has fewer states than M, there are two states of M that are equivalent to the same state of N, and therefore equivalent to each other. But M was designed so that all its states are distinguishable from each other. We have a contradiction, so the assumption that N exists is wrong. In fact (stronger), there must be a 1-1 correspondence between the states of any other minimum-state N and the DFA M, showing that the minimum-state DFA for A is unique up to renaming of the states.

41 Table Filling Algorithm
Engineered for Tomorrow Table Filling Algorithm Definition: let M = (Q, , , q0, F) be a DFA, and let q1 and q2 be two distinct states. We say that a string x in * distinguishes q1 from q2 if exactly one of (q1, x) and (q2, x) is in F. We say q1 and q2 are k-indistinguishable if and only if there is no x, with |x|  k, which distinguishes q1 and q2.

42 q1 and q2 are equivalent states.
Engineered for Tomorrow Definition: We say q1 and q2 are (q1  q2) indistinguishable if and only if they are k-indistinguishable for all k  0. q1 and q2 are equivalent states.

43 Engineered for Tomorrow
start A B D C E F G 1

44 Table filling algorithm (p157)
Engineered for Tomorrow Table filling algorithm (p157) Basis: If p is an accepting state and q is a nonaccepting state, then (p, q) is a distinguishable pair of states. Induction: Let p and q be states such that (p,a) = r and (q,a) = s for some input symbol a. If (r, s) is a known pair of distinguishable states, then (p,q) is also a pair of distinguishable states.

45 Table of state inequivalences
Engineered for Tomorrow Table of state inequivalences B C D E F G A

46 Engineered for Tomorrow
Assignment 3 Use the Pumping Lemma to prove that the following languages over  = {0, 1} are not regular. a). The language L1 consisting of all palindromes. A palindrome is a string that equals its own reverse, such as or b). The language L2 consisting of all strings in which the number of 1's is exactly three times the number of 0's.

47 Engineered for Tomorrow
Find a minimal equivalent DFA for the following DFA, where A is the start state, C and F are accepting states 1 A B C D F E

48 Any FA has a unique minimum-state equivalent DFA.
Engineered for Tomorrow Summary The regular languages are closed under union, concatenation, star, and some other operations. Any FA has a unique minimum-state equivalent DFA.


Download ppt "Properties of Regular Languages"

Similar presentations


Ads by Google