# lecture 19 - iitkhome.iitk.ac.in/~akasha/mth401/lectures/lecture19.pdfcfg pdm akash anand Ø let l =...

of 54/54
MTH401A Theory of Computation Lecture 19

Post on 05-May-2018

214 views

Category:

## Documents

Embed Size (px)

TRANSCRIPT

• MTH401ATheory of Computation

Lecture 19

• CFG and PDM

Akash Anand

Equivalence of Context Free Languages and Pushdown

Machines

Conversion of CFG to PDMConversion of PDM to CFG

• CFG PDM

Akash Anand

Let L = L(G) Construct PDM P such that N(P) = L

• CFG PDM

Akash Anand

Let L = L(G) Construct PDM P such that N(P) = L

P has :q One state qq Input symbols = terminals of Gq Stack symbols = all symbols of Gq Start symbol = start symbol of Gq Transitions ??

• CFG PDM

Akash Anand

P has :q Transitions :

1. (q, a, a) = {(q, )}.2. If A is a production of G then

(q, , A) contains (q, ).

• CFG PDM

Akash Anand

Example : Grammar, G : S 0S0 | 1S1 | .

Pushdown Machine, P :States, Q = {q}Input Symbols, = {0, 1}Stack Symbols, = {0,1, S}Start State, q0 = qFinal State, F = {q}

• CFG PDM

Akash Anand

Example : Grammar, G : S 0S0 | 1S1 | .

Pushdown Machine, P :Start Symbol, Z0 = S

• CFG PDM

Akash Anand

Example : Grammar, G : S 0S0 | 1S1 | .

Pushdown Machine, P :Start Symbol, Z0 = STransition Function, :

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

Example : Grammar, G : S 0S0 | 1S1 | .

Pushdown Machine, P :Start Symbol, Z0 = STransition Function, :(q, 0, 0) = {(q, )}(q, 1, 1) = {(q, )}(q, , S) = {(q, 0S0), (q, 1S1), (q, )}

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

S

Example : 101101 : S1S110S01101S101101101

1 0 1 1 0 1

q

• CFG PDM

Akash Anand

S

Example : 101101 : S1S110S01101S101101101

1 0 1 1 0 1

q

(q, , S) = {(q,0S0), (q,1S1), (q, )}

• CFG PDM

Akash Anand

1

S

1

Example : 101101 : S1S110S01101S101101101

1 0 1 1 0 1

q

• CFG PDM

Akash Anand

1

S

1

Example : 101101 : S1S110S01101S101101101

1 0 1 1 0 1

q

(q, 1, 1) = {(q, )}

• CFG PDM

Akash Anand

1

S

Example : 101101 : S1S110S01101S101101101

0 1 1 0 1

q

• CFG PDM

Akash Anand

1

S

Example : 101101 : S1S110S01101S101101101

0 1 1 0 1

q

(q, , S) = {(q,0S0), (q,1S1), (q, )}

• CFG PDM

Akash Anand

1

0

S

0

Example : 101101 : S1S110S01101S101101101

0 1 1 0 1

q

• CFG PDM

Akash Anand

1

0

S

0

Example : 101101 : S1S110S01101S101101101

0 1 1 0 1

q

(q, 0, 0) = {(q, )}

• CFG PDM

Akash Anand

1

0

S

Example : 101101 : S1S110S01101S101101101

1 1 0 1

q

• CFG PDM

Akash Anand

1

0

S

Example : 101101 : S1S110S01101S101101101

1 1 0 1

q

(q, , S) = {(q,0S0), (q,1S1), (q, )}

• CFG PDM

Akash Anand

1

0

1

S

1

Example : 101101 : S1S110S01101S101101101

1 1 0 1

q

• CFG PDM

Akash Anand

1

0

1

S

1

Example : 101101 : S1S110S01101S101101101

1 1 0 1

q

(q, 1, 1) = {(q, )}

• CFG PDM

Akash Anand

1

0

1

S

Example : 101101 : S1S110S01101S101101101

1 0 1

q

• CFG PDM

Akash Anand

1

0

1

S

Example : 101101 : S1S110S01101S101101101

1 0 1

q

(q, , S) = {(q,0S0), (q,1S1), (q, )}

• CFG PDM

Akash Anand

1

0

1

Example : 101101 : S1S110S01101S101101101

1 0 1

q

• CFG PDM

Akash Anand

1

0

1

Example : 101101 : S1S110S01101S101101101

1 0 1

q

(q, 1, 1) = {(q, )}

• CFG PDM

Akash Anand

1

0

Example : 101101 : S1S110S01101S101101101

0 1

q

• CFG PDM

Akash Anand

1

0

Example : 101101 : S1S110S01101S101101101

0 1

q

(q, 0, 0) = {(q, )}

• CFG PDM

Akash Anand

1

Example : 101101 : S1S110S01101S101101101

1

q

• CFG PDM

Akash Anand

1

Example : 101101 : S1S110S01101S101101101

1

q

(q, 1, 1) = {(q, )}

• CFG PDM

Akash Anand

Example : 101101 : S1S110S01101S101101101

q

• CFG PDM

Akash Anand

Example : 101101 : S1S110S01101S101101101

q

Accept !

• CFG PDM

Akash Anand

Example (continued) : 101101 : S1S110S01101S101101101

(q, 101101, S) (q, 101101, 1S1) (q, 01101, S1) (q, 01101, 0S01) (q, 1101, S01) (q, 1101, 1S101) (q, 101, S101) (q, 101, 101) (q, 01, 01) (q, 1, 1) (q, , ).

• CFG PDM

Akash Anand

Formally :

(q,wx,S) * (q,x,) S * w

• CFG PDM

Akash Anand

Formally :

(q,wx,S) * (q,x,) S * w

( ) is an induction on the number of steps made by P.

• CFG PDM

Akash Anand

Formally :

(q,wx,S) * (q,x,) S * w

( ) is an induction on the number of steps made by P.

Basis : (0 steps)Then, (q,wx,S) * (q,x,) andS * w are true with =S, w=.

• CFG PDM

Akash Anand

( ) continued

Induction : Consider n moves of P (q,wx,S) * (q,x,) and assume the IH for n-1 moves.

• CFG PDM

Akash Anand

( ) continued

Induction : Consider n moves of P (q,wx,S) * (q,x,) and assume the IH for n-1 moves.

There are two cases, depending on whether the last move uses a type 1 or type 2 rule.

• CFG PDM

Akash Anand

( ) continued

Induction : Consider n moves of P (q,wx,S) * (q,x,) and assume the IH for n-1 moves.

There are two cases, depending on whether the last move uses a type 1 or type 2 rule.

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

( ) continued

1. The move sequence must be of the form (q,yax,S) * (q,ax,a) (q,x,), where w = ya.

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

( ) continued

1. The move sequence must be of the form (q,yax,S) * (q,ax,a) (q,x,), where w = ya.By IH (applied to first n-1 steps), S * ya but w = ya so S * w.

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

( ) continued

2. The move sequence must be of the form (q,wx,S) * (q,x,A) (q,x,), where A is a production and = .

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

( ) continued

2. The move sequence must be of the form (q,wx,S) * (q,x,A) (q,x,), where A is a production and = .By IH (applied to first n-1 steps), S * wA. Thus S * w = w.

1. (q, a, a) = {(q, )}.2. If A is a production of G then (q, , A) contains (q, ).

• CFG PDM

Akash Anand

(q,wx,S) * (q,x,) S * w

() is an induction on the number of steps in the leftmost derivation.

• CFG PDM

Akash Anand

(q,wx,S) * (q,x,) S * w

() is an induction on the number of steps in the leftmost derivation.

Similar idea! Complete the proof.

• CFG PDM

Akash Anand

(q,wx,S) * (q,x,) S * w

() is an induction on the number of steps in the leftmost derivation.

Similar idea! Complete the proof. If it helps, you can assume that

the grammar is in Chomsky Normal form.

• PDM GFG

Akash Anand

• PDM GFG

Akash Anand

Let L = N(P) Construct CFG G such that L(G) = L

• PDM GFG

Akash Anand

Let L = N(P) Construct CFG G such that L(G) = L

If P accepts w by (p,w,X) * (q,,) then we need to have a variable that generates w and its productions :q Lets call this variable [pXq]q [pXq] generates all and only those

strings w such that (p,w,X) * (q,,)

• PDM GFG

Akash Anand

X

Simplest Case :

p

(p, a, X) = {, (q, ), }

a

• PDM GFG

Akash Anand

Simplest Case :

q

• PDM GFG

Akash Anand

Simplest Case :

Then the production is : [pXq] a

q

• PDM GFG

Akash Anand

Next Simplest Case :

(p, a, X) = {, (r, Y), }

n:

21X

p

a w1 w2 wn

• PDM GFG

Akash Anand

n:

21Y

Next Simplest Case :

r

w1 w2 wn

• PDM GFG

Akash Anand

n:

21Y

Next Simplest Case :

Then the production is : [pXq] a [rYq]

r

w1 w2 wn