Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pumping Lemma for Context-Free Languages: A Comprehensive Guide, Study notes of Theory of Automata

A detailed explanation of the pumping lemma for context-free languages (cfls), a fundamental tool in formal language theory. It covers the lemma's statement, proof, and applications in proving languages are not context-free. The document also includes illustrative examples and a game view of the lemma, making it accessible to students of computer science and related fields.

Typology: Study notes

2024/2025

Available from 01/27/2025

urban-muses-studio
urban-muses-studio 🇮🇳

5 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 Pumping Lemma
1.1 Non-context-free languages
Non-Context Free Languages
Question
Are there languages that are not context-free? What about L={anbncn|n0}?
Answer
Lis not context-free, because
Recognizing if wLrequires remembering the number of as seen, bs seen and cs seen
We can remember one of them on the stack (say as) , and compare them to another (say bs)
by popping, but not to both bs and cs
The precise way to capture this intuition is through the pumping lemma
1.2 The Statement
Pumping Lemma for CFLs
Informal Statement
For all sufficiently long strings zin a context free language L, it is possible to find two substrings,
not too far apart, that can be simultaneously pumped to obtain more words in L.
Lemma 1. If Lis a CFL, then p(pumping length) such that zL, if |z| pthen u, v , w, x, y
such that z=uvwxy
1. |vwx| p
2. |vx|>0
3. i0. uviwxiyL
Proof
Defered to later in the lecture.
Two Pumping Lemmas side-by-side
Context-Free Languages
If Lis a CFL, then p(pumping length) such that zL, if |z| pthen u, v, w, x, y such that
z=uvwxy
1. |vwx| p
2. |vx|>0
1
pf3
pf4
pf5

Partial preview of the text

Download Pumping Lemma for Context-Free Languages: A Comprehensive Guide and more Study notes Theory of Automata in PDF only on Docsity!

1 Pumping Lemma

1.1 Non-context-free languages

Non-Context Free Languages

Question Are there languages that are not context-free? What about L = {anbncn^ | n ≥ 0 }?

Answer L is not context-free, because

  • Recognizing if w ∈ L requires remembering the number of as seen, bs seen and cs seen
  • We can remember one of them on the stack (say as) , and compare them to another (say bs) by popping, but not to both bs and cs

The precise way to capture this intuition is through the pumping lemma

1.2 The Statement

Pumping Lemma for CFLs Informal Statement

For all sufficiently long strings z in a context free language L, it is possible to find two substrings, not too far apart, that can be simultaneously pumped to obtain more words in L.

Lemma 1. If L is a CFL, then ∃p (pumping length) such that ∀z ∈ L, if |z| ≥ p then ∃u, v, w, x, y such that z = uvwxy

  1. |vwx| ≤ p
  2. |vx| > 0
  3. ∀i ≥ 0. uviwxiy ∈ L

Proof Defered to later in the lecture.

Two Pumping Lemmas side-by-side

Context-Free Languages If L is a CFL, then ∃p (pumping length) such that ∀z ∈ L, if |z| ≥ p then ∃u, v, w, x, y such that z = uvwxy

  1. |vwx| ≤ p
  2. |vx| > 0
  1. ∀i ≥ 0. uviwxiy ∈ L

Regular Languages If L is a regular language, then ∃p (pumping length) such that ∀z ∈ L, if |z| ≥ p then ∃u, v, w such that z = uvw

  1. |uv| ≤ p
  2. |v| > 0
  3. ∀i ≥ 0. uviw ∈ L

Pumping Lemma for CFLs Game View Game between Defender, who claims L satisfies the pumping condition, and Chal- lenger, who claims L does not.

Defender Challenger Pick pumping length p

p −→ ←−^ z Pick z ∈ L s.t. |z| ≥ p Divide z into u, v, w, x, y s.t. |vwx| ≤ p, and |vx| > 0

u,v,w,x,y −→ ←−^ i Pick i, s.t. uviwxiy 6 ∈ L

Pumping Lemma: If L is CFL, then there is always a winning strategy for the defender (i.e., challenger will get stuck). Pumping Lemma (in contrapositive): If there is a winning strategy for the challenger, then L is not CFL. Consequences of Pumping Lemma

  • If L is context-free then L satisfies the pumping lemma.
  • If L satisfies the pumping lemma that does not mean L is context-free
  • If L does not satisfy the pumping lemma (i.e., challenger can win the game, no matter what the defender does) then L is not context-free.

1.3 Examples

Example I

Proposition 2. Lanbncn = {anbncn^ | n ≥ 0 } is not a CFL.

Proof. Suppose Lanbncn is context-free. Let p be the pumping length.

Proof. Suppose E is context-free. Let p be the pumping length.

  • Consider z = 0p 1 p 0 p 1 p^ ∈ L.
  • Since |z| > p, there are u, v, w, x, y such that z = uvwxy, |vwx| ≤ p, |vx| > 0 and uviwxiy ∈ L for all i ≥ 0.
  • vwx must straddle the midpoint of z.
    • Suppose vwx is only in the first half. Then in uv^2 wx^2 y the second half starts with 1. Thus, it is not of the form ww.
    • Case when vwx is only in the second half. Then in uv^2 wx^2 y the first half ends in a 0. Thus, it is not of the form ww.
    • Suppose vwx straddles the middle. Then uv^0 wx^0 y must be of the form 0p 1 i 0 j^1 p, where either i or j is not p. Thus, uv^0 wx^0 y 6 ∈ E.

1.4 Proof of the Pumping Lemma: Informal Ideas

Proof of Pumping Lemma

Lemma 6. If L is a CFL, then ∃p (pumping length) such that ∀z ∈ L, if |z| ≥ p then ∃u, v, w, x, y such that z = uvwxy

  1. |vwx| ≤ p
  2. |vx| > 0
  3. ∀i ≥ 0. uviwxiy ∈ L

Let G be a CFG in Chomsky Normal Form such that L(G) = L. Let z be a “very long” string in L (“very long” made precise later).

S

z

A

A

u v w x y

Figure 1: Parse Tree for z

  • Since z ∈ L there is a parse tree for z
  • Since z is very long, the parse tree (which is a binary tree) must be “very tall”
  • The longest path in the tree, by pigeon hole principle, must have some variable (say) A repeat. Let u, v, w, x, y be as shown.

Pumping down and up

S

A

u

w

y

Figure 2: Pumping zero times

S

A

A

u v

A

v w x

x y

Figure 3: Pumping two times

  • Thus, uviwxiy has a parse tree, for any i.

1.5 Formal Proof

Proof of Pumping Lemma

Proof. Let G be a grammar in Chomsky Normal Form with k variables such that L(G) = L. Take p = 2k. Consider z ∈ L such that |z| ≥ p = 2k.

  • Consider a parse tree for z. Height of this tree is at least k + 1. For proof see Homework 6, problem 3.
  • Repeated Variables: