163
Computational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context Free Languages Non Context Free Languages Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.1

A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Computational Models– Lecture 5

A Few More PDAs Examples

Equivalence of PDAs and CFLs

Pumping Lemma for Context Free Languages

Non Context Free Languages

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

Page 2: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 and i = j or i = k}

Informally:

read and push a’s

either pop and match with b’s

or else pop and match with c’s

non-deterministic choice!

Note: non-determinism essential here!Unlike finite automata, non-determinismdoes add power

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

Page 3: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 and i = j or i = k}

Informally:

read and push a’s

either pop and match with b’s

or else pop and match with c’s

non-deterministic choice!

Note: non-determinism essential here!Unlike finite automata, non-determinismdoes add power

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

Page 4: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 and i = j or i = k}

Informally:

read and push a’s

either pop and match with b’s

or else pop and match with c’s

non-deterministic choice!

Note: non-determinism essential here!Unlike finite automata, non-determinismdoes add power

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

Page 5: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 and i = j or i = k}

Informally:

read and push a’s

either pop and match with b’s

or else pop and match with c’s

non-deterministic choice!

Note: non-determinism essential here!Unlike finite automata, non-determinismdoes add power

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

Page 6: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example

A PDA that accepts{

aibjck|i, j, k > 0 and i = j or i = k}

Informally:

read and push a’s

either pop and match with b’s

or else pop and match with c’s

non-deterministic choice!

Note: non-determinism essential here!Unlike finite automata, non-determinismdoes add power

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

Page 7: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Another Example (2)

ε,ε $

1q

q2

q3 q4ε,$ ε

q5 q0 q7ε,ε

ε

εb,a εc, ε

εa, a εb, ε c,a ε

ε,ε ε ε,ε ε ε,ε ε

This PDA accepts{

aibjck|i, j, k > 0 and i = j or i = k}

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

Page 8: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 9: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 10: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 11: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 12: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 13: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 14: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

A palindrome is a string w satisfying w = wR.

“Madam I’m Adam”

“Dennis and Edna sinned”

“Red rum, sir, is murder”

“Able was I ere I saw Elba”

“In girum imus nocte et consumimur igni”

“νιψoν ανoµηµατα µη µoναν oψιν”

Palindromes also appear in nature. For example asDNA sites (short strings over {A,C, T,G}) being cutby restriction enzymes.

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

Page 15: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Yet Another Example

ε,ε $1q q2

q3q4 ε,$ ε

0,ε 0ε1, 1

ε,ε ε

ε1,1ε0,0

This PDA accepts binary palindromes of even length.

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

Page 16: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Equivalence Theorem

Theorem: A language is context free if and only ifsome pushdown automata accepts it.

This time, the proofs of both the “if” part and the

“only if” part are interesting.

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

Page 17: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Equivalence Theorem

Theorem: A language is context free if and only ifsome pushdown automata accepts it.

This time, the proofs of both the “if” part and the

“only if” part are interesting.

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

Page 18: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

If Part

Theorem: If a language is context free, then somepushdown automaton accepts it.

Let A be a context-free language.

By definition, A has a context-free grammar Ggenerating it.

On input w, the PDA P should figure out if thereis a derivation of w using G.

Question: How does P figure out which substitutionto make?

Answer: It guesses.

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

Page 19: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

If Part

Theorem: If a language is context free, then somepushdown automaton accepts it.

Let A be a context-free language.

By definition, A has a context-free grammar Ggenerating it.

On input w, the PDA P should figure out if thereis a derivation of w using G.

Question: How does P figure out which substitutionto make?

Answer: It guesses.

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

Page 20: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

If Part

Theorem: If a language is context free, then somepushdown automaton accepts it.

Let A be a context-free language.

By definition, A has a context-free grammar Ggenerating it.

On input w, the PDA P should figure out if thereis a derivation of w using G.

Question: How does P figure out which substitutionto make?

Answer: It guesses.

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

Page 21: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

If Part

Theorem: If a language is context free, then somepushdown automaton accepts it.

Let A be a context-free language.

By definition, A has a context-free grammar Ggenerating it.

On input w, the PDA P should figure out if thereis a derivation of w using G.

Question: How does P figure out which substitutionto make?

Answer: It guesses.

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

Page 22: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

If Part

Theorem: If a language is context free, then somepushdown automaton accepts it.

Let A be a context-free language.

By definition, A has a context-free grammar Ggenerating it.

On input w, the PDA P should figure out if thereis a derivation of w using G.

Question: How does P figure out which substitutionto make?

Answer: It guesses.

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

Page 23: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA

Informally:

P pushes start variable S on stack

keeps making substitutions, storing intermediatestrings

when only terminals remain . . .

tests whether derived string equals input

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

Page 24: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA

Informally:

P pushes start variable S on stack

keeps making substitutions, storing intermediatestrings

when only terminals remain . . .

tests whether derived string equals input

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

Page 25: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA

Informally:

P pushes start variable S on stack

keeps making substitutions, storing intermediatestrings

when only terminals remain . . .

tests whether derived string equals input

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

Page 26: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA

Informally:

P pushes start variable S on stack

keeps making substitutions, storing intermediatestrings

when only terminals remain . . .

tests whether derived string equals input

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

Page 27: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (2)Where do we keep the intermediate string?

Can’t put it all on the stack

Keep on stack only symbols after first variable

Terminal symbols before first variable matchedimmediately to input string symbols.

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

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

Page 28: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (2)Where do we keep the intermediate string?

Can’t put it all on the stack

Keep on stack only symbols after first variable

Terminal symbols before first variable matchedimmediately to input string symbols.

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

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

Page 29: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (2)Where do we keep the intermediate string?

Can’t put it all on the stack

Keep on stack only symbols after first variable

Terminal symbols before first variable matchedimmediately to input string symbols.

read unread

pop

push

A1A0$

011001

intermediate string: A1A001

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

Page 30: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (2)Where do we keep the intermediate string?

Can’t put it all on the stack

Keep on stack only symbols after first variable

Terminal symbols before first variable matchedimmediately to input string symbols.

read unread

pop

push

A1A0$

011001

intermediate string: A1A001Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.9

Page 31: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (3)

Informal description:

push S$ on stack

if top of stack is a variable A,non-deterministically select rule and substitute.

if top of stack is terminal, a, read next input andcompare. If they differ, reject on this branch ofthe nondeterminism.

if top of stack is $, enter accept state (here weaccept only if input has all been read, as acceptstate will have no exits labeled with inputsymbols!).

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

Page 32: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (3)

Informal description:

push S$ on stack

if top of stack is a variable A,non-deterministically select rule and substitute.

if top of stack is terminal, a, read next input andcompare. If they differ, reject on this branch ofthe nondeterminism.

if top of stack is $, enter accept state (here weaccept only if input has all been read, as acceptstate will have no exits labeled with inputsymbols!).

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

Page 33: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (3)

Informal description:

push S$ on stack

if top of stack is a variable A,non-deterministically select rule and substitute.

if top of stack is terminal, a, read next input andcompare. If they differ, reject on this branch ofthe nondeterminism.

if top of stack is $, enter accept state (here weaccept only if input has all been read, as acceptstate will have no exits labeled with inputsymbols!).

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

Page 34: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (3)

Informal description:

push S$ on stack

if top of stack is a variable A,non-deterministically select rule and substitute.

if top of stack is terminal, a, read next input andcompare. If they differ, reject on this branch ofthe nondeterminism.

if top of stack is $, enter accept state (here weaccept only if input has all been read, as acceptstate will have no exits labeled with inputsymbols!).

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

Page 35: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (4)

Need shorthand to push entire string onto stack (inthis example the pushed string is w = xyz).

(r, w) ∈ δ(q, a, s)

Easy to do by introducing intermediate states.

q

r

q

r

a,s xyz

a,s z

ε,ε y

ε,ε x

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

Page 36: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (5)

States of P are

start state, qs

accept state, qaloop state, q`E states, shorthand for pushing entire strings

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

Page 37: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (5)

States of P are

start state, qsaccept state, qa

loop state, q`E states, shorthand for pushing entire strings

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

Page 38: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (5)

States of P are

start state, qsaccept state, qaloop state, q`

E states, shorthand for pushing entire strings

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

Page 39: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

CFL Implies PDA (5)

States of P are

start state, qsaccept state, qaloop state, q`E states, shorthand for pushing entire strings

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

Page 40: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Transition FunctionInitialize stack – δ(qs, ε, ε) = {q`, S$}

Top of stack is variable –δ(q`, ε, A) = {(q`, w)| where A→ w is a rule }Top of stack is terminal – δ(q`, a, a) = {(q`, ε)}End of Stack – δ(q`, ε, $) = {(qa, ε)}

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

Page 41: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Transition FunctionInitialize stack – δ(qs, ε, ε) = {q`, S$}Top of stack is variable –δ(q`, ε, A) = {(q`, w)| where A→ w is a rule }

Top of stack is terminal – δ(q`, a, a) = {(q`, ε)}End of Stack – δ(q`, ε, $) = {(qa, ε)}

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

Page 42: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Transition FunctionInitialize stack – δ(qs, ε, ε) = {q`, S$}Top of stack is variable –δ(q`, ε, A) = {(q`, w)| where A→ w is a rule }Top of stack is terminal – δ(q`, a, a) = {(q`, ε)}

End of Stack – δ(q`, ε, $) = {(qa, ε)}

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

Page 43: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Transition FunctionInitialize stack – δ(qs, ε, ε) = {q`, S$}Top of stack is variable –δ(q`, ε, A) = {(q`, w)| where A→ w is a rule }Top of stack is terminal – δ(q`, a, a) = {(q`, ε)}End of Stack – δ(q`, ε, $) = {(qa, ε)}

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

Page 44: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Transition Function

ε,$ ε

qs

qa

ql

ε,ε S$

εa,aε,A w

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

Page 45: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example

S → aTb|bT → Ta|ε

Initialization:qs

qa

ql

ε,ε S$

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

Page 46: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

S → aTb|bT → Ta|ε

Rules for Sqs

qa

ql

ε,ε S$Sε, b

Tε,ε

ε,ε a

Sε, b

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

Page 47: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example

S → aTb|bT → Ta|ε

Rules for Tqs

qa

ql

ε,ε S$Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

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

Page 48: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

S → aTb|bT → Ta|ε

Rules for terminalsqs

qa

ql

ε,ε S$

Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

εaaεbb

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

Page 49: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (3)

S → aTb|bT → Ta|ε

Termination:qs

qa

ql

ε,ε S$

Sε, b

Tε,ε

ε,ε a

ε, aT ε,ε a

Sε, bε,T ε

εaaεbbε, ε$

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

Page 50: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Only If Part

Theorem: If a PDA accepts a language, L, then L iscontext-free.

Given a pushdown automata P , we want to design acontext-free grammar G that “simulates” it:

The strings generated byG should be exactly those that

cause P to go from the start state to an accepting state.

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

Page 51: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Only If Part

Theorem: If a PDA accepts a language, L, then L iscontext-free.

Given a pushdown automata P , we want to design acontext-free grammar G that “simulates” it:

The strings generated byG should be exactly those that

cause P to go from the start state to an accepting state.

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

Page 52: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Only If Part

Theorem: If a PDA accepts a language, L, then L iscontext-free.

For each pair of states p and q in P , we will havea variable Apq in the grammar G.

This variable, Apq, generates all strings that takeP from p with an empty stack to q with emptystack.

Same string also takes p with any stack to q withsame stack!

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

Page 53: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Only If Part

Theorem: If a PDA accepts a language, L, then L iscontext-free.

For each pair of states p and q in P , we will havea variable Apq in the grammar G.

This variable, Apq, generates all strings that takeP from p with an empty stack to q with emptystack.

Same string also takes p with any stack to q withsame stack!

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

Page 54: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Only If Part

Theorem: If a PDA accepts a language, L, then L iscontext-free.

For each pair of states p and q in P , we will havea variable Apq in the grammar G.

This variable, Apq, generates all strings that takeP from p with an empty stack to q with emptystack.

Same string also takes p with any stack to q withsame stack!

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

Page 55: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL

To make things easier, we slightly modify P

Has single accept state qa.

It empties stack before accepting.

Each transition either pushes a symbol on stack,or pops a symbol from stack, but not both.

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

Page 56: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL

To make things easier, we slightly modify P

Has single accept state qa.

It empties stack before accepting.

Each transition either pushes a symbol on stack,or pops a symbol from stack, but not both.

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

Page 57: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL

To make things easier, we slightly modify P

Has single accept state qa.

It empties stack before accepting.

Each transition either pushes a symbol on stack,or pops a symbol from stack, but not both.

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

Page 58: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (2)

Modify P to make things easier

single accept state qa

ε,ε ε

ε,ε ε

empties stack before accepting

each transition pushes or pops, but not both.

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

Page 59: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (2)

Modify P to make things easier

single accept state qa

ε,ε ε

ε,ε ε

empties stack before accepting

each transition pushes or pops, but not both.

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

Page 60: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (2)

Modify P to make things easier

single accept state qa

ε,ε ε

ε,ε ε

empties stack before accepting

each transition pushes or pops, but not both.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.23

Page 61: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (3)Modify P to make things easier

single accept state qa√

empties stack before accepting

ε,ε ε

ε,ε ε

ε,ε ε

ε,ε ε

εε,a

ε,ε ε

transition either pushes or pops, but not both.

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

Page 62: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (3)Modify P to make things easier

single accept state qa√

empties stack before accepting

ε,ε ε

ε,ε ε

ε,ε ε

ε,ε ε

εε,a

ε,ε ε

transition either pushes or pops, but not both.

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

Page 63: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (3)Modify P to make things easier

single accept state qa√

empties stack before accepting

ε,ε ε

ε,ε ε

ε,ε ε

ε,ε ε

εε,a

ε,ε ε

transition either pushes or pops, but not both.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.24

Page 64: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (4)Modify P to make things easier

single accept state qa√

empties stack before accepting√

transition either pushes or pops, but not botha,b c

a,b ε cε,ε

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

Page 65: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (4)Modify P to make things easier

single accept state qa√

empties stack before accepting√

transition either pushes or pops, but not botha,b c

a,b ε cε,ε

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

Page 66: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

PDA Implies CFL (4)Modify P to make things easier

single accept state qa√

empties stack before accepting√

transition either pushes or pops, but not botha,b c

a,b ε cε,ε

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

Page 67: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof IdeaSuppose string x takes P from p with empty stack to qwith empty stack.

First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.

Stack was also empty at some point in between.

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

Page 68: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof IdeaSuppose string x takes P from p with empty stack to qwith empty stack.

First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.

Stack was also empty at some point in between.

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

Page 69: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof IdeaSuppose string x takes P from p with empty stack to qwith empty stack.

First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.

Stack was also empty at some point in between.

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

Page 70: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof Idea (2)

Suppose string x takes P from p with empty stack to qwith empty stack.First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.Simulate by: Apq → aArsb, where a, b are firstand last symbols in x (shorter x will be taken careof too), r follows p, and s precedes q.

Stack was also empty at some point in between.Simulate by: Apq → AprArq, r is intermediatestate where P has empty stack.

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

Page 71: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof Idea (2)

Suppose string x takes P from p with empty stack to qwith empty stack.First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.Simulate by: Apq → aArsb, where a, b are firstand last symbols in x (shorter x will be taken careof too), r follows p, and s precedes q.

Stack was also empty at some point in between.Simulate by: Apq → AprArq, r is intermediatestate where P has empty stack.

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

Page 72: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof Idea (2)

Suppose string x takes P from p with empty stack to qwith empty stack.First move that touches the stack must be a push, lastmust be a pop.In between, two possibilities:

Stack is empty only at start and finish, but not inmiddle.Simulate by: Apq → aArsb, where a, b are firstand last symbols in x (shorter x will be taken careof too), r follows p, and s precedes q.

Stack was also empty at some point in between.Simulate by: Apq → AprArq, r is intermediatestate where P has empty stack.

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

Page 73: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Details of Simulating Grammar

Given PDA P = (Q,Σ,Γ, δ, q0, {qa}), constructgrammar G. Variables are {Apq | p, q ∈ Q}.

Start variable is Aq0qa.

Rules:

For p, q, r, s ∈ Q, t ∈ Γ, and a, b ∈ Σ, if(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t),add rule Apq → aArsb .

for every p, q, r ∈ Q, add rule Apq → AprArq .

for each p ∈ Q, add rule App → ε .

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

Page 74: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Details of Simulating Grammar

Given PDA P = (Q,Σ,Γ, δ, q0, {qa}), constructgrammar G. Variables are {Apq | p, q ∈ Q}.

Start variable is Aq0qa.

Rules:

For p, q, r, s ∈ Q, t ∈ Γ, and a, b ∈ Σ, if(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t),add rule Apq → aArsb .

for every p, q, r ∈ Q, add rule Apq → AprArq .

for each p ∈ Q, add rule App → ε .

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

Page 75: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Details of Simulating Grammar

Given PDA P = (Q,Σ,Γ, δ, q0, {qa}), constructgrammar G. Variables are {Apq | p, q ∈ Q}.

Start variable is Aq0qa.

Rules:

For p, q, r, s ∈ Q, t ∈ Γ, and a, b ∈ Σ, if(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t),add rule Apq → aArsb .

for every p, q, r ∈ Q, add rule Apq → AprArq .

for each p ∈ Q, add rule App → ε .

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

Page 76: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Overall StructureWill now prove

Claim: Apq generates x if and only if x brings Pfrom p with empty stack to q with empty stack.

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

Page 77: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

First PartClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

If generates thenApq x, x takes

with empty stack toP from p q

with empty stack.

basis1−step derivation

induction stepk−step derivations

first derivation first derivationApq Arsa b Apq Apr Arq

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

Page 78: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

First Part (2)

Claim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

If generates thenApq x, x takes

with empty stack toP from p q

with empty stack.

basis1−step derivation

induction stepk−step derivations

first derivation first derivationApq Arsa b Apq Apr Arq

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

Page 79: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

BasisClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Proof by induction on number of steps in derivation.

Basis: The only single-step derivation is App → ε.

Reminder: This is a rule in G,

for each p ∈ Q, we’ve added the rule

App → ε .

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

Page 80: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

BasisClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Proof by induction on number of steps in derivation.

Basis: The only single-step derivation is App → ε.

Reminder: This is a rule in G,

for each p ∈ Q, we’ve added the rule

App → ε .

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

Page 81: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

Claim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

If generates thenApq x, x takes

with empty stack toP from p q

with empty stack.

basis1−step derivation

induction stepk−step derivations

first derivation first derivationApq Arsa b Apq Apr Arq

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

Page 82: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k steps, and letApq

∗⇒ x in k + 1 steps.

Two cases:

1. first derivation is Apq → aArsb.

2. first derivation is Apq → AprArq.

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

Page 83: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k steps, and letApq

∗⇒ x in k + 1 steps.

Two cases:

1. first derivation is Apq → aArsb.

2. first derivation is Apq → AprArq.

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

Page 84: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step, case I

Claim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

If generates thenApq x, x takes

with empty stack toP from p q

with empty stack.

basis1−step derivation

induction stepk−step derivations

first derivation first derivationApq Arsa b Apq Apr Arq

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

Page 85: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.

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

Page 86: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.

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

Page 87: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.

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

Page 88: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.

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

Page 89: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.

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

Page 90: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

Assume first derivation is Apq → aArsb.

x = ayb, where Ars∗⇒ y in k steps.

P starts in p with empty stack

reads a, pushes t, enters r.

by induction hypothesis, P reaches s with t onstack

finally P pops t and reaches q with empty stack.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.36

Page 91: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step, case II

Claim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

If generates thenApq x, x takes

with empty stack toP from p q

with empty stack.

basis1−step derivation

induction stepk−step derivations

first derivation first derivationApq Arsa b Apq Apr Arq

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

Page 92: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

First derivation is Apq → AprArq.

x = yz, where Apr∗⇒ y and Arr

∗⇒ z in ≤ ksteps.

induction hypothesis: y carries P from q withempty stack to r with empty stack

induction hypothesis: z carries P from r withempty stack to q with empty stack.

This completes proof of claim. ♣

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

Page 93: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

First derivation is Apq → AprArq.x = yz, where Apr

∗⇒ y and Arr∗⇒ z in ≤ k

steps.

induction hypothesis: y carries P from q withempty stack to r with empty stack

induction hypothesis: z carries P from r withempty stack to q with empty stack.

This completes proof of claim. ♣

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

Page 94: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

First derivation is Apq → AprArq.x = yz, where Apr

∗⇒ y and Arr∗⇒ z in ≤ k

steps.

induction hypothesis: y carries P from q withempty stack to r with empty stack

induction hypothesis: z carries P from r withempty stack to q with empty stack.

This completes proof of claim. ♣

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

Page 95: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If Apq generates x, then x takes P from pwith empty stack to q with empty stack.

Induction Step: Assume claim for k-step, and letA

∗⇒ w.

First derivation is Apq → AprArq.x = yz, where Apr

∗⇒ y and Arr∗⇒ z in ≤ k

steps.

induction hypothesis: y carries P from q withempty stack to r with empty stack

induction hypothesis: z carries P from r withempty stack to q with empty stack.

This completes proof of claim. ♣Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.38

Page 96: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Other DirectionClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Induction on number of steps in computation.

Base Case: zero-step computation.√

Induction Step: k-step computation.Two cases:

1. stack never empty during computation.

2. stack empty at intermediate state r.

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

Page 97: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Other DirectionClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Induction on number of steps in computation.

Base Case: zero-step computation.√

Induction Step: k-step computation.Two cases:

1. stack never empty during computation.

2. stack empty at intermediate state r.

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

Page 98: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Other DirectionClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Induction on number of steps in computation.

Base Case: zero-step computation.√

Induction Step: k-step computation.Two cases:

1. stack never empty during computation.

2. stack empty at intermediate state r.

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

Page 99: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Other Direction (2)

Claim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

basis1−step computation

induction step

If x P with empty stack tofrom pq with empty stack,

carriesApq generates x.

k−step computation

stack empty onlyat beginning and end

stack empty atintermediate state

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

Page 100: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

BasisClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

basis1−step computation

induction step

If x P with empty stack tofrom pq with empty stack,

carriesApq generates x.

k−step computation

stack empty onlyat beginning and end

stack empty atintermediate state

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

Page 101: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

BasisClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Proof by induction on number of steps incomputation.

Basis: In any zero-step computation, P reads only ε.

Reminder: this is a rule in G –

For each p ∈ Q, add rule

App → ε.

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

Page 102: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

Assume claim for k-step computation.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

Two cases:

1. stack never empty during computation.

2. stack empty at intermediate state r.

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

Page 103: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

Assume claim for k-step computation.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

Two cases:

1. stack never empty during computation.

2. stack empty at intermediate state r.

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

Page 104: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

basis1−step computation

induction step

If x P with empty stack tofrom pq with empty stack,

carriesApq generates x.

k−step computation

stack empty onlyat beginning and end

stack empty atintermediate state

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

Page 105: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

basis1−step computation

induction step

If x P with empty stack tofrom pq with empty stack,

carriesApq generates x.

k−step computation

stack empty onlyat beginning and end

stack empty atintermediate state

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

Page 106: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.

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

Page 107: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.

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

Page 108: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.

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

Page 109: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.

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

Page 110: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.

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

Page 111: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.

If stack never empty during computation then

first symbol pushed, t, is last symbol popped.

let a be input read in first move

let r be the state state after first move

let s be the state before last move

(r, t) ∈ δ(p, a, ε) and (q, ε) ∈ δ(s, b, t) so

Apq → aArsb is a rule.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.46

Page 112: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction Step

basis1−step computation

induction step

If x P with empty stack tofrom pq with empty stack,

carriesApq generates x.

k−step computation

stack empty onlyat beginning and end

stack empty atintermediate state

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

Page 113: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction StepClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Again, induction on number of steps in computation.Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.Suppose stack empty at intermediate state r.

Computations from p to r and from r to q each contain ≤ k

steps.

Let y be input in first portion, and z in second.

Induction hypothesis says that Apr∗⇒ y and Arq

∗⇒ z.

But we have rule Apq → AprArq.

This completes the proof of equivalence theorem. ♣

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

Page 114: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction StepClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Again, induction on number of steps in computation.Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.Suppose stack empty at intermediate state r.

Computations from p to r and from r to q each contain ≤ k

steps.

Let y be input in first portion, and z in second.

Induction hypothesis says that Apr∗⇒ y and Arq

∗⇒ z.

But we have rule Apq → AprArq.

This completes the proof of equivalence theorem. ♣

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

Page 115: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction StepClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Again, induction on number of steps in computation.Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.Suppose stack empty at intermediate state r.

Computations from p to r and from r to q each contain ≤ k

steps.

Let y be input in first portion, and z in second.

Induction hypothesis says that Apr∗⇒ y and Arq

∗⇒ z.

But we have rule Apq → AprArq.

This completes the proof of equivalence theorem. ♣

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

Page 116: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction StepClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Again, induction on number of steps in computation.Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.Suppose stack empty at intermediate state r.

Computations from p to r and from r to q each contain ≤ k

steps.

Let y be input in first portion, and z in second.

Induction hypothesis says that Apr∗⇒ y and Arq

∗⇒ z.

But we have rule Apq → AprArq.

This completes the proof of equivalence theorem. ♣

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

Page 117: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Induction StepClaim: If x brings P from p with empty stack to qwith empty stack, then Apq generates x.

Again, induction on number of steps in computation.Suppose x brings P from p with empty stack to q withempty stack in k + 1 steps.Suppose stack empty at intermediate state r.

Computations from p to r and from r to q each contain ≤ k

steps.

Let y be input in first portion, and z in second.

Induction hypothesis says that Apr∗⇒ y and Arq

∗⇒ z.

But we have rule Apq → AprArq.

This completes the proof of equivalence theorem. ♣Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.48

Page 118: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Corollary

Every regular language is context-free.

context freelanguages

regularlanguages

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

Page 119: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Non-Context-Free Languages

pumping lemma for finite automata is our(almost) only tool for showing that languagesare not regular.

we will now do the same for context-freelanguages.

it’s slightly more complicated . . .

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

Page 120: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Non-Context-Free Languages

pumping lemma for finite automata is our(almost) only tool for showing that languagesare not regular.

we will now do the same for context-freelanguages.

it’s slightly more complicated . . .

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

Page 121: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Non-Context-Free Languages

pumping lemma for finite automata is our(almost) only tool for showing that languagesare not regular.

we will now do the same for context-freelanguages.

it’s slightly more complicated . . .

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

Page 122: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Non-Context-Free Languages

pumping lemma for finite automata is our(almost) only tool for showing that languagesare not regular.

we will now do the same for context-freelanguages.

it’s slightly more complicated . . .

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

Page 123: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Pumping Lemma for CFL

Also known as the uvxyz Theorem.

Theorem: If A is a CFL , there is an ` (criticallength), such that if s ∈ A and |s| ≥ `, thens = uvxyz where

for every i ≥ 0, uvixyiz ∈ A

|vy| > 0, (non-triviality)

|vxy| ≤ `.

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

Page 124: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Pumping Lemma for CFL

Also known as the uvxyz Theorem.

Theorem: If A is a CFL , there is an ` (criticallength), such that if s ∈ A and |s| ≥ `, thens = uvxyz where

for every i ≥ 0, uvixyiz ∈ A|vy| > 0, (non-triviality)

|vxy| ≤ `.

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

Page 125: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Pumping Lemma for CFL

Also known as the uvxyz Theorem.

Theorem: If A is a CFL , there is an ` (criticallength), such that if s ∈ A and |s| ≥ `, thens = uvxyz where

for every i ≥ 0, uvixyiz ∈ A|vy| > 0, (non-triviality)

|vxy| ≤ `.

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

Page 126: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Basic IntuitionLet A be a CFL and G its CFG.

Let s be a “very long” string in A.

Then s has a “tall” parse tree.

And some root-to-leaf path must repeat a symbol.ahmmm,. . . why is that so?

T

R

u v x y z

R

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

Page 127: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Basic IntuitionLet A be a CFL and G its CFG.

Let s be a “very long” string in A.

Then s has a “tall” parse tree.

And some root-to-leaf path must repeat a symbol.ahmmm,. . . why is that so?

T

R

u v x y z

R

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

Page 128: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 129: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 130: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 131: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 132: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 133: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Prooflet G be a CFG for CFL A.

let c be the max number of symbols inright-hand-side of any rule.

no node in parse tree has > c children.

at depth d, no more than cd leaves.

let |V | be the number of variables in G.

let ` = c|V |+2.

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

Page 134: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (2)

let s be a string where |s| ≥ `

let τ be parse tree for s with fewest nodes

τ has height ≥ |V |+ 2

some path in τ has length ≥ |V |+ 2

that path repeats a variable R

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

Page 135: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (2)

let s be a string where |s| ≥ `

let τ be parse tree for s with fewest nodes

τ has height ≥ |V |+ 2

some path in τ has length ≥ |V |+ 2

that path repeats a variable R

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

Page 136: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (2)

let s be a string where |s| ≥ `

let τ be parse tree for s with fewest nodes

τ has height ≥ |V |+ 2

some path in τ has length ≥ |V |+ 2

that path repeats a variable R

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

Page 137: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (2)

let s be a string where |s| ≥ `

let τ be parse tree for s with fewest nodes

τ has height ≥ |V |+ 2

some path in τ has length ≥ |V |+ 2

that path repeats a variable R

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

Page 138: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (2)

let s be a string where |s| ≥ `

let τ be parse tree for s with fewest nodes

τ has height ≥ |V |+ 2

some path in τ has length ≥ |V |+ 2

that path repeats a variable R

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

Page 139: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence of R produces a string

upper produces string vxy

lower produces string x

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

Page 140: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence of R produces a string

upper produces string vxy

lower produces string x

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

Page 141: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence of R produces a string

upper produces string vxy

lower produces string x

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

Page 142: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (3)

Split s = uvxyz

T

R

u v x y z

R

each occurrence of R produces a string

upper produces string vxy

lower produces string xSlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.55

Page 143: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

ProofReplacing smaller by larger yields uvixyiz, for i > 0.

T

R

u v x y z

R

v yx

R

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

Page 144: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (4)

Replacing larger by smaller yields uxz.

T

R

u

x

zTogether, they establish:

for i ≥ 0, uvixyiz ∈ ASlides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.57

Page 145: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (5)

Next condition is:

|vy| > 0

If v and y are both ε, thenT

R

u

x

z

is a parse tree for s with fewer nodes.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.58

Page 146: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (6)

Final condition is |vxy| ≤ `:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence of R generates vxy.

can choose symbols such that both occurrences ofR lie in bottom |V |+ 1 variables on path.

subtree where R generates vxy is ≤ |V |+ 2 high.

strings by subtree at most b|V |+2 = ` long.

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

Page 147: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (6)

Final condition is |vxy| ≤ `:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence of R generates vxy.

can choose symbols such that both occurrences ofR lie in bottom |V |+ 1 variables on path.

subtree where R generates vxy is ≤ |V |+ 2 high.

strings by subtree at most b|V |+2 = ` long.

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

Page 148: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (6)

Final condition is |vxy| ≤ `:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence of R generates vxy.

can choose symbols such that both occurrences ofR lie in bottom |V |+ 1 variables on path.

subtree where R generates vxy is ≤ |V |+ 2 high.

strings by subtree at most b|V |+2 = ` long.

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

Page 149: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (6)

Final condition is |vxy| ≤ `:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence of R generates vxy.

can choose symbols such that both occurrences ofR lie in bottom |V |+ 1 variables on path.

subtree where R generates vxy is ≤ |V |+ 2 high.

strings by subtree at most b|V |+2 = ` long.

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

Page 150: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Proof (6)

Final condition is |vxy| ≤ `:T

R

u v x y z

R |V|+2

b |V|+2

the upper occurrence of R generates vxy.

can choose symbols such that both occurrences ofR lie in bottom |V |+ 1 variables on path.

subtree where R generates vxy is ≤ |V |+ 2 high.

strings by subtree at most b|V |+2 = ` long.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.59

Page 151: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example

Theorem: B = {anbncn} is not a CFL.Proof: By contradiction.

Let ` be the critical length.

Consider s = a`b`c`.If s = uvxyz, neither v nor y can contain

both a’s and b’s, or

both b’s and c’s, because

uv2xy2z would have out-of-order symbols.But if v and y contain only one symbol, then uv2xy2zhas an imbalance!

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

Page 152: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example

Theorem: B = {anbncn} is not a CFL.Proof: By contradiction.

Let ` be the critical length.

Consider s = a`b`c`.If s = uvxyz, neither v nor y can contain

both a’s and b’s, or

both b’s and c’s, because

uv2xy2z would have out-of-order symbols.But if v and y contain only one symbol, then uv2xy2zhas an imbalance!

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

Page 153: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.

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

Page 154: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.

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

Page 155: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.

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

Page 156: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.

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

Page 157: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.61

Page 158: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.61

Page 159: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.61

Page 160: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (2)

The language C ={

aibjck|0 ≤ i ≤ j ≤ k}

is notcontext-free.Let ` be the critical length, and s = a`b`c`.

Let s = uvxyz

neither v nor y contains contains two distinct symbols,

because uv2xy2z would have out-of-order symbols.

vxy not all b’s (why?)

vxy < `, so either

v contains only a’s and y contains only b’s, but then

uv2xy2z has too few c’s.

v contains only b’s and y contains only c’s. but then

uv0xy0z has too many a’s.Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. – p.61

Page 161: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (3)

The language D = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0`1`0`1` As before, suppose s = uvxyz .

Recall that |vxy| ≤ `.

if vxy is in the first half of s, uv2xy2z moves a 1 into the

first position in second half.

if vxy is in the second half, uv2xy2z moves a 0 into the last

position in first half.

if vxy straddles the midpoint, then pumping down to uxz

yields 0`1i0j1` where i and j cannot both be `.

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

Page 162: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (3)

The language D = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0`1`0`1` As before, suppose s = uvxyz .

Recall that |vxy| ≤ `.

if vxy is in the first half of s, uv2xy2z moves a 1 into the

first position in second half.

if vxy is in the second half, uv2xy2z moves a 0 into the last

position in first half.

if vxy straddles the midpoint, then pumping down to uxz

yields 0`1i0j1` where i and j cannot both be `.

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

Page 163: A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models– Lecture 5 A Few More PDAs Examples Equivalence of PDAs and CFLs Pumping Lemma for Context

Example (3)

The language D = {ww|w ∈ {0, 1}∗} is notcontext-free.Let s = 0`1`0`1` As before, suppose s = uvxyz .

Recall that |vxy| ≤ `.

if vxy is in the first half of s, uv2xy2z moves a 1 into the

first position in second half.

if vxy is in the second half, uv2xy2z moves a 0 into the last

position in first half.

if vxy straddles the midpoint, then pumping down to uxz

yields 0`1i0j1` where i and j cannot both be `.

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