Treat the fixed letters , the empty-language and empty-word symbols, and the punctuation of expressions as a finite token alphabet. In the usual syntax allowing parentheses, union, concatenation, and star, the following context-free grammar generates exactly the syntactically valid regular expressions:
Structural induction proves that every generated string is an expression and that every expression has a derivation. Grammar ambiguity does not affect the context-free language assertion.
If the language of these expressions were a regular language, its intersection with the regular token language consisting of some opening parentheses, then , then some closing parentheses would be regular. That intersection is exactly
The pumping lemma for regular languages contradicts regularity: a sufficiently long opening-parenthesis prefix forces a pumpable segment wholly within that prefix, and pumping it changes the two parenthesis counts unequally. Hence the expression syntax is context-free but not regular. This conclusion concerns the strings describing expressions, not the languages those expressions denote; it uses the usual concrete syntax with arbitrary nested parentheses.
Use . The context-free grammar generates exactly , so it is a context-free language. It is not a regular language: if is a pumping length, any allowed decomposition of has a nonempty pumped segment consisting only of 's. Pumping down leaves fewer 's than 's, contradicting the pumping lemma for regular languages. Thus is a context-free language but not a regular language.
Let be the diagonal halting set, which is undecidable. The pumping argument below actually holds for every subset ; nonregularity needs the stated convention, or at least a set of exponents whose unary language is nonregular.
The pumping lemma for regular languages holds with pumping length one. For an accepted nonempty word, pump its first symbol. A word containing only s remains in even if that symbol is deleted. If there is a zero and a nonempty prefix before its last zero, pumping the first symbol leaves the last zero and its following ones unchanged. If the word is , pumping its initial zero produces ; this is accepted for , and for it belongs to . In every case the pumped substring is nonempty and lies in the first position.
If were a regular language, closure under intersection would make
regular. A finite-state automaton for this intersection would decide membership of in the diagonal halting set by reading , a contradiction. Thus satisfies the pumping lemma but is not regular, under the usual meaning of . If were arbitrary, the printed conclusion would be false, for example for .
The pumping lemma for regular languages states that for every regular language there is an integer such that every with can be written
with
To prove it, let a deterministic finite automaton with states recognize . During the reading of the first symbols of an accepted word , the automaton visits states, including the initial state. By the pigeonhole principle, two of them agree, say with . Let be the first symbols, the next symbols, and the remaining suffix. Reading is a nonempty closed path from to itself. Traversing this path any number of times and then reading therefore reaches the same accept state. This proves all three assertions.
Let be the undecidable set denoted in the question. The language satisfies the pumping lemma for regular languages with pumping length one. For any nonempty , write with , its first symbol, and the remaining suffix.
If , then for every . Otherwise for some . If the chosen first symbol lies in , pumping it preserves the same final suffix . If , then : pumping down gives , while every positive pump gives and all but its last can be absorbed into . Thus every sufficiently long word has a valid pumping decomposition.
Nevertheless, if were regular language, closure under intersection would make
regular. A finite automaton deciding this unary language would decide whether by running it on , contradicting the halting problem. Therefore
This is a nonregular language satisfying the pumping lemma.
A deterministic finite automaton is a tuple with finite state set , finite input alphabet , transition function , initial state , and accepting-state set . It accepts a word when the extended transition function of a deterministic finite automaton carries to a state in . A regular language is a language accepted by some deterministic finite automaton.
The pumping lemma for regular languages says that if a regular language is accepted by an automaton with states, every accepted word of length at least has a decomposition with , , and in the language for every . Indeed, among the states visited before and after the first symbols, two are equal by the pigeonhole principle. The intervening nonempty word labels a loop, which may be traversed any number of times without changing the final accepting state.
In base two, the powers of two have representations , so their language is the regular expression and is regular.
Suppose instead that their base-ten representations formed a regular language. Apply the pumping lemma to a sufficiently long decimal power of two , and put . Pumping gives decimal integers represented by , all powers of two. A direct place-value calculation shows that
for a constant independent of . The lengths, and hence the exponents in , tend to infinity. Dividing by gives
For large , the right side has absolute value less than one while the left side is an integer, so it must vanish. This would make a power of two equal to , impossible for by unique prime factorization. Thus the decimal powers of two are not a regular language.
The pumping lemma for regular languages says that sufficiently long accepted words split as with , , and accepted for all . Applying it to pumps only zeros, so language (i) is not regular.
The pumping lemma for regular languages states that if is regular, then some has the following property: every with can be written with , , and for every . Indeed, while a deterministic finite automaton with states reads the first symbols, two of the first visited states coincide; the intervening nonempty loop may be traversed any number of times.
The language is not regular. If its pumping length were , apply the lemma to . The pumped block is for some . Pumping once more gives zeros, but
so their number is not a square.
Let . The pumping lemma for regular languages states that every with can be written
with
Thus one may take the pumping number to be exactly the number of states of the given automaton, whether or not all of them are accessible.
The pumping lemma for regular languages says that for some , every accepted word of length at least factors with , , and accepted for every .
Over an alphabet containing , the language is not regular language. Intersecting it with the regular language gives exactly
which fails the pumping lemma for regular languages.