Вы находитесь на странице: 1из 42

Closure and decision properties

DVA337 HT17 – LECTURE 11 of CFL, DPDA and relative


strength DPDA/NPDA
EXERCISE
Find a context free grammar for L = { anbmck : k = m + n }
RECAP, NPDA
Many choices – some connected
 choose the most convenient, but be clear which one it is!

We will be working with


 M = (Q, Σ, Γ, δ, q0, z, F)
 accept(w) = (q0,w,z) ⊢* (q, λ, u), q ∈ F, u ∈ Γ*
 δ : Q ⨯ (Σ ∪ { λ }) ⨯ (Γ ∪ { λ }) → Pfin(Q ⨯ Γ*)

3
EXERCISE
Create NPDA for L = { anb2n : n ≥ 0 }
EXERCISE, SEMANTICS OF NPDA
Show execution of aabbb for NPDA on last slide.
NPDA ⇔ CFG
How do we prove
{ L(M) : M ∈ NPDA } = { L(G) : G ∈ CFG }
CFG ⇒ NPDA
From G ∈ CFG construct MG ∈ NPDA
CFG ⇒ NPDA
For any production For any terminal
Aw a

, A / w a, a / 

,  / S , $ / $
q0 q1 q2

8
NPDA ⇒ CFG
More complex!
Encode stack in non-terminals

Name non-terminals qnAqm and construct cfg in such a way that string generated by
qnAqm (which we can write [qnAqm]) are the strings matched by the NFA when going
from state qn and state qm while consuming an A from the stack
[qnAqm] = { u : (qn, uv, AV) ⊢ (qm,v,V) }

Systematic construction based on restrictions on form of underlying NPDA (wlog)


RELATION BETWEEN LANGUAGES, GRAMMARS
AND AUTOMATA

Context-free L = L(G) Context-free


Language L Grammar G

L= L(G) =
L(M) L(M)
Push-down
Automaton M
CLOSURE PROPERTIES of context-free languages
CLOSURE PROPERTIES, RL
Regular languages, closed under
 union,
 concatenation,
 Kleene closure,
 reversal,
 intersection, and
 difference
CLOSURE UNDER UNION
Given L1, L2 ∈ CFL how can we prove that L1 ∪ L2 ∈ CFL?
EXERCISE, CLOSURE UNDER CONCATENATION
For L1, L2 ∈ CFL prove that L1L2 ∈ CFL
EXERCISE, CLOSURE UNDER REVERSAL
For L ∈ CFL prove that LR ∈ CFL
CLOSURE UNDER INTERSECTION
Show that for L1, L2 ∈ CFL it does not have to be the case that L1 ∩ L2 ∈ CFL
EXPERIMENT
Try to create an NPDA for L = { anbncn : n ≥ 0 }
COMPLEMENT
Show that for L ∈ CFL it does not have to be the case that L∁ ∈ CFL
DIFFERENCE
Are CFL closed under difference, i.e., L1, L2 ∈ CFL does it hold that L1 ∖ L2 ∈ CFL
CLOSURE PROPERTIES, SUMMARY
Regular languages, closed under Context-free languages, closed under
 union,  union,
 concatenation,  concatenation,
 Kleene closure, and  Klenee closure, and
 reversal,  reversal

as well as under but not under


 intersection,  intersection,
 difference, and  difference, and
 complement  complement
REGULAR CLOSURE UNDER INTERSECTION
Show that if L1 ∈ CFL and L2 ∈ RL then L1 ∩ L2 ∈ CFL
DECISION PROPERTIES of context-free languages

22
MEMBERSHIP
Given a context-free language L and a string w, how can we check w ∈ L

23
EMPTY LANGUAGE
Given a context-free language L, how can we check if L is empty?

24
FINITENESS QUESTION
Given a language L how can we check if L is finite?

25
DECISION PROPERTIES, SUMMARY
Regular languages Context-free languages
 membership, in |w| time  membership, in |w|3 time
 run the DFA  6.3 in Linz
 empty language, in N + E time  empty language,
 compute reachable nodes, e.g., using BFS  construct dependency graph
 infinite language, in N + E time  mark productive non-terminals, check if S is productive
 DFS traversal to find back edges  infinite language,
 construct dependency graph of productive non-terminals
 find cycles
For L1, L2 ∈ RL
 L1 = L 2 Not decidable for L1, L2 ∈ CFL
 L1 ⊆ L2  L1 = L 2
 L1 and L2 disjoint  L1 ⊆ L2
 L1 and L2 disjoint
DPDA Deterministic Pushdown
Automata
DPDA
How can we define a deterministic PDA?

a, b / w1 q2

q1

a , c / w2
q3
PREVENTING NON DETERMINISM 1/3
Non-determinism without using λ transitions

29
PREVENTING NON-DETERMINISM 2/3
Non-determinism from λ-transitions on input string

30
PREVENTING NON-DETERMINISM 3/3
Non-determinism from λ-transitions on the stack.

31
DPDA
|δ(q,a,b)| = 1
for all a ∈ Σ ∪ { λ }, b ∈ Γ ∪ { λ }
a, b / w1 q2
if |δ(q,λ,b)| = 1 then
|δ(q,a,b)| = 0 for all a ∈ Σ q1

if |δ(q,a,λ)| = 1 then a , c / w2
|δ(q,a,b)| = 0 for all b ∈ Γ q3
32
NPDA OR DPDA?
|δ(q,a,b)| = 1, for all a ∈ Σ ∪ { λ }, b ∈ Γ ∪ { λ }
if |δ(q,λ,b)| = 1 then |δ(q,a,b)| = 0 for all a ∈ Σ
if |δ(q,a,λ)| = 1 then |δ(q,a,b)| = 0 for all b ∈ Γ

a,  / a b, a / 

a,  / a b, a /  , $ / $ q3
q0 q1 q2
DETERMINISTIC CONTEXT-FREE
A language L is deterministic context-free if there exists a M ∈ DPDA such that
L = L(M)

Is L = { anbn : n ≥ 0 } deterministic context-free?


NPDA OR DPDA?
|δ(q,a,b)| = 1, for all a ∈ Σ ∪ { λ }, b ∈ Γ ∪ { λ }
if |δ(q,λ,b)| = 1 then |δ(q,a,b)| = 0 for all a ∈ Σ
if |δ(q,a,λ)| = 1 then |δ(q,a,b)| = 0 for all b ∈ Γ

a,  / a a, a / 
b,  / b b, b / 

q0 ,  /  q1 , $ / $ q2
RELATIVE STRENGTH
Are NPDAs and DPDAs equivalent?
RELATIVE STRENGTH
Consider the NPDA for L = { wwR : w ∈ {a,b}* }
 can it be turned into a DPDA?
RELATIVE STRENGTH
There is a context-free language that is not deterministic context-free
Proof:
Consider L = { anbn : n ≥ 0 } ∪ { anb2n : n ≥ 0 }.
1) L is context-free
2) We will show that if there exists DPDA that recognizes L, then we can build NPDA
that recognizes L’ = { anbncn : n ≥ 0 } (which is not context-free)
3) We have that L’ is not context-free
2) + 3) implies that there can exist no DPDA that recognized L (otherwise, we have a
contradiction), hence L is not deterministic context-free.
RELATIVE STRENGTH
Given DPDA that accepts L = { anbn : n ≥ 0 } ∪ { anb2n : n ≥ 0 } construct NPDA that
accepts L’ = { anbncn : n ≥ 0 }
SUMMARY
NPDA – definition and execution
DPDA – special deterministic case of NPDA
Not every CFL is deterministic CF
 there exists context-free languages that are only recognizable by NPDAs (wwR, anbncn)

Closure properties of CFL


 closed under union, concatenation, Klenee closure, and reversal
 not closed under intersection, difference, and complement

Decision properties of CFL


 membership, empty language and infinite language decidable
 equality, sublanguage, disjoint language not decidable
IF TIME, EXERCISE
Show derivation for aabaaaa in the following grammar
 S → aABB | aAA
 A → aBB | a
 B → bBB | A
IF TIME, EXERCISE
Construct an NPDA from the following grammar
 S → aABB | aAA
 A → aBB | a
 B → bBB | A

Show execution for abaaa and contrast with


 S ⇒ aAA ⇒ aaBBA ⇒ aabBBBA ⇒ aabABBA ⇒ aabaBBA

Вам также может понравиться