CDT314
This presentation is the property of its rightful owner.
Sponsored Links
1 / 154

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 10 PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on
  • Presentation posted in: General

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 10 Mälardalen University 2012. Content The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL Example of Midterm Exam 2 (CFL). The Pumping Lemma for Context-Free Languages.

Download Presentation

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 10

An Image/Link below is provided (as is) to download presentation

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


Cdt314 faber formal languages automata and models of computation lecture 10

CDT314

FABER

Formal Languages, Automata and Models of Computation

Lecture 10

Mälardalen University

2012


Cdt314 faber formal languages automata and models of computation lecture 10

ContentThe Pumping Lemma for CFLApplications of the Pumping Lemma for CFLExample of Midterm Exam 2 (CFL)


The pumping lemma for context free languages

The Pumping LemmaforContext-Free Languages

Based on C Busch, RPI, Models of Computation


Cdt314 faber formal languages automata and models of computation lecture 10

Take an infinite context-free language.

It generates an infinite number of different strings:

Example:


Cdt314 faber formal languages automata and models of computation lecture 10

A derivation


Cdt314 faber formal languages automata and models of computation lecture 10

string

Derivation tree


Cdt314 faber formal languages automata and models of computation lecture 10

string

Derivation tree

repeated


Cdt314 faber formal languages automata and models of computation lecture 10

Repeated part


Cdt314 faber formal languages automata and models of computation lecture 10

Another possible derivation


Cdt314 faber formal languages automata and models of computation lecture 10

derivation


Cdt314 faber formal languages automata and models of computation lecture 10

derivation


Cdt314 faber formal languages automata and models of computation lecture 10

derivation


Cdt314 faber formal languages automata and models of computation lecture 10

Therefore, the string

is also generated by the grammar


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

We also know the following string is generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

Therefore, the following string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

Therefore, the following string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

Therefore, the following string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

Therefore, knowing that

is generated by grammar

We also know that

is generated by


Cdt314 faber formal languages automata and models of computation lecture 10

We are given an infinite

context-free grammar .

In general

Assume has no unit-productions

and no -productions.


Cdt314 faber formal languages automata and models of computation lecture 10

Take a string

with length bigger than

(Number of productions) x

(Largest right side of a production)

>

Consequence:

Some variable must be repeated

in the derivation of .


Cdt314 faber formal languages automata and models of computation lecture 10

string

Last repeated variable

repeated

stringsof terminals


Cdt314 faber formal languages automata and models of computation lecture 10

Possible

derivations


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

Following string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

This string is also generated:

The original


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

This string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

This string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

We know:

This string is also generated:


Cdt314 faber formal languages automata and models of computation lecture 10

Therefore, any string of the form

is generated by the grammar


Cdt314 faber formal languages automata and models of computation lecture 10

Therefore

knowing that

we also know that


Cdt314 faber formal languages automata and models of computation lecture 10

(Number of productions) x

(Largest right side of a production)

Observation:

Since is the last repeated variable

A string has length bigger than

>


Cdt314 faber formal languages automata and models of computation lecture 10

Observation

Since there are no unit or productions


Cdt314 faber formal languages automata and models of computation lecture 10

For infinite context-free language

there exists an integer such that

for any string

we can write

with lengths

and

The Pumping Lemma for CFL


Applications of the pumping lemma for cfl

Applicationsof The Pumping Lemma for CFL


Cdt314 faber formal languages automata and models of computation lecture 10

Unrestricted grammarlanguages

Non-regular languages

Context-Free Languages

Regular Languages


Cdt314 faber formal languages automata and models of computation lecture 10

Example

Theorem

The language

is not context free.

Proof

Use the Pumping Lemma

for context-free languages.


Cdt314 faber formal languages automata and models of computation lecture 10

Assume thecontrary, that

is context-free.

Since is context-free and infinite

we can apply the pumping lemma.


Cdt314 faber formal languages automata and models of computation lecture 10

Pumping Lemma gives a number

such that:

for any string with length

We can choose e.g.


Cdt314 faber formal languages automata and models of computation lecture 10

We can write:

with lengths and


Cdt314 faber formal languages automata and models of computation lecture 10

Pumping Lemma says:

for all


Cdt314 faber formal languages automata and models of computation lecture 10

We examine all the possible locations

of string in


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

is within


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

and consist from only


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

Repeating and


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

From Pumping Lemma:


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

From Pumping Lemma:

However:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2:

is within


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2: Similar analysis to case 1


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3:

is within


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3: Similar analysis to case 1


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

overlaps and


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

contains only

Possibility 1:

contains only


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

Possibility 1:

contains only

contains only


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

From Pumping Lemma:


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

From Pumping Lemma:

However:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

Possibility 2:

contains and

contains only


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

Possibility 2:

contains and

contains only


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

From Pumping Lemma:


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

From Pumping Lemma:

However:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

Possibility 3:

contains only

contains and


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4: Possibility 3: contains only

contains and

Similar analysis with Possibility 2


Cdt314 faber formal languages automata and models of computation lecture 10

Case 5:

overlaps and


Cdt314 faber formal languages automata and models of computation lecture 10

Case 5: Similar analysis to case 4


Cdt314 faber formal languages automata and models of computation lecture 10

(Since , string cannot

overlap , and at the same time)

There are no other cases to consider.


Cdt314 faber formal languages automata and models of computation lecture 10

In all cases we obtain a contradiction.

Therefore:

The original assumption that

is context-free must be wrong.

Conclusion:

is not context-free.

END OF PROOF


Comparison between the pumping lemma for context free and regular languages

Comparison between the Pumping Lemma for Context Free and Regular Languages


What is the difference between context free languages and regular languages

......

......

What is the difference between Context Free Languages and Regular Languages?

In regular languages a single symbol/substring in the string w can be “pumped”.


The difference between context free languages and regular languages

The difference between Context Free Languages and Regular Languages

In CFL’s multiple symbols/substrings in the string w can be “pumped”.

Consider the language {an bn | n > 0}

No single symbol can be pumped and allow us to stay in the language.

However, there do exist pairs of symbols which can be pumped resulting in strings which stay in the language.

Thus a CFL pumping lemma applies.


Cdt314 faber formal languages automata and models of computation lecture 10

CFG productions


Cdt314 faber formal languages automata and models of computation lecture 10

stringsof terminals

String

Last repeated variable

repeated


Pumping conditions for rl and cfl

A language L satisfies the RLpumping condition if:

there exists an integer m > 0 such that

for all strings w in L of length at least m

there exist strings x, y, zsuch that

w = xyzand

|xy| ≤ mand

|y| ≥ 1and

for all i ≥ 0, xyizis in L

|xy| ≤ m is in the beginning of the w and can be pumped within m symbols.

A language L satisfies theCFLpumping condition if:

there exists an integer m > 0such that

for all strings w in L of length at least m

there exist strings u, v, x, y, z such that

w = uvxyzand

|vxy| ≤ mand

|vy| ≥ 1and

for all i ≥ 0, uvixyiz is in L

|vxy| ≤ mand u comes first in the w and it can be arbitrarily long.

Pumping Conditions for RL and CFL


Pumping lemma

CFL’s

“Pumping Languages”

All languages over {a,b}

Pumping Lemma

All CFL’s satisfy the CFL pumping condition

But some languages that satisfy CFL pumping condition are not CFL!


Implications

Implications

CFL’s

“Pumping Languages”

All languages over {a,b}

We can use the pumping lemma to prove a language Lis not a CFL.

Show that L does not satisfy the CFL pumping condition.

We cannot use the pumping lemma to prove a language is CFL.

Showing L satisfies the pumping condition does not guarantee that L is context-free.


Pumping lemma1

Pumping Lemma

What does it mean?


Pumping condition

Pumping Condition

  • A language L satisfies the CFL pumping condition if:

    • there exists an integer m > 0such that

    • for all strings w in L of length at least m

    • there exist strings u, v, x, y, zsuch that

      • w = uvxyzand

      • |vxy| ≤ m and

      • |vy| ≥ 1 and

        Then for all i ≥ 0, uviwyizis in L


V and y can be pumped

v and y can be pumped

1) w in L2) w = uvxyz3) for all i ≥ 0, uvixyiz is in L

  • Let w = abcdefgbe in L

  • Then there exist substrings v and y in w such that v and y can be repeated (pumped) and the resulting string is still in L:

    uvixyiz is in L for all i ≥ 0


Cdt314 faber formal languages automata and models of computation lecture 10

For example w =abcdefg

v = cdand y = f

uv0xy0z = uxz =abegis in L

uv1xy1z = uvxyz = abcdefgis in L

uv2xy2z = uvvxyyz = abcdcdeffgis in L

uv3xy3z = uvvvxyyyz = abcdcdcdefffg is in L


What the other parts mean

What the other parts mean

A language L satisfies the CFL pumping condition if:

there exists an integer m > 0 such that

for all strings w in L of length at least m

w must be in L


What the other parts mean1

What the other parts mean

There exist strings u, v, x, y, z such that

  • w = uvxyz and

  • |vxy| ≤ m and

    v and y are contained within m characters of w

    Note: these are NOT necessarily the first m characters of w

    |vy| ≥ 1

    (v and y cannot both be , one of them might be , but not both)

  • For all i ≥ 0, uvixyiz is in L


Applying cfl pumping lemma to prove that a language l is not context free

APPLYING CFL PUMPING LEMMA TO PROVE THAT A LANGUAGE LIS NOT CONTEXT-FREE


How we use the pumping lemma

How we use the Pumping Lemma

  • We choose a specific language L.

  • We show that L does not satisfy the pumping condition.

  • We conclude that L is not context-free.


Showing that l does not pump

A language L satisfies the CFL pumping condition if:

there exists an integer m > 0 such that

for all strings w in L of length at least m

there exist strings u, v, x, y, z such that

w = uvxyz and

|vxy| ≤ m and

|vy| ≥ 1 and

for all i ≥ 0, uvixyiz is in L

A language L does not satisfy the CFL pumping condition if:

for all integers m of sufficient size

there exists a string w in L of length at least m such that

for all strings u, v, x, y, z where

w = uvxyz and

|vxy| ≤ m and

|vy| ≥ 1

there exists a i ≥ 0 such that uvixyiz is not in L

Showing that L “does not pump”


Cdt314 faber formal languages automata and models of computation lecture 10

Unrestricted grammarlanguages

Non-regular languages

Context-Free Languages

Regular Languages


More pumping lemma applications

More Pumping Lemma Applications


Cdt314 faber formal languages automata and models of computation lecture 10

For infinite context-free language

there exists an integer such that

for any string

we can write

with lengths

then

The Pumping Lemma for CFL

and


Cdt314 faber formal languages automata and models of computation lecture 10

Example

Theorem

The language

is not context free.

Proof

Use the Pumping Lemma

for context-free languages.


Cdt314 faber formal languages automata and models of computation lecture 10

Assume the contrary - that

is context-free.

Since is context-free and infinite

we can apply the pumping lemma.


Cdt314 faber formal languages automata and models of computation lecture 10

Pumping Lemma gives a number

such that we can

pick any string of

with length at least

So we pick:


Cdt314 faber formal languages automata and models of computation lecture 10

and

with lengths

We can write:

Pumping Lemma says:

for all


Cdt314 faber formal languages automata and models of computation lecture 10

We examine all the possible locations

of string in


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

is within the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

is within the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

is within the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 1:

is within the first

However, from Pumping Lemma:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2:

is in the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2:

is in the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2:

is in the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 2:

is in the first

is in the first

However, from Pumping Lemma:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3:

overlaps the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3:

overlaps the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3:

overlaps the first

is in the first


Cdt314 faber formal languages automata and models of computation lecture 10

Case 3:

overlaps the first

is in the first

However, from Pumping Lemma:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

Case 4:

in the first

overlaps the first

Analysis is similar to case 3


Cdt314 faber formal languages automata and models of computation lecture 10

or

or

Other cases:

is within

Analysis is similar to case 1:


Cdt314 faber formal languages automata and models of computation lecture 10

More cases:

overlaps

or

Analysis is similar to cases 2,3,4:


Cdt314 faber formal languages automata and models of computation lecture 10

There are no other cases to consider.

Since , it is impossible for

to overlap:

neither

nor

nor


Cdt314 faber formal languages automata and models of computation lecture 10

is not context-free.

In all cases we obtain a contradiction.

Therefore:

The original assumption that

is context-free must be wrong.

Conclusion:

END OF PROOF


Cdt314 faber formal languages automata and models of computation lecture 10

Unrestricted grammarlanguages

Non-regular languages

Context-Free Languages

Regular Languages


Cdt314 faber formal languages automata and models of computation lecture 10

Example

Theorem

The language

is not context free.

Proof

Use the Pumping Lemma

for context-free languages.


Cdt314 faber formal languages automata and models of computation lecture 10

Since is context-free and infinite

we can apply the pumping lemma.

Assume to the contrary that

is context-free.


Cdt314 faber formal languages automata and models of computation lecture 10

Pumping Lemma gives a number

such that we can:

pick any string of with length at least

so we pick:


Cdt314 faber formal languages automata and models of computation lecture 10

We can write:

with lengths

and

Pumping Lemma says:

for all


Cdt314 faber formal languages automata and models of computation lecture 10

We examine all the possible locations

of the string in

There is only one case to consider.


Cdt314 faber formal languages automata and models of computation lecture 10

Since

for

we have:


Cdt314 faber formal languages automata and models of computation lecture 10

However, from Pumping Lemma:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

We obtained a contradiction

Therefore:

The original assumption that

is context-free must be wrong

Conclusion:

is not context-free

END OF PROOF


Cdt314 faber formal languages automata and models of computation lecture 10

Unrestrictedgrammarlanguages

Context-free languages

Regular Languages


Cdt314 faber formal languages automata and models of computation lecture 10

Example

Theorem

The language

is not context free

Proof

Use the Pumping Lemma

for Context-free languages


Cdt314 faber formal languages automata and models of computation lecture 10

Since is context-free and infinite

we can apply the pumping lemma.

Assume to the contrary that

is context-free.


Cdt314 faber formal languages automata and models of computation lecture 10

Pumping Lemma gives a number

such that we can:

pick any string of with length at least

so we choose:


Cdt314 faber formal languages automata and models of computation lecture 10

We can write:

with lengths and

Pumping Lemma says:

for all


Cdt314 faber formal languages automata and models of computation lecture 10

We examine all the possible locations

of string in


Cdt314 faber formal languages automata and models of computation lecture 10

The most complicated case:

is in

is in


Cdt314 faber formal languages automata and models of computation lecture 10

and

The most complicated sub-case:


Cdt314 faber formal languages automata and models of computation lecture 10

and

The most complicated sub-case:


Cdt314 faber formal languages automata and models of computation lecture 10

and

The most complicated sub-case:


Cdt314 faber formal languages automata and models of computation lecture 10

and


Cdt314 faber formal languages automata and models of computation lecture 10

However, from Pumping Lemma:

Contradiction!


Cdt314 faber formal languages automata and models of computation lecture 10

When we examine the rest of the cases

we also obtain a contradiction.


Cdt314 faber formal languages automata and models of computation lecture 10

is not context-free.

Conclusion:

In all cases we obtain a contradiction.

Therefore:

The original assumption that

is context-free must be wrong.

END OF PROOF


Check your knowledge before the midterm 2 selected examples of context free language problems

Check your knowledge before the Midterm 2!Selected ExamplesofContext Free Language Problems


Problem 1 find a cfg for the following language

Problem 1. Find a CFG for the following language

Solution 1.

Let G be the grammar with productions:

Claim: L(G) = L


Find a cfg for the following language

Find a CFG for the following language:

Proof:

Consider the following derivation:

(the first * applies S  aSc n times, the second * to B  bBc m times)

Since all words in L(G) must follow this pattern in their derivations, it is clear that L(G)  L


Find a cfg for the following language1

Find a CFG for the following language

Considerw  L, w = anbmc(n + m)for some n, m  0

The derivation

S * anScn anBcn * anbmBcmcn anbmc(n + m)

clearly produces w for any n, m.

 L  L(G)

 L  L(G)

G is a CFG for L

END OF PROOF


Find a pda and cfg for the following language

Problem 2.

Find a PDA and CFG for the following language

Solution 2.

Is the automaton deterministic? Yes.

It acts in a unique way in each state, no l-transitions.


Cdt314 faber formal languages automata and models of computation lecture 10

CFG :


Find a pda and cfg for the following language1

Problem 3.

Find a PDA and CFG for the following language

Solution 3.

PDA


Cdt314 faber formal languages automata and models of computation lecture 10

CFG :


Cdt314 faber formal languages automata and models of computation lecture 10

Problem 4.

Prove that the language L is context-free

Consider the following two languages:

L1 ={w : w is made from a’s and b’s

and the length of w is a multiple of 10}

L2 = {an bn: n  0}

Solution 4.


Cdt314 faber formal languages automata and models of computation lecture 10

L1 ={w : w is made from a’s and b’s and the length of w is a multiple of ten}

L2 = {an bn: n  0}

LetL1cdenote the complement of L1.

We have that: L = L1c  L2.

L1is a regular language, since we can easily build a finite automaton with 10 states that accepts any string in this language.

L1cis regular too, since regular languages are closed under complement.


Cdt314 faber formal languages automata and models of computation lecture 10

The language L2is context-free.

The grammar is: S  aSb | 

Therefore, the language L = L1c  L2is also context-free,

since context-free languages are closed under regular intersection (Regular Closure).

END O PROOF


Find a pda and cfg for the following language2

Problem 5.

Find a PDA and CFG for the following language

Solution 5.

CFG

Production ex.


Cdt314 faber formal languages automata and models of computation lecture 10

Remember converting grammar to NPDA, example:

Grammar

NPDA


Cdt314 faber formal languages automata and models of computation lecture 10

PDA


Find a pda and cfg for the following language3

Problem 6.

Find a PDA and CFG for the following language:

Solution 6.

PDA


Cdt314 faber formal languages automata and models of computation lecture 10

CFG, direct construction

Strings start and finish with different symbols

Strings contain at least one more a than b

(we must have AA here as only one A just balances b)


Cdt314 faber formal languages automata and models of computation lecture 10

Further Reading

Famous Pushdown Automata Examples

http://www.liacs.nl/~hoogeboo/praatjes/tarragona/schoolpda-VIII.pdf

Computational and evolutionary aspects of language

http://www.nature.com/nature/journal/v417/n6889/full/nature00771.html


  • Login