Why is {a^nb^n | n >= 0} not regular?

2019-01-12 02:47发布

In a CS course I'm taking there is an example of a language that is not regular:

{a^nb^n | n >= 0}

I can understand that it is not regular since no Finite State Automaton/Machine can be written that validates and accepts this input since it lacks a memory component. (Please correct me if I'm wrong)

The wikipedia entry on Regular Language also lists this example, but does not provide a (mathematical) proof why it is not regular.

Can anyone enlighten me on this and provide proof for this, or point me too a good resource?

3条回答
冷血范
2楼-- · 2019-01-12 03:27

Finite State Automaton has no data structure (stack) - memory as in case of push down automaton. Yeah it can give you some 'a's followed by some 'b's but not exact amount of 'a' followed by that no 'b'.

查看更多
爷的心禁止访问
3楼-- · 2019-01-12 03:31

What you're looking for is Pumping lemma for regular languages.

Here is an example with your exact problem:

Examples:
Let L = {ambm | m ≥ 1}.
Then L is not regular.
Proof: Let n be as in Pumping Lemma.
Let w = anbn.
Let w = xyz be as in Pumping Lemma.
Thus, xy2z ∈ L, however, xy2z contains more a’s than b’s.

查看更多
Deceive 欺骗
4楼-- · 2019-01-12 03:40

Because you can't write a finite state machine that will 'count' identical sequences of 'a' and 'b' symbols. In a nutshell, FSMs cannot 'count'. Try imagining such a FSM: how many states would you give to symbol 'a'? How many to 'b'? What if your input sequence has more?

Note that if you had n <= X with X an integer value you could prepare such FSM (by having one with a lots of states, but still a finite number); such language would be regular.

查看更多
登录 后发表回答