0% found this document useful (0 votes)
62 views19 pages

Pumping Lemma For Context-Free Languages: CSCI 3130 Formal Languages and Automata Theory

This document discusses the pumping lemma for context-free languages and uses it to determine whether certain languages are context-free or not. It begins by introducing the pumping lemma, which states that for any context-free language L and string s in L of length greater than m, s can be split into uvwxy such that uv^iwx^iy is in L for all i. It then shows examples of using the pumping lemma to prove languages like {a^n b^n c^n} are not context-free, since for any split of a long string, uv^2wx^2y would not be in the language. The document concludes by determining which of several example languages are context-free using

Uploaded by

Wafa Elgalhoud
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)
62 views19 pages

Pumping Lemma For Context-Free Languages: CSCI 3130 Formal Languages and Automata Theory

This document discusses the pumping lemma for context-free languages and uses it to determine whether certain languages are context-free or not. It begins by introducing the pumping lemma, which states that for any context-free language L and string s in L of length greater than m, s can be split into uvwxy such that uv^iwx^iy is in L for all i. It then shows examples of using the pumping lemma to prove languages like {a^n b^n c^n} are not context-free, since for any split of a long string, uv^2wx^2y would not be in the language. The document concludes by determining which of several example languages are context-free using

Uploaded by

Wafa Elgalhoud
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/ 19

Pumping Lemma for Context-Free Languages

CSCI 3130 Formal Languages and Automata Theory

Siu On CHAN
Fall 2018
Chinese University of Hong Kong

1/18
regular
context-free

L1 = {an bn | n > 0}
L2 = {z | z has the same number of a’s and b’s}
L3 = {an bn cn | n > 0}
L4 = {zz R | z ∈ {a, b}∗ }
L5 = {zz | z ∈ {a, b}∗ }

These languages are not regular


Are they context-free?

2/18
An attempt

L3 = {an bn cn | n > 0}

Let’s try to design a CFG or PDA

S → aBc | ε read a / push x


read b / pop x
B → ???
???

3/18
Suppose we could construct some CFG G for L3
S ⇒ CC
⇒ SBC
e.g. ⇒ SCSC
S → CC | BC | a ⇒ SSBSC
B → CS | b ⇒ SSBBCC
C → SB | c ⇒ aSBBCC
⇒ aaBBCC
How does a long
⇒ aabBCC
derivation look like?
⇒ aabbCC
⇒ aabbcC
⇒ aabbcc

4/18
Repetition in long derivations

If a derivation is long enough, some variable must appear twice on


the same root-to-leave path in a parse tree
S ⇒ CC
⇒ SBC
⇒ SCSC S
⇒ SSBSC C C
⇒ SSBBCC S B c
⇒ aSBBCC
a C S
⇒ aaBBCC
S B B C
⇒ aabBCC
⇒ aabbCC a b b c

⇒ aabbcC
⇒ aabbcc
5/18
Pumping example

Then we can “cut and paste” part of parse tree

S
S C C
C C S B c

S B c a C S
a C S S B B C
S B B C a C S b c
a b b c S B B C

aabbcc a b b c

aaabbcbcc

6/18
Pumping example

We can repeat this many times


aabbcc ⇒ aaabbcbcc ⇒ aaaabbcbcbcc ⇒ . . .
⇒ (a)i ab(bc)i c

Every sufficiently large derivation will have a middle part that can be
repeated indefinitely

7/18
Pumping in general

u
u A y

u A y v

A y v A x u
v A x v A y

A x v A x w
w A x v uwy
uvwxy w A x
2 2
uv wx y w
uv wx 3 y
3

8/18
Example

L3 = {an bn cn | n > 0}

If L3 has a context-free grammar G, then for any sufficiently long


s ∈ L(G)

s can be split into s = uvwxy such that L(G) also contains uv 2 wx 2 y,


uv 3 wx 3 y, …

What happens if s = am bm cm

No matter how it is split, uv 2 wx 2 y ∈


/ L3

9/18
Pumping lemma for context-free languages

For every context-free language L


There exists a number m such that for every long string s in L
(|s| > m), we can write s = uvwxy where
1. |vwx| 6 m
2. |vx| > 1
3. For every i > 0, the string uv i wx i y is in L

At least
one is
non-empty

u v w x y

6m

10/18
Pumping lemma for context-free languages

To prove L is not context-free, it is enough to show that

For every m there is a long string s ∈ L, |s| > m, such that for every
way of writing s = uvwxy where

1. |vwx| 6 m
2. |vx| > 1

there is i > 0 such that uv i wx i y is not in L

11/18
Using the pumping lemma

L3 = {an bn cn | n > 0}

1. for every m
2. there is s = am bm cm (at least m symbols)
3. no matter how the pumping lemma splits s into uvwxy
(|vwx| 6 m, |vx| > 1)
4. uv 2 wx 2 y ∈
/ L3 (but why?)

12/18
Using the pumping lemma

Case 1: v or x contains two kinds of symbols


aa aabb
| {z } bbcccc
v
2 2
Then uv wx y ∈
/ L3 because the pattern is wrong

Case 2: v and x both contain (at most) one kind of symbol


aaa |{z}
a b |{z}
bb bcccc
v x
2 2
Then uv wx y does not have the same number of a’s, b’s and c’s

Conclusion: uv 2 wx 2 y ∈
/ L3

13/18
Which is context-free?

L1 = {an bn | n > 0} 3
L2 = {z | z has the same number of a’s and b’s} 3
n n n
L3 = {a b c | n > 0} 7
R
L4 = {zz | z ∈ {a, b} }∗
3
L5 = {zz | z ∈ {a, b} } ∗

14/18
Example

L5 = {zz | z ∈ {a, b}∗ }

1. for every m
2. there is s = am bam b (at least m symbols)
3. no matter how the pumping lemma splits s into uvwxy
(|vwx| 6 m, |vx| > 1)
4. Is uv 2 wx 2 y ∈
/ L5 ?

15/18
Example

L5 = {zz | z ∈ {a, b}∗ }

1. for every m
2. there is s = am bam b (at least m symbols)
3. no matter how the pumping lemma splits s into uvwxy
(|vwx| 6 m, |vx| > 1)
4. Is uv 2 wx 2 y ∈
/ L5 ?

aaa |{z}
a aba |{z}
a aaab
v x

15/18
Example

L5 = {zz | z ∈ {a, b}∗ }

1. for every m
2. there is s = am bm am bm (at least m symbols)
3. no matter how the pumping lemma splits s into uvwxy
(|vwx| 6 m, |vx| > 1)
4. Is uv i wx i y ∈
/ L5 for some i?

Recall that |vwx| 6 m

16/18
Example

Three cases

Case 1 aaa aabbb


| {z } bbaaaaabbbbb
vwx
vwx is in the first half of am bm am bm

Case 2 aaaaabb bbbaa


| {z } aaabbbbb
vwx
vwx is in the middle part of am bm am bm

Case 3 aaaaabbbbbaaa aabbb


| {z } bb
vwx
vwx is in the second half of am bm am bm

17/18
Example

Apply pumping lemma with i = 0

Case 1 aaa aabbb


| {z } bbaaaaabbbbb
vwx
uwy becomes aj bk am bm , where j < m or k < m

Case 2 aaaaabb bbbaa


| {z } aaabbbbb
vwx
uwy becomes am bj ak bm , where j < m or k < m

Case 3 aaaaabbbbbaaa aabbb


| {z } bb
vwx
uwy becomes am bm aj bk , where j < m or k < m

Not of the form zz


This covers all cases, so L5 is not context-free
18/18

You might also like