0% found this document useful (0 votes)
245 views43 pages

The Pumping Lemma For Context-Free Languages

The Pumping Lemma states that for any context-free language that generates an infinite number of strings, there must exist a string length such that strings of that length or longer can be broken down into five parts that can be pumped or repeated to generate new strings while preserving membership in the language. Specifically: 1) Take an infinite context-free language and its generating grammar 2) The grammar must have a pumping length p, defined as the number of productions times the largest right side, plus one 3) For any string in the language of length at least p, the string can be broken into parts where one part repeats to generate new strings in the language

Uploaded by

Teja Anumolu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
245 views43 pages

The Pumping Lemma For Context-Free Languages

The Pumping Lemma states that for any context-free language that generates an infinite number of strings, there must exist a string length such that strings of that length or longer can be broken down into five parts that can be pumped or repeated to generate new strings while preserving membership in the language. Specifically: 1) Take an infinite context-free language and its generating grammar 2) The grammar must have a pumping length p, defined as the number of productions times the largest right side, plus one 3) For any string in the language of length at least p, the string can be broken into parts where one part repeats to generate new strings in the language

Uploaded by

Teja Anumolu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

The Pumping Lemma

for
Context-Free Languages

1
Take an infinite context-free language

Generates an infinite number


of different strings

Example: S  AB
A  aBb
B  Sb
Bb
2
S  AB
A  aBb
B  Sb
Bb 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 Bb
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

Bb

*
S  abbBb
10
S
*
A B
S  abbB
a B b b
*
B  aBbbb b

Bb

*
0 0
S  abbB  abbb  abb(a ) b(bbb)

11
* *
S  abbB B  aBbbb Bb

*
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

Bb
*
S  abbB

13
S
*
S  abbB A B

* a B b S b

B  aBbbb b A B

Bb 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
Bb 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

Bb 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 Bb

*
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

Bb 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

Bb 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
Bb 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 Bb

*
3 3
S  abb(a) b(bbb)

3 3
abb(a) b(bbb)  L(G )
21
In General:

* *
S  abbB B  aBbbb Bb

*
i i
S  abb(a ) b(bbb)

i i
abb(a ) b(bbb)  L(G ) i0
22
Consider now an infinite
context-free language L

Let G be the grammar of L  {}

Take G so that it has no unit-productions


no  -productions
23
Let p = (Number of productions) x
(Largest right side of a production)
 (G )

Let m  p 1
Example G : S  AB
p  4  3  12
A  aBb
B  Sb m  p  1  13
Bb
24
v1  v2    vk  w
k Number of productions
in grammar

Some production must be repeated


v1    a1 Aa2    a3 Aa4    w
S  r1
Repeated A  r2
B  r2
variable

25
w L(G ) | w | m
Derivation of string w
S    a1 Aa2    a3 Aa4    w

Some variable is repeated

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

This string is also generated:

 *
S  uAz  uxz

0 0
uv xy z
29
We know:
  
S  uAz A  vAy A x

This string is also generated:

 * *
S  uAz  uvAyz  uvxyz

1 1
The original w  uv xy z
30
We know:
  
S  uAz A  vAy A x

This string is also generated:

 * * *
S  uAz  uvAyz  uvvAyyz  uvvxyyz

2 2
uv xy z
31
We know:
  
S  uAz A  vAy A x

This string is also generated:


 * *
S  uAz  uvAyz  uvvAyyz 
* *
 uvvvAyyyz  uvvvxyyyz
3 3
uv xy z
32
We know:
  
S  uAz A  vAy A x
This string is also generated:
* uAz 
S * uvAyz 
* uvvAyyz *
* uvvvAyyyz 
* 
* uvvvvAy  yyyz *

* uvvvvxy  yyyz

i i
uv xy z
33
Therefore, any string of the form

i i
uv xy z i0

is generated by the grammar G

34
Therefore,

knowing that uvxyz  L(G )

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

for any string w  L, | w | m


we can write w  uvxyz
with lengths | vxy | m and | vy | 1
and it must be:
i i
uv xy z  L, for all i  0
38
Reminders
Choosing m :

• The thing to remember about the pumping length


m is that you don’t get to choose it!
• The pumping lemma itself “supplies” this value to
you. So you cannot make any assumption about
what the value of m is, you simply must use it as a
fixed value over which you have no control.

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

You might also like