Is the set of binary words with at least 2 ones regular?

124 Views Asked by At

Let $L=\{w\in\{0,1\}^*:\#_0(w)<\#_1(w)\}\cup\{w\in\{0,1\}^*:\#_1(w)>2\}$,

where $\#_0(w)$ is the number of zeroes in $w$. Is the language $L$ regular?

I tried to proof that $\{w\in\{0,1\}^*:\#_0(w)<\#_1(w)\}$ is regular, by showing, that for any $i\in\mathbb N_0$ $\{w\in\{0,1\}^*:\#_0(w)<\#_1(w), |w|=i\}$ is regular. But I'm not sure if $\{w\in\{0,1\}^*:\#_1(w)>2\}$ is regular.

3

There are 3 best solutions below

0
On BEST ANSWER

Setting $A = \{0,1\}$, your language can be written as \begin{align} L &= \{w \in \{0,1\}^* \mid \#_1(w)>2\} \cup \{w \in \{0,1\}^* \mid \#_0(w)<\#_1(w) \leqslant 2\}\\ &= A^*1A^*1A^*1A^* \cup \underbrace{\{\varepsilon, 1, 11\}}_{\#_0(w) = 0} \cup \underbrace{\{0, 01, 10, 011, 101, 110\}}_{\#_0(w) = 1} \end{align} and is therefore regular.

0
On

Your strategy is:

  1. If I could show that both sides of the union are regular, then $L$ would be regular
  2. The left side is regular because for any $i\in\mathbb N_0$ $\{w\in\{0,1\}^*:\#_0(w)<\#_1(w), |w|=i\}$ is regular
  3. Now I need to show that the right side is regular

This was a reasonable thing to try! (1) would work, if you could do (2) and (3). And it is not hard to prove (3). Unfortunately (2) is false and your argument that it is true is unsound.

Your argument in step (2) follows this pattern:

$$\{w : P(w) \text{ and } |w|=i\}\text{ is regular for all $i$}\\ \text{therefore}\\ \{w : P(w) \}\text { is regular}$$

This is wrong. The language $\{w : P(w) \text{ and } |w|=i\}$ is finite, therefore it is always regular. So for example $$\{w : w\in0^n1^n \text{ and } |w|=i\}$$ is regular for all $i$ (again, because it is finite, and in fact it contains at most one element) but $$\{w : w\in0^n1^n\}$$ is the prototypical example of a language that is not regular.

So step (2) is unsound. And in fact you can't prove that the left side of the union is regular, because it isn't regular.


The left-hand side of the union is not regular, and you should make sure you understand why this is before you proceed. Imagine that you are the finite machine, looking at a very long string, trying to decide if it has more ones than zeros. How would you do this? What if you only had one small piece of paper to keep notes? What if there were a great many ones and zeroes? If there were too many, you might lose count.

What saves you in this case? The right side of the union gives you an escape hatch: if the string has a great many ones, you don't have to care about the left side of the union. If a string has many ones, then whether it is in the left side or not, it is definitely in the right side, and you can accept it immediately.

So you only have to worry about the left side of the union for strings that have only a few ones, and that is what makes the union regular.

Your hint is:

Consider that $$P\text{ or }Q$$ is equivalent to $$(P\text{ and not }Q)\text{ or }Q$$

0
On

It is also possible to construct a FSM:

FSM for L