# how to generate regular expression for the language where symbols have to maintain certain length?

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.

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)^*$$

• @HendrikJan Sorry, I am not sure what you are trying to say. Commented Feb 16 at 17:23
• Oh yeah, you are right! Commented Feb 16 at 22:42

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.