Top Banner
Computational Models - Lecture 3 Non Regular Languages and the Pumping Lemma Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1
153

Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Jun 04, 2020

Download

Documents

dariahiddleston
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: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Computational Models - Lecture 3

Non Regular Languages and the PumpingLemma

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

Page 2: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Computational Models - Lecture 3

Non Regular Languages and the Pumping Lemma

Algorithmic questions for NDAs

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

Page 3: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Computational Models - Lecture 3

Non Regular Languages and the Pumping Lemma

Algorithmic questions for NDAs

Context Free Grammars

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

Page 4: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Computational Models - Lecture 3

Non Regular Languages and the Pumping Lemma

Algorithmic questions for NDAs

Context Free Grammars

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

Page 5: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Computational Models - Lecture 3

Non Regular Languages and the Pumping Lemma

Algorithmic questions for NDAs

Context Free Grammars

Sipser’s book, 1.4, 2.1, 2.2

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

Page 6: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

if you can’t hear me

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.2

Page 7: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

if you can’t hear me

you should move closer

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.2

Page 8: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

if you can’t hear me

you should move closer

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.2

Page 9: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

if you can’t hear me

you should move closer

no functioning amplification equipment expectedin the near future (next year or so)

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.2

Page 10: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Proved Last TimeThm.: A language, L, is described by a regular

expression, R, if and only if L is regular.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.3

Page 11: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Proved Last TimeThm.: A language, L, is described by a regular

expression, R, if and only if L is regular.

=⇒ construct an NFA accepting R.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.3

Page 12: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Proved Last TimeThm.: A language, L, is described by a regular

expression, R, if and only if L is regular.

=⇒ construct an NFA accepting R.

⇐= Given a regular language, L, construct an

equivalent regular expression.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.3

Page 13: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

We have made a lot of progress understanding whatfinite automata can do. But what can’t they do?

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.4

Page 14: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

We have made a lot of progress understanding whatfinite automata can do. But what can’t they do?Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.4

Page 15: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

We have made a lot of progress understanding whatfinite automata can do. But what can’t they do?Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}Consider B:

DFA must “remember” how many 0’s it has seen

impossible with finite state.

The others are exactly the same.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.4

Page 16: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.5

Page 17: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}Consider B:

DFA must “remember” how many 0’s it has seen

impossible with finite state.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.5

Page 18: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}Consider B:

DFA must “remember” how many 0’s it has seen

impossible with finite state.

The others are exactly the same...

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.5

Page 19: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}Consider B:

DFA must “remember” how many 0’s it has seen

impossible with finite state.

The others are exactly the same...

Question: Is this a proof?

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.5

Page 20: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Negative Results

Is there a DFA that accepts

B = {0n1n|n ≥ 0}C = {w|w has an equal number of 0’s and 1’s}D = {w|w has an equal number of occurrences

of 01 and 10 substrings}Consider B:

DFA must “remember” how many 0’s it has seen

impossible with finite state.

The others are exactly the same...

Question: Is this a proof?

Answer: No, D is regular!??? (see problem set 1)Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.5

Page 21: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

We will show that all regular languages have a specialproperty.

Suppose L is regular.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.6

Page 22: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

We will show that all regular languages have a specialproperty.

Suppose L is regular.

If a string in L is longer than a certain criticallength � (the pumping length),

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.6

Page 23: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

We will show that all regular languages have a specialproperty.

Suppose L is regular.

If a string in L is longer than a certain criticallength � (the pumping length),

then it can be “pumped” to a longer string byrepeating an internal substring any number oftimes.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.6

Page 24: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

We will show that all regular languages have a specialproperty.

Suppose L is regular.

If a string in L is longer than a certain criticallength � (the pumping length),

then it can be “pumped” to a longer string byrepeating an internal substring any number oftimes.

The longer string must be in L too.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.6

Page 25: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

We will show that all regular languages have a specialproperty.

Suppose L is regular.

If a string in L is longer than a certain criticallength � (the pumping length),

then it can be “pumped” to a longer string byrepeating an internal substring any number oftimes.

The longer string must be in L too.

This is a powerful technique for showing that alanguage is not regular.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.6

Page 26: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

Theorem: If L is a regular language, then there is an� > 0 (the pumping length), where if s is any string inL of length |s| > �, then s may be divided into threepieces s = xyz such that

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.7

Page 27: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

Theorem: If L is a regular language, then there is an� > 0 (the pumping length), where if s is any string inL of length |s| > �, then s may be divided into threepieces s = xyz such that

for every i > 0, xyiz ∈ L,

|y| > 0, and

|xy| ≤ �.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.7

Page 28: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

Theorem: If L is a regular language, then there is an� > 0 (the pumping length), where if s is any string inL of length |s| > �, then s may be divided into threepieces s = xyz such that

for every i > 0, xyiz ∈ L,

|y| > 0, and

|xy| ≤ �.

Remarks: Without the second condition, the theoremwould be trivial.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.7

Page 29: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma

Theorem: If L is a regular language, then there is an� > 0 (the pumping length), where if s is any string inL of length |s| > �, then s may be divided into threepieces s = xyz such that

for every i > 0, xyiz ∈ L,

|y| > 0, and

|xy| ≤ �.

Remarks: Without the second condition, the theoremwould be trivial.The third condition is technical and sometimes useful.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.7

Page 30: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof

Let M = (Q,Σ, δ, q1, F ) be a DFA that accepts L.

Let � be |Q|, the number of states of M .

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.8

Page 31: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof

Let M = (Q,Σ, δ, q1, F ) be a DFA that accepts L.

Let � be |Q|, the number of states of M .

If s ∈ L has length at least �, consider the sequence ofstates M goes through as it reads s:

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.8

Page 32: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof

Let M = (Q,Σ, δ, q1, F ) be a DFA that accepts L.

Let � be |Q|, the number of states of M .

If s ∈ L has length at least �, consider the sequence ofstates M goes through as it reads s:

s1 s2 s3 s4 s5 s6 . . . sn

↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑q1 q20 q9 q17 q12 q13 q9 q2 q5 ∈ F

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.8

Page 33: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof

Let M = (Q,Σ, δ, q1, F ) be a DFA that accepts L.

Let � be |Q|, the number of states of M .

If s ∈ L has length at least �, consider the sequence ofstates M goes through as it reads s:

s1 s2 s3 s4 s5 s6 . . . sn

↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑q1 q20 q9 q17 q12 q13 q9 q2 q5 ∈ F

Since the sequence of states is of length |s| + 1 > �,

and there are only � different states in Q, at least one

state is repeated (by the pigeonhole principle).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.8

Page 34: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof (cont.)

Write down s = xyz

q1

q9

q5x

y

z

By inspection, M accepts xykz for every k ≥ 0.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.9

Page 35: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof (cont.)

Write down s = xyz

q1

q9

q5x

y

z

By inspection, M accepts xykz for every k ≥ 0.

|y| > 0 because the state (q9 in figure) is repeated.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.9

Page 36: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Pumping Lemma – Proof (cont.)

Write down s = xyz

q1

q9

q5x

y

z

By inspection, M accepts xykz for every k ≥ 0.

|y| > 0 because the state (q9 in figure) is repeated.

To ensure that |xy| ≤ �, pick first state repetition,which must occure no later than � + 1 states insequence.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.9

Page 37: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

An Application

Theorem: The language B = {0n1n|n > 0} is notregular.

Proof: By contradiction. Suppose B is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.10

Page 38: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

An Application

Theorem: The language B = {0n1n|n > 0} is notregular.

Proof: By contradiction. Suppose B is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Bfor every k.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.10

Page 39: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

An Application

Theorem: The language B = {0n1n|n > 0} is notregular.

Proof: By contradiction. Suppose B is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Bfor every k.

If y is all 0, then xykz has too many 0’s.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.10

Page 40: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

An Application

Theorem: The language B = {0n1n|n > 0} is notregular.

Proof: By contradiction. Suppose B is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Bfor every k.

If y is all 0, then xykz has too many 0’s.

If y is all 1, then xykz has too many 1’s.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.10

Page 41: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

An Application

Theorem: The language B = {0n1n|n > 0} is notregular.

Proof: By contradiction. Suppose B is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Bfor every k.

If y is all 0, then xykz has too many 0’s.

If y is all 1, then xykz has too many 1’s.

If y is mixed, then xykz is not of right form. ♣Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.10

Page 42: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another Application

Theorem: The languageC = {w|w has an equal number of 0’s and 1’s} is notregular.Proof: By contradiction. Suppose C is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.11

Page 43: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another Application

Theorem: The languageC = {w|w has an equal number of 0’s and 1’s} is notregular.Proof: By contradiction. Suppose C is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Cfor every k.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.11

Page 44: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another Application

Theorem: The languageC = {w|w has an equal number of 0’s and 1’s} is notregular.Proof: By contradiction. Suppose C is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Cfor every k.

If y is all 0, then xykz has too many 0’s.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.11

Page 45: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another Application

Theorem: The languageC = {w|w has an equal number of 0’s and 1’s} is notregular.Proof: By contradiction. Suppose C is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Cfor every k.

If y is all 0, then xykz has too many 0’s.

If y is all 1, then xykz has too many 1’s.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.11

Page 46: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another Application

Theorem: The languageC = {w|w has an equal number of 0’s and 1’s} is notregular.Proof: By contradiction. Suppose C is regular,accepted by DFA M . Let � be the pumping length.

Consider the string s = 0�1�.

By pumping lemma s = xyz, where xykz ∈ Cfor every k.

If y is all 0, then xykz has too many 0’s.

If y is all 1, then xykz has too many 1’s.

If y is mixed, then since |xy| ≤ �, y must be all0’s, contradiction. ♣

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.11

Page 47: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context Switch

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.12

Page 48: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Algorithmic Questions for NDAs

Q.: Given an NDA, N , and a string s, is s ∈ L(N)?

Answer: Construct the DFA equivalent to N and runit on w.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.13

Page 49: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Algorithmic Questions for NDAs

Q.: Given an NDA, N , and a string s, is s ∈ L(N)?

Answer: Construct the DFA equivalent to N and runit on w.

Q.: Is L(N) = ∅?Answer: This is a reachability question in graphs: Isthere a path in the states’ graph of N from the startstate to some accepting state. There are simple,efficient algorithms for this task.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.13

Page 50: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Algorithmic Questions for NDAs

Q.: Is L(N) = Σ∗?

Answer: Check if L(N) = ∅.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.14

Page 51: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Algorithmic Questions for NDAs

Q.: Is L(N) = Σ∗?

Answer: Check if L(N) = ∅.

Q.: Given N1 and N2, is L(N1) ⊆ L(N2)?

Answer: Check if L(N2) ∩ L(N1) = ∅.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.14

Page 52: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Algorithmic Questions for NDAs

Q.: Is L(N) = Σ∗?

Answer: Check if L(N) = ∅.

Q.: Given N1 and N2, is L(N1) ⊆ L(N2)?

Answer: Check if L(N2) ∩ L(N1) = ∅.

Q.: Given N1 and N2, is L(N1) = L(N2)?

Answer: Check if L(N1) ⊆ L(N2) andL(N2) ⊆ L(N1).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.14

Page 53: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Algorithmic Questions for NDAs

Q.: Is L(N) = Σ∗?

Answer: Check if L(N) = ∅.

Q.: Given N1 and N2, is L(N1) ⊆ L(N2)?

Answer: Check if L(N2) ∩ L(N1) = ∅.

Q.: Given N1 and N2, is L(N1) = L(N2)?

Answer: Check if L(N1) ⊆ L(N2) andL(N2) ⊆ L(N1).

In the future, we will see that for stronger models ofcomputations, many of these problems cannot besolved by any algorithm.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.14

Page 54: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 55: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 56: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 57: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 58: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 59: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

We now introduce stronger machines andlanguages with more expressive power:

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 60: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

We now introduce stronger machines andlanguages with more expressive power:

pushdown automata,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 61: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

We now introduce stronger machines andlanguages with more expressive power:

pushdown automata,context-free languages,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 62: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

We now introduce stronger machines andlanguages with more expressive power:

pushdown automata,context-free languages,context-free grammars,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 63: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Another, More Radical Context SwitchSo far we saw

finite automata,regular languages,regular expressions,pumping lemma for regular languages.

We now introduce stronger machines andlanguages with more expressive power:

pushdown automata,context-free languages,context-free grammars,pumping lemma for context-free languages.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.15

Page 64: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free GrammarsThis is an example of a context free grammer, G1:

A → 0A1

A → B

B → #

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.16

Page 65: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free GrammarsThis is an example of a context free grammer, G1:

A → 0A1

A → B

B → #

Terminology:

Each line is a substitution rule or production.

Each rule has the form: symbol → string.The left-hand symbol is a variable(usually upper-case).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.16

Page 66: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free GrammarsThis is an example of a context free grammer, G1:

A → 0A1

A → B

B → #

Terminology:

Each line is a substitution rule or production.

Each rule has the form: symbol → string.The left-hand symbol is a variable(usually upper-case).

A string consists of variables and terminals.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.16

Page 67: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free GrammarsThis is an example of a context free grammer, G1:

A → 0A1

A → B

B → #

Terminology:

Each line is a substitution rule or production.

Each rule has the form: symbol → string.The left-hand symbol is a variable(usually upper-case).

A string consists of variables and terminals.

One variable is the start variable.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.16

Page 68: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Rules for Generating Strings

Write down the start variable (lhs of top rule).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.17

Page 69: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Rules for Generating Strings

Write down the start variable (lhs of top rule).

Pick a variable written down in current string anda derivation that starts with that variable.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.17

Page 70: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Rules for Generating Strings

Write down the start variable (lhs of top rule).

Pick a variable written down in current string anda derivation that starts with that variable.

Replace that variable with right-hand side of thatderivation.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.17

Page 71: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Rules for Generating Strings

Write down the start variable (lhs of top rule).

Pick a variable written down in current string anda derivation that starts with that variable.

Replace that variable with right-hand side of thatderivation.

Repeat until no variables remain.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.17

Page 72: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Rules for Generating Strings

Write down the start variable (lhs of top rule).

Pick a variable written down in current string anda derivation that starts with that variable.

Replace that variable with right-hand side of thatderivation.

Repeat until no variables remain.

Return final string (concatenation of terminals).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.17

Page 73: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Grammar G1:

A → 0A1

A → B

B → #

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.18

Page 74: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Grammar G1:

A → 0A1

A → B

B → #

Derivation with G1:

A ⇒ 0A1

⇒ 00A11

⇒ 000A111

⇒ 000B111

⇒ 000#111

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.18

Page 75: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

A Parse TreeA

A

A

B

#0 10 0 1 1

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.19

Page 76: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

A Parse TreeA

A

A

B

#0 10 0 1 1

Question: What strings can be generated in this wayfrom the grammar G1?

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.19

Page 77: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

A Parse TreeA

A

A

B

#0 10 0 1 1

Question: What strings can be generated in this wayfrom the grammar G1?

Answer: Exactly those of the form 0n#1n (n ≥ 0).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.19

Page 78: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free Languages

The language generated in this way is the language ofthe grammar.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.20

Page 79: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free Languages

The language generated in this way is the language ofthe grammar.

For example, L(G1) is {0n#1n|n ≥ 0}.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.20

Page 80: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Context-Free Languages

The language generated in this way is the language ofthe grammar.

For example, L(G1) is {0n#1n|n ≥ 0}.

Any language generated by a context-free grammar is

called a context-free language.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.20

Page 81: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

A Useful AbbreviationRules with same variable on left hand side

A → 0A1

A → B

are written as:

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.21

Page 82: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

A Useful AbbreviationRules with same variable on left hand side

A → 0A1

A → B

are written as:

A → 0A1 | B

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.21

Page 83: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

English-like Sentences

A grammar G2 to describe a few English sentences:

< SENTENCE > → < NOUN-PHRASE >< VERB >

< NOUN-PHRASE > → < ARTICLE >< NOUN >

< NOUN > → boy | girl | flower

< ARTICLE > → a | the

< VERB > → touches | likes | sees

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.22

Page 84: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Deriving English-like Sentences

A specific derivation in G2:

< SENTENCE > ⇒ < NOUN-PHRASE >< VERB >

⇒ < ARTICLE >< NOUN >< VERB >

⇒ a < NOUN >< VERB >

⇒ a boy < VERB >

⇒ a boy sees

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.23

Page 85: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Deriving English-like Sentences

A specific derivation in G2:

< SENTENCE > ⇒ < NOUN-PHRASE >< VERB >

⇒ < ARTICLE >< NOUN >< VERB >

⇒ a < NOUN >< VERB >

⇒ a boy < VERB >

⇒ a boy sees

More strings in G2:

a flower sees

the girl touches

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.23

Page 86: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Derivation and Parse Tree

< SENTENCE > ⇒ < NOUN-PHRASE >< VERB >

⇒ < ARTICLE >< NOUN >< VERB >

⇒ a < NOUN >< VERB >

⇒ a boy < VERB >

⇒ a boy sees

SENTENCE

NOUN-PHRASE VERB

ARTICLE NOUN

a boy seesSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.24

Page 87: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal DefinitionsA context-free grammar is a 4-tuple (V,Σ, R, S)where

V is a finite set of variables,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.25

Page 88: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal DefinitionsA context-free grammar is a 4-tuple (V,Σ, R, S)where

V is a finite set of variables,

Σ is a finite set of terminals,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.25

Page 89: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal DefinitionsA context-free grammar is a 4-tuple (V,Σ, R, S)where

V is a finite set of variables,

Σ is a finite set of terminals,

R is a finite set of rules: each rule is a variableand a finite string of variables and terminals.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.25

Page 90: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal DefinitionsA context-free grammar is a 4-tuple (V,Σ, R, S)where

V is a finite set of variables,

Σ is a finite set of terminals,

R is a finite set of rules: each rule is a variableand a finite string of variables and terminals.

S is the start symbol.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.25

Page 91: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal Definitions

If u and v are strings of variables and terminals,

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.26

Page 92: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal Definitions

If u and v are strings of variables and terminals,

and A → w is a rule of the grammar, then

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.26

Page 93: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal Definitions

If u and v are strings of variables and terminals,

and A → w is a rule of the grammar, then

we say uAv yields uwv, written uAv ⇒ uwv.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.26

Page 94: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal Definitions

If u and v are strings of variables and terminals,

and A → w is a rule of the grammar, then

we say uAv yields uwv, written uAv ⇒ uwv.

We write u∗⇒ v if u = v or

u ⇒ u1 ⇒ . . . ⇒ uk ⇒ v.

for some sequence u1, u2, . . . , uk.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.26

Page 95: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Formal Definitions

If u and v are strings of variables and terminals,

and A → w is a rule of the grammar, then

we say uAv yields uwv, written uAv ⇒ uwv.

We write u∗⇒ v if u = v or

u ⇒ u1 ⇒ . . . ⇒ uk ⇒ v.

for some sequence u1, u2, . . . , uk.

Definition: The language of the grammar is{w | S

∗⇒ w}

.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.26

Page 96: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Consider G4 = (V, {a, b} , R, S).

R (Rules): S → aSb | SS | ε .

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.27

Page 97: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Consider G4 = (V, {a, b} , R, S).

R (Rules): S → aSb | SS | ε .

Some words in the language: aabb, aababb.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.27

Page 98: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Consider G4 = (V, {a, b} , R, S).

R (Rules): S → aSb | SS | ε .

Some words in the language: aabb, aababb.

Q.: But what is this language?

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.27

Page 99: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Example

Consider G4 = (V, {a, b} , R, S).

R (Rules): S → aSb | SS | ε .

Some words in the language: aabb, aababb.

Q.: But what is this language?

Hint: Think of parentheses.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.27

Page 100: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Arythmetic Example

Consider (V,Σ, R,E) where

V = {E, T, F}Σ = {a,+,×, (, )}

Rules:E → E + T | TT → T × F | FF → (E) | a

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.28

Page 101: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Arythmetic Example

Consider (V,Σ, R,E) where

V = {E, T, F}Σ = {a,+,×, (, )}

Rules:E → E + T | TT → T × F | FF → (E) | a

Strings generated by the grammer:a + a × a and (a + a) × a.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.28

Page 102: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Arythmetic Example

Consider (V,Σ, R,E) where

V = {E, T, F}Σ = {a,+,×, (, )}

Rules:E → E + T | TT → T × F | FF → (E) | a

Strings generated by the grammer:a + a × a and (a + a) × a.What is the language of this grammer?Hint: arithmetic expressions.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.28

Page 103: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Arythmetic Example

Consider (V,Σ, R,E) where

V = {E, T, F}Σ = {a,+,×, (, )}

Rules:E → E + T | TT → T × F | FF → (E) | a

Strings generated by the grammer:a + a × a and (a + a) × a.What is the language of this grammer?Hint: arithmetic expressions.

E = expression, T = term, F = factor.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.28

Page 104: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Parse Tree for a + a × a

E → E + T | TT → T × F | FF → (E) | a

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.29

Page 105: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Parse Tree for a + a × a

E → E + T | TT → T × F | FF → (E) | a

aXa+a

FFF

T T

TE

E

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.29

Page 106: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Parse Tree for (a + a) × a

E → E + T | TT → T × F | FF → (E) | a

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.30

Page 107: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Parse Tree for (a + a) × a

E → E + T | TT → T × F | FF → (E) | a

( a + aX)a

F F F

T T

E

E

F

T

T

E

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.30

Page 108: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Designing Context-Free Grammars

No recipe in general, but few rules-of-thumb

If CFG is the union of several CFGs, renamevariables (not terminals) so they are disjoint, andadd new rule S → S1 | S2 | . . . | Si.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.31

Page 109: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Designing Context-Free Grammars

No recipe in general, but few rules-of-thumb

If CFG is the union of several CFGs, renamevariables (not terminals) so they are disjoint, andadd new rule S → S1 | S2 | . . . | Si.

To construct CFG for a regular language,“follow” a DFA for the language. For initial stateq0, make R0 the start variable. For state transitionδ(qi, a) = qj add rule Ri → aRj to grammer. Foreach final state qf , add rule Rf → ε to grammer.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.31

Page 110: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Designing Context-Free Grammars

No recipe in general, but few rules-of-thumb

If CFG is the union of several CFGs, renamevariables (not terminals) so they are disjoint, andadd new rule S → S1 | S2 | . . . | Si.

To construct CFG for a regular language,“follow” a DFA for the language. For initial stateq0, make R0 the start variable. For state transitionδ(qi, a) = qj add rule Ri → aRj to grammer. Foreach final state qf , add rule Rf → ε to grammer.

For languages with linked substrings (like{0n#1n|n ≥ 0} ), a rule of form R → uRv maybe helpful, forcing desired relation betweensubstrings.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.31

Page 111: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed under

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 112: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunion

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 113: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenation

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 114: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenationstar

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 115: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenationstar

Context-Free Languages are closed under

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 116: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenationstar

Context-Free Languages are closed underunion : S → S1 | S2

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 117: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenationstar

Context-Free Languages are closed underunion : S → S1 | S2

concatenation S → S1S2

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 118: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Closure Properties

Regular languages are closed underunionconcatenationstar

Context-Free Languages are closed underunion : S → S1 | S2

concatenation S → S1S2

star S → ε | SS

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.32

Page 119: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Closure Properties

Regular languages are also closed under

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.33

Page 120: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Closure Properties

Regular languages are also closed undercomplement (reverse accept/non-accept statesof DFA)

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.33

Page 121: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Closure Properties

Regular languages are also closed undercomplement (reverse accept/non-accept statesof DFA)

intersection(L1 ∩ L2 = L1 ∪ L2

).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.33

Page 122: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Closure Properties

Regular languages are also closed undercomplement (reverse accept/non-accept statesof DFA)

intersection(L1 ∩ L2 = L1 ∪ L2

).

What about complement and intersection ofcontext-free languages?

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.33

Page 123: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

More Closure Properties

Regular languages are also closed undercomplement (reverse accept/non-accept statesof DFA)

intersection(L1 ∩ L2 = L1 ∪ L2

).

What about complement and intersection ofcontext-free languages?

Not clear . . .

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.33

Page 124: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Ambiguity

Grammar: E → E+E | E×E | (E) | a

aXa+a

EEE

E

E

aXa+a

EEE

E

E

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.34

Page 125: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Ambiguity

We say that a string w is derived ambiguously fromgrammer G if w has two or more parse trees thatgenerate it from G.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.35

Page 126: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Ambiguity

We say that a string w is derived ambiguously fromgrammer G if w has two or more parse trees thatgenerate it from G.

Ambiguity is usually not only a syntactic notion butalso a semantic one, implying multiple meanings forthe same string.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.35

Page 127: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Ambiguity

We say that a string w is derived ambiguously fromgrammer G if w has two or more parse trees thatgenerate it from G.

Ambiguity is usually not only a syntactic notion butalso a semantic one, implying multiple meanings forthe same string.

It is sometime possible to eliminate ambiguity byfinding a different context free grammer generatingthe same language. This is true for the grammerabove, which can be replaced by unambiguousgrammer from slide (14x2).

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.35

Page 128: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Ambiguity

We say that a string w is derived ambiguously fromgrammer G if w has two or more parse trees thatgenerate it from G.

Ambiguity is usually not only a syntactic notion butalso a semantic one, implying multiple meanings forthe same string.

It is sometime possible to eliminate ambiguity byfinding a different context free grammer generatingthe same language. This is true for the grammerabove, which can be replaced by unambiguousgrammer from slide (14x2).

Some languages (e.g. {1i2j3k | i = j or j = k} areinherentrly ambigous.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.35

Page 129: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Chomsky Normal Form

A simplified, canonical form of context freegrammers.Every rule has the form

A → BC

A → a

S → ε

where S is the start symbol, A, B and C are any vari-

able, except B and C not the start symbol, and A can

be the start symbol.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.36

Page 130: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

TheoremTheorem: Any context-free language is generated bya context-free grammar in Chomsky normal form.Basic idea:

Add new start symbol S0.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.37

Page 131: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

TheoremTheorem: Any context-free language is generated bya context-free grammar in Chomsky normal form.Basic idea:

Add new start symbol S0.

Eliminate all ε rules of the form A → ε.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.37

Page 132: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

TheoremTheorem: Any context-free language is generated bya context-free grammar in Chomsky normal form.Basic idea:

Add new start symbol S0.

Eliminate all ε rules of the form A → ε.

Eliminate all “unit” rules of the form A → B.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.37

Page 133: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

TheoremTheorem: Any context-free language is generated bya context-free grammar in Chomsky normal form.Basic idea:

Add new start symbol S0.

Eliminate all ε rules of the form A → ε.

Eliminate all “unit” rules of the form A → B.

Patch up rules so that grammar generates thesame language.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.37

Page 134: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

TheoremTheorem: Any context-free language is generated bya context-free grammar in Chomsky normal form.Basic idea:

Add new start symbol S0.

Eliminate all ε rules of the form A → ε.

Eliminate all “unit” rules of the form A → B.

Patch up rules so that grammar generates thesame language.

Convert remaining long rules to proper form.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.37

Page 135: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofAdd new start symbol S0 and rule S0 → S.

Guarantees that new start symbol does not appear on

right-hand-side of a rule.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.38

Page 136: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminating ε rules.

Repeat:

remove some A → ε.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.39

Page 137: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminating ε rules.

Repeat:

remove some A → ε.

for each R → uAv, add rule R → uv.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.39

Page 138: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminating ε rules.

Repeat:

remove some A → ε.

for each R → uAv, add rule R → uv.

and so on: for R → uAvAw add R → uvAw,R → uAvw, and R → uvw.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.39

Page 139: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminating ε rules.

Repeat:

remove some A → ε.

for each R → uAv, add rule R → uv.

and so on: for R → uAvAw add R → uvAw,R → uAvw, and R → uvw.

for R → A add R → ε, except if R → ε hasalready been removed.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.39

Page 140: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminating ε rules.

Repeat:

remove some A → ε.

for each R → uAv, add rule R → uv.

and so on: for R → uAvAw add R → uvAw,R → uAvw, and R → uvw.

for R → A add R → ε, except if R → ε hasalready been removed.

until all ε-rules not involving the original startvariable have been removed.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.39

Page 141: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminate unit rules.

Repeat:

remove some A → B.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.40

Page 142: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminate unit rules.

Repeat:

remove some A → B.

for each B → u, add rule A → u, unless this ispreviously removed unit rule. (u is a string ofvariables and terminals.)

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.40

Page 143: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofEliminate unit rules.

Repeat:

remove some A → B.

for each B → u, add rule A → u, unless this ispreviously removed unit rule. (u is a string ofvariables and terminals.)

until all unit rules have been removed.

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.40

Page 144: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofFinally, convert long rules.To replace each A → u1u2 . . . uk (for k ≥ 3),introduce new non-terminals

N1, N2, . . . , Nk−1

and rules

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.41

Page 145: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

ProofFinally, convert long rules.To replace each A → u1u2 . . . uk (for k ≥ 3),introduce new non-terminals

N1, N2, . . . , Nk−1

and rules

A → u1N1

N1 → u2N2...

Nk−3 → uk−2Nk−2

Nk−2 → uk−1uk ♠Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.41

Page 146: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example

Initial Grammar:

S → ASA | aB

A → B | S

B → b | ε

(1) Add new start state:

S0 → S

S → ASA | aB

A → B | S

B → b | ε

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.42

Page 147: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (2)

S0 → S

S → ASA | aB

A → B | S

B → b | ε

(2) Remove ε-rule B → ε:

S0 → S

S → ASA | aB | a

A → B | S | ε

B → b | εSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.43

Page 148: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (3)

S0 → S

S → ASA | aB | a

A → B | S | ε

B → b

(3) Remove ε-rule A → ε:

S0 → S

S → ASA | aB | a | AS | SA | S

A → B | S | ε

B → bSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.44

Page 149: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (4)

S0 → S

S → ASA | aB | a | AS | SA | S

A → B | S

B → b

(4) Remove unit rule S → S

S0 → S

S → ASA | aB | a | AS | SA | S

A → B | S

B → bSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.45

Page 150: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (5)

S0 → S

S → ASA | aB | a | AS | SA

A → B | S

B → b

(5) Remove unit rule S0 → S:

S0 → S | ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → B | S

B → bSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.46

Page 151: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (6)

S0 → ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → B | S

B → b

(6) Remove unit rule A → B:

S0 → ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → B | S | b

B → bSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.47

Page 152: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (7)

S0 → ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → S | b

B → b

Remove unit rule A → S:

S0 → ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → S | b | ASA | aB | a | AS | SA

B → bSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.48

Page 153: Non Regular Languages and the Pumping Lemmabchor/CM05/Compute3.pdf · Pumping Lemma Theorem:IfL is a regular language, then there is an > 0 (the pumping length), where if s is any

Conversion Example (8)

S0 → ASA | aB | a | AS | SA

S → ASA | aB | a | AS | SA

A → b | ASA | aB | a | AS | SA

B → b

(8) Final simplification – treat long rules:

S0 → AA1 | UB | a | SA | AS

S → AA1 | UB | a | SA | AS

A → b | AA1 | UB | a | SA | AS

A1 → SA

U → a

B → b√

Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.49