0% found this document useful (0 votes)
20 views37 pages

22 Pushdown Automata Equivalence

Uploaded by

junioradamec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views37 pages

22 Pushdown Automata Equivalence

Uploaded by

junioradamec
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Pushdown Automata

Equivalence
Athanasios Aris Panagopoulos
Section Summary
• Equivalence of PDAs and CFGs
• CGF to PDA conversion
• PDA to CFG conversion
CFLs and PDAs
Theorem: The class of languages accepted by PDA is exactly the class
of CFL
Proof:
1. Lemma I: {CFL} ⊆ {PDA}
2. Lemma II: {CFL} ⊇ {PDA}
Lemma I: {CFL} ⊆ {PDA}
Lemma I: {CFL} ⊆ {PDA}: Each CFL is accepted by (at least one) PDA
Proof: CFG → PDA (Show that we can always construct a
corresponding PDA for a CFG)
CFG → PDA
Let G = (V, S, R, S) be a context-free grammar; we can construct a pushdown
automaton M such that L(M) = L(G):
M = ({p, q}, Σ, V, ∆N ∪ ∆P ∪ ∆I, p, {q})
1. ∆N = {(p, e, e), (q, S))} CFG PDA
2. ∆P = {(q, e, A), (q, x)) : (A → x) ∈ R}
3. ∆I = {((q, α, α), (q, e)) : α ∈ Σ}

• The machine we construct has only two states, p and q, and remains
permanently in state q after its first move.
• Also, M uses V, the set of terminals and nonterminal, as its stack alphabet.
➢ We have three rule types.
CFG → PDA
We have three rule types:
1. ∆N = {(p, e, e), (q, S))}
Begin by pushing S to the stack.
2. ∆P = {(q, e, A), (q, x)) : (A → x) ∈ R}
Replace the topmost symbol A by x.
3. ∆I = {((q, α, α), (q, e)) : α ∈ Σ}
Compare the topmost symbol from the stack with the input symbol
simulation of a leftmost derivation.
Example: CFG → PDA
Create a PDA for L(G) = {wcwR: w ∈ {α, b}∗}:

G = (V, Σ, R, S), where:


• V = {S, α, b, c}
• Σ = {α, b, c}
• R = {S → αSα, S → bSb, S → c }

and show the recognition of αbbcbbα step by step.


Example: CFG → PDA
Solution: M = (K, Σ, Γ, ∆, s, F) State Transition Unread Input Stack
p - αbbcbbα e
K = {p, q}, Γ = V, s = p, F = {q} q ∆1 αbbcbbα S
q ∆2 αbbcbbα αSα
∆ = {∆1, ∆2, ∆3, ∆4, ∆5, ∆6, ∆7} q ∆5 bbcbbα Sα
∆N ➢ ∆1: ((p, e, e), (q, S)) q ∆3 bbcbbα bSbα

➢ ∆2: ((q, e, S), (q, αSα)) q ∆6 bcbbα Sbα


q ∆3 bcbbα bSbbα
∆P ➢ ∆3: ((q, e, S), (q, bSb))
q ∆6 cbbα Sbbα
➢ ∆4: ((q, e, S), (q, c)) q ∆4 cbbα cbbα
➢ ∆5: ((q, α, α), (q, e)) q ∆7 bbα bbα
∆I ➢ ∆6: ((q, b, b), (q, e)) q ∆6 bα bα

➢ ∆7: ((q, c, c), (q, e)) q ∆6 α α


q ∆5 e e
Example: CFG → PDA
Create a PDA for L(G) where: G = (V, Σ, R, S), where: V = {S, S1, α, b}, Σ =
{α, b} and R = {
S → S1αS1αS1,
S1 → αS1b,
S1 → bS1α,
S1 → S1S1,
S1 → ε }
and show the recognition of αbααbbααbα step by step.
Example: CFG → PDA
Solution: M = (K, Σ, Γ, ∆, p, F) where: K = {p, q}, Σ = {α, b}, Γ = {S, S1, α,
b}, F = {q} and Δ = {
∆1: ( (p, e, e) , (q, S) ) ∆N
∆2: ( (q, e, S) , (q, S1αS1αS1) )
∆3: ( (q, e, S1), (q, αS1b) )
∆P
∆4: ( (q, e, S1), (q, bS1α) )
∆5: ( (q, e, S1), (q, S1S1) )
∆6: ( (q, e, S1), (q, e) )
∆7: ( (q, α, α), (q, e) ) ∆I
∆8: ( (q, b, b), (q, e) )}

αbααbbααbα
Example: CFG → PDA
Solution: State Transition Unread Input Stack
p - αbααbbααbα e
q ∆1 αbααbbααbα S
q ∆2 αbααbbααbα S1αS1αS1
q ∆3 αbααbbααbα αS1bαS1αS1
q ∆7 bααbbααbα S1bαS1αS1
q ∆6 bααbbααbα bαS1αS1
q ∆8 ααbbααbα αS1αS1
∆7 αbbααbα α1αS1
q ∆5 αbbααbα S1S1αS1
q ∆3 αbbααbα αS1bS1αS1
q ∆7 bbααbα S1bS1αS1
q ∆6 bbααbα bS1αS1



Example: CFG → PDA
Solution:



State Transition Unread Input Stack
q ∆8 bααbα S1αS1
q ∆4 bααbα bS1ααS1
q ∆8 ααbα S1ααS1
q ∆6 ααbα ααS1
q ∆7 αbα αS1
q ∆7 bα S1
q ∆4 bα bS1α
q ∆8 α S1 α
q ∆6 α α
q ∆7 e e
Example: CFG → PDA
Construct a PDA for L = {wcu: w, u ∈ {α, b}* and u contains wR as a substring} and
the G = (V, Σ, R, S), where: V = {S, W, X, α, b, c}, Σ = {α, b, c} and
R={
• S → WX
• W → αWα
• W → bWb
• W → cX
• X → αX | bX | ε
}
and show the recognition of αbcαbαb (transition table) step by step.
Example: CFG → PDA State
p
Transition
-
Unread Input
αbcαbαb
Stack
e
q ∆1 αbcαbαb S
q ∆2 αbcαbαb WX
Solution:
q ∆3 αbcαbαb αWαX
M = (K, Σ, Γ, ∆, p, F) where:
q ∆9 bcαbαb WαX
K = {p, q}, Σ = {α, b, c}, Γ = {S, W, α, b, c}, F = {q}
q ∆4 bcαbαb bWbαX
Δ={ q ∆10 cαbαb WbαX
∆1:( (p, e, e), (q, S) ) ∆N q ∆5 cαbαb cXbαX
∆1:( (q, e, S), (q, WX) )
∆1:( (q, e, W), (q, αWα) ) q ∆11 αbαb XbαX
∆1:( (q, e, W), (q, bWb) ) q ∆6 αbαb αXbαX
∆1:( (q, e, W), (q, cX) ) ∆P q ∆9 bαb XbαX
∆1:( (q, e, X), (q, αX) ) q ∆8 bαb bαX
∆1:( (q, e, X), (q, bX) )
q ∆10 αb αX
∆1:( (q, e, X), (q, e)
∆1:( (q, α, α), (q, e) q ∆9 b X
∆I
∆1:( (q, b, b), (q, e) q ∆7 b bX
∆1:( (q, c, c), (q, e) q ∆10 e X
} q ∆8 e e
CFG → PDA
Claim: L(M) = L(G)
• Consider w ∈ Σ∗ and α ∈ (V − S)V∗ ∪ {e}
• then S ⇒∗𝐺 wα  (q, w, S) ⊢𝑀 ∗
(q, e, α)
Proof
• ⇒ : induction on the length of the leftmost derivation
• ⇐ : induction on the number of transitions of type ∆P
➢ Beyond the scope of this class ☺
CFLs and PDAs
Theorem: The class of languages accepted by PDA is exactly the class
of CFL
Proof:
1. Lemma I: {CFL} ⊆ {PDA}
2. Lemma II: {CFL} ⊇ {PDA}
Lemma II: {CFL} ⊇ {PDA}
Lemma II: {CFL} ⊇ {PDA}: The language accepted by a PDA is a CFL
Proof: CFG  PDA
(Show that we can always construct a corresponding CFG for a PDA)
CFG  PDA
It is difficult to go directly so we will use a simplified PDA

CFG PDA

Simplified
PDA
Simplified PDA
A simplified PDA:
1. Has a single accepting state
2. Must empty its stack before accepting
3. Each transition of the pushdown automaton must either push to or
pop from the stack, but not both simultaneously

➢ If a language is accepted by a PDA then it is also accepted by a


simplified PDA
Simplified PDA
A simplified PDA M is a 6-tuple (K, Σ, Γ, ∆, s, f):
• K, a finite set of states
• Σ, an alphabet (the input symbols)
• Γ, an alphabet (the stack symbols)
• Δ, the transition relation where: Δ ⊆ ( K × (Σ ∪ {e}) × Γ ) × ( K × {e} ) (push) U ( K ×
(Σ ∪ {e}) × {e}) × ( K × Γ ) (pop)
• s ∈ K, the initial state
• f, the final state (|F| =1)
➢ We accept by empty stack and final state
Simplified PDA
A simplified PDA:
1. Has a single accepting state
2. Must empty its stack before accepting
3. Each transition of the pushdown automaton must either push to or
pop from the stack, but not both simultaneously
4. We push or pop only one symbol at a time

➢ If a language is accepted by a PDA then it is also accepted by a


simplified PDA
PDA → Simplified PDA
Rule 1: We ensure that we have only one final state by including e
transitions:
e, e → e
q1 q1
e, e → e q4

q2 q3 q2 q3 e, e → e
Simplified PDA
A simplified PDA:
1. Has a single accepting state
2. Must empty its stack before accepting
3. Each transition of the pushdown automaton must either push to or
pop from the stack, but not both simultaneously
4. We push or pop only one symbol at a time

➢ If a language is accepted by a PDA then it is also accepted by a


simplified PDA
PDA → Simplified PDA
Rule 2: Insert a symbol $ in the stack at the beginning (that we will
remove before acceptance) so that the stack is empty only in
acceptance:
e, e → $
q0 → q 0' q0

e, $ → e
q0 → q0 q0’

We ensure that the stack is empty before acceptance:


Simplified PDA
A simplified PDA:
1. Has a single accepting state
2. Must empty its stack before accepting
3. Each transition of the pushdown automaton must either push to or
pop from the stack, but not both simultaneously
4. We push or pop only one symbol at a time

➢ If a language is accepted by a PDA then it is also accepted by a


simplified PDA
PDA → Simplified PDA
Rule 3: We ensure each transition of the pushdown automaton must
either push to or pop from the stack, but not both.

α, bb → c α, bb → e e, e → c
q0 q1 → q0 q01' q1

α, e → e α, e → b e, b → e
q0 q1 → q0 q01' q1

If we have an epsilon transition that neither pushes nor pops, then we replace it with two “dummy”
transitions that push and then immediately pop the same stack symbol.
Simplified PDA
A simplified PDA:
1. Has a single accepting state
2. Must empty its stack before accepting
3. Each transition of the pushdown automaton must either push to or
pop from the stack, but not both simultaneously
4. We push or pop only one symbol at a time

➢ If a language is accepted by a PDA then it is also accepted by a


simplified PDA
Step IV - PDA → Simplified PDA
Rule 4: We ensure that we pop or push one symbol at a time:

α, bbαS → e e, b → e e, b → e e, α → e e, S → e

q0 q1 → q0 r1 r2 r3 q1

e, e → b e, e → b b, e → b
b, e→ bbb
q0 q1 → q0 r1 r2 q1
Simplified PDA → CFG
Given a simplified PDA we can get a corresponding CFG using the
following rules:
PDA CFG

p … q S → Apq

q Αqq → e

α, e → X
p r
Αpq → αΑrsb
Note that X is pushed and popped
s q (α=e or b=e is also allowed)
b, X → e

p r q Αpq → ΑprΑrq
Example: PDA → CFG
Identify the corresponding CFG from the following PDA:

α, e → X
α, Y → e
b, e → Y
b, X → e
e, Z → e
e, e → Z
q1 q2
Example: PDA → CFG
Solution: Step I
First, we convert the PDA to a simplified one:
α, e → X
b, e → Y
α, Υ → e
b, Χ → e
e, Z → e
e, e → $ e, e → Z e, $ → e
q0 q1 q2 q3
Example: PDA → CFG
S: Αpq → αΑrsb: Aij → AikAjk:
• S → A03 • A03 → A12 A00 → A00A00 | A01A10 | A02A20 | A03A30
• A12 → A22 A01 → A00A01 | A01A11 | A02A21 | A03A31
Aii → e: A02 → A00A02 | A01A12 | A02A22 | A03A32
• A22 → αA22b
A03 → A00A03 | A01A13 | A02A23 | A03A33
• A00 → e • A22 → bA22α ...
• A11 → e A30 → A30A00 | A31A10 | A32A20 | A33A30
• A22 → e A31 → A30A01 | A31A11 | A32A21 | A33A31
• A33 → e A32 → A30A02 | A31A12 | A32A22 | A33A32
A33 → A30A03 | A31A13 | A32A23 | A33A33
43=64 rules (…)
Example: PDA → CFG
Extract the corresponding CFG for the following PDA:

0, e → 0
0, 1 → e
1, e → 1
1, 0 → e

q1
Example: PDA → CFG
Solution:
0, e → 0 S: Αpq → αΑrsb:
0, 1 → e
1, e → 1 • S → A02 • A11 → 0A111
1, 0 → e • A11 → 1A110
e, e → $ e, $ → e App → e: • A02 → A11
q0 q1 q2
• A00 → e
Aij → AikA jk :
• A11 → e
• A02 → A01A12
• A22 → e
• A01 → A01A11
• A12 → A11A12
• A11 → A11A11
Example: PDA → CFG
Solution: The produced CFG (after eliminating unreachable non-terminals) will be:
G = (V, Σ ,R, S), where V = {S, A02, A11}, Σ = {0, 1},
R ={ • S →A
02
• A02 → A11
• A11 → A11A11
• A11 → 0A111
• A11 → 1A110
• A11 → e
}

• L = {w ∈ {0, 1}*: has the same number of 0’s and 1’s}


PDA → CFG
Claim: L(G) = L(M’)
• ∀ p, q ∈ K’, A ∈ Γ U {e}, x ∈ Σ*
• Apq ⇒∗𝐺 x  (q, x, A) ⊢∗𝑀 (p, e, e)
Proof:
• ⇒ : induction on the length of the production of G
• ⇐ : induction on the length of computation by M’

➢ Out of the scope of this class ☺


References

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy