# Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.

## Presentation on theme: "Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages."— Presentation transcript:

Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages

Courtesy Costas Busch - RPI2 Take an infinite context-free language Example: Generates an infinite number of different strings

Courtesy Costas Busch - RPI3 A derivation: In a derivation of a long string, variables are repeated

Courtesy Costas Busch - RPI4 Derivation treestring

Courtesy Costas Busch - RPI5 repeated Derivation treestring

Courtesy Costas Busch - RPI6

7 Repeated Part

Courtesy Costas Busch - RPI8 Another possible derivation from

Courtesy Costas Busch - RPI9

10 A Derivation from

Courtesy Costas Busch - RPI11

Courtesy Costas Busch - RPI12

Courtesy Costas Busch - RPI13 A Derivation from

Courtesy Costas Busch - RPI14

Courtesy Costas Busch - RPI15

Courtesy Costas Busch - RPI16

Courtesy Costas Busch - RPI17

Courtesy Costas Busch - RPI18 A Derivation from

Courtesy Costas Busch - RPI19

Courtesy Costas Busch - RPI20

Courtesy Costas Busch - RPI21

Courtesy Costas Busch - RPI22 In General:

Courtesy Costas Busch - RPI23 Consider now an infinite context-free language Take so that it has no unit-productions no -productions Let be the grammar of

Courtesy Costas Busch - RPI24 (Number of productions) x (Largest right side of a production) = Let Example : Let

Courtesy Costas Busch - RPI25 Take a string with length We will show: in the derivation of a variable of is repeated

Courtesy Costas Busch - RPI26

Courtesy Costas Busch - RPI27 maximum right hand side of any production

Courtesy Costas Busch - RPI28 Number of productions in grammar

Courtesy Costas Busch - RPI29 Number of productions in grammar Some production must be repeated Repeated variable

Courtesy Costas Busch - RPI30 Some variable is repeated Derivation of string

Courtesy Costas Busch - RPI31 Last repeated variable repeated Strings of terminals Derivation tree of string

Courtesy Costas Busch - RPI32 Possible derivations:

Courtesy Costas Busch - RPI33 We know: This string is also generated:

Courtesy Costas Busch - RPI34 This string is also generated: The original We know:

Courtesy Costas Busch - RPI35 This string is also generated: We know:

Courtesy Costas Busch - RPI36 This string is also generated: We know:

Courtesy Costas Busch - RPI37 This string is also generated: We know:

Courtesy Costas Busch - RPI38 Therefore, any string of the form is generated by the grammar

Courtesy Costas Busch - RPI39 knowing that we also know that Therefore,

Courtesy Costas Busch - RPI40 Observation: Since is the last repeated variable

Courtesy Costas Busch - RPI41 Observation: Since there are no unit or -productions

Courtesy Costas Busch - RPI42 The Pumping Lemma: there exists an integer such that for any string we can write For infinite context-free language with lengths and it must be:

Courtesy Costas Busch - RPI43 Reminders Choosing m : The thing to remember about the pumping length m is that you don’t get to choose it! The pumping lemma itself “supplies” this value to you. So you cannot make any assumption about what the value of m is, you simply must use it as a fixed value over which you have no control.

Courtesy Costas Busch - RPI44 Reminders Choosing w : A good place to start is with a string that incorporates the pumping length m in it somehow, e.g. a m b m if your alphabet is {a, b}. The right string can reduce the number of different partitions you must consider. As you work through more and more examples of these types of proofs, you gather insight into the types of strings that will work best. So the best way to get better at choosing w is to read examples and, even better, to work problems.

Courtesy Costas Busch - RPI45 Reminders Choosing the partition of w : The thing to remember about the partition of w into its parts u, v, x, y & z is, again, that you don’t get to choose it! The partition is, in some sense, chosen for you. But it is never explicitly given to you (the way you can think of the pumping length as being given to you), so you must consider all possible partitions. Remember, that for each partition of w, you must show that for some integer i, the string uv i xy i z is not in L.

Courtesy Costas Busch - RPI46 Reminders Choosing i : You do get to choose this, and you’re given quite a bit of freedom. You may pick i so that it is any integer greater than 1, or even 0. It doesn’t make sense to select i = 1, since that would describe w, a string which you already know to be in L.) You may even choose i differently in different cases of your proof. This is useful, for example, if some cases work only if you “pump down” to i = 0, while others work only if you “pump up” to i = 2 or i = 3.

Courtesy Costas Busch - RPI47 Cautions Be sure that the w you choose is actually in the language L you are trying to prove something about! If not, the pumping lemma doesn’t guarantee anything about whether pumping that w should give strings in L. Also, be sure that your string w is long enough: it must have length at least m. In the pumping lemma for context-free languages, when you pump a particular string, note that the i describing the number of repetitions of v must be the same i describing the number of repetitions of y. So it doesn’t help your proof to show a “pumped” string uv 0 xy 2 z which is not in L, since 0 ≠ 2.

Courtesy Costas Busch - RPI48 Applications of The Pumping Lemma

Courtesy Costas Busch - RPI49 Context-free languages Non-context free languages

Courtesy Costas Busch - RPI50 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

Courtesy Costas Busch - RPI51 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

Courtesy Costas Busch - RPI52 Pumping Lemma gives a magic number such that: Pick any string with length We pick:

Courtesy Costas Busch - RPI53 We can write: with lengths and

Courtesy Costas Busch - RPI54 Pumping Lemma says: for all

Courtesy Costas Busch - RPI55 We examine all the possible locations of string in

Courtesy Costas Busch - RPI56 Case 1: is within

Courtesy Costas Busch - RPI57 Case 1: and consist from only

Courtesy Costas Busch - RPI58 Case 1: Repeating and

Courtesy Costas Busch - RPI59 Case 1: From Pumping Lemma:

Courtesy Costas Busch - RPI60 Case 1: From Pumping Lemma: However: Contradiction!!!

Courtesy Costas Busch - RPI61 Case 2: is within

Courtesy Costas Busch - RPI62 Case 2: Similar analysis with case 1

Courtesy Costas Busch - RPI63 Case 3: is within

Courtesy Costas Busch - RPI64 Case 3: Similar analysis with case 1

Courtesy Costas Busch - RPI65 Case 4: overlaps and

Courtesy Costas Busch - RPI66 Case 4: Possibility 1:contains only

Courtesy Costas Busch - RPI67 Case 4: Possibility 1:contains only

Courtesy Costas Busch - RPI68 Case 4: From Pumping Lemma:

Courtesy Costas Busch - RPI69 Case 4: From Pumping Lemma: However: Contradiction!!!

Courtesy Costas Busch - RPI70 Case 4: Possibility 2:contains and contains only

Courtesy Costas Busch - RPI71 Case 4: Possibility 2:contains and contains only

Courtesy Costas Busch - RPI72 Case 4: From Pumping Lemma:

Courtesy Costas Busch - RPI73 Case 4: From Pumping Lemma: However: Contradiction!!!

Courtesy Costas Busch - RPI74 Case 4: Possibility 3:contains only contains and

Courtesy Costas Busch - RPI75 Case 4: Possibility 3:contains only contains and Similar analysis with Possibility 2

Courtesy Costas Busch - RPI76 Case 5: overlaps and

Courtesy Costas Busch - RPI77 Case 5: Similar analysis with case 4

Courtesy Costas Busch - RPI78 There are no other cases to consider (since, string cannot overlap, and at the same time)

Courtesy Costas Busch - RPI79 In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion:is not context-free

Courtesy Costas Busch - RPI80 More Applications of The Pumping Lemma

Courtesy Costas Busch - RPI81 The Pumping Lemma: there exists an integer such that for any string we can write For infinite context-free language with lengths and it must be:

Courtesy Costas Busch - RPI82 Context-free languages Non-context free languages

Courtesy Costas Busch - RPI83 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

Courtesy Costas Busch - RPI84 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

Courtesy Costas Busch - RPI85 Pumping Lemma gives a magic number such that: Pick any string of with length at least we pick:

Courtesy Costas Busch - RPI86 We can write: with lengths and Pumping Lemma says: for all

Courtesy Costas Busch - RPI87 We examine all the possible locations of string in

Courtesy Costas Busch - RPI88 Case 1: is within the first

Courtesy Costas Busch - RPI89 Case 1: is within the first

Courtesy Costas Busch - RPI90 Case 1: is within the first

Courtesy Costas Busch - RPI91 Case 1: is within the first Contradiction!!! However, from Pumping Lemma:

Courtesy Costas Busch - RPI92 is in the first Case 2:

Courtesy Costas Busch - RPI93 is in the first Case 2:

Courtesy Costas Busch - RPI94 is in the first Case 2:

Courtesy Costas Busch - RPI95 is in the first Case 2: Contradiction!!! However, from Pumping Lemma:

Courtesy Costas Busch - RPI96 is in the first overlaps the first Case 3:

Courtesy Costas Busch - RPI97 is in the first overlaps the first Case 3:

Courtesy Costas Busch - RPI98 is in the first overlaps the first Case 3:

Courtesy Costas Busch - RPI99 is in the first overlaps the first Case 3: Contradiction!!! However, from Pumping Lemma:

Courtesy Costas Busch - RPI100 Overlaps the first in the first Case 4: Analysis is similar to case 3

Courtesy Costas Busch - RPI101 Other cases: is within or Analysis is similar to case 1:

Courtesy Costas Busch - RPI102 More cases: overlaps or Analysis is similar to cases 2,3,4:

Courtesy Costas Busch - RPI103 Since, it is impossible to overlap: There are no other cases to consider nor

Courtesy Costas Busch - RPI104 In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion:is not context-free

Courtesy Costas Busch - RPI105 Context-free languages Non-context free languages

Courtesy Costas Busch - RPI106 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

Courtesy Costas Busch - RPI107 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

Courtesy Costas Busch - RPI108 Pumping Lemma gives a magic number such that: Pick any string of with length at least we pick:

Courtesy Costas Busch - RPI109 We can write: with lengths and Pumping Lemma says: for all

Courtesy Costas Busch - RPI110 We examine all the possible locations of string in There is only one case to consider

Courtesy Costas Busch - RPI111

Courtesy Costas Busch - RPI112

Courtesy Costas Busch - RPI113

Courtesy Costas Busch - RPI114

Courtesy Costas Busch - RPI115 Since, for we have:

Courtesy Costas Busch - RPI116

Courtesy Costas Busch - RPI117 Contradiction!!! However, from Pumping Lemma:

Courtesy Costas Busch - RPI118 We obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion:is not context-free

Courtesy Costas Busch - RPI119 Context-free languages Non-context free languages

Courtesy Costas Busch - RPI120 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

Courtesy Costas Busch - RPI121 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

Courtesy Costas Busch - RPI122 Pumping Lemma gives a magic number such that: Pick any string of with length at least we pick:

Courtesy Costas Busch - RPI123 We can write: with lengths and Pumping Lemma says: for all

Courtesy Costas Busch - RPI124 We examine all the possible locations of string in

Courtesy Costas Busch - RPI125 Most complicated case: is in

Courtesy Costas Busch - RPI126

Courtesy Costas Busch - RPI127 Most complicated sub-case:and

Courtesy Costas Busch - RPI128 Most complicated sub-case:and

Courtesy Costas Busch - RPI129 Most complicated sub-case:and

Courtesy Costas Busch - RPI130 and

Courtesy Costas Busch - RPI131

Courtesy Costas Busch - RPI132 However, from Pumping Lemma: Contradiction!!!

Courtesy Costas Busch - RPI133 When we examine the rest of the cases we also obtain a contradiction

Courtesy Costas Busch - RPI134 In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion:is not context-free

Download ppt "Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages."

Similar presentations