This is the simple finite automata I tried, what am I doing it wrong?
-
1How is this thing supposed to keep track of how many `a`s it's seen? If you feed it a string starting with `aaaab`, how is it going to know it needs to see 3 more `b`s? – user2357112 Dec 28 '15 at 06:26
-
2Are you mixing this up with the language `(ab)^n`? – user2357112 Dec 28 '15 at 06:27
4 Answers
The b transition leads to a final state which halts the machine. Your machine will only halt if given a sequence of 'ab' of length 1 or more.

- 4,368
- 5
- 44
- 72
-
I think the machine is halted only if the input sequence ends/ delimiter is identified.am i wrong? – user Dec 28 '15 at 06:20
The language a^n b^n where n>=1 is not regular, and it can be proved using the pumping lemma. Assume there is a finite state automaton that can accept the language. This finite automaton has a finite number of states k, and there is string x in the language such that n > k. According to the pumping lemma, x can be decomposed such that x=uvw, and any finite automaton that accepts x must also accept uv*w. v is non-empty and can be made to consist of only a's or only b's since n > k. Let v consist of only a's. If the finite automaton accepts x = uvw, it must also accept x = uvvw, which has more a's than b's and is not of the form a^n b^n. This is a contradiction, so a^n b^n cannot be a regular language.

- 949
- 1
- 9
- 19
This matches (ab)^n, not a^nb^n.
What you're looking for is Pumping lemma for regular languages.
Examples:
Let L = {a^mb^m | m ≥ 1}.
Then L is not regular.
Proof: Let n be as in Pumping Lemma.
Let w = a^nb^n.
Let w = xyz be as in Pumping Lemma.
Thus, xy^2z ∈ L, however, xy^2z contains more a’s than b’s.

- 1,105
- 4
- 30
- 68