Top Banner
Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 Williams College
63

Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

May 03, 2018

Download

Documents

dinhliem
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Theory ofComputation

Non-regular Languages

Barath RaghavanCS 361 Fall 2009Williams College

Page 2: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

MISC

Homework 1 dueQuiz 1 out Monday

(covers Sipser 1.1-1.3self-timed, 2 hours)

Page 3: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

What does it mean for a language to be

REGULAR?

Page 4: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 5: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

L = {w | w has the same number of 01s as 10s}

Is the following language regular?

Σ = {0, 1}

Page 6: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

L = {w | w has the same number of 01s as 10s}

A

B

C

0

0

1

10

D

E

1

1

0

01

Page 7: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 8: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?L = {w | w has the same number of 0s and 1s}

Σ = {0, 1}

Page 9: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

NON

RegularLanguages

Page 10: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How do we prove that a language is

not regular?

Page 11: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

Page 12: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {anbn}

Page 13: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

Page 14: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

PumpingLemma

Page 15: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

((0 ∪ 1)∗0)∗

Page 16: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

((0 ∪ 1)∗0)∗

A B

0 11

0

Page 17: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

A B

0 11

0Let’s look at strings s, |s| = 4

What is true about the automaton for all strings of length 4 it reads?

Page 18: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

What is the shortest string that will cause a

repeated state?

A B

0 11

0

Page 19: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Suppose DFA M has |Q| states.Any string s,

|s| ≥ |Q|

will cause M to repeat a state.

Page 20: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

What does it mean to

repeat a state?

Page 21: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

A B

0 11

0Input: 10

State Sequence: ABA

Last appearance

First appearance

Page 22: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Input: 10State Sequence: ABA

A B1

0

ActualSequenceTraversed

Page 23: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Input: 10State Sequence: ABA

Also accepted:1010

101010

A B1

0

ActualSequenceTraversed

Page 24: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

A B C

1

0 0

Input: 010State Sequence: ABBC

Also accepted:01*0

Page 25: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

A B C

1

0 0

Generalized process:1. Pick a string s of length |Q|.2. Find where it repeats a state.3. Repeat that part of the string.

s = xyz, where y is the repeating part.

Page 26: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

(Draft 1)Property: Every regular language with a DFA of |Q| states has a string s of length |Q| where s = xyz and y can be repeated.

Page 27: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

(Draft 2)Property: Every regular language with a DFA of |Q| states has a string s of length |Q| where s = xyz and y can be repeated and |y| > 0.

Page 28: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

(Draft 3)Property: Every regular language with a DFA of |Q| states has a string s of length |Q| where s = xyz and y can

be repeated, |y| > 0, and |xy| ≤ |Q|.

Page 29: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Pumping LemmaFor every regular language L there exists some integer p where for every string s in L of length at least p, s = xyz and y can be repeated,

|y| > 0, and |xy| ≤ p.

Page 30: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

How to show a language L is not regular:1. Identify some property P that is true for all regular languages.

2. Assume P holds true for language L.3. Obtain a contradiction, thereby showing L is not regular.

Page 31: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

L = {0n1n | n ≥ 0}Is the following language regular?

Σ = {0, 1}

Page 32: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

L = {0n1n | n ≥ 0}Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Page 33: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Assume L is regular and thus has a DFA and is pumpable.

3. Obtain a contradiction, thereby showing L is not regular.

L = {0n1n | n ≥ 0}

Page 34: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Assume L is regular and thus has a DFA and is pumpable.

3. Obtain a contradiction, thereby showing L is not regular.

L = {0n1n | n ≥ 0}

Page 35: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

Page 36: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = 0p1p s ∈ LLet

Page 37: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

Page 38: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = xyz xy∗z ∈ L

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

Page 39: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = xyz xy∗z ∈ L

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

3 CASES

Page 40: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = xyz xy∗z ∈ L

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

1. y ∈ {0∗}3 CASES

Page 41: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = xyz xy∗z ∈ L

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

1. y ∈ {0∗} 2. y ∈ {1∗}3 CASES

Page 42: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

s = xyz xy∗z ∈ L

s = 0p1p s ∈ LLet

The pumping lemma guarantees:

1. y ∈ {0∗} 2. y ∈ {1∗} 3. y ∈ {0i1j}3 CASES

Page 43: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

3 CASES

s = xyz xy∗z ∈ L

Page 44: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

3 CASES

1. y ∈ {0∗} Impossible because repeating y would produce more 0s than 1s.

s = xyz xy∗z ∈ L

Page 45: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

3 CASES

1. y ∈ {0∗} Impossible because repeating y would produce more 0s than 1s.

s = xyz xy∗z ∈ L

2. y ∈ {1∗} Impossible because repeating y would produce more 1s than 0s.

Page 46: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0n1n | n ≥ 0}

3 CASES

1. y ∈ {0∗} Impossible because repeating y would produce more 0s than 1s.

s = xyz xy∗z ∈ L

2. y ∈ {1∗} Impossible because repeating y would produce more 1s than 0s.

3. y ∈ {0i1j} Impossible because repeating y would mis-order 1s and 0s.

Page 47: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Therefore

L = {0n1n | n ≥ 0}is NOT regular.

Page 48: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 49: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

Σ = {0, 1}L = {w | w has the same number of 0s and 1s}

Page 50: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Pumping LemmaFor every regular language L there exists some integer p where for every string s in L of length at least p, s = xyz and y can be repeated,

|y| > 0, and |xy| ≤ p.

L = {w | w has the same number of 0s and 1s}

Page 51: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Assume L is regular and thus has a DFA and is pumpable.

3. Obtain a contradiction, thereby showing L is not regular.

L = {w | w has the same number of 0s and 1s}

s = 0p1p

|xy| ≤ p =⇒ y ∈ {0∗} =⇒ xy2z /∈ L

Page 52: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 53: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

Σ = {0, 1}L = {wwR}

Page 54: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Pumping LemmaFor every regular language L there exists some integer p where for every string s in L of length at least p, s = xyz and y can be repeated,

|y| > 0, and |xy| ≤ p.

L = {wwR}

Page 55: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Assume L is regular and thus has a DFA and is pumpable.

3. Obtain a contradiction, thereby showing L is not regular.

L = {wwR}

s = 0p110p

|xy| ≤ p, |y| > 0 =⇒ y ∈ {0+} =⇒ xy0z /∈ L

Page 56: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 57: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

L = {0i1j | i > j}Is the following language regular?

Σ = {0, 1}

Page 58: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Pumping LemmaFor every regular language L there exists some integer p where for every string s in L of length at least p, s = xyz and y can be repeated,

|y| > 0, and |xy| ≤ p.

L = {0i1j | i > j}

Page 59: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

1. Identify some property P that is true for all regular languages.

There exists some DFA that recognizes any regular language and accepts some string s of length p for which we can apply the pumping lemma.

2. Assume P holds true for language L.

Assume L is regular and thus has a DFA and is pumpable.

3. Obtain a contradiction, thereby showing L is not regular.

|xy| ≤ p, |y| > 0 =⇒ y ∈ {0+} =⇒ xy0z /∈ L

L = {0i1j | i > j}

s = 0p+11p

Page 60: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

?

Page 61: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

Σ = {0, 1}

L = {0i1j0k | i > 10 > j > k > 0}

Page 62: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Is the following language regular?

L = {0i1j0k | i > 10 > j > k > 0}

YESR = 0+010((19(08 ∪ 07 ∪ . . . ∪ 01))∪

(18(07 ∪ 06 ∪ . . . ∪ 01))∪. . .∪(12(01)))

Page 63: Theory of - ICSIbarath/cs361/lectures/cs361...Theory of Computation Non-regular Languages Barath Raghavan CS 361 Fall 2009 ... s = xyz, where y is the repeating part. How to show a

Reading: Sipser 1.4