The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1...

78
The Pumping Lemma For every regular language L, there is a number 1 satisfying the pumping lemma property: All w L with | w|≥ can be expressed as a concatenation of three strings, w = u 1 vu 2 , where u 1 , v and u 2 satisfy: | v|≥ 1 (i.e. v = ε) | u 1 v|≤ for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.) Note similarity to construction in Kleene (b)

Transcript of The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1...

Page 1: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The Pumping Lemma

For every regular language L, there is a number ℓ ≥ 1

satisfying the pumping lemma property:

All w ∈ L with |w| ≥ ℓ can be expressed as aconcatenation of three strings, w = u1vu2, where u1, vand u2 satisfy:

◮ |v| ≥ 1 (i.e. v 6= ε)

◮ |u1v| ≤ ℓ

◮ for all n ≥ 0, u1vnu2 ∈ L(i.e. u1u2 ∈ L, u1vu2 ∈ L [but we knew that anyway],

u1vvu2 ∈ L, u1vvvu2 ∈ L, etc.)

Note similarity to construction in Kleene (b)

Page 2: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Suppose L = L(M) for a DFA M = (Q, Σ, δ, s, F).Taking ℓ to be the number of elements in Q, if n ≥ ℓ,then in

s = q0

a1−→ q1

a2−→ q2 · · ·aℓ−→ qℓ

︸ ︷︷ ︸

ℓ+1 states

· · ·an−→ qn ∈ F

q0, . . . , qℓ can’t all be distinct states. So qi = qj for some0 ≤ i < j ≤ ℓ. So the above transition sequence looks like

s = q0u1 ∗qi

v

∗= qj

u2 ∗qn ∈ F

where

u1 , a1 . . . ai v , ai+1 . . . aj u2 , aj+1 . . . an

Page 3: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

How to use the Pumping Lemmato prove that a language L

is not regular

For each ℓ ≥ 1, find some w ∈ L of length ≥ ℓ so that

no matter how w is split into three, w = u1vu2,with |u1v| ≤ ℓ and |v| ≥ 1, there is some n ≥ 0

for which u1vnu2 is not in L

(†)

Page 4: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}

Page 5: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

Page 6: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

Page 7: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

Page 8: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

so u1v0u2 =

Page 9: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

so u1v0u2 = ar ǫ aℓ−r−sbℓ =

Page 10: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

so u1v0u2 = ar ǫ aℓ−r−sbℓ = aℓ−sbℓ

Page 11: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

so u1v0u2 = ar ǫ aℓ−r−sbℓ = aℓ−sbℓ

But aℓ−sbℓ 6∈ L1

Page 12: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L1 = {anbn | n ≥ 0}

For each ℓ ≥ 1, take w = aℓbℓ ∈ L1

If w = u1vu2 with |u1v| ≤ ℓ & |v| ≥ 1, then forsome r and s:

◮ u1 = ar

◮ v = as, with r + s ≤ ℓ and s ≥ 1

◮ u2 = al−r−sbℓ

so u1v0u2 = ar ǫ aℓ−r−sbℓ = aℓ−sbℓ

But aℓ−sbℓ 6∈ L1 , so, by the Pumping Lemma, L1 isnot a regular language

Page 13: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}[For each ℓ ≥ 1, aℓbℓ ∈ L1 is of length ≥ ℓ and has property (†).]

Page 14: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}[For each ℓ ≥ 1, aℓbℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(ii) L2 , {w ∈ {a, b}∗ | w a palindrome}

Page 15: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}[For each ℓ ≥ 1, aℓbℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(ii) L2 , {w ∈ {a, b}∗ | w a palindrome}[For each ℓ ≥ 1, aℓbaℓ ∈ L1 is of length ≥ ℓ and has property (†).]

Page 16: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}[For each ℓ ≥ 1, aℓbℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(ii) L2 , {w ∈ {a, b}∗ | w a palindrome}[For each ℓ ≥ 1, aℓbaℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(iii) L3 , {ap | p prime}

Page 17: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

Page 18: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

Page 19: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

so u1vp−su2 =

Page 20: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

so u1vp−su2 = ar as(p−s) ap−r−s =

Page 21: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

so u1vp−su2 = ar as(p−s) ap−r−s = a(p−s)(s+1)

Page 22: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

so u1vp−su2 = ar as(p−s) ap−r−s = a(p−s)(s+1)

but s ≥ 1 ⇒ s + 1 ≥ 2

and (p − s) > (2ℓ− ℓ) ≥ 1 ⇒ (p − s) ≥ 2

Page 23: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L3 = {ap | p prime}

For each ℓ ≥ 1 let w = ap ∈ L3, p prime & p > 2ℓ

If w = u1vu2 with the usual . . .

then u1 = ar v = as u2 = ap−r−s

with s ≥ 1 & r + s ≤ ℓ

so u1vp−su2 = ar as(p−s) ap−r−s = a(p−s)(s+1)

but s ≥ 1 ⇒ s + 1 ≥ 2

and (p − s) > (2ℓ− ℓ) ≥ 1 ⇒ (p − s) ≥ 2

so a(p−s)(s+1) 6∈ L3

Page 24: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Examples

None of the following three languages are regular:

(i) L1 , {anbn | n ≥ 0}[For each ℓ ≥ 1, aℓbℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(ii) L2 , {w ∈ {a, b}∗ | w a palindrome}[For each ℓ ≥ 1, aℓbaℓ ∈ L1 is of length ≥ ℓ and has property (†).]

(iii) L3 , {ap | p prime}[For each ℓ ≥ 1, we can find a prime p with p > 2ℓ and then ap ∈ L3 has length ≥ ℓ andhas property (†).]

Page 25: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Pumping Lemma property is necessaryfor a language to be regular

It is not sufficient

Page 26: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Example of a non-regular languagewith the pumping lemma property

L , {cmanbn | m ≥ 1 & n ≥ 0} ∪ {ambn | m, n ≥ 0}

satisfies the pumping lemma property with ℓ = 1.

[For any w ∈ L of length ≥ 1, can take u1 = ε, v = first letter of w,

u2 = rest of w.]

But L is not regular – see Exercise 5.1.

Page 27: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L is not regular: (sketch)

.

Page 28: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L is not regular: (sketch)

If L is regular there is a DFA M with L = L(M).Let’s build a new machine, M′ from it.

.

Page 29: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L is not regular: (sketch)

If L is regular there is a DFA M with L = L(M).Let’s build a new machine, M′ from it.

Take a c transition from the start state of M .Make the state you reach the start state ofM′.

Page 30: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L is not regular: (sketch)

If L is regular there is a DFA M with L = L(M).Let’s build a new machine, M′ from it.

Take a c transition from the start state of M .Make the state you reach the start state ofM′.

Delete all transitions involving c (and remove cfrom the alphabet). But don’t remove anystates and keep the same accept states.

Page 31: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

L is not regular: (sketch)

If L is regular there is a DFA M with L = L(M).Let’s build a new machine, M′ from it.

Take a c transition from the start state of M .Make the state you reach the start state ofM′.

Delete all transitions involving c (and remove cfrom the alphabet). But don’t remove anystates and keep the same accept states.

What language does M′ recognise?

Page 32: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in THEORY

◮ What does is mean for a functionto be computable?[ Ib Computation Theory ]

Page 33: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in THEORY

◮ What does is mean for a functionto be computable?[ Ib Computation Theory ]

◮ Are some computational tasksintrinsiclaly unfeasible?[ Ib ComplexityTheory ]

Page 34: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in THEORY

◮ What does is mean for a functionto be computable?[ Ib Computation Theory ]

◮ Are some computational tasksintrinsiclaly unfeasible?[ Ib ComplexityTheory ]

◮ How do we specify and reasonabout program behaviour?[ Ib Logic and Proof,1b Semantics of PLs ]

Page 35: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in FORMAL LANGUAGES

◮ Are there other useful languageclasses?

Page 36: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in FORMAL LANGUAGES

◮ Are there other useful languageclasses?

◮ Are there other useful automataclasses that have a correspondenceto them?

Page 37: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

The way ahead, in FORMAL LANGUAGES

◮ Are there other useful languageclasses?

◮ Are there other useful automataclasses that have a correspondenceto them?

◮ What if we ask the same questionsabout them that we asked aboutregular languages?

Page 38: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Chomsky Hierarchy of Languages

Regular Languages⊂ Context Free Languages⊂ Context Sensitive Languages⊂ Recursively Enumerable Languages

Page 39: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Grammars

Grammars are a shorthand way of expressingthe inductive definition of subset inclusion forstrings in a Language.

Page 40: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Grammars

Grammars are a shorthand way of expressingthe inductive definition of subset inclusion forstrings in a Language.

Often by convention we use capitals fornon-terminal symbols (which are disjoint fromsymbols in the alphabet used by the language).

Page 41: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Grammars

Grammars are a shorthand way of expressingthe inductive definition of subset inclusion forstrings in a Language.

Often by convention we use capitals fornon-terminal symbols (which are disjoint fromsymbols in the alphabet used by the language).

We also have productions (or production rules)of the form e.g. A → a which says that thenon-terminal symbol A can be replaced by the(terminal) symbol a. More complex productionsare allowed.

Page 42: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Grammars

Grammars are a shorthand way of expressingthe inductive definition of subset inclusion forstrings in a Language.

Often by convention we use capitals fornon-terminal symbols (which are disjoint fromsymbols in the alphabet used by the language).

We also have productions (or production rules)of the form e.g. A → a which says that thenon-terminal symbol A can be replaced by the(terminal) symbol a. More complex productionsare allowed.

There is also a distinguished non-terminal calledthe goal symbol (we’ll use G)

Page 43: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

Page 44: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

Page 45: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T

Page 46: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

Page 47: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

Page 48: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

∆2→

T + x

Page 49: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

∆2→

T + x∆4→ P + x

Page 50: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

∆2→

T + x∆4→ P + x

∆5→ (E) + x

Page 51: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

∆2→

T + x∆4→ P + x

∆5→ (E) + x→ . . . → (x + x) + x

Page 52: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Everybody’s favourite grammarG → E ∆0

E → E + T ∆1

E → T ∆2

T → T ∗ P ∆3

T → P ∆4

P → (E) ∆5

P → x ∆6

so, e.g. G∆0→ E

∆1→ E + T∆4→ E + P

∆6→ E + x

∆2→

T + x∆4→ P + x

∆5→ (E) + x→ . . . → (x + x) + x

is a derivation of (x + x) + x

Page 53: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

α, β, γ any strings of terminals andnon-terminals

Page 54: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

α, β, γ any strings of terminals andnon-terminals

Context Free Languages: [ Type 2 ]productions of form N → β

Page 55: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

α, β, γ any strings of terminals andnon-terminals

Context Free Languages: [ Type 2 ]productions of form N → β

Context Sensitive Languages: [ Type 1 ]productions of the form αNβ → αγβ

Page 56: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

α, β, γ any strings of terminals andnon-terminals

Context Free Languages: [ Type 2 ]productions of form N → β

Context Sensitive Languages: [ Type 1 ]productions of the form αNβ → αγβ

Recursively Enumerable Languages: [ Type 0 ]productions of the form α → β

Page 57: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

Page 58: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

How about Regular Languages? [ Type 3 ]

Page 59: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

How about Regular Languages? [ Type 3 ]

A, B any non-terminals, a any terminal symbol, Sany non-terminal that doesn’t appear on rightside

Page 60: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

How about Regular Languages? [ Type 3 ]

A, B any non-terminals, a any terminal symbol, Sany non-terminal that doesn’t appear on rightside

production of the form A → a or S → ε orA → aB (right regular)

Page 61: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

How about Regular Languages? [ Type 3 ]

A, B any non-terminals, a any terminal symbol, Sany non-terminal that doesn’t appear on rightside

production of the form A → a or S → ε orA → aB (right regular)

or of the form A → a or S → ε or A → Ba(left regular)

Page 62: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Language classes by forms of production

How about Regular Languages? [ Type 3 ]

A, B any non-terminals, a any terminal symbol, Sany non-terminal that doesn’t appear on rightside

production of the form A → a or S → ε orA → aB (right regular)

or of the form A → a or S → ε or A → Ba(left regular)

but not both left and right regular in the samegrammar

Page 63: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Machines?????

◮ Regular Languages: Deterministic FiniteAutomata

Page 64: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Machines?????

◮ Regular Languages: Deterministic FiniteAutomata

◮ Context Free Languages: NondeterministicPush-Down Automata

Page 65: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Machines?????

◮ Regular Languages: Deterministic FiniteAutomata

◮ Context Free Languages: NondeterministicPush-Down Automata

◮ Context Sensitive Languages: LinearBounded Nondeterministic Turing Machine

Page 66: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Machines?????

◮ Regular Languages: Deterministic FiniteAutomata

◮ Context Free Languages: NondeterministicPush-Down Automata

◮ Context Sensitive Languages: LinearBounded Nondeterministic Turing Machine

◮ Recursively Enumerable Languages: TuringMachine

Page 67: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Machines?????

◮ Regular Languages: Deterministic FiniteAutomata

◮ Context Free Languages: NondeterministicPush-Down Automata

◮ Context Sensitive Languages: LinearBounded Nondeterministic Turing Machine

◮ Recursively Enumerable Languages: TuringMachine

Context Free Languages (and particularly thesubset that can be recognised by deterministicpush-down automata) are important sincemost programming languages are deterministiccontext free languages.

Page 68: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Deterministic Push-Down Automata (Sketch)

Idea: need some way to remember arbitrarynumber of things that we have seen, eg anbn

Page 69: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Deterministic Push-Down Automata (Sketch)

Idea: need some way to remember arbitrarynumber of things that we have seen, eg anbn

Slightly modified DFA along with a stack whichstores pairs of states and symbols.

Page 70: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Deterministic Push-Down Automata (Sketch)

Idea: need some way to remember arbitrarynumber of things that we have seen, eg anbn

Slightly modified DFA along with a stack whichstores pairs of states and symbols.

DPDA looks at top of stack as well as input todecide what to do

Page 71: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

Deterministic Push-Down Automata (Sketch)

Idea: need some way to remember arbitrarynumber of things that we have seen, eg anbn

Slightly modified DFA along with a stack whichstores pairs of states and symbols.

DPDA looks at top of stack as well as input todecide what to do

on state transitions, DPDA can pop and/orpush things on the stack as well as (perhaps)reading symbol

Page 72: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Page 73: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Page 74: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Yes.

Page 75: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Yes. Proved in 1997.

Page 76: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Yes. Proved in 1997. Earned 2002 GödelPrize.

Page 77: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Yes. Proved in 1997. Earned 2002 GödelPrize.

But for NPDA, the question of equivalence is

Page 78: The Pumping Lemma · The Pumping Lemma For every regular language L, there is a number ℓ≥ 1 satisfying the pumping lemma property: All w ∈ L with |w| ≥ ℓcan be expressed

What about our "questions"?

Given two DPDA, M1 and M2, can we determineif L(M1) = L(M2)?

Yes. Proved in 1997. Earned 2002 GödelPrize.

But for NPDA, the question of equivalence isundecidable