Pumping Lemma for Context-free Languages Costas Busch - LSU
Take an infinite context-free language Generates an infinite number of different strings Example: Costas Busch - LSU
A possible derivation: In a derivation of a “long” enough string, variables are repeated A possible derivation: Costas Busch - LSU
Derivation Tree Repeated variable Costas Busch - LSU
Derivation Tree Repeated variable Costas Busch - LSU
Costas Busch - LSU
Costas Busch - LSU
Costas Busch - LSU
Putting all together Costas Busch - LSU
We can remove the middle part Costas Busch - LSU
Costas Busch - LSU
We can repeated middle part two times 1 2 Costas Busch - LSU
Costas Busch - LSU
We can repeat middle part three times 1 2 3 Costas Busch - LSU
Costas Busch - LSU
Repeat middle part times 1 i Costas Busch - LSU
For any Costas Busch - LSU
We inferred that a family of strings is in From Grammar and given string We inferred that a family of strings is in for any Costas 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) Costas Busch - LSU
Let be the number of variables Let be the maximum right-hand size of any production Example: Costas Busch - LSU
Claim: Proof: 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: Proof by contradiction Costas Busch - LSU
Derivation tree of We will show: some variable is repeated Costas Busch - LSU
First we show that the tree of has at least levels of nodes Suppose the opposite: At most Levels Costas Busch - LSU
Maximum number of nodes per level The maximum right-hand side of any production Costas Busch - LSU
Maximum number of nodes per level Costas Busch - LSU
Maximum number of nodes per level At most Level : nodes Levels Level : nodes Maximum possible string length = max nodes at level = Costas Busch - LSU
maximum length of string : Therefore, maximum length of string : However we took, Contradiction!!! Therefore, the tree must have at least levels Costas Busch - LSU
Thus, there is a path from the root to a leaf with at least nodes Variables Levels symbol (leaf) Costas Busch - LSU
Since there are at most different variables, some variable is repeated Pigeonhole principle END OF CLAIM PROOF Costas Busch - LSU
Take to be the deepest, so that only is repeated in subtree 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 Costas Busch - LSU
We can write Strings of terminals yield yield yield yield yield Costas Busch - LSU
Example: Costas Busch - LSU
Possible derivations Costas Busch - LSU
Example: Costas Busch - LSU
Remove Middle Part Yield: Costas Busch - LSU
Repeat Middle part two times 1 2 Yield: Costas Busch - LSU
Costas Busch - LSU
Repeat Middle part times 1 i Yield: Costas Busch - LSU
Costas Busch - LSU
Therefore, If we know that: then we also know: For all since Costas Busch - LSU
Observation 1: At least one of or is not Since has no unit and -productions At least one of or is not Costas Busch - LSU
Observation 2: since in subtree only variable is repeated subtree of Explanation follows…. Costas Busch - LSU
since no variable is repeated in subtree of Various yields since no variable is repeated in Maximum right-hand side of any production Costas Busch - LSU
Thus, if we choose critical length then, we obtain the pumping lemma for context-free languages Costas Busch - LSU
For any infinite context-free language 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: Costas Busch - LSU
Applications of The Pumping Lemma Costas Busch - LSU
Non-context free languages Costas Busch - LSU
for context-free languages Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages Costas Busch - LSU
Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma Costas Busch - LSU
Let be the critical length of the pumping lemma Pick any string with length We pick: Costas Busch - LSU
From pumping lemma: we can write: with lengths and Costas Busch - LSU
Pumping Lemma says: for all Costas Busch - LSU
We examine all the possible locations of string in Costas Busch - LSU
Case 1: is in Costas Busch - LSU
Costas Busch - LSU
Costas Busch - LSU
From Pumping Lemma: However: Contradiction!!! Costas Busch - LSU
Case 2: is in Similar to case 1 Costas Busch - LSU
Case 3: is in Similar to case 1 Costas Busch - LSU
Case 4: overlaps and Costas Busch - LSU
Sub-case 1: contains only contains only Costas Busch - LSU
Costas Busch - LSU
Costas Busch - LSU
From Pumping Lemma: However: Contradiction!!! Costas Busch - LSU
Sub-case 2: contains and contains only Costas Busch - LSU
By assumption Costas Busch - LSU
Costas Busch - LSU
From Pumping Lemma: However: Contradiction!!! Costas Busch - LSU
Sub-case 3: contains only contains and Similar to sub-case 2 Costas Busch - LSU
Case 5: overlaps and Similar to case 4 Costas Busch - LSU
Case 6: overlaps , and Impossible! Costas 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 Costas Busch - LSU