09.01.2015 Views

Pushdown Automata - Hampden-Sydney College

Pushdown Automata - Hampden-Sydney College

Pushdown Automata - Hampden-Sydney College

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

<strong>Pushdown</strong> <strong>Automata</strong> - Equivalence to CFGs<br />

Lecture 19<br />

Section 2.2<br />

Robb T. Koether<br />

<strong>Hampden</strong>-<strong>Sydney</strong> <strong>College</strong><br />

Wed, Oct 8, 2008


Outline<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

1 Homework Review<br />

2 Equivalence of PDAs and CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

3 Long Example<br />

4 Short Example<br />

5 Assignment


Homework Review<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Exercise<br />

Let Σ = {a, (, ), [, ]}. Design a PDA whose language is<br />

{w | w contains balanced parentheses and brackets}.<br />

Short<br />

Example<br />

Assignment


Homework Review<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Solution<br />

The a’s can be placed anywhere.<br />

A ( or a [ can be read anywhere, but ( must eventually<br />

be balanced by ) and [ must eventually be balanced by<br />

].<br />

Use the stack to assure that the parentheses and<br />

brackets are properly matched.


Homework Review<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Solution<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

a, ε → ε<br />

(, ε → (<br />

[, ε → [<br />

), ( → ε<br />

], [ → ε<br />

ε, ε → $ ε, $ → ε


Equivalence of PDAs and CFGs<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Theorem (Equivalence of PDAs and CFGs)<br />

A language is context-free if and only if it is accepted by<br />

some PDA.<br />

Short<br />

Example<br />

Assignment


Equivalence of PDAs and CFGs<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Proof (⇒).<br />

We are given a CFG G and we will construct a PDA M.<br />

Let M have four states:<br />

Q = {q 0 , q 1 , q 2 , q 3 }.<br />

q 0 is the start state.<br />

q 3 is the accept state.<br />

Assignment


Equivalence of PDAs and CFGs<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇒).<br />

The transitions are<br />

δ(q 0 , ε, ε) = {(q 1 , $)}<br />

δ(q 1 , ε, ε) = {(q 2 , S)}<br />

δ(q 2 , ε, A) = {(q 2 , w)}, where A → w is a rule.<br />

δ(q 2 , a, a) = {(q 2 , ε)}, for all a ∈ Σ.<br />

δ(q 2 , ε, $) = {(q 3 , ε)}<br />

It is clear that L(M) = L(G).


Equivalence of PDAs and CFGs<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Proof (⇒).<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

ε, ε → $<br />

A, ε → w<br />

a, a → ε<br />

ε, ε → S ε, $ → ε


Equivalence of PDAs and CFGs<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇐).<br />

Given a PDA M, we must construct a grammar G that<br />

generates L(M).<br />

Modify M so that<br />

M has a single accept state.<br />

M empties its stack before accepting.<br />

Each transition either pushes one symbol or pops one<br />

symbol, but not both.


The Variables<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇐).<br />

For every pair of states p and q in M, we create a<br />

variable A pq .<br />

The variable A pq is interpreted to mean<br />

“Get from state p with an empty stack to state q with an<br />

empty stack.”<br />

Since the stack starts and ends empty, we must push a<br />

symbol at the beginning and pop a symbol at the end.


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Proof (⇐).<br />

There are two possibilities in going from p to q.<br />

The first symbol pushed does not match the last symbol<br />

popped.<br />

The first symbol pushed matches the last symbol<br />

popped.<br />

Assignment


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇐).<br />

For the rules in Group 1, use all pairs of transitions<br />

where the first transition pushes a symbol and the<br />

second transition pops a symbol, whether or not they<br />

are the same symbol.<br />

For each such pair of transitions δ(p, a, ε) = (s, c) and<br />

δ(t, b, d) = (q, ε), write the rules<br />

A pq → A pr A rq<br />

for all intermediate states r ∈ Q.


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Proof (⇐).<br />

The Group 1 rules allow us to break the processing up<br />

into segments that begin and end with an empty stack,<br />

but during which the stack is never empty.<br />

Short<br />

Example<br />

Assignment


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Proof (⇐).<br />

Stack<br />

depth<br />

x, ε → a<br />

x, y → ε<br />

x, ε → z<br />

x, b → ε<br />

Short<br />

Example<br />

Assignment<br />

p<br />

r<br />

q<br />

State


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇐), continued.<br />

For the rules in Group 2, use all pairs of transitions<br />

where the second transition pops the same symbol that<br />

the first transition pushes.<br />

For each such pair of transitions δ(p, a, ε) = (r, c) and<br />

δ(s, b, c) = (q, ε), write the rule<br />

A pq → aA rs b.


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Proof (⇐).<br />

Stack<br />

depth<br />

a, ε → c b, c → ε<br />

Short<br />

Example<br />

Assignment<br />

p<br />

r<br />

s<br />

q<br />

State


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Proof (⇐).<br />

Stack<br />

depth<br />

a, ε → c b, c → ε<br />

Short<br />

Example<br />

Assignment<br />

p<br />

r<br />

s<br />

q<br />

State


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Proof (⇐), continued.<br />

Finally, the Group 3 rules are of the form<br />

A pp → ε<br />

for every state p.<br />

Assignment


The Start Symbol<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Proof (⇐), conclusion.<br />

Let q start be the start state and q accept be the accept<br />

state.<br />

Then the start symbol is A qstart q accept<br />

.<br />

If we can eventually replace the start symbol with all<br />

terminals, then the string of terminals must be in the<br />

language.<br />

Therefore, L(G) = L(M).


Example<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Example (Convert a PDA to a CFG)<br />

Find a grammar for the following PDA.<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

p<br />

a, ε → a<br />

ε, ε → $<br />

q<br />

ε, $ → ε<br />

b, a → ε<br />

r


Example<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Example (Convert a PDA to a CFG)<br />

The variables are A pp , A pq , A pr , A qp , A qq , A qr , A rp , A rq ,<br />

and A rr .<br />

Short<br />

Example<br />

Assignment


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

Then we get the Group 1 grammar rules, based on the<br />

transitions.<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

δ(q, ε, $) = (r, ε)<br />

Assignment


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

Find all pairs of transitions where<br />

The first transition pushes a symbol x.<br />

The second transition pops a symbol y.<br />

The rules:<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

δ(q, ε, $) = (r, ε)


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, b, a) = (q, ε)<br />

gives the rules A pq → A px A xq for all x ∈ Q.<br />

That is,<br />

A pq → A pp A pq<br />

A pq → A pq A qq<br />

A pq → A pr A rq


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rules A pr → A px A xr for all x ∈ Q.<br />

That is,<br />

A pr → A pp A pr<br />

A pr → A pq A qr<br />

A pr → A pr A rr


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rules A qq → A qx A xq for all x ∈ Q.<br />

That is,<br />

A qq → A qp A pq<br />

A qq → A qq A qq<br />

A qq → A qr A rq


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rules A qr → A qx A xr for all x ∈ Q.<br />

That is,<br />

A qr → A qp A pr<br />

A qr → A qq A qr<br />

A qr → A qr A rr


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

We get the first group of rules.<br />

A pq → A pp A pq A qq → A qp A pq<br />

A pq → A pq A qq A qq → A qq A qq<br />

A pq → A pr A rq A qq → A qr A rq<br />

A pr → A pp A pr A qr → A qp A pr<br />

A pr → A pq A qr A qr → A qq A qr<br />

A pr → A pr A rr A qr → A qr A rr


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

We may eliminate all rules with variables that represent<br />

impossible situations.<br />

A pq → A pp A pq A qq → A qp A pq<br />

A pq → A pq A qq A qq → A qq A qq<br />

A pq → A pr A rq A qq → A qr A rq<br />

A pr → A pp A pr A qr → A qp A pr<br />

A pr → A pq A qr A qr → A qq A qr<br />

A pr → A pr A rr A qr → A qr A rr


The Grammar Rules (Group 1)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The Group 1 rules are<br />

A pq → A pp A pq<br />

A pq → A pq A qq<br />

A pr → A pp A pr<br />

A pr → A pq A qr<br />

A pr → A pr A rr<br />

A qq → A qq A qq<br />

A qr → A qq A qr<br />

A qr → A qr A rr


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

Then we get the Group 2 grammar rules, based on the<br />

transitions.<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

δ(q, ε, $) = (r, ε)<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

For every stack symbol s and for every pair of<br />

transitions, one of which pushes s and the other of<br />

which pops s, we write a grammar rule<br />

A xy → aA zw b<br />

where a is the symbol read when s is pushed and b is<br />

the symbol read when s is popped.


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rule<br />

A pr → εA qq ε = A qq<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rule<br />

A pr → εA qq ε = A qq<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rule<br />

A pr → εA qq ε = A qq<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rule<br />

A pr → εA qq ε = A qq<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(p, ε, ε) = (q, $)<br />

δ(q, ε, $) = (r, ε)<br />

gives the rule<br />

A pr → εA qq ε = A qq<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rule<br />

A qq → aA qq b<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rule<br />

A qq → aA qq b<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rule<br />

A qq → aA qq b<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rule<br />

A qq → aA qq b<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

The pair<br />

δ(q, a, ε) = (q, a)<br />

δ(q, b, a) = (q, ε)<br />

gives the rule<br />

A qq → aA qq b<br />

Assignment


The Grammar Rules (Group 2)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Example (Convert a PDA to a CFG)<br />

The Group 2 rules are<br />

A pr → A qq<br />

A qq → aA qq b<br />

Short<br />

Example<br />

Assignment


The Grammar Rules (Group 3)<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

Finally, the Group 3 rules are<br />

A pp → ε<br />

A qq → ε<br />

A rr → ε<br />

Assignment


The Grammar Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

This gives us the grammar rules<br />

A pq → A pp A pq<br />

A pq → A pq A qq<br />

A pr → A pp A pr<br />

A pr → A pq A qr<br />

A pr → A pr A rr<br />

A qq → A qq A qq<br />

A qr → A qq A qr<br />

A qr → A qr A rr<br />

A pr → A qq<br />

A qq → aA qq b<br />

A pp → ε<br />

A qq → ε<br />

A rr → ε


The Grammar<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Example (Convert a PDA to a CFG)<br />

The start symbol is A pr .<br />

Long Example<br />

Short<br />

Example<br />

Assignment


The Grammar<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The complete grammar is<br />

A pr → A pp A pr | A pq A qr | A pr A rr | A qq<br />

A pp → ε<br />

A pq → A pp A pq | A pq A qq<br />

A qq → aA qq b | A qq A qq | ε<br />

A qr → A qq A qr | A qr A rr<br />

A rr → ε.


Example<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Example (Convert a PDA to a CFG)<br />

Find a grammar for the language of the following PDA.<br />

(, ε → ( ), ( → ε<br />

ε, ε → $<br />

a, ε → ε<br />

ε, $ → ε<br />

+, ε → ε<br />

Assignment


Example<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

First, we need to modify the PDA:<br />

(, ε → (<br />

), ( → ε<br />

a, ε → ( r ε, ( → ε<br />

ε, ε → $<br />

ε, $ → ε<br />

p<br />

q<br />

s<br />

ε, ( → ε t +, ε → (<br />

u


Example<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

The transitions are<br />

Pushes<br />

Pops<br />

δ(p, ε, ε) = (q, $) δ(r, ε, () = (s, ε)<br />

δ(q, (, ε) = (q, () δ(s, ), () = (s, ε)<br />

δ(q, a, ε) = (r, () δ(t, ε, () = (q, ε)<br />

δ(s, +, ε) = (t, () δ(s, ε, $) = (u, ε)


Group 1 Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

For the Group 1 rules, there are 16 combinations of a<br />

transition that pushes with a transition that pops.<br />

However, there are only three beginning states {p, q, s}<br />

and three ending states {s, q, u}.<br />

So there are only 9 sets of rules:<br />

A ps → A px A xs for all x ∈ Q<br />

A pq → A px A xq for all x ∈ Q<br />

A pu → A px A xu for all x ∈ Q<br />

A qs → A qx A xs for all x ∈ Q<br />

A qq → A qx A xq for all x ∈ Q<br />

A qu → A qx A xu for all x ∈ Q<br />

A ss → A sx A xs for all x ∈ Q<br />

A sq → A sx A xq for all x ∈ Q<br />

A su → A sx A xu for all x ∈ Q


Group 1 Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

That gives 54 rules.<br />

We can eliminate the ones containing variables of the<br />

form A xp for x ≠ p and A ux for x ≠ u.<br />

That eliminates 12 rules, leaving 42.<br />

A ps → A px A xs for all x ∈ Q, x ≠ u<br />

A pq → A px A xq for all x ∈ Q, x ≠ u<br />

A pu → A px A xu for all x ∈ Q<br />

A qs → A qx A xs for all x ∈ Q, x ≠ p, u<br />

A qq → A qx A xq for all x ∈ Q, x ≠ p, u<br />

A qu → A qx A xu for all x ∈ Q, x ≠ p<br />

A ss → A sx A xs for all x ∈ Q, x ≠ p, u<br />

A sq → A sx A xq for all x ∈ Q, x ≠ p, u<br />

A su → A sx A xu for all x ∈ Q, x ≠ p


Group 2 Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

There is 1 combination of transitions that pushes and<br />

pops $.<br />

There are 9 combinations of transitions that push and<br />

pop (.<br />

So there are 10 rules in Group 2.<br />

A pu → A qs<br />

A qs → (A qr<br />

A qs → (A qs )<br />

A qq → (A qt<br />

A qs → aA rr<br />

A qs → aA rs )<br />

A qq → aA rt<br />

A ss → +A tr<br />

A ss → +A ts )<br />

A sq → +A tt


Group 3 Rules<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Example (Convert a PDA to a CFG)<br />

There are 6 rules in Group 3.<br />

A pp → ε<br />

A qq → ε<br />

A rr → ε<br />

A ss → ε<br />

A tt → ε<br />

A uu → ε


Assignment<br />

<strong>Pushdown</strong><br />

<strong>Automata</strong> -<br />

Equivalence<br />

to CFGs<br />

Robb T.<br />

Koether<br />

Homework<br />

Review<br />

Equivalence<br />

of PDAs and<br />

CFGs<br />

Proof ⇒<br />

Proof ⇐<br />

Long Example<br />

Short<br />

Example<br />

Assignment<br />

Homework<br />

Read Section 2.2, pages 115 - 123.<br />

Exercises 11, 12, page 129.<br />

Find a grammar for the language<br />

L = {w | w contains an equal number of a’s and b’s}<br />

with PDA<br />

a, ε → a<br />

a, b → ε<br />

b, a → ε b, ε → b<br />

a > b<br />

a, ε → $ b, ε → $<br />

b. $ → ε<br />

a. $ → ε<br />

a < b

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!