0% found this document useful (0 votes)
24 views17 pages

Aug Lecture 10

Uploaded by

Manikandan K
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)
24 views17 pages

Aug Lecture 10

Uploaded by

Manikandan K
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/ 17

3. Context-Free Languages and Pushdown Automata 3.4.

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

Proof of Theorem 3.20 (cont.)


Idea: A grammar G that simulates the computations of M through
leftmost derivations.
Let G := (N, Σ, P, S), where
N := {S} ∪ [Q × Γ × Q],
P := { S → (q0 , #, q) | q ∈ Q }
∪ { [q, A, q � ] → a | (q � , ε) ∈ δ(q, a, A) }
∪ { [q, A, q � ] → a[q1 , B, q � ] | (q1 , B) ∈ δ(q, a, A), q � ∈ Q }
∪ { [q, A, q � ] → a[q1 , C, q2 ][q2 , B, q � ] |
(q1 , BC) ∈ δ(q, a, A), q � , q2 ∈ Q }.

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 Theorem 3.20 (cont.)

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

(q, A, ay ) �M (q1 , B2 B1 , y ) �i−1


M (p, ε, ε),

that is, (q1 , B2 B1 ) ∈ δ(q, a, A).

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 180 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata

Proof of Theorem 3.20 (cont.)

Proof of Claim (cont.)


As M can only read and replace the topmost symbol on the pushdown,
it follows that y = y1 y2 , and that the above computation can be
factored as follows:

(q1 , B1 , y1 ) �kM1 (q2 , ε, ε) and (q2 , B2 , y2 ) �kM2 (p, ε, ε),

where q2 ∈ Q, and k1 + k2 = i − 1.
From the I.H. we obtain the leftmost derivations

[q1 , B1 , q2 ] →klm1 y1 and [q2 , B2 , p] →klm2 y2 .

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 181 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata

Proof of Theorem 3.20 (cont.)

Proof of Claim (cont.)


Because of the transition in step 1, we have

([q, A, p] → a[q1 , B1 , q2 ][q2 , B2 , p]) ∈ P,

and therewith we obtain the following leftmost derivation in G:

[q, A, p] →lm a[q1 , B1 , q2 ][q2 , B2 , p]


→klm1 ay1 [q2 , B2 , p]
→klm2 ay1 y2 = ay = x,

that is, we have [q, A, p] →ilm x.

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 182 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata

Proof of Theorem 3.20 (cont.)

Proof of Claim (cont.)


Now we prove the converse implication, again by induction on i.
For i = 1, [q, A, p] → x implies that x ∈ Σ ∪ {ε} and (p, ε) ∈ δ(q, x, A),
that is, (q, A, x) �M (p, ε, ε).
Now assume that the implication has been proved for i − 1, and
assume that

[q, A, p] → a[q1 , B1 , q2 ][q2 , B2 , p] →i−1


lm x ∈ Σ∗
.

Then x = ax1 x2 , where [q1 , B1 , q2 ] →klm1 x1 , [q2 , B2 , p] →klm2 x2 ,


and k1 + k2 = i − 1.
From the I.H. we obtain (q1 , B1 , x1 ) �kM1 (q2 , ε, ε) and
(q2 , B2 , x2 ) �kM2 (p, ε, ε).

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 183 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata

Proof of Theorem 3.20 (cont.)

Proof of Claim (cont.)


Hence, we have
(q1 , B2 B1 , x1 ) �kM1 (q2 , B2 , ε).
As (q1 , B2 B1 ) ∈ δ(q, a, A), this yields the following computation:

(q, A, x) = (q, A, ax1 x2 ) �M (q1 , B2 B1 , x1 x2 )


�kM1 (q2 , B2 , x2 ) �kM2 (p, ε, ε),

that is, we have (q, A, x) �iM (p, ε, ε).

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 184 / 294
3. Context-Free Languages and Pushdown Automata 3.4. Pushdown Automata

Proof of Theorem 3.20 (cont.)


For all x ∈ Σ∗ we have the following equivalent statements:
x ∈ L(G) iff S →∗lm x
iff S → [q0 , #, q] →ilm x for some q ∈ Q and i ≥ 1
iff (q0 , #, x) �iM (q, ε, ε).
It follows that L(G) = N(M).

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

3.5. Closure Properties


Theorem 3.22
The class of context-free languages CFL is closed under the
operations of union, product, Kleene star, and morphism.

Proof.

(a) Let G1 = (N1 , Σ, P1 , S1 ), G2 = (N2 , Σ, P2 , S2 ), N1 ∩ N2 = ∅.


For G3 := (N1 ∪ N2 ∪ {S}, Σ, P1 ∪ P2 ∪ {S → S1 |S2 }, S),
we have L(G3 ) = L(G1 ) ∪ L(G2 ).
(b) For G4 := (N1 ∪ N2 ∪ {S}, Σ, P1 ∪ P2 ∪ {S → S1 S2 }, S),
we have L(G4 ) = L(G1 ) · L(G2 ).
(c) W.l.o.g.: S1 does not occur on the right-hand side of P1 .
For G5 := (N1 ∪ {S}, Σ, P1 ∪ {S → ε|S1 |SS1 } � {S1 → ε}, S),
we have L(G5 ) = (L(G1 ))∗ .

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 186 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties

Proof of Theorem 3.22 (cont.)

(d) Let h : Σ∗ → Γ∗ be a morphism.


For G6 := (N1 , Γ, { A → h(r ) | (A → r ) ∈ P1 }, S1 ), where h is
extended to a morphism h : (N1 ∪ Σ)∗ → (N1 ∪ Γ)∗ by taking
h(A) = A for all A ∈ N1 , we have L(G6 ) = h(L(G1 )).

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

δ � ((q, p), a, A) = { ((q � , p� ), α) | (q � , α) ∈ δ(q, a, A), p� = η(p, a) },


δ � ((q, p), ε, A) = { ((q � , p), α) | (q � , α) ∈ δ(q, ε, A) },

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

δ � (p0 , ε, Z0 ) = δ(q0 , b, Z0 ) and


δ � (q, a, A) = δ(q, a, A) for all q ∈ Q, a ∈ Σ, and A ∈ Γ.

Then N(M � ) = b \ N(M).

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

Proof of Theorem 3.26 (cont.)


(1) δ � ([q, ax], ε, A) = { ([p, x], γ) | (p, γ) ∈ δ(q, a, A) }
∪ { ([p, ax], γ) | (p, γ) ∈ δ(q, ε, A) },
(2) δ � ([q, ε], a, A) = {([q, h(a)], A)} for all a ∈ Σ.

The second component of the states of M � is used as a “buffer” for


storing the word h(a) for a letter a ∈ Σ read. This word is then
processed through a simulation of a computation of M.
It follows that h−1 (L) ⊆ L(M � ).
Concersely, let w = a1 a2 · · · an ∈ L(M � ).
A transition reading a letter a ∈ Σ can only be applied if and when the
buffer is empty, that is, each accepting computation of M � on input w
can be written as follows:

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 192 / 294
3. Context-Free Languages and Pushdown Automata 3.5. Closure Properties

Proof of Theorem 3.26 (cont.)


([q0 , ε], Z0 , a1 a2 · · · an )
�∗M � ([p1 , ε], α1 , a1 a2 · · · an ) (simulating ε-transitions of M)
�M � ([p1 , h(a1 )], α1 , a2 · · · an ) (h(a1 ) is “read”)
�∗M � ([p2 , ε], α2 , a2 . . . an ) (for (p1 , α1 , h(a1 )) �∗M (p2 , α2 , ε))
..
.
�M � ([pn , h(an )], αn , ε) (h(an ) is “read”)
�∗M � ([pn+1 , ε], αn+1 , ε) (for (pn , αn , h(an )) �∗M (pn+1 , αn+1 , ε)).

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

In analogy to Corollary 2.29 we have the following closure property.


Corollary 3.27
The class CFL is closed under finite transductions, that is, if
T ⊆ Σ∗ × Δ∗ is a finite transduction, and if L ∈ CFL(Σ), then
T (L) ∈ CFL(Δ).

Prof. Dr. F. Otto (Universität Kassel) Automata and Grammars 194 / 294

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