0
$\begingroup$

I am having hard time creating regex for languages where symbols must be in certain length. I hope I am not ignorant about rules. we have to generate regex using $^*,|,+ \text{ and }\cdot$ right?

I am expected to generate a regex for the language $\{ L = \{ w ∈ \{0,1\}^∗ : |w|_0 and |w|_1 \text{ is odd } \}$. both 0s and 1s have must have odd length.

I was able to generate it for the same language but with even length, but can't find a pattern for this.

$\endgroup$
2

2 Answers 2

2
$\begingroup$

I created a DFA recognizing the language and used the Brzozowski and McCluskey's algorithm (state elimination method) to obtain:

$$(00\mid 11)^*(01\mid 10)\left(00\mid 11 \mid (01\mid 10)(00\mid 11)^*(01\mid 10)\right)^* $$

$\endgroup$
2
  • $\begingroup$ @HendrikJan Sorry, I am not sure what you are trying to say. $\endgroup$
    – Nathaniel
    Feb 16 at 17:23
  • $\begingroup$ Oh yeah, you are right! $\endgroup$
    – Nathaniel
    Feb 16 at 22:42
2
$\begingroup$

The odd-odd language can be accepted by a four state finite state automaton. It stores for each of the symbols whether it has seen an even or odd number of that symbol. Thus we need two bits, one for each of $0,1$. Reading and $0$ or a $1$ will flip the corresponding bit.

The fun part is that we can reduce this elegantly into a two state automaton, holding a single bit (representing both parities at the same time), when reading two symbols at a time.

This is seen as follows. Reading $00$ or $11$ will stay in the same state: the parity of both symbols does not change. Reading $01$ or $10$ will move to the other state, both parities change.

Both numbers have to be odd, so we need the strings that have $01+10$ an odd number of times, and any number of $00+11$. This is a much simpler exercise, but equivalent to the original question.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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