3

In the book "The New Turing Omnibus", an excercise reads as the follows:

"Show that no finite automaton can accept the language consisting of all words of the form $a^n b^n, n=1,2,3,...$ The formula represents $n$ a's followed by $n$ b's."

I have no idea why a finite automaton shouldn't accept such words. Couldn't one simply design an automaton that reads a word and always outputs "Accepted"?

David Richerby
  • 82,470
  • 26
  • 145
  • 239
Robert Hönig
  • 175
  • 1
  • 6

4 Answers4

9

Check the definitions. The language accepted by an automaton is the set of strings it accepts. So, for an automaton to accept a particular language (e.g., $\{a^nb^n\mid n\geq 1\}$), it must not only accept every string in the language, but also reject every string not in the language. Your suggestion of the automaton that just accepts every input meets the first criterion but not the second.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
4

In formal language theory, when we say an automaton accepts a language, we mean that it accepts exactly that language, no more, no less.

Your automaton accepts words in $a^n b^n$, but also words with different numbers of as and bs. No finite automaton is capable of distinguishing words with equal numbers of as and bs, and words with different numbers.

You will want to read up on the pumping lemma in order to prove this.

Joey Eremondi
  • 30,277
  • 5
  • 67
  • 122
3

Let $\cal A$ be a deterministic finite automaton that accepts the language $L = \{a^n b^n : n \geq 0\}$. Denote by $q_n$ the state that $\cal A$ arrives at after reading the word $a^n$. Since $\cal A$ has only finitely many states, by the pigeonhole principle we must have $q_n = q_m$ for some $n \neq m$.

What happens when $\cal A$ reads $b^n$, starting at $q_n$? On the one hand, since $a^n b^n \in L$, $\cal A$ must arrive at an accepting state. On the other hand, since $a^m b^n \notin L$ and $q_m = q_n$, $\cal A$ must arrive at a rejecting state. This contradiction shows that $\cal A$ cannot exist.

This argument can be generalized to give a neat algebraic characterization of the regular languages, known as Myhill–Nerode theory. Given a language $L$, say that two words $x,y$ are equivalent if for all words $z$, either $xz,yz \in L$ or $xz,yz \notin L$. If $x,y$ are not equivalent that any automaton accepting $L$ must reach different states after reading $x$ and $y$. Hence if there are infinitely many pairwise inequivalent words, $L$ is not regular. The Myhill–Nerode theorem states that the converse also holds: if any collection of pairwise inequivalent words is finite, then $L$ is regular.

Normally this is stated in terms of equivalence classes: $L$ is regular if and only if the Myhill–Nerode relation (the equivalence relation defined in the preceding paragraph) has finitely many equivalence classes. Moreover, if $L$ is regular and the Myhill–Nerode relation has $n$ equivalence classes, then every DFA accepting $L$ must have at least $n$ states, and there is a unique DFA with exactly $n$ states, known as the minimal DFA.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
2

A finite automaton does not has a memory unit associated with it. It only knows its current state and behaves according to the input provided to the current state.It cannot remember how many 'a's it has already read and how many 'b's it has to further count so as to make number of 'a's equal to number of 'b's ( as 'n' is a variable entity). But if we provide specific number of 'a's and 'b's ( like a3b3 or a5b5) then the automaton will have a dedicated state for every alphabet read.

Another ways of getting it

A finite automaton is a machine to accept regular languages. We can prove by pumping lemma that anbn is not a regular language.

Akash Mahapatra
  • 868
  • 8
  • 16