Tutorial 03 -- CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( ) 2009-09-27.

Slides:



Advertisements
Similar presentations
CSCI 3130: Formal languages and automata theory Tutorial 5
Advertisements

INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
Fall 2006Costas Busch - RPI1 Non-regular languages (Pumping Lemma)
CSCI 2670 Introduction to Theory of Computing September 13, 2005.
CSCI 2670 Introduction to Theory of Computing September 15, 2004.
CS21 Decidability and Tractability
Examples for Context-free Language and Pumping Lemma CSC3130 Tutorial 5 Xiao Linfu Department of Computer Science & Engineering.
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.
1 Introduction to Computability Theory Lecture4: Non Regular Languages Prof. Amos Israeli.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
Lecture 15UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 15.
CS5371 Theory of Computation
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
127 The Chomsky Hierarchy(review) Recursively Enumerable Sets Turing Machines Post System Markov Algorithms,  -recursive Functions Regular Expression.
Costas Busch - RPI1 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
1 Introduction to Computability Theory Lecture4: Non Regular Languages Prof. Amos Israeli.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
1 CSCI 3130: Formal Languages and Automata Theory Tutorial 4 Hung Chun Ho Office: SHB 1026 Department of Computer Science & Engineering.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Tutorial CSC3130 : Formal Languages and Automata Theory Tu Shikui ( ) SHB 905, Office hour: Thursday 2:30pm-3:30pm
Prof. Busch - LSU1 Non-regular languages (Pumping Lemma)
1 Non-regular languages. 2 Regular languages Non-regular languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Pushdown Automata (PDAs)
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
Introduction to CS Theory
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
 2005 SDU Lecture13 Reducibility — A methodology for proving un- decidability.
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.
CS 203: Introduction to Formal Languages and Automata
Homework 4 due 11/25.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
January 20, 2016CS21 Lecture 71 CS21 Decidability and Tractability Lecture 7 January 20, 2016.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Equivalence with FA * Any Regex can be converted to FA and vice versa, because: * Regex and FA are equivalent in their descriptive power ** Regular language.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
 2005 SDU Lecture11 Decidability.  2005 SDU 2 Topics Discuss the power of algorithms to solve problems. Demonstrate that some problems can be solved.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
Complexity and Computability Theory I Lecture #12 Instructor: Rina Zviel-Girshin Lea Epstein.
1 Advanced Theory of Computation Finite Automata with output Pumping Lemma Theorem.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Formal Language & Automata Theory
Non-regular languages
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PROPERTIES OF REGULAR LANGUAGES
Context-Free Grammars
Elementary Questions about Regular Languages
Non-regular languages
Non-Regular Languages
Instructor: Aaron Roth
Non-regular languages
Non-regular languages
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Tutorial CSC3130 : Formal Languages and Automata Theory Haifeng Wan ( )

Outline Pumping Lemma DFA Minimization Context-free Languages

Pigeonhole Principle Pigeonhole principle If m objects are put into n containers, where m>n, then at least one container must hold more than one object. The pigeonhole can be used to prove that certain infinite languages are not regular. Remind: any finite language is regular.

Pumping Lemma for Regular Languages Theorem: For every regular language L There exists a number n such that for every string z in L, we can write z = uvw where  |uv| ≤ n  |v| ≥ 1  For every i ≥ 0, the string u v i w is in L. z …… u v w

Pumping Lemma What does the Pumping Lemma say? If an infinite language is regular, it can be defined by a DFA. The DFA has a finite number m of states. Since the language is infinite, some strings of the language must have length greater than m. For a string of length greater than m accepted by the DFA, the walk through the DFA must contain a cycle. Repeating the cycle an arbitrary number of times must yield another string accepted by the DFA. Remind: the Pumping Lemma is not sufficient. It is one way to prove that a given infinite language is not regular, while it cannot be used to prove that a given infinite language is regular.

Outline to Prove by Pumping Lemma Main idea: prove by contradiction. Brief outline: Assume the language L is regular (and thus the Pumping Lemma holds). Show that repeating the cycle some number of times (“pumping” the cycle) yields a string that is not in L. Conclude that L is not regular by contradiction. What can we think about during using Pumping Lemma? On choosing the particular string z in L. On choosing the number of times to “pump” the cycle.

Example 1 Prove that L 3 ={uu: u in {0,1}*} is not regular. Suppose L 3 is regular,there exists n Choose a string z=0 m 10 m 1 with m>n, Although the decomposition of z into uvw is unknown, uv must consist entirely of 0 s because |uv| ≤ n. Moreover, |v| ≥1. Simply choose i=2. Thus uv 2 w will have more 0 s before the first 1 than the second 1, which is not in L 3. Thus L 3 is not regular due to the contradiction.

Prove that L={x: x has different numbers of 0s and 1s} is not regular. Trick: Instead of directly prove this, let’s prove its dual stated language D={x: x has the same number of 0s and 1s} is not regular. Steps: Remind that we have proven L={0 n 1 n : n≥0} is not regular. And L = D If L is regular, then D should also be regular. Thus D is not regular according to the contradiction. Neither is L.. Example 2

Take x = 0^n1^{n! + n}. Then the adversary splits it as uvw. Let k be the length of the v part. Now pump it (n!+k)/k times. Then you get uv^iw = 0^{k((n!+k)/k) + (n- k)}1^{n!+n} = 0^{n! + n}1^{n! + n}

Example Prove that L 2 ={ 1 m : m is prime} is not regular. Suppose L 2 is regular, and thus Pumping Lemma holds. Although n is unknown, we can still assume that there is one. Choose a string z=1 m where m is a prime number and |uvw|=m>n+1. Any prefix of z consists entirely of 1 s. Although the decomposition of z into uvw is unknown, it follows that |w|>1 due to |uvw|> n. Moreover, |v| ≥1. Choose i=|uw|. (Remind |w|>1 and |uw|>1 ). We have |u v i w|=|uw|+|v||uw|=(1+|v|)|uw|. Because both 1+|v| and |uw| are greater than 1, the product must be a composite number, i.e., |u v i w| is a composite not a prime number. It is not in L 2. Thus, L 2 is not regular due to the contradiction. Q.E.D.

Outline Pumping Lemma DFA Minimization Context-free grammars (CFG)

DFA Minimization There is an algorithm to start with any DFA and reduce it to the smallest possible DFA The algorithm attempts to identify classes of equivalent states These are states that can be merged together without affecting the answer of the computation

Equivalent and Distinguishable States Two states q, q’ are equivalent if Here,  (q, w) is the state that the machine is in if it starts at q and reads the string w q, q’ are distinguishable if they are not equivalent: ^ For every string w, the states  (q, w) and  (q’, w) are either both accepting or both rejecting ^ ^ For some string w, one of the states  (q, w),  (q’, w) is accepting and the other is rejecting

DFA Minimization Algorithm Find all pairs of distinguishable states as follows: For any pair of states q, q’ : If q is accepting and q’ is rejecting Mark (q, q’) as distinguishable Repeat until nothing is marked: For any pair of states (q, q’) : For every alphabet symbol a : If (  (q, a),  (q’, a)) are marked as distinguishable Mark (q, q’) as distinguishable For any pair of states (q, q’) : If (q, q’) is not marked as distinguishable Merge q and q’ into a single state   

Example 1 qq qq qq qq qq qq qq qq qq qq qq qq qq 00 0, qq qq

Example 1 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq 00 0, xxxx  q 4 is distinguishable from all other states

Example 1 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq 00 0, xxxx  q 0 is distinguishable from q 1, q 2, q 3, q 4 x x x

Example 1 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq 00 0, xxxx x x x  Merge states not marked distinguishable q 0 cannot be merged → group A q , q 2, q 3 are equivalent → group B q 4 cannot be merged → group C B BB

Example 1 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq 00 0, xxxx x x x B BB qq qq qCqC 1 minimized DFA: 0 0, 1 A B C

Example 2 qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x  q 2 is distinguishable from all other states

Example 2 (cont.) qq qq qq qq qq qq qq  q 0 is distinguishable from q 1, q 2, q 4, q 5, q 6 qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x x x x x

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x  q 1 is distinguishable from q 0, q 2, q 3, q 4, q 5 x x x x x x x

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x  q 3 is distinguishable from q 1, q 2, q 4, q 5, q 6 x x x x x x x x xx

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x  q 4 is distinguishable from q 0, q 1, q 2, q 3, q 5, q 6 x x x x x x x x xxx x

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x  q 5 is distinguishable from q 0, q 1, q 2, q 3, q 4, q 6 x x x x x x x x xxx xx

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x x x x x x x x x xxx xx  Merge states not marked distinguishable q 0, q 3 are equivalent → group A q , q 6 are equivalent → group B q 2 cannot be merged → group C q 4 cannot be merged → group D q 5 cannot be merged → group E

Example 2 (cont.) qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq qq xx x x x x x x x x x x x x xxx xx qAqA qEqE qCqC 1 minimized DFA: A B C DE qBqB qDqD

Outline Pumping Lemma DFA Minimization Context-free Languages

Relations Context-free Languages L Context-free Grammars G Push-down Automata M L = L(G) L = L(M) L(G) = L(M) PDA = NFA + a stack (infinite memory)

Example (I) Given the following CFG S  X | Y X  aXb | aX | a Y  aYb | Yb | b (1) L(G) = ? Σ={a, b}

Example (I) --- solution: L(S) S  X | Y X  aXb | aX | a Y  aYb | Yb | b Try to write some strings generated by it: S  X  aXb  aaXbb  aaaXbb  aaaabb S  Y  aYb  aYbb  aaYbbb  aabbbb more a’s than b’s more b’s than a’s Observations: Start from S, we can enter two States X & Y, and X, Y are “independent”; In X state, always more a are generated; In Y state, always more b are generated. Ls = Lx U Ly Lx = { a i b j ; i>j } Lx = { a i b j ; i<j } L(S) = { a i b j ; i≠j }

End of this tutorial! Thanks for coming!

Example (II) Given the following language: (1) design a CFG for it; L = {0 i 1 j : i ≤ j ≤ 2i, i=0,1,…},  = {0, 1}

Example (II) -- solution: CFG L = {0 i 1 j : i ≤ j ≤ 2i, i=0,1,…},  = {0, 1} Consider two extreme cases: (a). if j = i, then L 1 = { 0 i 1 j : i=j }; (b). if j = 2i, then L 2 = { 0 i 1 j : 2i=j }. S  0S1 S  ε S  0S11 S  ε If i ≤ j ≤ 2i, then randomly choose “red- rule” or “blue-rule” in the generation. “red-rule” “blue-rule” S  0S1 S  0S11 S  ε

Example (II) -- solution: CFG L = {0 i 1 j : i ≤ j ≤ 2i, i=0,1,…},  = {0, 1} S  0S1 S  0S11 S  ε Need to verify L = L(G) G = 1). L(G) is a subset of L: The “red-rule” and “blue-rule” guarantee that in each derivation, the number of 1s generated is one or two times larger than that of 0s. So, L(G) is a subset of L. 2). L is a subset of L(G): For any w = 0 i 1 j, i ≤ j ≤ 2i, we use “red-rule” ( 2i - j ) times and then “blue-rule” ( j - i ) times, i.e., S =*=> 0 2i-j S1 2i-j =*=> 0 2i-j 0 j-i S1 2(j-i) 1 2i-j ==> 0 i 1 j = w