1
$\begingroup$

L = {x in {0,1}* | x has an equal number of 0s & 1s}

Based on the recursive definition of regular languages, isn't it possible to form a single regular language set over the binary alphabet {0,1} by doing the following?

  1. concatenating 0's and 1's to form each of the binary strings satisfying the condition, resulting in a regular language consisting of that single string
  2. union all the single-string regular languages together into one single regular language
$\endgroup$
  • $\begingroup$ There must be something wrong with your proof attempt, since it would apply to any language and there are surely some non-regular languages. The answers explain what. $\endgroup$ – David Richerby Apr 6 at 19:47
3
$\begingroup$

Every language is the union of regular languages: $$ L = \bigcup_{x \in L} \{ x \}. $$ However, the set of regular languages is not closed under infinite unions. It isn't even closed under countably infinite unions, as your example demonstrates.

You can prove that your language is not regular in many ways. For example, if your language were regular, then so would its intersection with $0^*1^*$ be; yet this language is $\{ 0^n 1^n : n \geq 0 \}$, the classical example of a non-regular language. You can also prove non-regularity of your language directly, using either the pumping lemma or Myhill–Nerode theory.

$\endgroup$
  • $\begingroup$ Thank you very much! $\endgroup$ – Shukie Apr 7 at 8:55
1
$\begingroup$

You're on the right track! There's just one thing you're missing.

The "build all the strings and union them together" approach works great—if you have a finite number of strings. There's a theorem that says "a union of finitely many regular languages is regular", but the key is the finitely many.

In this case, there are infinitely many strings in the language, so the union-them-all trick no longer works.

If you want to prove that the language is not regular (as opposed to just failing to prove that it is regular), try a fooling set proof:

  • Let $F$ be the language $1^*$. It's clearly infinite.
  • Let $x$ and $y$ be two distinct strings in $F$. These can be written as $1^i$ and $1^j$ with $i \neq j$.
  • Now, let $z$ be $0^i$. From the definition of your language, we can see that $xz$ is in the language, but $yz$ is not.
  • Therefore, all the different strings in $F$ are distinguishable as prefixes. Since the language has infinitely many distinguishable prefixes, it cannot be regular.
$\endgroup$
  • $\begingroup$ Thank you very much! That finite part wasn't mentioned in my lecture notes unfortunately. $\endgroup$ – Shukie Apr 7 at 8:56
  • $\begingroup$ @Shukie It's an unfortunate fact that many lecturers gloss over the "fine print" in the proofs. Often that works just fine, and then you run into one of the cases like this where the fine print matters! (In other words, it's a good question to ask!) $\endgroup$ – Draconis Apr 7 at 16:11
1
$\begingroup$

After you process n zeroes, the set of following strings leading to an accept state are all those with n 1’s more than 0’s. All these sets are different. And each set is roughly the same as a state in a state machine - so you can’t have a state machine with finite number of states.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.