110 likes | 128 Views
Explore the concepts of the Pumping Lemma and Myhill-Nerode Theorem in Computer Science theory, including their applications, proofs, and examples. Learn how to prove a language nonregular using the Pumping Lemma, distinguish strings, and minimize automata. Understand regular and nonregular languages, equivalence relations, and automaton construction.
E N D
Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski pf@cs.rit.edu
Theorem (The Pumping Lemma) Let L be a regular language. There is an integer n such that for any x L with |x| n there are strings u, v, w such that x = uvw |uv| ≤ n |v| > 0 For each m 0, uvmw L Applications of the pumping lemma Showing that some language is not regular Prove that for this language the pumping lemma does not hold Just because the pumping lemma holds does not mean that the language is regular! The Pumping Lemma
Proving a Language Nonregular Set L = {aibi | i N }. Goal: Show that L is not regular. Proof. (by contradiction) Suppose that L is regular. Thus, pumping lemma holds for L and there exists an n such that for each string x in L, |x| > n, there are strings u, v, w such that • x = uvm, • |uv| ≤ n • |v| > 0 • For each m 0, uvmw L Pick x = anbn. The pumping lemma implies however that for some j 1 it holds that an+jbn is in L! But this is false. A contradiction..
Nonmechanical elements of a “pumping lemma”-based nonregularity proof Choose x of length at least n. Choose m (often 0 or 2, never 1) Derive the contradiction Some examples: L1 = {ai | i is a square} L2 = {ai | i is prime} L3 = {ww | w Σ*} L4 = {w | w has an equal number of a’s and b’s} What about: {aibjcj | i,j N} {bjck | j,k N} {x | no prefix of x has more 0s than 1s} Steps of a “Pumping Lemma” Proof
How do we know a language is regular? Give a regular expression Find an NFA … ? How do we know a language is not regular? Pumping lemma … ? Regular and Nonregular Languages What if we cannot come up with an NFA or a regular expressin, but we also have trouble showing the language is not regular via the pumping lemma?
Distinguishing two strings Two strings x, y are distinguishable if L/x ≠ L/y If L is regular and x and y are two distinguishable strings, can there be an FA that ends in the same state after processing x and after processing y? Distinguishing Strings Def. Let L be a language over Σ, and x be a string in Σ*. The set L/x is defined as follows: L/x = {z Σ* | xz L} Theorem. Let L be a language over Σ. Suppose there are n > 0 strings that are pairwise distinguishable with respect to L. Then there can be no FA recognizing L with fewer than n states
Properties of IL IL is an equivalence relation We will later see that L is regular if and only if the set of equivalence classes of IL is finite (Myhill-Nerode Theorem) Applications of Myhill-Nerode Theorem Show that a language is regular Show that a language is not regular Derive an FA for a regular language with a minimum number of states. Myhill-Nerode Theorem Def. Let L be a language over Σ. The indistinguishability relation IL on Σ* is defined as follows: For all x, y Σ*, x IL y iff L/x = L/y.
Example Σ = {0,1} Show that the language of palindromes is not regular: L = {wΣ* | w = wR } Show that the following language is regular: L’ = {wΣ* | w ends with 10 } Myhill-Nerode Theorem: Examples
Constructing an FA from IL • Theorem. Let L be a language over Σ and let QL be the set of equivalence classes of IL. If QL is finite, then ML = (QL, Σ, q0, ALδ) is a finite automaton accepting L, where: • q0 = [ε] • AL = { qQL|QL L≠} • δ([x], a) = [xa] • ML has the fewest states of any FA accepting L.
We can use Myhill-Nerode to construct a minimal automaton for a regular language specified via an automaton. Minimizing an automaton Remove all states unreachable from the start state. For p, q Q, p ≡ q if and only if for all strings z, (δ*(p,z) A δ*(q,z) A) Determine all pairs of equivalent states. Then identify all equivalent states. Why is that correct? Claim. For any two strings, x, y, x IL y iff δ*(q0, x) ≡ δ*(q0, y). Minimizing an FA 0, 1 0 2 3 1 0 0, 1 0 6 1 1 0 1 0 4 5 0, 1
Algorithm for Determining Equivalent States 0 • Algorithm • List all unordered pairs of states (p,q) where p ≠ q • Mark each pair on the list that has exactly one element in A • Make a pass through the list of states and mark those pairs (p,q) such that (δ(p,a), δ(q,a)) is marked • Repeat 3. until you make a pass where no new pairs are marked. • Marked pairs are exactly those that contain states that are not equivalent. 4 0 0 1 2 0 1 5 1 0 1 1 6 1 0 3 0 1 7 1