You are on page 1of 64

THE PUMPING LEMMA

THE PUMPING LEMMA
Theorem. For any regular language L there exists an integer
n, such that for all x ∈ L with |x| ≥ n, there exist u, v, w ∈ Σ∗ ,
such that
(1) x = uvw
(2) |uv| ≤ n
(3) |v| ≥ 1
(4) for all i ≥ 0: uv i w ∈ L.

x
x
L

THE PUMPING LEMMA
Theorem. For any regular language L there exists an integer
n, such that for all x ∈ L with |x| ≥ n, there exist u, v, w ∈ Σ∗ ,
such that
(1) x = uvw
(2) |uv| ≤ n
(3) |v| ≥ 1
(4) for all i ≥ 0: uv i w ∈ L.

n

x
x
L

THE PUMPING LEMMA Theorem. such that for all x ∈ L with |x| ≥ n. v. For any regular language L there exists an integer n. such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) for all i ≥ 0: uv i w ∈ L. n x x L . there exist u. w ∈ Σ∗ .

n x x L . such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) for all i ≥ 0: uv i w ∈ L.THE PUMPING LEMMA Theorem. there exist u. For any regular language L there exists an integer n. v. w ∈ Σ∗ . such that for all x ∈ L with |x| ≥ n.

For any regular language L there exists an integer n. w ∈ Σ∗ . v. such that for all x ∈ L with |x| ≥ n. such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) for all i ≥ 0: uv i w ∈ L. there exist u.THE PUMPING LEMMA Theorem. n x u vx w L .

THE PUMPING LEMMA Theorem. w ∈ Σ∗ . n x u u w vx w L . there exist u. For any regular language L there exists an integer n. such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) for all i ≥ 0: uv i w ∈ L. such that for all x ∈ L with |x| ≥ n. v.

THE PUMPING LEMMA
Theorem. For any regular language L there exists an integer
n, such that for all x ∈ L with |x| ≥ n, there exist u, v, w ∈ Σ∗ ,
such that
(1) x = uvw
(2) |uv| ≤ n
(3) |v| ≥ 1
(4) for all i ≥ 0: uv i w ∈ L.

n

L

x
u
u
u

w
vx
w
v v

w

THE PUMPING LEMMA
Theorem. For any regular language L there exists an integer
n, such that for all x ∈ L with |x| ≥ n, there exist u, v, w ∈ Σ∗ ,
such that
(1) x = uvw
(2) |uv| ≤ n
(3) |v| ≥ 1
(4) for all i ≥ 0: uv i w ∈ L.

n

L

x
u
u
u
u

w
vx
w
v v
w
v v v

w

PROOF OF P.L. (SKETCH)

Take n be the number of states of M plus 1.L. .PROOF OF P. (SKETCH) Let M be a DFA for L.

L. Consider the path (from start state to an accepting state) in M that corresponds to x. (SKETCH) Let M be a DFA for L. The length of this path is |x| ≥ n.PROOF OF P. Take n be the number of states of M plus 1. Take any x ∈ L with |x| ≥ n. .

Consider the path (from start state to an accepting state) in M that corresponds to x. Take any x ∈ L with |x| ≥ n. Since M has at most n − 1 states. some state must be visited twice or more in the first n steps of the path. The length of this path is |x| ≥ n. Take n be the number of states of M plus 1. .L.PROOF OF P. (SKETCH) Let M be a DFA for L.

some state must be visited twice or more in the first n steps of the path. u w v . Since M has at most n − 1 states.PROOF OF P. (SKETCH) Let M be a DFA for L. Consider the path (from start state to an accepting state) in M that corresponds to x. Take n be the number of states of M plus 1.L. Take any x ∈ L with |x| ≥ n. The length of this path is |x| ≥ n.

L. Take any x ∈ L with |x| ≥ n. u w v uw ∈ L x = uvw ∈ L uvvw ∈ L uvvvw ∈ L ..PROOF OF P. some state must be visited twice or more in the first n steps of the path. Consider the path (from start state to an accepting state) in M that corresponds to x. . The length of this path is |x| ≥ n.. Take n be the number of states of M plus 1. Since M has at most n − 1 states. (SKETCH) Let M be a DFA for L.

L.L. v. . L non-regular =⇒ ? L non-regular ⇐= L doesn’t satisfy P. w ∈ Σ∗ all of these hold: (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) ∀ i ≥ 0: uv i w ∈ L. Negation: ∃ n ∈ N ∀ x ∈ L with |x| ≥ n ∃ u.USING PUMPING LEMMA TO PROVE NON-REGULARITY L regular =⇒ L satisfies P.

w ∈ Σ∗ all of these hold: (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) ∀ i ≥ 0: uv i w ∈ L. .L. v. Negation: ∃ n ∈ N ∀ x ∈ L with |x| ≥ n ∃ u. L non-regular =⇒ ? L non-regular ⇐= L doesn’t satisfy P.USING PUMPING LEMMA TO PROVE NON-REGULARITY L regular =⇒ L satisfies P.L.

L. v. Negation: ∃ n ∈ N ∀ x ∈ L with |x| ≥ n ∃ u. .USING PUMPING LEMMA TO PROVE NON-REGULARITY L regular =⇒ L satisfies P. v. w ∈ Σ∗ all of these hold: ∀ n ∈ N ∃ x ∈ L with |x| ≥ n ∀ u.L. L non-regular =⇒ ? L non-regular ⇐= L doesn’t satisfy P. (4) ∀ i ≥ 0: uv i w ∈ L. w ∈ Σ∗ not all of these hold: (1) x = uvw (1) x = uvw (2) |uv| ≤ n (2) |uv| ≤ n (3) |v| ≥ 1 (3) |v| ≥ 1 (4) ∀ i ≥ 0: uv i w ∈ L.

. L non-regular =⇒ ? L non-regular ⇐= L doesn’t satisfy P. v.L. v. w ∈ Σ∗ not all of these hold: (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) ∀ i ≥ 0: uv i w ∈ L.L.USING PUMPING LEMMA TO PROVE NON-REGULARITY L regular =⇒ L satisfies P. ∀ n ∈ N ∃ x ∈ L with |x| ≥ n ∀ u. w ∈ Σ∗ all of these hold: (1) x = uvw Equivalently: (2) |uv|(1) ≤∧n (2) ∧ (3) ⇒ not(4) where not(4) is: (3) |v| ≥ 1 i ∃ i : uv w �∈ L (4) ∀ i ≥ 0: uv i w ∈ L. Negation: ∃ n ∈ N ∀ x ∈ L with |x| ≥ n ∃ u.

EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. .

L. holds doesn’t mean regularity). Proof. doesn’t hold (note: showing P. .EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. Show that P.L.

.L.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular.L. holds doesn’t mean regularity). doesn’t hold (note: showing P. then by P. Show that P. ∃ n such that . . Proof. If L is regular. .L.

. holds doesn’t mean regularity). Proof. Show that P.L. then by P. ∃ n such that .L. doesn’t hold (note: showing P.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular.L. Now let x = 0n 1n . If L is regular. .

Show that P. . . Proof. v. ∃ n such that .EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. . then by P. doesn’t hold (note: showing P.L. ∃u. so by P. Now let x = 0n 1n x ∈ L and |x| ≥ n.L.L.L. w such that (1)–(4) hold. holds doesn’t mean regularity). If L is regular.

EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. .L. ∃u.L. . Show that P. doesn’t hold (note: showing P.L. We show that ∀ u. so by P. If L is regular. v. Now let x = 0n 1n x ∈ L and |x| ≥ n. w (1)–(4) don’t all hold. . Proof.L. ∃ n such that . holds doesn’t mean regularity). then by P. w such that (1)–(4) hold. v.

v. If (1). . If L is regular. We show that ∀ u. v.L. so by P.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. w (1)–(4) don’t all hold. . ∃ n such that . . doesn’t hold (note: showing P. holds doesn’t mean regularity). (2). then by P. (3) hold then x = 0n 1n = uvw with |uv| ≤ n and |v| ≥ 1.L. Now let x = 0n 1n x ∈ L and |x| ≥ n.L.L. Show that P. ∃u. w such that (1)–(4) hold. Proof.

w (1)–(4) don’t all hold.L. doesn’t hold (note: showing P. w such that (1)–(4) hold.L. So. If L is regular.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. If (1).L. ∃u. v = 0t .L. (2). Now let x = 0n 1n x ∈ L and |x| ≥ n. holds doesn’t mean regularity). . v. so by P. (3) hold then x = 0n 1n = uvw with |uv| ≤ n and |v| ≥ 1. . u = 0s . w = 0p 1n with . v. ∃ n such that . We show that ∀ u. Proof. Show that P. then by P.

L. Show that P. v = 0t . . (2). Now let x = 0n 1n x ∈ L and |x| ≥ n. v. (3) hold then x = 0n 1n = uvw with |uv| ≤ n and |v| ≥ 1. then by P. . u = 0s . holds doesn’t mean regularity). So. p ≥ 0. We show that ∀ u. s + t + p = n. doesn’t hold (note: showing P. v.L. If L is regular.L. w (1)–(4) don’t all hold. so by P. Proof. t ≥ 1. ∃u. . If (1). ∃ n such that .L. w such that (1)–(4) hold.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. w = 0p 1n with s + t ≤ n.

v. (3) hold then x = 0n 1n = uvw with |uv| ≤ n and |v| ≥ 1. . v. w (1)–(4) don’t all hold. (2). If L is regular. v = 0t . w such that (1)–(4) hold.L. ∃u. .L. u = 0s . Now let x = 0n 1n x ∈ L and |x| ≥ n.L. doesn’t hold (note: showing P. w = 0p 1n with s + t ≤ n. t ≥ 1. s + t + p = n. ∃ n such that . .L. So. then by P. We show that ∀ u. holds doesn’t mean regularity). Proof. Show that P. But then (4) fails for i = 0: p ≥ 0.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. If (1). so by P.

L.L. w (1)–(4) don’t all hold. ∃u. s + t + p = n. v. w such that (1)–(4) hold. .L. doesn’t hold (note: showing P. w = 0p 1n with s + t ≤ n. t ≥ 1. Show that P. v. But then (4) fails for i = 0: p ≥ 0. v = 0t . ∃ n such that . holds doesn’t mean regularity). If L is regular. (3) hold then x = 0n 1n = uvw with |uv| ≤ n and |v| ≥ 1. So. Proof. uv 0 w = uw = 0s 0p 1n = 0s+p 1n �∈ L. Now let x = 0n 1n x ∈ L and |x| ≥ n.L. If (1). so by P.EXAMPLE 1 Prove that L = {0i 1i : i ≥ 0} is NOT regular. u = 0s . . (2). since s + p �= n . then by P. We show that ∀ u.

w such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 (4) ∀ i ∈ N : uv i w ∈ L.IN PICTURE ∃ u. . v.

. . . . w such that (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 u v w � �� � ���� � �� � 00000 0 . 01111 . . v.IN PICTURE ∃ u. 1 ∈ L (4) ∀ i ∈ N : uv i w ∈ L.

w such that non-empty (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 u v w � �� � ���� � �� � 00000 0 . . . 01111 .IN PICTURE ∃ u. 1 ∈ L (4) ∀ i ∈ N : uv i w ∈ L. . . v. .

.IN PICTURE ∃ u. let i = 0. (2). . . If (1). w such that non-empty (1) x = uvw (2) |uv| ≤ n (3) |v| ≥ 1 u v w � �� � ���� � �� � 00000 0 . 1 ∈ L (4) ∀ i ∈ N : uv i w ∈ L. uw �∈ L. . v. . In particular. 01111 . (3) hold then (4) fails: it is not the case that for all i. uv i w is in L.

EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. .

EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular.L. We show that P. doesn’t hold. . Proof.

We show that P. If L is regular. . doesn’t hold. Proof. .EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular.L. . then by P.L. ∃ n such that .

Proof. . . ∃ n such that .L.L. doesn’t hold.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. Now let x = 0m where m ≥ n + 2 is prime. . then by P. We show that P. If L is regular.

w such that (1)–(4) hold. doesn’t hold. then by P. If L is regular. . We show that P. ∃ n such that . ∃u. v. so by P.L.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. .L. x ∈ L and |x| ≥ n. Now let x = 0m where m ≥ n + 2 is prime. . Proof.L.

Now let x = 0m where m ≥ n + 2 is prime. We show that P.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. x ∈ L and |x| ≥ n. . .L. so by P.L. If L is regular. v. doesn’t hold.L. Proof. then by P. . ∃u. We show that ∀ u. w (1)–(4) don’t all hold. v. ∃ n such that . w such that (1)–(4) hold.

If L is regular.L. ∃ n such that . We show that P. so by P. . Now let x = 0m where m ≥ n + 2 is prime. . then by P. .EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. then 0m = 0|u| 0|v| 0|w| . v. Proof. If 0m is written as 0m = uvw. w such that (1)–(4) hold. v.L. doesn’t hold.L. ∃u. We show that ∀ u. x ∈ L and |x| ≥ n. w (1)–(4) don’t all hold.

Proof. x ∈ L and |x| ≥ n. then by P. so by P. If L is regular. We show that P.L. . If |uv| ≤ n and |v| ≥ 1. ∃ n such that . w such that (1)–(4) hold. We show that ∀ u. v. Now let x = 0m where m ≥ n + 2 is prime. If 0m is written as 0m = uvw.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. ∃u. v. then consider i = |v| + |w|: . w (1)–(4) don’t all hold.L. .L. then 0m = 0|u| 0|v| 0|w| . doesn’t hold.

Proof. x ∈ L and |x| ≥ n. If |uv| ≤ n and |v| ≥ 1. v. w such that (1)–(4) hold. We show that P. w (1)–(4) don’t all hold. doesn’t hold. so by P. Now let x = 0m where m ≥ n + 2 is prime. ∃ n such that . If 0m is written as 0m = uvw. If L is regular. v. .L.L.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular. . then 0m = 0|u| 0|v| 0|w| . then by P.L. ∃u. We show that ∀ u. then consider i = |v| + |w|: i uv w = 0 0 0 |v| |v|(|v|+|w|) |w| = 0 (|v|+1)(|v|+|w|) �∈ L .

v. . then 0m = 0|u| 0|v| 0|w| . w such that (1)–(4) hold. then consider i = |v| + |w|: i uv w = 0 0 0 |v| |v|(|v|+|w|) |w| = 0 (|v|+1)(|v|+|w|) Both factors ≥ 2 �∈ L . w (1)–(4) don’t all hold. ∃u. If L is regular. Now let x = 0m where m ≥ n + 2 is prime. We show that ∀ u.L. doesn’t hold. .L. then by P. so by P. We show that P.L. ∃ n such that . v. Proof. If |uv| ≤ n and |v| ≥ 1. x ∈ L and |x| ≥ n. If 0m is written as 0m = uvw.EXAMPLE 2 Prove that L = {0i : i is a prime} is NOT regular.

1}∗ } is NOT regular. .EXAMPLE 3 Prove that L = {yy : y ∈ {0.

Again we try to show that P.EXAMPLE 3 Prove that L = {yy : y ∈ {0.L. doesn’t hold. 1}∗ } is NOT regular. .

then by P. . ∃ n such that . . 1}∗ } is NOT regular.L. doesn’t hold. .L. If L is regular. Again we try to show that P.EXAMPLE 3 Prove that L = {yy : y ∈ {0.

L.EXAMPLE 3 Prove that L = {yy : y ∈ {0. doesn’t hold. If L is regular. 1}∗ } is NOT regular.L. Let us consider x = 0n 0n ∈ L. then by P. . ∃ n such that . Obviously |x| ≥ n. . Again we try to show that P. .

1}∗ } is NOT regular. Again we try to show that P. ∃ n such that . .L.EXAMPLE 3 Prove that L = {yy : y ∈ {0. If L is regular. doesn’t hold. Let us consider x = 0n 0n ∈ L.L. . then by P. Obviously |x| ≥ n. Can 0n 0n be written as 0n 0n = uvw such that |uv| ≤ n |v| ≥ 1 and that for all i: uv i w ∈ L? .

Again we try to show that P. 1}∗ } is NOT regular. Obviously |x| ≥ n. Can 0n 0n be written as 0n 0n = uvw such that |uv| ≤ n |v| ≥ 1 and that for all i: uv i w ∈ L? YES! Let u = �. Let us consider x = 0n 0n ∈ L. If L is regular. .L.L. ∃ n such that . . doesn’t hold.EXAMPLE 3 Prove that L = {yy : y ∈ {0. v = 00. and w = 02n−2 . then by P. .

Let us consider x = 0n 0n ∈ L. Obviously |x| ≥ n.EXAMPLE 3 Prove that L = {yy : y ∈ {0. uv i w is of the form 02k = 0k 0k . v = 00. If L is regular. doesn’t hold. . 1}∗ } is NOT regular. . Again we try to show that P. then by P. Then ∀i . Can 0n 0n be written as 0n 0n = uvw such that |uv| ≤ n |v| ≥ 1 and that for all i: uv i w ∈ L? YES! Let u = �. ∃ n such that .L.L. . and w = 02n−2 .

. Does this mean that L is regular? . Again we try to show that P. Let us consider x = 0n 0n ∈ L. . then by P.L. 1}∗ } is NOT regular. Obviously |x| ≥ n. ∃ n such that . Then ∀i . and w = 02n−2 .EXAMPLE 3 Prove that L = {yy : y ∈ {0. uv i w is of the form 02k = 0k 0k . v = 00. doesn’t hold. If L is regular.L. Can 0n 0n be written as 0n 0n = uvw such that |uv| ≤ n |v| ≥ 1 and that for all i: uv i w ∈ L? YES! Let u = �.

Does this mean that L is regular? NO. We have chosen a bad string x. . 1}∗ } is NOT regular. To show that L fails the P. doesn’t hold. Then ∀i . v = 00. ∃ n such that . . Obviously |x| ≥ n. Let us consider x = 0n 0n ∈ L.EXAMPLE 3 Prove that L = {yy : y ∈ {0. and w = 02n−2 . If L is regular. .L.L. we only need to exhibit some x that cannot be “pumped” (and |x| ≥ n). Can 0n 0n be written as 0n 0n = uvw such that |uv| ≤ n |v| ≥ 1 and that for all i: uv i w ∈ L? YES! Let u = �. uv i w is of the form 02k = 0k 0k .. Again we try to show that P. then by P.L.

. 1}∗ } is NOT regular.EXAMPLE 3. 2ND ATTEMPT Prove that L = {yy : y ∈ {0.

let x = (01)n (01)n . 2ND ATTEMPT Prove that L = {yy : y ∈ {0. 1}∗ } is NOT regular.EXAMPLE 3. Obviously x ∈ L and |x| ≥ n. Given n from the P. .L..

2ND ATTEMPT Prove that L = {yy : y ∈ {0.EXAMPLE 3. v. let x = (01)n (01)n . Q: Can x be “pumped” for some choice of u. Given n from the P.L. 1}∗ } is NOT regular. Obviously x ∈ L and |x| ≥ n.. w with |uv| ≤ n and |v| ≥ 1? .

. Obviously x ∈ L and |x| ≥ n. w = (01)2n−2 . 2ND ATTEMPT Prove that L = {yy : y ∈ {0. Given n from the P.L. w with |uv| ≤ n and |v| ≥ 1? A: Yes! Take u = �.EXAMPLE 3. let x = (01)n (01)n . . v = 0101. 1}∗ } is NOT regular. v. Q: Can x be “pumped” for some choice of u.

w = (01)2n−2 . v. 1}∗ } is NOT regular. w with |uv| ≤ n and |v| ≥ 1? A: Yes! Take u = �. let x = (01)n (01)n . v = 0101. 2ND ATTEMPT Prove that L = {yy : y ∈ {0..L. Another bad choice of x! . Given n from the P. Q: Can x be “pumped” for some choice of u.EXAMPLE 3. Obviously x ∈ L and |x| ≥ n.

3RD ATTEMPT Prove that L = {yy : y ∈ {0. .EXAMPLE 3. 1}∗ } is NOT regular.

. Again x ∈ L and |x| ≥ n. let x = 0n 10n 1. 1}∗ } is NOT regular. Given n from the P.EXAMPLE 3..L. 3RD ATTEMPT Prove that L = {yy : y ∈ {0.

let x = 0n 10n 1. Given n from the P. 3RD ATTEMPT Prove that L = {yy : y ∈ {0. v.EXAMPLE 3. Again x ∈ L and |x| ≥ n. w such that 0n 10n 1 = uvw and |uv| ≤ n and |v| ≥ 1: .L.. ∀u. 1}∗ } is NOT regular.

1}∗ } is NOT regular. Thus consider .. w such that 0n 10n 1 = uvw and |uv| ≤ n and |v| ≥ 1: must have uv contained in the first group of 0n . v.EXAMPLE 3. let x = 0n 10n 1. 3RD ATTEMPT Prove that L = {yy : y ∈ {0. Again x ∈ L and |x| ≥ n.L. Given n from the P. ∀u.

let x = 0n 10n 1. Again x ∈ L and |x| ≥ n. v. Thus consider uv w = 0 0 n−|v| 10 1. Given n from the P. 3RD ATTEMPT Prove that L = {yy : y ∈ {0. ∀u. n .EXAMPLE 3.L. 1}∗ } is NOT regular. w such that 0n 10n 1 = uvw and |uv| ≤ n and |v| ≥ 1: must have uv contained in the first group of 0n ..

v. 1}∗ } is NOT regular. 3RD ATTEMPT Prove that L = {yy : y ∈ {0.. Thus consider uv w = 0 0 n−|v| 10 1. Given n from the P. this is clearly not of the form yy. let x = 0n 10n 1. ∀u. . Again x ∈ L and |x| ≥ n. n Since |v| is at least 1. w such that 0n 10n 1 = uvw and |uv| ≤ n and |v| ≥ 1: must have uv contained in the first group of 0n .EXAMPLE 3.L.