Aug Lecture 10
Aug Lecture 10
Pushdown Automata
Theorem 3.20
The language N(M) is context-free for each PDA M.
Proof.
Let M = (Q, Σ, Γ, δ, q0 , #, F ) be a PDA, and let L = N(M).
W.l.o.g. we can assume the following:
For all (q � , B1 B2 · · · Bk ) ∈ δ(q, a, A), we have k ≤ 2.
Otherwise, we replace (q � , B1 B2 · · · Bk ) ∈ δ(q, a, A) (k > 2)
by the following transitions:
(q1 , B1 B2 ) ∈ δ(q, a, A),
{(q2 , B2 B3 )} = δ(q1 , ε, B2 ),
..
.
{(q � , Bk −1 Bk )} = δ(qk −2 , ε, Bk −1 ),
where q1 , q2 , . . . , qk −1 are new states.
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 178 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Claim:
∀p, q ∈ Q ∀A ∈ Γ ∀x ∈ Σ∗ : [q, A, p] →∗lm x iff (q, A, x) �∗M (p, ε, ε).
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 179 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Proof of Claim.
First we prove by induction on i that
(q, A, x) �iM (p, ε, ε) implies that [q, A, p] →ilm x.
For i = 1,
if (q, A, x) �M (p, ε, ε), then (p, ε) ∈ δ(q, x, A) and x ∈ Σ ∪ {ε}.
Hence, G contains the production [q, A, p] → x, and so, [q, A, p] →lm x.
Now assume that the above implication has been established for i − 1,
let x = ay , and let
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 180 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
where q2 ∈ Q, and k1 + k2 = i − 1.
From the I.H. we obtain the leftmost derivations
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 181 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 182 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 183 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 184 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata
Corollary 3.21
For each language L ⊆ Σ∗ , the following statements are equivalent:
(1) L ∈ CFL(Σ), that is, L is generated by a context-free grammar.
(2) L is generated by a context-free grammar in CNF.
(3) L is generated by a context-free grammar in Greibach NF.
(4) There exists a PDA M such that L = N(M).
(5) There exists a PDA M such that L = L(M).
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 185 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Proof.
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 186 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Theorem 3.23
The class CFL is not closed under intersection nor under complement.
Proof.
L1 := { ai bj c j | i, j > 0 } ∈ CFL and L2 := { ai bi c j | i, j > 0 } ∈ CFL,
but L1 ∩ L2 = { ai bi c i | i > 0 } �∈ CFL, that is,
CFL is not closed under intersection.
L1 ∩ L2 = (L1 ∪ L2 ), that is,
CFL is not closed under complement, either.
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 187 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Theorem 3.24
The class CFL is closed under intersection with regular languages,
that is, if L ∈ CFL and R ∈ REG, then L ∩ R ∈ CFL.
Proof.
Let M = (Q, Σ, Γ, δ, q0 , Z0 , F ) be a PDA, and
let A = (P, Σ, η, p0 , G) be a DFA.
We define a PDA M � := (Q × P, Σ, Γ, δ � , (q0 , p0 ), Z0 , F × G) by taking
where q, q � ∈ Q, p, p� ∈ P, a ∈ Σ, A ∈ Γ, and α ∈ Γ∗ .
Then it is easily seen that L(M � ) = L(M) ∩ L(A).
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 188 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Theorem 3.25
Let L ⊆ Σ∗ be a context-free language, and let w ∈ Σ∗ . Then the
left quotient w \ L := { u ∈ Σ∗ | wu ∈ L } is a context-free language.
Proof.
Let M = (Q, Σ, Γ, δ, q0 , Z0 , F ) be a PDA without ε-transitions,
and let w ∈ Σ∗ . Actually, we only consider the special case that
w = b ∈ Σ.
We define a PDA M � := (Q ∪ {p0 }, Σ, Γ, δ � , p0 , Z0 , F ) by taking
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 189 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Remark:
We saw in Section 3 that the language
L := { ai bj c k d � | i, j, k , � ≥ 0, and i > 0 implies j = k = � }
satisfies the Pumping Lemma for context-free languages.
Claim:
L is not context-free.
Proof.
Assume that L is context-free. Then also the language
L� := L ∩ a · b∗ · c ∗ · d ∗ = { abn c n d n | n ≥ 0 }
is context-free, and so is the language a \ L� = { bn c n d n | n ≥ 0 },
which, however, is not context-free by the Pumping Lemma,
a contradiction!
Thus, it follows that L is not context-free.
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 190 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Theorem 3.26
The class CFL is closed under inverse morphisms, that is,
if L ∈ CFL(Δ), and if h : Σ∗ → Δ∗ is a morphism, then
h−1 (L) = { w ∈ Σ∗ | h(w) ∈ L } ∈ CFL(Σ).
Proof.
Let h : Σ∗ → Δ∗ be a morphism, and
let M = (Q, Δ, Γ, δ, q0 , Z0 , F ) be a PDA s.t. L(M) = L.
We construct a PDA M � = (Q � , Σ, Γ, δ � , q0� , Z0 , F � ) for
L� := h−1 (L) = { w ∈ Σ∗ | h(w) ∈ L } :
– Q � := { [q, x] | q ∈ Q, and x is a suffix of h(a), a ∈ Σ },
– q0� := [q0 , ε],
– F� := { [q, ε] | q ∈ F }, and
– δ � is defined by:
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 191 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 192 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
It follows that
(q0 , Z0 , h(a1 a2 · · · an )) = (q0 , Z0 , h(a1 )h(a2 ) · · · h(an )) �∗M (pn+1 , αn+1 , ε).
As M � accepts, pn+1 ∈ F , which implies that M accepts, too.
Thus, L(M � ) = h−1 (L), which yields h−1 (L) ∈ CFL(Σ).
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 193 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties
Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 194 / 294