Professional Documents
Culture Documents
for
Context-Free Languages
1
Take an infinite context-free language
Example: S AB
A aBb
B Sb
Bb
2
S AB
A aBb
B Sb
Bb In a derivation of a long string,
variables are repeated
A derivation:
S AB aBbB abbB
abbSb abbABb abbaBbBb
abbabbBb abbabbbb
3
Derivation tree string abbabbbb
S
A B
a B b S b
b A B
a B b b
b
4
Derivation tree string abbabbbb
S
A B
a B b S b
b A B
a B b b
repeated b
5
B Sb ABb B
aBbBb aBbbb S b
A B
a B b b
b
*
B aBbbb Bb
6
Repeated Part B
S b
A B
a B b b
*
B aBbbb
7
B
Another possible
derivation from B S b
* A B
B aBbbb a B b b
S b
A B
a B b b
* *
B aBbbb aaBbbbbbb
8
B
S b
* A B
B aBbbb a B b b
S b
A B
a B b b
* *
2 2
B (a ) B (bbb) (a ) B (bbb)
9
A Derivation from S
S
*
S abbB A B
a B b
*
B aBbbb b
Bb
*
S abbBb
10
S
*
A B
S abbB
a B b b
*
B aBbbb b
Bb
*
0 0
S abbB abbb abb(a ) b(bbb)
11
* *
S abbB B aBbbb Bb
*
0 0
S abb(a ) b(bbb)
0 0
abb(a) b(bbb) L(G )
12
A Derivation from S
S
*
S abbB A B
a B b
*
B aBbbb b
Bb
*
S abbB
13
S
*
S abbB A B
* a B b S b
B aBbbb b A B
Bb a B b b
* *
S abbB abbaBbbb
14
S
*
S abbB A B
a
* B b S b
B aBbbb b A B
a B b b
Bb S b
A B
a B b b
* *
2 2
S abb(a ) B (bbb) abb(a ) B (bbb)
15
S
*
S abbB A B
a B b S b
*
B aBbbb b A B
a B b b
Bb S b
A B
a B b b
* *
2 2 2 2
S abb(a) B(bbb) abb(a) b(bbb)
16
* *
S abbB B aBbbb Bb
*
2 2
S abb(a ) b(bbb)
2 2
abb(a ) b(bbb) L(G )
17
A Derivation from S S
A B
*
S abbB a B b S b
* b A B
B aBbbb a B b b
Bb S b
A B
a B b b
*
2 2
S abb(a ) B (bbb)
18
S
* A B
S abbB a B b S b
* b A B
B aBbbb a B b b
Bb S b
A B
a B b b
S b
A B
a B b b
* *
2 2 3 3
S abb(a ) B (bbb) abb( a ) B (bbb)
19
S
* A B
S abbB a B b S b
* b A B
B aBbbb a B b b
S b
Bb A B
a B b b
S b
A B
a B b b
*
3 3 3 3
S abb(a ) B (bbb) abb(a) b(bbb)
20
* *
S abbB B aBbbb Bb
*
3 3
S abb(a) b(bbb)
3 3
abb(a) b(bbb) L(G )
21
In General:
* *
S abbB B aBbbb Bb
*
i i
S abb(a ) b(bbb)
i i
abb(a ) b(bbb) L(G ) i0
22
Consider now an infinite
context-free language L
Let m p 1
Example G : S AB
p 4 3 12
A aBb
B Sb m p 1 13
Bb
24
v1 v2 vk w
k Number of productions
in grammar
26
Derivation tree of string w
S
u z
Last repeated variable A
v y
w uvxyz
repeated A
u , v, x, y , z :
Strings of terminals
x 27
S
Possible
derivations: u z
A
S uAz
v y
A vAy A
A x
x 28
We know:
S uAz A vAy A x
*
S uAz uxz
0 0
uv xy z
29
We know:
S uAz A vAy A x
* *
S uAz uvAyz uvxyz
1 1
The original w uv xy z
30
We know:
S uAz A vAy A x
* * *
S uAz uvAyz uvvAyyz uvvxyyz
2 2
uv xy z
31
We know:
S uAz A vAy A x
i i
uv xy z
33
Therefore, any string of the form
i i
uv xy z i0
34
Therefore,
i i
we also know that uv xy z L(G )
L(G ) L {}
i i
uv xy z L
35
S
u z
A
v y
A
x
Observation: | vxy | m
Since A is the last repeated variable 36
S
u z
A
v y
A
x
Observation: | vy | 1
Since there are no unit or -productions 37
The Pumping Lemma:
For infinite context-free language L
there exists an integer m such that
39
Reminders
Choosing w :
• A good place to start is with a string that
incorporates the pumping length m in it somehow,
e.g. ambm if your alphabet is {a, b}.
• The right string can reduce the number of
different partitions you must consider.
• As you work through more and more examples of
these types of proofs, you gather insight into the
types of strings that will work best. So the best
way to get better at choosing w is to read
examples and, even better, to work problems.
40
Reminders
Choosing the partition of w :
• The thing to remember about the partition of w
into its parts u, v, x, y & z is, again, that
you don’t get to choose it!
• The partition is, in some sense, chosen for you.
But it is never explicitly given to you (the way you
can think of the pumping length as being given to
you), so you must consider all possible partitions.
• Remember, that for each partition of w, you must
show that for some integer i, the string uvixyiz is
not in L.
41
Reminders
Choosing i :
• You do get to choose this, and you’re given quite a
bit of freedom. You may pick i so that it is any
integer greater than 1, or even 0.
• It doesn’t make sense to select i = 1, since that
would describe w, a string which you already know
to be in L.)
• You may even choose i differently in different
cases of your proof. This is useful, for example,
if some cases work only if you “pump down” to i =
0, while others work only if you “pump up” to i = 2
or i = 3.
42
Cautions
• Be sure that the w you choose is actually in the
language L you are trying to prove something
about! If not, the pumping lemma doesn’t
guarantee anything about whether pumping that w
should give strings in L.
• Also, be sure that your string w is long enough: it
must have length at least m.
• In the pumping lemma for context-free
languages, when you pump a particular string, note
that the i describing the number of repetitions of
v must be the same i describing the number of
repetitions of y.
So it doesn’t help your proof to show a “pumped”
string uv0xy2z which is not in L, since 0 ≠ 2.
43