1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s...

27
1 Module 36 • Non context-free languages – Examples and Intuition • Pumping lemma for CFL’s – Pumping condition – No proof of pumping lemma – Applying pumping lemma to prove that some languages are not CFL’s
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    224
  • download

    0

Transcript of 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s...

Page 1: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

1

Module 36

• Non context-free languages– Examples and Intuition

• Pumping lemma for CFL’s– Pumping condition– No proof of pumping lemma– Applying pumping lemma to prove that some

languages are not CFL’s

Page 2: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

2

Examples and Intuition

Page 3: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

3

Examples *

• What are some examples of nonregular languages?

• Can we build on any of these languages to create a non context-free language?

Page 4: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

4

Intuition *

• Try and prove that these languages are CFL’s and identify the stumbling blocks– Why can’t we construct a CFG to generate this language?

– Why can’t we construct a PDA to accept this language?

– Compare to similar CFL languages to try and identify differences.

Page 5: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

5

Pumping Lemma for CFL’s

Page 6: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

6

Comparison to regular language pumping lemma/condition

Page 7: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

7

What’s different about CFL’s than regular languages? *

• In regular languages, a single substring “pumps”– Consider the language of even length strings over {a,b}– We can identify a single substring which can be pumped

• In CFL’s, multiple substrings can “pump”– Consider the language {anbn | n > 0}– No single substring can be pumped and allow us to stay in the

language– However, there do exist pairs of substrings which can be

pumped resulting in strings which stay in the language

• This results in a modified pumping condition

Page 8: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

8

Modified Pumping Condition

• A language L satisfies the regular language pumping

condition if: – there exists an integer n > 0

such that

– for all strings x in L of length at least n

– there exist strings u, v, w such that

• x = uvw and

• |uv| <= n and

• |v| >= 1 and

• For all k >= 0, uvkw is in L

• A language L satisfies the CFL

pumping condition if: – there exists an integer n > 0

such that

– for all strings x in L of length at least n

– there exist strings u, v, w, y, z such that

• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1 and

• For all k >= 0, uvkwykz is in L

Page 9: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

9

Pumping Lemma

• All CFL’s satisfy the CFL pumping condition

All languages over {a,b}

CFL’s

“Pumping Languages”

Page 10: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

10

Implications

• We can use the pumping lemma to prove a language L is not a CFL– Show L does not satisfy the CFL pumping

condition

• We cannot use the pumping lemma to prove a language is context-free– Showing L satisfies the pumping condition does

not guarantee that L is context-free

CFL

Pumping

Page 11: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

11

Pumping Lemma

What does it mean?

Page 12: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

12

Pumping Condition

• A language L satisfies the CFL pumping condition if: – there exists an integer n > 0 such that

– for all strings x in L of length at least n

– there exist strings u, v, w, y, z such that• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1 and

• For all k >= 0, uvkwykz is in L

Page 13: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

13

v and y can be pumped

• Let x = abcdefg be in L• Then there exist 2 substrings v and y in x such that v and y can

be repeated (pumped) in place any number of times and the resulting string is still in L– uvkwykz is in L for all k >= 0

• For example– v = cd and y = f

• uv0wy0z = uwz = abeg is in L• uv1wy1z = uvwyz = abcdefg is in L• uv2wy2z = uvvwyyz = abcdcdeffg is in L• uv3wy3z = uvvvwyyyz = abcdcdcdefffg is in L • …

1) x in L2) x = uvwyz3) For all k >= 0, uvkwykz is in L

Page 14: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

14

What the other parts mean• A language L satisfies the CFL pumping condition if:

– there exists an integer n > 0 such that• Since we skip this proof, we will not see what n really means

– for all strings x in L of length at least n• x must be in L and have sufficient length

– there exist strings u, v, w, y, z such that• x = uvwyz and

• |vwy| <= n and– v and y are contained within n characters of x– Note: these are NOT necessarily the first n characters of x

• |vy| >= 1 and– v and y cannot both be – One of them might be , but not both

• For all k >= 0, uvkwykz is in L

Page 15: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

15

Example *

• Let L be the set of palindromes over {a,b}– Let x = aabaa

– Let n = 3

– What are the possibilities for v and y ignoring the pumping constraint?

– Which ones satisfy the pumping lemma?

Page 16: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

16

Pumping Lemma

Applying it to prove a specific language L is not context-free

Page 17: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

17

How we use the Pumping Lemma

• We choose a specific language L– For example, {ajbjcj | j > 0}

• We show that L does not satisfy the pumping condition

• We conclude that L is not context-free

Page 18: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

18

Showing L “does not pump”

• A language L satisfies the CFL

pumping condition if: – there exists an integer n > 0

such that

– for all strings x in L of length at least n

– there exist strings u, v, w, y, z such that

• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1 and

• For all k >= 0, uvkwykz is in L

• A language L does not satisfy

the CFL pumping condition if: – for all integers n of sufficient

size

– there exists a string x in L of length at least n such that

– for all strings u, v, w, y, z such that

• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1

– There exists a k >= 0 such that uvkwykz is not in L

Page 19: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

19

Example Proof

• A language L does not satisfy

the CFL pumping condition if: – for all integers n of sufficient

size

– there exists a string x in L of length at least n such that

– for all strings u, v, w, y, z such that

• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1

– There exists a k >= 0 such that uvkwykz is not in L

• Proof that L = {aibici | i>0} does not satisfy the CFL pumping condition

• Let n be the integer from the pumping lemma

• Choose x = anbncn

• Consider all strings u, v, w, y, z s.t.• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1

• Argue that uvkwykz is not in L for some k >= 0

– Argument must apply to all possible u,v,w,y,z

– Continued on next slide

Page 20: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

20

Example Proof Continued *• Proof that L = {aibici | i>0} does not

satisfy the CFL pumping condition

• Let n be the integer from the pumping lemma

• Choose x = anbncn

• Consider all strings u, v, w, y, z s.t.• x = uvwyz and

• |vwy| <= n and

• |vy| >= 1

• Argue that uvkwykz is not in L for some k >= 0– Argument must apply to all possible

u,v,w,y,z

– Continued next column

• Identify possible cases for vwy• What is impossible for vwy?

• Case 1– vwy contains no a’s

• Case 2– vwy contains no c’s

• Must argue uvkwykz is not in L for both cases described above– Can use different values of k– Continued on next slide

Page 21: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

21

Example Proof Continued

• Identify possible cases for vwy• What is impossible for vwy?

• Case 1– vwy contains no a’s

• Case 2– vwy contains no c’s

• Must argue uvkwykz is not in L for both cases described above– Can use different values of k– Continued next column

• Case 1: vwy contains no a’s– vy contains at least 1 b or c

• follows from – vwy contains no a’s and– |vy| >= 1

– uwz is not in L• uwz has n a’s

– follows from fact vwy contains no a’s and x originally had n a’s

• uwz has fewer than n b’s or fewer than n c’s

– follows from vy contains at least 1 b or c and x originally only had n b’s and n c’s

• Continued next slide

Page 22: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

22

Example Proof Continued *

• Case 1: vwy contains no a’s– vy contains at least 1 b or c

• follows from – vwy contains no a’s and– |vy| >= 1

– uwz is not in L• uwz has n a’s

– follows from fact vwy contains no a’s and x originally had n a’s

• uwz has fewer than n b’s or fewer than n c’s

– follows from vy contains at least 1 b or c and x originally only had n b’s and n c’s

• Continued next column

• Case 2: vwy contains no c’s– vy contains at least

– uv2wy2z is not in L• uv2wy2z has n c’s

– follows from fact vwy contains no c’s and x originally had n c’s

• uv2wy2z has more than n a’s or more than n b’s

– follows from vy contains at least 1 a or b and x originally has n a’s and n b’s

• Continued next slide

Page 23: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

23

Example Proof Completed

• For all possible u, v, w, y, z, we have shown there exists a k>=0 such that– uvkwykz is not in L

• Note, we used a different value of k for each case (though we didn’t have to)

• Therefore L does not satisfy the CFL pumping condition

• There L is not a CFL

• Case 2: vwy contains no c’s– vy contains at least

– uv2wy2z is not in L• uv2wy2z has n c’s

– follows from fact vwy contains no c’s and x originally had n c’s

• uv2wy2z has more than n a’s or more than n b’s

– follows from vy contains at least 1 a or b and x originally has n a’s and n b’s

• Continued next column

Page 24: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

24

Other example languages

• TWOCOPIES = {ww | w is in {a,b}* }– abbabb is in TWOCOPIES but abaabb is not

• EQUAL3 = the set of strings over {a, b, c} such that the number of a’s equals the number of b’s equals the number of c’s

• {aibjck | i < j < k}

Page 25: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

25

Pumping Lemma

Two rules of thumb

Page 26: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

26

Two Rules of Thumb

• Try to use blocks of at least n characters in x– For TWOCOPIES, choose x = anbnanbn rather than

anbanb• Guarantees v and y cannot be in more than 2 blocks of x

• Try k=0 or k=2– k=0

• This reduces number of occurrences of v and y

– k=2• This increases number of occurrences of v and y

Page 27: 1 Module 36 Non context-free languages –Examples and Intuition Pumping lemma for CFL’s –Pumping condition –No proof of pumping lemma –Applying pumping.

27

Summary

• We use the Pumping Lemma to prove a language is not a CFL– Note, does not work for all non CFL languages– Can be strengthened to Ogden’s Lemma

• In book

• Choosing a good string x is first key step

• Choosing a good k is second key step

• Typically have several cases for v, w, y