The Pumping Lemma for ContextFree Languages Costas Busch
The Pumping Lemma for Context-Free Languages Costas Busch - RPI 1
Take an infinite context-free language Generates an infinite number of different strings Example: Costas Busch - RPI 2
In a derivation of a long string, variables are repeated A derivation: Costas Busch - RPI 3
Derivation tree string Costas Busch - RPI 4
Derivation tree string repeated Costas Busch - RPI 5
Costas Busch - RPI 6
Repeated Part Costas Busch - RPI 7
Another possible derivation from Costas Busch - RPI 8
Costas Busch - RPI 9
A Derivation from Costas Busch - RPI 10
Costas Busch - RPI 11
Costas Busch - RPI 12
A Derivation from Costas Busch - RPI 13
Costas Busch - RPI 14
Costas Busch - RPI 15
Costas Busch - RPI 16
Costas Busch - RPI 17
A Derivation from Costas Busch - RPI 18
Costas Busch - RPI 19
Costas Busch - RPI 20
Costas Busch - RPI 21
In General: Costas Busch - RPI 22
Consider now an infinite context-free language Let Take be the grammar of so that I has no unit-productions no -productions Costas Busch - RPI 23
Let = (Number of productions) x (Largest right side of a production) Let Example : Costas Busch - RPI 24
Take a string with length We will show: in the derivation of a variable of is repeated Costas Busch - RPI 25
Costas Busch - RPI 26
maximum right hand side of any production Costas Busch - RPI 27
Number of productions in grammar Costas Busch - RPI 28
Number of productions in grammar Some production must be repeated Repeated variable Costas Busch - RPI 29
Derivation of string Some variable is repeated Costas Busch - RPI 30
Derivation tree of string Last repeated variable repeated Strings of terminals Costas Busch - RPI 31
Possible derivations: Costas Busch - RPI 32
We know: This string is also generated: Costas Busch - RPI 33
We know: This string is also generated: The original Costas Busch - RPI 34
We know: This string is also generated: Costas Busch - RPI 35
We know: This string is also generated: Costas Busch - RPI 36
We know: This string is also generated: Costas Busch - RPI 37
Therefore, any string of the form is generated by the grammar Costas Busch - RPI 38
Therefore, knowing that we also know that Costas Busch - RPI 39
Observation: Since is the last repeated variable Costas Busch - RPI 40
Observation: Since there are no unit or Costas Busch - RPI -productions 41
The Pumping Lemma: For infinite context-free language there exists an integer such that for any string we can write with lengths and it must be: Costas Busch - RPI 42
Applications of The Pumping Lemma Costas Busch - RPI 43
Non-context free languages Context-free languages Costas Busch - RPI 44
Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages Costas Busch - RPI 45
Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma Costas Busch - RPI 46
Pumping Lemma gives a magic number such that: Pick any string with length We pick: Costas Busch - RPI 47
We can write: with lengths and Costas Busch - RPI 48
Pumping Lemma says: for all Costas Busch - RPI 49
We examine all the possible locations of string in Costas Busch - RPI 50
Case 1: is within Costas Busch - RPI 51
Case 1: and consist from only Costas Busch - RPI 52
Case 1: Repeating and Costas Busch - RPI 53
Case 1: From Pumping Lemma: Costas Busch - RPI 54
Case 1: From Pumping Lemma: However: Contradiction!!! Costas Busch - RPI 55
Case 2: is within Costas Busch - RPI 56
Case 2: Similar analysis with case 1 Costas Busch - RPI 57
Case 3: is within Costas Busch - RPI 58
Case 3: Similar analysis with case 1 Costas Busch - RPI 59
Case 4: overlaps Costas Busch - RPI and 60
Case 4: Possibility 1: contains only Costas Busch - RPI 61
Case 4: Possibility 1: contains only Costas Busch - RPI 62
Case 4: From Pumping Lemma: Costas Busch - RPI 63
Case 4: From Pumping Lemma: However: Contradiction!!! Costas Busch - RPI 64
Case 4: Possibility 2: contains and contains only Costas Busch - RPI 65
Case 4: Possibility 2: contains and contains only Costas Busch - RPI 66
Case 4: From Pumping Lemma: Costas Busch - RPI 67
Case 4: From Pumping Lemma: However: Contradiction!!! Costas Busch - RPI 68
Case 4: Possibility 3: contains only contains and Costas Busch - RPI 69
Case 4: Possibility 3: contains only contains and Similar analysis with Possibility 2 Costas Busch - RPI 70
Case 5: overlaps Costas Busch - RPI and 71
Case 5: Similar analysis with case 4 Costas Busch - RPI 72
There are no other cases to consider (since overlap , string , and Costas Busch - RPI cannot at the same time) 73
In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion: is not context-free Costas Busch - RPI 74
- Slides: 74