CSE 135: Introduction to Theory of Computation CFLs ...

90
CSE 135: Introduction to Theory of Computation CFLs: Closure Properties and Membership Test Sungjin Im University of California, Merced 03-31-2014

Transcript of CSE 135: Introduction to Theory of Computation CFLs ...

Page 1: CSE 135: Introduction to Theory of Computation CFLs ...

CSE 135: Introduction to Theory of ComputationCFLs: Closure Properties and Membership Test

Sungjin Im

University of California, Merced

03-31-2014

Page 2: CSE 135: Introduction to Theory of Computation CFLs ...

Union of CFLs

Let L1 be language recognized by G1 = (V1,Σ1,R1,S1) and L2 thelanguage recognized by G2 = (V2,Σ2,R2, S2)Is L1 ∪ L2 a context free language?

Yes.Just add the rule S → S1|S2But make sure that V1 ∩ V2 = ∅ (by renaming some variables).

Closure of CFLs under UnionG = (V ,Σ,R,S) such that L(G ) = L(G1) ∪ L(G2):

I V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

I Σ = Σ1 ∪ Σ2

I R = R1 ∪ R2 ∪ {S → S1|S2}

Page 3: CSE 135: Introduction to Theory of Computation CFLs ...

Union of CFLs

Let L1 be language recognized by G1 = (V1,Σ1,R1,S1) and L2 thelanguage recognized by G2 = (V2,Σ2,R2, S2)Is L1 ∪ L2 a context free language? Yes.

Just add the rule S → S1|S2But make sure that V1 ∩ V2 = ∅ (by renaming some variables).

Closure of CFLs under UnionG = (V ,Σ,R,S) such that L(G ) = L(G1) ∪ L(G2):

I V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

I Σ = Σ1 ∪ Σ2

I R = R1 ∪ R2 ∪ {S → S1|S2}

Page 4: CSE 135: Introduction to Theory of Computation CFLs ...

Union of CFLs

Let L1 be language recognized by G1 = (V1,Σ1,R1,S1) and L2 thelanguage recognized by G2 = (V2,Σ2,R2, S2)Is L1 ∪ L2 a context free language? Yes.Just add the rule S → S1|S2

But make sure that V1 ∩ V2 = ∅ (by renaming some variables).

Closure of CFLs under UnionG = (V ,Σ,R,S) such that L(G ) = L(G1) ∪ L(G2):

I V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

I Σ = Σ1 ∪ Σ2

I R = R1 ∪ R2 ∪ {S → S1|S2}

Page 5: CSE 135: Introduction to Theory of Computation CFLs ...

Union of CFLs

Let L1 be language recognized by G1 = (V1,Σ1,R1,S1) and L2 thelanguage recognized by G2 = (V2,Σ2,R2, S2)Is L1 ∪ L2 a context free language? Yes.Just add the rule S → S1|S2But make sure that V1 ∩ V2 = ∅ (by renaming some variables).

Closure of CFLs under UnionG = (V ,Σ,R,S) such that L(G ) = L(G1) ∪ L(G2):

I V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

I Σ = Σ1 ∪ Σ2

I R = R1 ∪ R2 ∪ {S → S1|S2}

Page 6: CSE 135: Introduction to Theory of Computation CFLs ...

Union of CFLs

Let L1 be language recognized by G1 = (V1,Σ1,R1,S1) and L2 thelanguage recognized by G2 = (V2,Σ2,R2, S2)Is L1 ∪ L2 a context free language? Yes.Just add the rule S → S1|S2But make sure that V1 ∩ V2 = ∅ (by renaming some variables).

Closure of CFLs under UnionG = (V ,Σ,R,S) such that L(G ) = L(G1) ∪ L(G2):

I V = V1 ∪ V2 ∪ {S} (the three sets are disjoint)

I Σ = Σ1 ∪ Σ2

I R = R1 ∪ R2 ∪ {S → S1|S2}

Page 7: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2,S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 8: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 9: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation:

L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 10: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 11: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure:

L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 12: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 13: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.

(Exercise: Complete the Proof!) �

Page 14: CSE 135: Introduction to Theory of Computation CFLs ...

Concatenation, Kleene Closure

Proposition

CFLs are closed under concatenation and Kleene closure

Proof.Let L1 be language generated by G1 = (V1,Σ1,R1, S1) and L2 thelanguage generated by G2 = (V2,Σ2,R2, S2)

I Concatenation: L1L2 generated by a grammar with anadditional rule S → S1S2

I Kleene Closure: L∗1 generated by a grammar with anadditional rule S → S1S |ε

As before, ensure that V1 ∩ V2 = ∅. S is a new start symbol.(Exercise: Complete the Proof!) �

Page 15: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages.

L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 16: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 17: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 18: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFL

I Generated by a grammar with rules S → XY ; X → aXb|ε;Y → cY |ε.

I L2 = {aibjc j | i , j ≥ 0} is a CFL.I Generated by a grammar with rules S → XY ; X → aX |ε;

Y → bYc|ε.I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 19: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.

I L2 = {aibjc j | i , j ≥ 0} is a CFL.I Generated by a grammar with rules S → XY ; X → aX |ε;

Y → bYc|ε.I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 20: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 21: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 22: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 =

{anbncn | n ≥ 0} is not a CFL. �

Page 23: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection

Let L1 and L2 be context free languages. L1 ∩ L2 is not necessarilycontext free!

Proposition

CFLs are not closed under intersection

Proof.

I L1 = {aibic j | i , j ≥ 0} is a CFLI Generated by a grammar with rules S → XY ; X → aXb|ε;

Y → cY |ε.I L2 = {aibjc j | i , j ≥ 0} is a CFL.

I Generated by a grammar with rules S → XY ; X → aX |ε;Y → bYc|ε.

I But L1 ∩ L2 = {anbncn | n ≥ 0} is not a CFL. �

Page 24: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 25: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R.

A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 26: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 27: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 28: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM)

: QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 29: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 30: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 31: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting:

FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 32: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 33: CSE 135: Introduction to Theory of Computation CFLs ...

Intersection with Regular Languages

Proposition

If L is a CFL and R is a regular language then L ∩ R is a CFL.

Proof.Let P be the PDA that accepts L, and let M be the DFA thataccepts R. A new PDA P ′ will simulate P and M simultaneouslyon the same input and accept if both accept. Then P ′ acceptsL ∩ R.

I The stack of P ′ is the stack of P

I The state of P ′ at any time is the pair (state of P, state ofM): QP′ = QP × QM

I These determine the transition function of P ′.

I The final states of P ′ are those in which both the state of Pand state of M are accepting: FP′ = FP × FM �

Why does this construction not work for intersection of two CFLs?

Page 34: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free?

No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 35: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 36: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation.

Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 37: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 38: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL.

Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 39: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL.

Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 40: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 41: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 42: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 43: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 44: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules

X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 45: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S →

A|B|AB|BABut L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 46: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 47: CSE 135: Introduction to Theory of Computation CFLs ...

Complementation

Let L be a context free language. Is L context free? No!

Proof 1.Suppose CFLs were closed under complementation. Then for anytwo CFLs L1, L2, we have

I L1 and L2 are CFL. Then, since CFLs closed under union,

L1 ∪ L2 is CFL. Then, again by hypothesis, L1 ∪ L2 is CFL.

I i.e., L1 ∩ L2 is a CFL

i.e., CFLs are closed under intersection. Contradiction! �

Proof 2.L = {x | x not of the form ww} is a CFL.

I L generated by a grammar with rules X → a|b, A→ a|XAX ,B → b|XBX , S → A|B|AB|BA

But L = {ww | w ∈ {a, b}∗} is not a CFL! (Why?) �

Page 48: CSE 135: Introduction to Theory of Computation CFLs ...

Set Difference

Proposition

If L1 is a CFL and L2 is a CFL then L1 \ L2 is not necessarily a CFL

Proof.Because CFLs not closed under complementation, andcomplementation is a special case of set difference. (How?) �

Proposition

If L is a CFL and R is a regular language then L \ R is a CFL

Proof.L \ R = L ∩ R �

Page 49: CSE 135: Introduction to Theory of Computation CFLs ...

Set Difference

Proposition

If L1 is a CFL and L2 is a CFL then L1 \ L2 is not necessarily a CFL

Proof.Because CFLs not closed under complementation, andcomplementation is a special case of set difference. (How?) �

Proposition

If L is a CFL and R is a regular language then L \ R is a CFL

Proof.L \ R = L ∩ R �

Page 50: CSE 135: Introduction to Theory of Computation CFLs ...

Set Difference

Proposition

If L1 is a CFL and L2 is a CFL then L1 \ L2 is not necessarily a CFL

Proof.Because CFLs not closed under complementation, andcomplementation is a special case of set difference. (How?) �

Proposition

If L is a CFL and R is a regular language then L \ R is a CFL

Proof.L \ R = L ∩ R �

Page 51: CSE 135: Introduction to Theory of Computation CFLs ...

Set Difference

Proposition

If L1 is a CFL and L2 is a CFL then L1 \ L2 is not necessarily a CFL

Proof.Because CFLs not closed under complementation, andcomplementation is a special case of set difference. (How?) �

Proposition

If L is a CFL and R is a regular language then L \ R is a CFL

Proof.L \ R = L ∩ R �

Page 52: CSE 135: Introduction to Theory of Computation CFLs ...

Emptiness Problem

Given a CFG G with start symbol S , is L(G ) empty?

Solution: Check if the start symbol S is generating. How long doesthat take?

Page 53: CSE 135: Introduction to Theory of Computation CFLs ...

Emptiness Problem

Given a CFG G with start symbol S , is L(G ) empty?Solution: Check if the start symbol S is generating.

How long doesthat take?

Page 54: CSE 135: Introduction to Theory of Computation CFLs ...

Emptiness Problem

Given a CFG G with start symbol S , is L(G ) empty?Solution: Check if the start symbol S is generating. How long doesthat take?

Page 55: CSE 135: Introduction to Theory of Computation CFLs ...

Determining generating symbols

Algorithm

Gen = {}for every rule A→ x where x ∈ Σ∗

Gen = Gen ∪ {A}repeat

for every rule A→ γif all variables in γ are generating then

Gen = Gen ∪ {A}until Gen does not change

I Both for-loops take O(n) time where n = |G |.I Each iteration of repeat-until loop discovers a new variable.

So number of iterations is O(n). And total is O(n2).

Page 56: CSE 135: Introduction to Theory of Computation CFLs ...

Determining generating symbols

Algorithm

Gen = {}for every rule A→ x where x ∈ Σ∗

Gen = Gen ∪ {A}repeat

for every rule A→ γif all variables in γ are generating then

Gen = Gen ∪ {A}until Gen does not change

I Both for-loops take O(n) time where n = |G |.

I Each iteration of repeat-until loop discovers a new variable.So number of iterations is O(n). And total is O(n2).

Page 57: CSE 135: Introduction to Theory of Computation CFLs ...

Determining generating symbols

Algorithm

Gen = {}for every rule A→ x where x ∈ Σ∗

Gen = Gen ∪ {A}repeat

for every rule A→ γif all variables in γ are generating then

Gen = Gen ∪ {A}until Gen does not change

I Both for-loops take O(n) time where n = |G |.I Each iteration of repeat-until loop discovers a new variable.

So number of iterations is O(n). And total is O(n2).

Page 58: CSE 135: Introduction to Theory of Computation CFLs ...

Membership Problem

Given a CFG G = (V ,Σ,R,S) in Chomsky Normal Form, and astring w ∈ Σ∗, is w ∈ L(G )?

Central question in parsing.

Page 59: CSE 135: Introduction to Theory of Computation CFLs ...

Membership Problem

Given a CFG G = (V ,Σ,R,S) in Chomsky Normal Form, and astring w ∈ Σ∗, is w ∈ L(G )?Central question in parsing.

Page 60: CSE 135: Introduction to Theory of Computation CFLs ...

“Simple” Solution

I Let |w | = n. Since G is in Chomsky Normal Form, w has aparse tree of size 2n − 1 iff w ∈ L(G )

I Construct all possible parse (binary) trees and check if any ofthem is a valid parse tree for w

I Number of parse trees of size 2n − 1 is k2n−1 where k is thenumber of variables in G . So algorithm is exponential in n!

I We will see an algorithm that runs in O(n3) time (theconstant will depend on k).

Page 61: CSE 135: Introduction to Theory of Computation CFLs ...

“Simple” Solution

I Let |w | = n. Since G is in Chomsky Normal Form, w has aparse tree of size 2n − 1 iff w ∈ L(G )

I Construct all possible parse (binary) trees and check if any ofthem is a valid parse tree for w

I Number of parse trees of size 2n − 1 is k2n−1 where k is thenumber of variables in G . So algorithm is exponential in n!

I We will see an algorithm that runs in O(n3) time (theconstant will depend on k).

Page 62: CSE 135: Introduction to Theory of Computation CFLs ...

“Simple” Solution

I Let |w | = n. Since G is in Chomsky Normal Form, w has aparse tree of size 2n − 1 iff w ∈ L(G )

I Construct all possible parse (binary) trees and check if any ofthem is a valid parse tree for w

I Number of parse trees of size 2n − 1 is k2n−1 where k is thenumber of variables in G . So algorithm is exponential in n!

I We will see an algorithm that runs in O(n3) time (theconstant will depend on k).

Page 63: CSE 135: Introduction to Theory of Computation CFLs ...

“Simple” Solution

I Let |w | = n. Since G is in Chomsky Normal Form, w has aparse tree of size 2n − 1 iff w ∈ L(G )

I Construct all possible parse (binary) trees and check if any ofthem is a valid parse tree for w

I Number of parse trees of size 2n − 1 is k2n−1 where k is thenumber of variables in G . So algorithm is exponential in n!

I We will see an algorithm that runs in O(n3) time (theconstant will depend on k).

Page 64: CSE 135: Introduction to Theory of Computation CFLs ...

“Simple” Solution

I Let |w | = n. Since G is in Chomsky Normal Form, w has aparse tree of size 2n − 1 iff w ∈ L(G )

I Construct all possible parse (binary) trees and check if any ofthem is a valid parse tree for w

I Number of parse trees of size 2n − 1 is k2n−1 where k is thenumber of variables in G . So algorithm is exponential in n!

I We will see an algorithm that runs in O(n3) time (theconstant will depend on k).

Page 65: CSE 135: Introduction to Theory of Computation CFLs ...

First Ideas

NotationSuppose w = w1w2 · · ·wn, where wi ∈ Σ. Let wi ,j denote thesubstring of w starting at position i of length j . Thus,wi ,j = wiwi+1 · · ·wi+j−1

Main IdeaFor every A ∈ V , and every i ≤ n, j ≤ n + 1− i , we will determineif A

∗⇒ wi ,j .

Now, w ∈ L(G ) iff S∗⇒ w1,n = w ; thus, we will solve the

membership problem.How do we determine if A

∗⇒ wi ,j for every A, i , j?

Page 66: CSE 135: Introduction to Theory of Computation CFLs ...

First Ideas

NotationSuppose w = w1w2 · · ·wn, where wi ∈ Σ. Let wi ,j denote thesubstring of w starting at position i of length j . Thus,wi ,j = wiwi+1 · · ·wi+j−1

Main IdeaFor every A ∈ V , and every i ≤ n, j ≤ n + 1− i , we will determineif A

∗⇒ wi ,j .

Now, w ∈ L(G ) iff S∗⇒ w1,n = w ; thus, we will solve the

membership problem.How do we determine if A

∗⇒ wi ,j for every A, i , j?

Page 67: CSE 135: Introduction to Theory of Computation CFLs ...

First Ideas

NotationSuppose w = w1w2 · · ·wn, where wi ∈ Σ. Let wi ,j denote thesubstring of w starting at position i of length j . Thus,wi ,j = wiwi+1 · · ·wi+j−1

Main IdeaFor every A ∈ V , and every i ≤ n, j ≤ n + 1− i , we will determineif A

∗⇒ wi ,j .

Now, w ∈ L(G ) iff S∗⇒ w1,n = w ; thus, we will solve the

membership problem.

How do we determine if A∗⇒ wi ,j for every A, i , j?

Page 68: CSE 135: Introduction to Theory of Computation CFLs ...

First Ideas

NotationSuppose w = w1w2 · · ·wn, where wi ∈ Σ. Let wi ,j denote thesubstring of w starting at position i of length j . Thus,wi ,j = wiwi+1 · · ·wi+j−1

Main IdeaFor every A ∈ V , and every i ≤ n, j ≤ n + 1− i , we will determineif A

∗⇒ wi ,j .

Now, w ∈ L(G ) iff S∗⇒ w1,n = w ; thus, we will solve the

membership problem.How do we determine if A

∗⇒ wi ,j for every A, i , j?

Page 69: CSE 135: Introduction to Theory of Computation CFLs ...

Base CaseSubstrings of length 1

ObservationFor any A, i , A

∗⇒ wi ,1 iff A→ wi ,1 is a rule.

I Since G is in Chomsky Normal Form, G does not have anyε-rules, nor any unit rules.

Thus, for each A and i , one can determine if A∗⇒ wi ,1.

Page 70: CSE 135: Introduction to Theory of Computation CFLs ...

Base CaseSubstrings of length 1

ObservationFor any A, i , A

∗⇒ wi ,1 iff A→ wi ,1 is a rule.

I Since G is in Chomsky Normal Form, G does not have anyε-rules, nor any unit rules.

Thus, for each A and i , one can determine if A∗⇒ wi ,1.

Page 71: CSE 135: Introduction to Theory of Computation CFLs ...

Base CaseSubstrings of length 1

ObservationFor any A, i , A

∗⇒ wi ,1 iff A→ wi ,1 is a rule.

I Since G is in Chomsky Normal Form, G does not have anyε-rules, nor any unit rules.

Thus, for each A and i , one can determine if A∗⇒ wi ,1.

Page 72: CSE 135: Introduction to Theory of Computation CFLs ...

Inductive StepLonger substrings

A

B C

wi ,k wi+k,j−k

Suppose for every variable X and every wi ,`

(` < j) we have determined if X∗⇒ wi ,`

I A∗⇒ wi ,j iff there are variables B and C

and some k < j such that A→ BC is arule, and B

∗⇒ wi ,k and C∗⇒ wi+k,j−k

I Since k and j − k are both less than j , wecan inductively determine if A

∗⇒ wi ,j .

Page 73: CSE 135: Introduction to Theory of Computation CFLs ...

Inductive StepLonger substrings

A

B C

wi ,k wi+k,j−k

Suppose for every variable X and every wi ,`

(` < j) we have determined if X∗⇒ wi ,`

I A∗⇒ wi ,j iff there are variables B and C

and some k < j such that A→ BC is arule, and B

∗⇒ wi ,k and C∗⇒ wi+k,j−k

I Since k and j − k are both less than j , wecan inductively determine if A

∗⇒ wi ,j .

Page 74: CSE 135: Introduction to Theory of Computation CFLs ...

Inductive StepLonger substrings

A

B C

wi ,k wi+k,j−k

Suppose for every variable X and every wi ,`

(` < j) we have determined if X∗⇒ wi ,`

I A∗⇒ wi ,j iff there are variables B and C

and some k < j such that A→ BC is arule, and B

∗⇒ wi ,k and C∗⇒ wi+k,j−k

I Since k and j − k are both less than j , wecan inductively determine if A

∗⇒ wi ,j .

Page 75: CSE 135: Introduction to Theory of Computation CFLs ...

Cocke-Younger-Kasami (CYK) Algorithm

Algorithm maintains Xi ,j = {A | A ∗⇒ wi ,j}.

Initialize: Xi ,1 = {A | A→ wi ,1}for j = 2 to n do

for i = 1 to n − j + 1 doXi ,j = ∅for k = 1 to j − 1 do

Xi ,j = Xi ,j ∪ {A | A→ BC , B ∈ Xi ,k , C ∈ Xi+k,j−k}

Correctness: After each iteration of the outermost loop, Xi ,j

contains exactly the set of variables A that can derive wi ,j , for eachi .Time = O(n3).

Page 76: CSE 135: Introduction to Theory of Computation CFLs ...

Cocke-Younger-Kasami (CYK) Algorithm

Algorithm maintains Xi ,j = {A | A ∗⇒ wi ,j}.

Initialize: Xi ,1 = {A | A→ wi ,1}for j = 2 to n do

for i = 1 to n − j + 1 doXi ,j = ∅for k = 1 to j − 1 do

Xi ,j = Xi ,j ∪ {A | A→ BC , B ∈ Xi ,k , C ∈ Xi+k,j−k}

Correctness: After each iteration of the outermost loop, Xi ,j

contains exactly the set of variables A that can derive wi ,j , for eachi .

Time = O(n3).

Page 77: CSE 135: Introduction to Theory of Computation CFLs ...

Cocke-Younger-Kasami (CYK) Algorithm

Algorithm maintains Xi ,j = {A | A ∗⇒ wi ,j}.

Initialize: Xi ,1 = {A | A→ wi ,1}for j = 2 to n do

for i = 1 to n − j + 1 doXi ,j = ∅for k = 1 to j − 1 do

Xi ,j = Xi ,j ∪ {A | A→ BC , B ∈ Xi ,k , C ∈ Xi+k,j−k}

Correctness: After each iteration of the outermost loop, Xi ,j

contains exactly the set of variables A that can derive wi ,j , for eachi .Time = O(n3).

Page 78: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5

{S ,A,C}

4

∅ {S ,A,C}

3

∅ {B} {B}

2

{S ,A} {B} {S ,C} {S ,A}

1 {B} {A,C} {A,C} {B} {A,C}b a a b a

Page 79: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5

{S ,A,C}

4

∅ {S ,A,C}

3

∅ {B} {B}

2

{S ,A} {B} {S ,C} {S ,A}

1 {B} {A,C} {A,C} {B} {A,C}b a a b a

Page 80: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5

{S ,A,C}

4

∅ {S ,A,C}

3

∅ {B} {B}

2 {S ,A} {B} {S ,C} {S ,A}1 {B} {A,C} {A,C} {B} {A,C}

b a a b a

Page 81: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5

{S ,A,C}

4

∅ {S ,A,C}

3 ∅ {B} {B}2 {S ,A} {B} {S ,C} {S ,A}1 {B} {A,C} {A,C} {B} {A,C}

b a a b a

Page 82: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5

{S ,A,C}

4 ∅ {S ,A,C}3 ∅ {B} {B}2 {S ,A} {B} {S ,C} {S ,A}1 {B} {A,C} {A,C} {B} {A,C}

b a a b a

Page 83: CSE 135: Introduction to Theory of Computation CFLs ...

Example

Example

Consider grammarS → AB | BC , A→ BA | a, B → CC | b, C → AB | a Let

w = baaba. The sets Xi ,j = {A | A ∗⇒ wi ,j}:

j/i 1 2 3 4 5

5 {S ,A,C}4 ∅ {S ,A,C}3 ∅ {B} {B}2 {S ,A} {B} {S ,C} {S ,A}1 {B} {A,C} {A,C} {B} {A,C}

b a a b a

Page 84: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 85: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 86: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?

I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 87: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 88: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 89: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.

Page 90: CSE 135: Introduction to Theory of Computation CFLs ...

More Decision Problems

Given a CFGs G1 and G2

I Is L(G1) = Σ∗?

I Is L(G1) ∩ L(G2) = ∅?I Is L(G1) = L(G2)?

I Is G1 ambiguous?

I Is L(G1) inherently ambiguous?

All these problems are undecidable.