11. Pumping Lemma for CFGs
Feb 10, 2022
Pumping lemma for context-free languages, also Bar-Hillem Lemma.
- Take some infinite CFL that generates infinite number of strings
- every infinite CFL can be pumped => if this property does not hold then language in not CFL
Choose a long enough string where variable(s) is repeated - example:
Grammar
=> this is infinite language
For arbitrary grammars
Consider arbitrary infinite context-free language
Take
Let
Claim: take string
Proof (by contradiction): show some variable is repeated.
First show that three of
-
maximum number of nodes per level:
- 0: 1,
- 1:
(the max right hand side of any production) - 2:
- => in general at level
: nodes
-
therefore the max length of string
-
however we took string
=> contradiction, therefore tree must have at least levels.
Thus, there is a path from the root to a leaf with at least
Take now a string
Example. For grammar
Possible derivations:
Remove middle part:
Repeat middle part: yields
Therefore, if we know for
Observations:
since has no unit and -productions → at least one of or is not since in subtree only variable is repeated- thus if we choose critical length
we obtain pumping lemma for context-free languages
Pumping lemma for CFGs
For any infinite context-free language
Applications
Assume L is CFL, choose
- case 1:
in - case 2:
in - case 3:
in - case 4:
overlaps and- subcase 1: y contains only a, y contains only b
- subcase 2: v contains a and b, and y contains only b
- subcase 3: v contains only a, y contains a and b
- case 5:
overlaps and (similar to case 4) - case 6:
overlaps and and - impossible by
=> in all cases we obtain contradiction, therefore