I need to prove whether the language $ L = \{w \in \{0,1\}^* \mid |w|_0 = |w|_1 \}$ can be written as a regular grammar. Obviously it can, but how do I prove it?
-
Your language is not regular, so cannot be described by a regular grammar. – Yuval Filmus Nov 21 '17 at 14:45
2 Answers
A language can be described by a regular grammar if and only if it is regular. Your language is nor regular, hence it cannot be described as a regular grammar.

- 276,994
- 27
- 311
- 503
-
-
1Its non-regularity can be proved in many ways. It's one of the basic examples of a non-regular language, so you can find the proof in any textbook. – Yuval Filmus Nov 21 '17 at 14:57
That's not a formal proof, but some intuition that can be used sometimes to distinguish between regular & no-regular languages :
The constraint is : number of 0s equals number of 1s. Since we can have any number of 0s, and if we want to assign a state that tells how much 0s we have generated, we would have an infinite number of states. Thus, we can't use states to guide us, we need something like a memory to remember how much 0s we have at a certain instant. Knowing that regular languages are those that are recognized by FA's, in addition with the fact that FA's don't have memory, it's impossible to build a finite automaton to recognize that language. We can conclude prematurely that the language isn't regular.