Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski...

11
Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski [email protected]

Transcript of Introduction to CS Theory Lecture 8 – Pumping Lemma, Myhill-Nerode Theorem Piotr Faliszewski...

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

Introduction to CS Theory

Lecture 8 – Pumping Lemma, Myhill-Nerode TheoremPiotr [email protected]

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

The Pumping Lemma

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 that1. x = uvw2. |uv| ≤ n

3. |v| > 0

4. 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!

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

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. x = uvm,

2. |uv| ≤ n3. |v| > 04. 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..

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

Steps of a “Pumping Lemma” Proof

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}

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

Regular and Nonregular Languages

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

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?

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

Distinguishing Strings

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?

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

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

Myhill-Nerode Theorem

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.

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.

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

Myhill-Nerode Theorem: Examples

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 }

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

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.

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

Minimizing an FA

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

2 3

4

6

5

1

0

1

0

0

0

0 1

1

0, 1

0, 1

0, 1

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

Algorithm for Determining Equivalent States

Algorithm

1. List all unordered pairs of states (p,q) where p ≠ q

2. Mark each pair on the list that has exactly one element in A

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

1

2

3

4

5

7

0

0

0

0

0

1

1

1

1

1

0

0

16

1