-1

Let be a language with the following alphabet : $\Sigma=\{a,b\}$

I want to write the regular expression of {$w$ | $w$ containing a number of $a$ that we can divide by $3$ }

A friend of mine thought of $(b^*+ab^*aa+aab^*a)^*$ and it seems alright for me but I said to me today that it wasn't true but I can't see why. I havn't found counter examples.

I rather thought of $(b^*ab^*ab^*ab^*)^*$ but I'm not sure. I haven't found counter examples yet.

Therfore, how to have the regular expression of a language with two letters, one which number of instances can be divided by three ?

  • 1
    As I noted below, your regular expression almost works, but since 3 divides 0, the string $b$ should be in your language, but isn't in the language denoted by your regular expression. – Rick Decker Feb 01 '17 at 18:36

1 Answers1

1

The first regular expression is incorrect. It assumes that for any string containing at least one $a$, it must contain consecutive $a$s. So, a string such as $ababa$ is a counterexample.

The second regular expression is almost correct for the given language, except it doesn't cover the case where there are no $a$s at all. So, you could consider expressing it as $$(b^*ab^*ab^*ab^*)^*+b^*$$ In general, constructing a finite automation for such a language is very easy. From there, you can convert it to a regular expression using methods such as this.

GoodDeeds
  • 851
  • 5
  • 14
  • FWIW, I'd go for the simpler $b^(ab^ab^ab^)^*$. But there are lots of ways to write a regular expression for this language. – rici Feb 01 '17 at 21:43