Sub topic 2
Where Regular Languages Stop: A Short Recap
This chapter assumes you know alphabets, strings, languages, regular expressions, and finite automata. A finite automaton has a fixed number of states and no unbounded memory.
What regular languages can remember
A language is regular if some finite automaton recognises it. A deterministic finite automaton (DFA) reads one input symbol at a time and changes state according to its transition function. It accepts when the whole input ends in an accepting state.
Finite automata can remember a fixed amount of information. For example, a DFA can remember whether it has seen an even or odd number of 1s. It can also remember whether an input ends in 01, because only a bounded suffix matters.
def accepts_even_ones(word):
"""Return True exactly when word contains an even number of 1s."""
state = "even"
for symbol in word:
if symbol == "1":
state = "odd" if state == "even" else "even"
elif symbol != "0":
return False
return state == "even"
print(accepts_even_ones("1010")) # True
print(accepts_even_ones("111")) # FalseThe same class of languages can be described using DFAs, nondeterministic finite automata (NFAs), and regular expressions. These descriptions differ in convenience, not in expressive power.
The memory boundary
Regular languages cannot generally compare two unbounded quantities. Consider
\[ L = \{a^n b^n \mid n \geq 1\}. \]
A machine recognising this language must remember how many a symbols occurred and then compare that number with the number of b symbols. No fixed collection of states can store every possible value of \(n\).
This is the point where context-free languages become useful. A context-free grammar can generate \(a^n b^n\), and a pushdown automaton can recognise it by storing one stack symbol for each a and removing one for each b.
| Language | Needed memory | Regular? |
|---|---|---|
| Strings with an even number of `1`s | Fixed state information | Yes |
| \(a^n b^n\) | Unbounded count comparison | No |
| Balanced parentheses | Unbounded nesting depth | No |
The distinction is about memory, not about whether a language has a short description. A regular expression may look complicated while still using only finite-state memory.
A useful diagnostic
When testing whether a language is regular, ask whether recognition requires unbounded matching, counting, or nesting. The pumping lemma for regular languages can prove non-regularity, but it cannot prove that a language is regular. To prove regularity, construct a DFA, NFA, or regular expression.
Exercise
Is \(L = \{a^i b^j \mid i,j \geq 0\}\) regular, and why?
Show answer
Yes. It is described by the regular expression \(a^b^\). The numbers of a and b do not need to match, so finite-state memory is sufficient.