Introduction to CS Theory Lecture 8 Pumping Lemma

  • Slides: 11
Download presentation
Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski pf@cs.

Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski pf@cs. rit. edu

The Pumping Lemma o Theorem (The Pumping Lemma) n Let L be a regular

The Pumping Lemma o Theorem (The Pumping Lemma) n 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 1. 2. 3. 4. x = uvw |uv| ≤ n |v| > 0 For each m 0, uvmw L Applications of the pumping lemma n Showing that some language is not regular o n 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!

Proving a Language Nonregular Set L = {aibi | i N }. Goal: Show

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 1. 2. 3. 4. 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. .

Steps of a “Pumping Lemma” Proof o Nonmechanical elements of a “pumping lemma”-based nonregularity

Steps of a “Pumping Lemma” Proof o Nonmechanical elements of a “pumping lemma”-based nonregularity proof n n n o Some examples: n Choose x of length at least n. Choose m (often 0 or 2, never 1) Derive the contradiction o n n n L 1 = {ai | i is a square} L 2 = {ai | i is prime} L 3 = {ww | w Σ*} L 4 = {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 0 s than 1 s}

Regular and Nonregular Languages o How do we know a language is regular? n

Regular and Nonregular Languages o How do we know a language is regular? n n n o Give a regular expression Find an NFA …? How do we know a language is not regular? n n Pumping lemma …? 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 Strings Def. Let L be a language over Σ, and x be a

Distinguishing Strings Def. Let L be a language over Σ, and x be a string in Σ*. The set L/x is defined as follows: o Distinguishing two strings n L/x = {z Σ* | xz L} n 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 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?

Myhill-Nerode Theorem Def. Let L be a language over Σ. The indistinguishability relation IL

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. o Properties of IL n n 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) o Applications of Myhill. Nerode Theorem n n n 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: Examples o Example Σ = {0, 1} n Show that the language

Myhill-Nerode Theorem: Examples o Example Σ = {0, 1} n Show that the language of palindromes is not regular: L = {w Σ* | w = w. R } n Show that the following language is regular: L’ = {w Σ* | w ends with 10 }

Constructing an FA from IL Theorem. Let L be a language over Σ and

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, Σ, q 0, AL δ) is a finite automaton accepting L, where: • q 0 = [ε] • AL = { q QL|QL L≠ } • δ([x], a) = [xa] ML has the fewest states of any FA accepting L.

Minimizing an FA o o We can use Myhill-Nerode to construct a minimal automaton

Minimizing an FA o o We can use Myhill-Nerode to construct a minimal automaton for a regular language specified via an automaton. o Why is that correct? Claim. For any two strings, x, y, x IL y iff δ*(q 0, x) ≡ δ*(q 0, y). Minimizing an automaton n n 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. 0, 1 0 2 3 1 0 0 0, 1 1 1 0 4 6 0 1 5 0, 1

Algorithm for Determining Equivalent States o 0 Algorithm 1. 2. 3. List all unordered

Algorithm for Determining Equivalent States o 0 Algorithm 1. 2. 3. 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 4. Repeat 3. until you make a pass where no new pairs are marked. 5. Marked pairs are exactly those that contain states that are not equivalent. 4 0 1 2 0 1 5 1 1 1 0 0 1 6 3 0 1 0 7 1