the pumping lemma for context free grammarscpennycu/2019/assets/fall/toc/11...pumping lemma for...
Post on 12-Sep-2020
2 Views
Preview:
TRANSCRIPT
The Pumping Lemma ForContext Free Grammars
Because the first
Pumping Lemma got lonely.
Building Intuition
What is the Pumping
Lemma for Regular
Languages?
How is the Pumping
Lemma for Regular
Languages used?
What computational feature does a Regular Language lack?
What is the analogous feature for Context Free Languages?
Building Intuition, Part 2: ExamplesContext Free Language
● {an bn
| n ≥ 1}
● {ai bj ck
| i = j or i = k}
● {ww
R
| w ∈ {0,1}*}
Non-Context Free Language
● {an bn cn
| n ≥ 1}
● {ai bj ck
| 0 ≤ i ≤ j ≤ k}
● {ww | w ∈ {0,1}*}
Building Intuition, Part 3: PicturesDFA Diagram CFG Parse Tree
Pumping Lemma for Context Free LanguagesIf A is a Context Free Language, then there is a number p (the
pumping length) where if s is any string in A of length at least p,
then s may be divided into 5 pieces, s = uvxyz, satisfying the
following conditions:
a. For each i ≥ 0, uv
i
xy
i
z ∈ A,
b. |vy| > 0, and
c. |vxy| ≤ p.
Pumping Lemma (CFL) ProofLet G be a CFG for CFL A. Let b be the maximum
number of symbols in the RHS of a rule (assume at
least 2) in G. In any parse tree, a node can have at
most b children. I.e., at most b
h
nodes are within h
steps to the start variable. (Implies height h limits string
to maximum length of b
h
. Conversely, if a string is at least b
h
+ 1
long, parse tree must be at least h + 1 high.)
|V| is number of variables in G. The pumping
length p = b
|V| + 1
. If s ∈ A and |s| ≥ p, parse tree
must be |V| + 1 high, because b
|V| + 1
≥ b
|V|
+ 1.
𝜏 is the smallest (least number of nodes) parse tree
of s. 𝜏 is at least |V| + 1 high, so the longest path
from root is at least |V| + 1.
That path has at least |V| + 2 nodes; one at a
terminal, all others are variables. Hence, that path
has at least |V| + 1 variables. With G having only
|V| variables, some variable R appears more than
once on that path. For convenience, we select R to
be a variable that repeats among the lowest |V| + 1
variables on this path (farthest from the root).
Divide s into uvxyz.
Each occurrence of R has a subtree. The upper
occurrence is larger and generates vxy. The lower
is smaller and generates x.
Pumping Lemma (CFL) Proof (cont.)Both subtrees are generated by R, so one may be
substituted for the other and still be a valid parse
tree. Replacing the smaller with the larger yields
uv
i
xy
i
z at each i > 1. Replacing larger by the
smaller yields uxz. This establishes condition 1 of
the lemma.
v and y are not both ε. If they were, the parse tree
obtained by pumping down would have fewer
nodes than 𝜏, but it would still generate s. This is
not possible because 𝜏 is a parse tree for s with the
least number of nodes, and is a contradiction. This
establishes condition 2.
In 𝜏, the upper R generates vxy. R was chosen to
fall within the bottom |V| + 1 variables on the path,
and we chose the longest path in the parse tree, so
the upper R is at most |V| + 1 high. This height can
generate a string of at most b
|V| + 1
= p. This
establishes condition 3. ∎
Compare the Pumpable PartsDFA Diagram CFG Parse Tree
Example applications of the Pumping Lemma (CFL)B = {an bn cn
| n ≥ 0}
Is this Language a Context Free Language?
● If Context Free, build a CFG or PDA
● If not Context Free, prove with Pumping
Lemma
Proof by Contradiction:
Assume B is a CFL, then Pumping Lemma
must hold.
p is the pumping length given by the PL.
Choose s to be ap bp cp
.
Because s ∈ B and |s| ≥ p, PL guarantees s can be
split into 5 pieces, s = uvxyz, where for any i ≥ 0,
uv
i
xy
i
z ∈ B. Consider 2 cases:
1. v and y each contain only one type of symbol.
uv
2
xy
2
z cannot contain equal numbers of a’s,
b’s and c’s. Thus a contradiction via condition
1 of PL.
2. Either v or y contains more than one type of
symbol. uv
2
xy
2
z may have same number of
a’s, b’s, and c’s, but will be out of order, which
is also a contradiction.
Contradiction is unavoidable, thus B is not Context
Free.
Example applications of the Pumping Lemma (CFL)C = {a
i
b
j
c
k
| 0 ≤ i ≤ j ≤ k}
Is this Language a Context Free Language?
● If Context Free, build a CFG or PDA
● If not Context Free, prove with Pumping
Lemma
Proof by Contradiction:
Assume C is a CFL, then Pumping Lemma
must hold.
p is the pumping length given by the PL.
Because s ∈ C and |s| ≥ p, PL guarantees s can be
split into 5 pieces, s = uvxyz, where for any i ≥ 0,
uv
i
xy
i
z ∈ C. Consider 2 cases:
1. v and y contain one type of symbol.
a. a’s in vy. Pump up.
b. b’s in vy. Pump up or down.
c. c’s in vy. Pump down.
2. Either v or y contains more than one type of
symbol.
a. a’s and b’s in vy. Pump up.
b. b’s and c’s in vy. Pump down.
Contradiction is unavoidable, thus C is not
Context Free.
Choose s to be ap bp cp
.
Example applications of the Pumping Lemma (CFL)D = {ww | w ∈ {0,1}*}
Is this Language a Context Free Language?
● If Context Free, build a CFG or PDA
● If not Context Free, prove with Pumping
Lemma
Proof by Contradiction:
Assume D is a CFL, then Pumping Lemma
must hold.
p is the pumping length given by the PL.
Because s ∈ D and |s| ≥ p, PL guarantees s can be
split into 5 pieces, s = uvxyz, where for any i ≥ 0,
uv
i
xy
i
z ∈ D. Remember condition 3: |vxy| ≤ p
1. vxy does not straddle midpoint of s. Pumping
renders s not in the form ww.
2. vxy straddles midpoint of s. Pumping renders
s in the form 0p 1i 0j 1p
, which is not in the
form ww.
Contradiction is unavoidable, thus D is not Context
Free.
Note: 0p 1 0p 1 is not a good choice for s!Choose s to be 0p 1p 0p 1p
.
Tools to prove that a
Language is not
Context Free:
The Pumping Lemma
Tools to prove that a
Language is
Context Free:
Context Free Grammar
Pushdown Automata
top related