0% found this document useful (0 votes)
12 views4 pages

Pda CFG

A simple PDA is defined with specific transition conditions, and it is established that every PDA can be converted to an equivalent simple PDA. The document outlines a construction method for a context-free grammar (CFG) from a simple PDA, including detailed production rules. Additionally, it provides a proof of the equivalence between the language accepted by the PDA and the language generated by the CFG.
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)
12 views4 pages

Pda CFG

A simple PDA is defined with specific transition conditions, and it is established that every PDA can be converted to an equivalent simple PDA. The document outlines a construction method for a context-free grammar (CFG) from a simple PDA, including detailed production rules. Additionally, it provides a proof of the equivalence between the language accepted by the PDA and the language generated by the CFG.
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/ 4

Definition 1.

A PDA A = (Q, Σ, Γ, ∆, q0 , F ) is said to be simple if

((p, x, α), (q, β)) ∈ ∆ =⇒ |α| ≤ 1, (1)


((p, x, ε), (q, β)) ∈ ∆ =⇒ ∀A ∈ Γ, ((p, x, A), (q, βA)) ∈ ∆. (2)

Remark 2. For every PDA there exists an equivalent simple PDA.

Theorem 3. For every PDA there exists an equivalent CFG.

Proof (Construction Part). With out loss of generality, let A = (Q, Σ, Γ, ∆, q0 , F ) be a


simple PDA. Construct a CFG G = (N, T = Σ, P, S) described as follows:
Set N = {S} ∪ {hp, A, qi | p, q ∈ Q; A ∈ Γ ∪ {ε}} and include the following four types of
production rules in P .

(a) For each qf ∈ F , the rule S −→ hq0 , ε, qf i.

(b) For each ((p, x, A), (q, X1 X2 · · · Xn )) ∈ ∆ with n > 0 and for all r, q1 , . . . , qn−1 ∈ Q,
the rule
hp, A, ri −→ xhq, X1 , q1 ihq1 , X2 , q2 i · · · hqn−1 , Xn , ri.

(c) For each ((p, x, A), (q, ε)) ∈ ∆ and for all r ∈ Q, the rule

hp, A, ri −→ xhq, ε, ri.

(d) For each q ∈ Q, the rule hq, ε, qi −→ ε.

A sample construction. Consider the PDA A = (Q, Σ, Γ, ∆, p, F ) which accepts the


language {0n 1n | n ≥ 0}, where Q = {p, q}, Σ = Γ = {0, 1}, F = {q} and ∆ has the
following transitions:

((p, 0, ε), (p, 0)) (3)


((p, ε, ε), (q, ε)) (4)
((q, 1, 0), (q, ε)) (5)

Step-I: Conversion to Simple PDA. All the transitions are satisfying the condition in (1)
but not of (2). So we include the following transitions in ∆.

((p, 0, 0), (p, 00)) (6)


((p, 0, 1), (p, 01)) (7)
((p, ε, 0), (q, 0)) (8)
((p, ε, 1), (q, 1)) (9)

Thus we have seven transitions (3) through (9) in ∆; and A is simple.

Step-II: ∗ Construction of CFG from A . We have the following production rules in the
required CFG.
Type (a):
[as q is only final state] S −→ hp, ε, qi (10)

Type(b):
[for (3) with r = p] hp, ε, pi −→ 0hp, 0, pi (11)


One may remove 1 from the Γ as we are not using it in stack, i.e. Γ = {0}. That minimizes the number
of production rules of CFG. In fact, the transitions (7) and (9) can be dropped from ∆. Accordingly, we
will not have the production rules: (17), (18), (19), (20), (23) and (24)
[for (3) with r = q] hp, ε, qi −→ 0hp, 0, qi (12)

[for (6) with r = p and 0p0] hp, 0, pi −→ 0hp, 0, pihp, 0, pi (13)

[for (6) with r = p and 0q0] hp, 0, pi −→ 0hp, 0, qihq, 0, pi (14)

[for (6) with r = q and 0p0] hp, 0, qi −→ 0hp, 0, pihp, 0, qi (15)

[for (6) with r = q and 0q0] hp, 0, qi −→ 0hp, 0, qihq, 0, qi (16)

[for (7) with r = p and 0p1] hp, 1, pi −→ 0hp, 0, pihp, 1, pi (17)

[for (7) with r = p and 0q1] hp, 1, pi −→ 0hp, 0, qihq, 1, pi (18)

[for (7) with r = q and 0p1] hp, 1, qi −→ 0hp, 0, pihp, 1, qi (19)

[for (7) with r = q and 0q1] hp, 1, qi −→ 0hp, 0, qihq, 1, qi (20)

[for (8) with r = p] hp, 0, pi −→ hq, 0, pi (21)

[for (8) with r = q] hp, 0, qi −→ hq, 0, qi (22)

[for (9) with r = p] hp, 1, pi −→ hq, 1, pi (23)

[for (9) with r = q] hp, 1, qi −→ hq, 1, qi (24)

Type(c):
[for (4) with r = p] hp, ε, pi −→ hq, ε, pi (25)

[for (4) with r = q] hp, ε, qi −→ hq, ε, qi (26)

[for (5) with r = p] hq, 0, pi −→ 1hq, ε, pi (27)

[for (5) with r = q] hq, 0, qi −→ 1hq, ε, qi (28)

Type(d):
[for state p] hp, ε, pi −→ ε (29)

[for state q] hq, ε, qi −→ ε (30)

Corresponding to the computation

(p, 0011, ε) ` (p, 011, 0) ` (p, 11, 00) ` (q, 11, 00) ` (q, 1, 0) ` (q, ε, ε)

for 0011 in A , we observe the following derivation for 0011 in G.

S =⇒ hp, ε, qi (by (10))


=⇒ 0hp, 0, qi (by (12))
=⇒ 00hp, 0, qihq, 0, qi (by (16))
=⇒ 00hq, 0, qihq, 0, qi (by (22))
=⇒ 001hq, ε, qihq, 0, qi (by (28))
=⇒ 001hq, 0, qi (by (30))
=⇒ 0011hq, ε, qi (by (28))
=⇒ 0011 (by (30))

2
Proof Continued. For p, q ∈ Q, A ∈ Γ ∪ {ε} and x ∈ Σ∗ , we claim that
∗ ∗
hp, A, qi =⇒ x if and only if (p, x, A) ` (q, ε, ε).

Since, x ∈ L(G) ⇐⇒ x ∈ L(A ) is equivalent to hq0 , A, qf i =⇒ x if and only if

(q0 , x, A) ` (qf , ε, ε), for some qf ∈ F , the above claim suffices.

∗ ∗
⇒: Assume hp, A, qi =⇒ x. We prove that (p, x, A) ` (q, ε, ε) by induction on the length of
the derivation.

Basis: If the derivation hp, A, qi =⇒ x has only one step then hp, A, qi −→ x is a rule of

type (d). Then A = x = ε and p = q so that (p, x, A) = (q, ε, ε). Hence, (p, x, A) ` (q, ε, ε).

∗ ∗
Inductive hypothesis: If a derivation hp, A, qi =⇒ x has k or fewer steps then (p, x, A) `
(q, ε, ε).
k+1 k
Induction: Assume hp, A, qi =⇒ x and write hp, A, qi =⇒ α =⇒ x. Then the rule
hp, A, qi −→ α is of type (b) or (c) (refer construction part).

Case-I: hp, A, qi −→ α is of type (b). Then, for n ≥ 1, write

α = yhp0 , X1 , p1 i · · · hpn−1 , Xn , pn = qi

so that ((p, y, A), (p0 , X1 · · · Xn )) ∈ ∆. Let x = yy1 · · · yn such that hpi−1 , Xi , pi i =⇒ yi , for
1 ≤ i ≤ n. Thus for each i these derivations are of k or fewer steps so that

(pi−1 , yi , Xi ) ` (pi , ε, ε).

Combining these computations

(p, x, A) = (p, yy1 · · · yn , A) ` (p0 , y1 · · · yn , X1 · · · Xn )



` (p1 , y2 · · · yn , X2 · · · Xn )
..
.
∗ ∗
` (pn−1 , yn , Xn ) ` (pn = q, ε, ε).

Case-II: hp, A, qi −→ α is of type (c). Then, α = yhr, ε, qi and ((p, y, A), (r, ε)) ∈ ∆,
where x = yz for some z ∈ Σ∗ , so that

(p, x, A) = (p, yz, A) ` (r, z, ε) ` (q, ε, ε).
∗ ∗
⇐: Assume (p, x, A) ` (q, ε, ε). We prove that hp, A, qi =⇒ x by induction on the length of
the computation.

Basis: If a computation (p, x, A) ` (q, ε, ε) has zero steps, then p = q and x = ε = A. Then

the conclusion hp, A, qi =⇒ x holds trivially as hp, ε, pi −→ ε is a type (d) production rule.
∗ ∗
Inductive hypothesis: If a computation (p, x, A) ` (q, ε, ε) has k or fewer steps then hp, A, qi =⇒
x.
k+1
Induction: Suppose (p, x, A) ` (q, ε, ε) and write, for n ≥ 0,
k
(p, x, A) ` (r, z, X1 · · · Xn ) ` (q, ε, ε).

3
Then there is y ∈ Σ∗ such that x = yz and (p, y, A) ` (r, ε, X1 · · · Xn ). This implies that

((p, y, A), (r, X1 · · · Xn )) ∈ ∆

or
n ≥ 1, A = Bn and ((p, y, ε), (r, X1 · · · Xn−1 )) ∈ ∆.
Since A is a simple the latter case implies the former so that ((p, y, A), (r, X1 · · · Xn )) ∈ ∆,
in any case.
Now, if n ≥ 1, each Xi is eventually removed from the stack via a sequence of states
say r = p0 , p1 , . . . , pn−1 , pn = q by consuming the corresponding input say z1 , . . . , zn , where
z = z1 · · · zn . That is,

(p, x, A) = (p, yz, A) ` (r, z, X1 · · · Xn )


= (r, z1 · · · zn , X1 · · · Xn )

` (q1 , z2 · · · zn , X2 · · · Xn )
..
.

` (qi , zi+1 · · · zn , Xi+1 · · · Xn )

` (qi+1 , zi+2 · · · zn , Xi+2 · · · Xn )
..
.

` (q, ε, ε).

Notice each computation (in each iteration) has k or fewer steps. Then, for 0 ≤ i ≤ n, by

inductive hypothesis hpi , Xi+1 , pi+1 i =⇒ zi+1 . Also, since ((p, y, A), (r, X1 · · · Xn )) ∈ ∆, we
have
hp, A, qi −→ yhr = p0 , X1 , p1 ihp1 , X2 , p2 i · · · hpn−1 , Xn , pn = qi
is a production rule of type (b). Thus by combining these we have

hp, A, qi =⇒ yhr = p0 , X1 , p1 ihp1 , X2 , p2 i · · · hpn−1 , Xn , pn = qi



=⇒ yz1 hp1 , X2 , p2 i · · · hpn−1 , Xn , pn = qi
..
.

=⇒ yz1 · · · zn = yz = x.
k ∗
If n = 0, (r, z, ε) ` (q, ε, ε). By inductive hypothesis hr, ε, qi =⇒ z. And since
hp, A, qi −→ yhr, ε, qi is a rule (of type (c)), we have

hp, A, qi =⇒ yhr, ε, qi =⇒ yz = x.

You might also like