Finding the regular expression

98 Views Asked by At

I have the problem below: I need to find the regular expression of the set of strings where $n(a)+n(b)$ is an even number (where $n(a)$ is the number of $a$'s and $n(b)$ is the number of $b$'s) ..

I know that $n(a)$, $n(b)$ must be or both even or both odd in order to get an even sum and I have also found that $L_1= b^* (ab^* ab^* )$ is the language of even $a$'s, $L_2= a^* (ba^* ba^* )$ is the language of even $b$'s but I don't know how to find their intersection..

2

There are 2 best solutions below

0
On BEST ANSWER

Let $A$ be the alphabet. If $A = \{a,b\}$, then $n(a) + n(b)$ is simply the length of the word. Therefore your language is the set of words of even length and $(AA)^*$ is a simple regular expression for it.

If $A$ has more than two letters, then a regular expression for your language is $\bigl(C + (a+b)C^*(a+b)\bigr)^*$, where $C = A - \{a,b\}$.

3
On

The a's and b's can appear in any order, but the total number of them has to be even. Hint: Think of generating a pair of letters at a time, then do this repeatedly.