Pumping Lemma for Context-free Languages

1 / 72

# Pumping Lemma for Context-free Languages - PowerPoint PPT Presentation

Pumping Lemma for Context-free Languages. Take an infinite context-free language. Generates an infinite number of different strings. Example:. In a derivation of a “long” enough string, variables are repeated. A possible derivation:. Derivation Tree. Repeated variable. Derivation Tree.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## Pumping Lemma for Context-free Languages

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Pumping LemmaforContext-free Languages

Prof. Busch - LSU

Take an infinite context-free language

Generates an infinite number

of different strings

Example:

Prof. Busch - LSU

In a derivation of a “long” enough

string, variables are repeated

A possible derivation:

Prof. Busch - LSU

Derivation Tree

Repeated

variable

Prof. Busch - LSU

Derivation Tree

Repeated

variable

Prof. Busch - LSU

Putting all together

Prof. Busch - LSU

Repeat middle part times

1

i

Prof. Busch - LSU

For any

Prof. Busch - LSU

From Grammar

and given string

We inferred that a family of strings is in

for any

Prof. Busch - LSU

Arbitrary Grammars

Consider now an arbitrary infinite

context-free language

Let be the grammar of

Take so that it has no unit-productions

and no -productions

(remove them)

Prof. Busch - LSU

Let be the number of variables

Let be the maximum right-hand size

of any production

Example:

Prof. Busch - LSU

Claim:

Take string with .

Then in the derivation tree of

there is a path from the root to a leaf

where a variable of is repeated

Proof:

Prof. Busch - LSU

Derivation tree of

We will show:

some variable

is repeated

Prof. Busch - LSU

First we show that the tree of

has at least levels of nodes

Suppose the opposite:

At most

Levels

Prof. Busch - LSU

Maximum number of nodes per level

Level 0:

nodes

Level 1:

nodes

nodes

The maximum right-hand side of any production

Prof. Busch - LSU

Maximum number of nodes per level

Level 0:

nodes

Level 1:

nodes

Level 2:

nodes

nodes

nodes

nodes

Prof. Busch - LSU

Maximum number of nodes per level

Level 0:

nodes

At most

Level :

nodes

Levels

Level :

nodes

Maximum possible string length

= max nodes at level =

Prof. Busch - LSU

Therefore,

maximum length of string :

However we took,

Therefore,

the tree must have at least levels

Prof. Busch - LSU

Thus, there is a path from the root

to a leaf with at least nodes

(root)

At least

Variables

Levels

symbol

(leaf)

Prof. Busch - LSU

Since there are at most different variables,

some variable is repeated

Pigeonhole

principle

END OF CLAIM PROOF

Prof. Busch - LSU

Take now a string

with

From claim:

some variable

is repeated

subtree of

Take to be the deepest, so that

only is repeated in subtree

Prof. Busch - LSU

We can write

yield

yield

yield

yield

yield

Strings of terminals

Prof. Busch - LSU

Example:

Prof. Busch - LSU

Possible derivations

Prof. Busch - LSU

Example:

Prof. Busch - LSU

Remove Middle Part

Yield:

Prof. Busch - LSU

Repeat Middle part two times

1

2

Yield:

Prof. Busch - LSU

Repeat Middle part times

1

i

Yield:

Prof. Busch - LSU

Therefore,

If we know that:

then we also know:

For all

since

Prof. Busch - LSU

Observation 1:

Since has no

unit and

-productions

At least one of or is not

Prof. Busch - LSU

Observation 2:

since in subtree

only variable

is repeated

subtree of

Explanation follows….

Prof. Busch - LSU

subtree of

Various yields

since no variable is repeated in

Maximum right-hand side of any production

Prof. Busch - LSU

Thus, if we choose critical length

then, we obtain the pumping lemma for

context-free languages

Prof. Busch - LSU

The Pumping Lemma:

For any infinite context-free language

there exists an integer such that

for any string

we can write

with lengths

and it must be that:

Prof. Busch - LSU

### Applicationsof The Pumping Lemma

Prof. Busch - LSU

Non-context free languages

Context-free languages

Prof. Busch - LSU

Theorem:

The language

is not context free

Proof:

Use the Pumping Lemma

for context-free languages

Prof. Busch - LSU

is context-free

Since is context-free and infinite

we can apply the pumping lemma

Prof. Busch - LSU

Let be the critical length

of the pumping lemma

Pick any string with length

We pick:

Prof. Busch - LSU

From pumping lemma:

we can write:

with lengths and

Prof. Busch - LSU

Pumping Lemma says:

for all

Prof. Busch - LSU

We examine all the possible locations

of string in

Prof. Busch - LSU

Case 1:

is in

Prof. Busch - LSU

From Pumping Lemma:

However:

Prof. Busch - LSU

Case 2:

is in

Similar to case 1

Prof. Busch - LSU

Case 3:

is in

Similar to case 1

Prof. Busch - LSU

Case 4:

overlaps and

Prof. Busch - LSU

Sub-case 1:

contains only

contains only

Prof. Busch - LSU

From Pumping Lemma:

However:

Prof. Busch - LSU

Sub-case 2:

contains and

contains only

Prof. Busch - LSU

By assumption

Prof. Busch - LSU

From Pumping Lemma:

However:

Prof. Busch - LSU

Sub-case 3:

contains only

contains and

Similar to sub-case 2

Prof. Busch - LSU

Case 5:

overlaps and

Similar to case 4

Prof. Busch - LSU

Case 6:

overlaps , and

Impossible!

Prof. Busch - LSU

In all cases we obtained a contradiction

Therefore:

the original assumption that

is context-free must be wrong

Conclusion:

is not context-free

Prof. Busch - LSU