Sub topic 3
The pumping lemma and non-regular languages
This chapter assumes you know DFAs, NFAs, and regular expressions, and that you can write a proof by contradiction.
The pumping lemma
If L is regular, there is a pumping length p such that every string w in L with |w| ≥ p splits into x, y, z where |xy| ≤ p, |y| ≥ 1, and x y^i z is in L for every i ≥ 0. A DFA with p states must repeat a state on any path of length p, and that repeated state creates the loop y.
To prove a language is not regular, assume it is regular, let the adversary choose any split, and pump to reach a string outside L.
def in_L(w):
# L = { a^n b^n : n >= 0 }
n = w.count("a")
return w == "a" * n + "b" * n
x, y, z = "", "a", "aabbb" # one possible split of w = "aaabbb"
for k in range(4):
print(k, in_L(x + y * k + z)) # only k = 1 stays in L> The pumping lemma gives a necessary condition only. Passing the pumping test does not prove that a language is regular.
The Myhill-Nerode theorem
Strings x and y are equivalent if, for every z, xz is in L exactly when yz is in L. L is regular if and only if it has finitely many equivalence classes, and that count equals the state count of the minimal DFA. For a^n b^n, the strings a^0, a^1, a^2, and so on are pairwise inequivalent, because b^n tells them apart. So there are infinitely many classes.
Decision problems for regular languages
For a given DFA, membership, emptiness, finiteness, and equivalence are all decidable. Emptiness asks whether an accepting state is reachable. Finiteness asks whether a cycle lies on a path from start to an accepting state. Equivalence minimizes both DFAs and compares them.
Regular grammars and automata
A right-linear grammar has rules of the form A → aB or A → a. Its language is regular. Each rule A → aB corresponds to an NFA transition from A to B, and every NFA converts back to a right-linear grammar.
Moore and Mealy machines
These are finite transducers, which produce output instead of accepting strings. In a Moore machine, the output depends only on the current state. In a Mealy machine, the output depends on the state and the input symbol.
GATE problem patterns and strategies
- To count states, minimize the DFA and count its classes.
- To judge regularity, suspect a counting constraint such as a^n b^n, then prove it with Myhill-Nerode.
- To check equivalence, compare the minimal DFAs.
Exercise
Is the language {a^n b^n : n ≥ 0} regular?
Show answer
No. Assume it is regular with pumping length p. Take w = a^p b^p. Any split has y made only of a's, so pumping with i = 0 gives more b's than a's, which is outside L. This is a contradiction.