Just as with regular languages, we can use this pumping theorem to show that a language is not context-free. The “rules of the game” are the same as for the pumping theorem for regular languages: we get to choose any qualifying string, but then we must show that there is no possibility of satisfying this pumping theorem. As usual, if a language is “pumpable”, we can draw no conclusions—the language may or may not be context-free.
Example 1
The language is not context-free. If it were, we could partition the string into five substrings, , such that also has runs of equal size of each letter. Since , there are five cases to consider:
- The variable appears wholly within the initial run of ’s. In this case, as and are pumped, the number of ’s increases while the number of the other letters doesn’t change, failing the pumping theorem.
- The variable contains both ’s and ’s. We may assume that . In this case, the number of ’s and/or ’s changes, but the ’s do not change, again failing the pumping theorem.
- The variable appears wholly within the run of 's. In this case, as and are pumped, the number of ’s increases while the number of the other letters doesn’t change, failing the pumping theorem, as in case 1 above.
- The variable contains both ’s and ’s. As in case 2, the number of ’s and/or ’s changes, but the ’s do not change, again failing the pumping theorem as in case 2 above.
- The variable appears wholly within the run of 's. In this case, as in cases 1 and 3 above, as and are pumped, the number of ’s increases while the number of the other letters doesn’t change, failing the pumping theorem.
Example 2
The language of two equal halves, , is not context-free. Consider the string . Once again, since , it is not possible for the various parts of the string to pump while keeping the halves of the string equal. There are seven cases to consider:
- The variable appears within the initial run of ’s. In this case, as and are pumped, the number of initial ’s increases while the number of ’s in the third run doesn’t change, failing the pumping theorem.
- The variable contains both ’s and ’s from the first two runs. We can assume that . In this case, the number of ’s and/or ’s in the first half changes, but the two trailing runs of letters do not, again failing the pumping theorem.
- The variable appears only within the first run of 's. In this case, the number of initial ’s changes but the second run of ’s does not, similar to case 1 above.
- The variable contains ’s followed by ’s, failing in the same manner as case 2.
- The variable is contained in the second run of ’s, which is analogous to cases 1 and 3.
- The variable contains ’s and ’s from the second half of the string, failing in the same way as cases 2 and 4.
- The variable is in the last run of ’s, failing the same way as cases 1, 3, and 5.
Example 3
The language is not context-free. Consider the string . Since , we know that . We will show that pumping up once to does not reach the next square, .
The difference between the two strings of square lengths is . However, the difference from pumping up once is:
Get hands-on with 1400+ tech skills courses.