A Few More PDAs Examples Equivalence of PDAs and ...bchor/CM/Compute5.pdfComputational Models–...

Preview:

Citation preview

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Recommended