Deterministic PDA`s

Deterministic PDA’s
Closure properties of DCFL’s
Deterministic PDA’s
Deepak D’Souza
Department of Computer Science and Automation
Indian Institute of Science, Bangalore.
21 October 2011
Complementing DPDA’s
Deterministic PDA’s
Closure properties of DCFL’s
Outline
1
Deterministic PDA’s
2
Closure properties of DCFL’s
3
Complementing DPDA’s
Complementing DPDA’s
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Deterministic PDA’s
b
a
a
b a
b a
q
a
a
b
a
X
Y
X
X
⊥
A PDA with restrictions that:
At most one move possible in any configuration.
For any state p, a ∈ A , and X ∈ Γ: at most one move of the
form (p , a , X ) → (q, γ) or (p , , X ) → (q, γ).
Effectively, a DPDA must see the current state, and top of
stack, and decide whether to make an -move or read input
and move.
Accepts by final state.
We need a right-end marker “a” for the input.
Deterministic PDA’s
Closure properties of DCFL’s
Example DPDA
Example DPDA for {a n b n | n ≥ 0}
(s , a , ⊥)
(p , a , A )
(p , b , A )
(q, b , A )
(q, a, ⊥)
(s , a, ⊥)
→
→
→
→
→
→
(p , A ⊥)
(p , AA )
(q, )
(q, )
(t , ⊥)
(t , ⊥).
Complementing DPDA’s
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Closure Properties of DCFL’s
All languages over A
CFL
DCFL
Regular
an bn cn
an bn cn
an bn
Closed?
Complementation
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Closure Properties of DCFL’s
All languages over A
CFL
DCFL
an bn cn
an bn cn
an bn
Regular
Closed?
Complementation
Union
√
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Closure Properties of DCFL’s
All languages over A
CFL
DCFL
an bn cn
an bn cn
an bn
Regular
Closed?
Complementation
Union
Intersection
√
X
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Closure Properties of DCFL’s
All languages over A
CFL
DCFL
an bn cn
an bn cn
an bn
Regular
Closed?
Complementation
Union
Intersection
√
X
X
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
DCFL’s are closed under complementation
Theorem (Closure under complementation)
The class of languages definable by Deterministic Pushdown
Automata (i.e. DCFL’s) is closed under complementation.
Deterministic PDA’s
Closure properties of DCFL’s
Problem with complementing a DPDA
Try flipping final and non-final states: Problems?
a
Loops denote an infinite sequence of -moves.
Complementing DPDA’s
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Desirable form of DPDA
a
f0
r0
Now we can make r 0 unique accepting state, to accept
complement of M.
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Construction - Step 1
Let M = (Q , A , Γ, s , δ, ⊥, F ) be given DPDA. First construct DPDA
M 0 which
Does not get stuck due to no transition or stack empty.
Has only “sink” final states.
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Construction - Step 1
Define M 0 = (Q ∪ Q 0 ∪ {s1 , r , r 0 }, A , Γ ∪ {y}, s1 , δ0 , y, F 0 ) where
Q 0 = {q0 | q ∈ Q } and F 0 = {f 0 | f ∈ F }.
δ0 is obtained from δ as follows:
Assume M is “complete” (does not get stuck due to no
transition). (If not, add a dead state and add transitions to it.)
Make sure M 0 never empties its stack, keep track of whether
we have seen end of input (primed states) or not (unprimed
states):
(s1 , , y)
(p , , y)
(p 0 , , y)
(p , a, X )
(p 0 , , X )
(r , a , X )
(r , a, X )
(r 0 , , X )
(f 0 , , X )
→
→
→
→
→
→
→
→
→
(s , ⊥y)
(r , y)
(p ∈ Q )
(r 0 , y)
(p 0 < F 0 )
(q0 , γ)
if (p , a, X ) → (q, γ) ∈ δ.
(q0 , γ)
if (p , , X ) → (q, γ) ∈ δ.
(r , X )
(r 0 , X )
(r 0 , X )
(f 0 , X )
(f ∈ F ) Also drop trans. going from f 0 .
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
After Step 1
DPDA M 0 only has the following kinds of behaviours now:
a
f0
Loops denote an infinite sequence of -moves.
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Construction - Step 2
A spurious transition in M 0 is a transition of the form
(p , , X ) → (q, γ) such that
∗
(p , , X ) ⇒ (p , , X α)
for some stack contents α.
∗
X
⇒
p
X
p
Identify spurious transitions in M 0 and remove them:
If (p , , X ) → (q, γ) is a spurious transition, replace it with
(p , , X ) → (r , X ) If p ∈ Q
(p , , X ) → (r 0 , X ) If p ∈ Q 0 − F 0 .
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Correctness
Argue that:
Deleting a spurious transition (starting from a non-F 0 -final
state) does not change the language of M 0 .
All infinite loops use a spurious transition.
Look at graph of stack height along infinite loop, and argue that
there are infinitely many future minimas.
Further look at transitions applied at these points and observe
that one must repeat.
Thus replacing spurious transitions as described earlier will
remove the remaining undesirable loops from M 0 ’s behaviours.
Deterministic PDA’s
Closure properties of DCFL’s
Complementing DPDA’s
Complementing
Resulting M 00 has the desired behaviour (every run either
reaches a final sink state or the reject sink state r 0 .).
a
f0
r0
Now make r 0 unique final state to complement the language
of M.