Properties of Regular Languages

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Closure Properties of Regular Languages
Advertisements

Theory Of Automata By Dr. MM Alam
Properties of Regular Languages
Lecture 9,10 Theory of AUTOMATA
Summary Showing regular Showing non-regular construct DFA, NFA
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Mount Holyoke College 2 Nonregular languages? We now know: –Regular languages may be specified either.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
Courtesy Costas Busch - RPI1 Non-regular languages.
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Definitions Equivalence to Finite Automata
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Properties of Regular Languages
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Undecidability Reading: Chapter 8 & 9. 2 Decidability vs. Undecidability There are two types of TMs (based on halting): (Recursive) TMs that always.
Decidable Questions About Regular languages 1)Membership problem: “Given a specification of known type and a string w, is w in the language specified?”
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
CHAPTER 1 Regular Languages
Chapter 4 Pumping Lemma Properties of Regular Languages Decidable questions on Regular Languages.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Chapter 4 Properties of Regular Languages
Chapter 6 Properties of Regular Languages. 2 Regular Sets and Languages  Claim(1). The family of languages accepted by FSAs consists of precisely the.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 2670 Introduction to Theory of Computing September 13.
CS 203: Introduction to Formal Languages and Automata
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
1 Introduction to the Theory of Computation Regular Expressions.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
1 Properties of Regular Languages Reading: Chapter 4.
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
General Discussion of “Properties” The Pumping Lemma Membership, Emptiness, Etc.
Chapter 2 Regular Languages & Finite Automata. Regular Expressions A finitary denotation of a regular language over . ØL Ø = Ø aL a = {a} where a ∈ 
Pumping Lemma.
Standard Representations of Regular Languages
Closure Properties of Regular Languages
PROPERTIES OF REGULAR LANGUAGES
FORMAL LANGUAGES AND AUTOMATA THEORY
CSE 3813 Introduction to Formal Languages and Automata
PDAs Accept Context-Free Languages
Closure Properties of Regular Languages
Single Final State for NFA
Jaya Krishna, M.Tech, Assistant Professor
Hierarchy of languages
Decision Properties of Regular Languages
Properties of Regular Languages
CS 154, Lecture 4: Limitations on DFAs (I),
Infiniteness Test The Pumping Lemma Nonregular Languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
4. Properties of Regular Languages
Decidable Languages Costas Busch - LSU.
Properties of Regular Languages
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Closure Properties of Regular Languages
Chapter 4 Properties of Regular Languages
The Pumping Lemma for CFL’s
Closure Properties of Regular Languages
Chapter 1 Regular Language - 02
Regular Languages ภาษาปกติ.
Instructor: Aaron Roth
Properties of Regular Sets
Instructor: Aaron Roth
Presentation transcript:

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, 000111} … now, try for the r.l., L={0k1k | 0≤k ≤ infinity}

{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, 000111}

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)?

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

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

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

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

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.

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

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.

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

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}?

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}

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*

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 Σ

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

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

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.

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.

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

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.

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)

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

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

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

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}

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

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

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.

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

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.

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

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

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

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.

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

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.

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

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.

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.

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.

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.

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

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.

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

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 00100 or 110011. b). The language L2 consisting of all strings in which the number of 1's is exactly three times the number of 0's.

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

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.