0

I have this homework question.

Which pair of regular expressions are equivalent?
a) (ab)* and a*b*
b) r(rr)* and (rr)*r
c) r+ and r*r
d) (b) and (c)

I have been told that the answer is (d). I think (b) and (c) should also be answers. Can someone clarify this for me?

Welbog
  • 59,154
  • 9
  • 110
  • 123
  • The answer `(d)` is that both `(b)` and `(c)` are equivalent. If you have to select only one, most correct answer, the answer is `(d)`, because both `(b)` and `(c)` are equivalent pairs. `(b)` is strings of odd numbers of `r`. `(c)` is strings of at least one `r`. – Welbog Dec 05 '17 at 15:21

1 Answers1

1

The first thing you should try is writing out a few simple strings in each language. If you find one that's in the language of one RE but not the other, you can check to make sure and, if so, you're done. Here's what that looks like for these:

(a)
 - (ab)*: e, ab, abab, ababab, ...
 - a*b* : e, a, b, aa, ab, bb, ...
 guess: a is in L(a*b*) but not (ab)*.
 check: (ab)* only generates strings with the same number of a's as b's.
 L((ab)*) != L(a*b*)

(b)
 - r(rr)*: r, rrr, rrrrr, rrrrrrr, ...
 - (rr)*r: r, rrr, rrrrr, rrrrrrr, ...
 guess: these look the same.
 proof: the first generates all and only strings of r's of odd length.
        the second generates all and only strings of r's of odd length.
        these languages are the same.
        alternatives:
        - derive DFAs L and R and show DFAs for L \ R and R \ L accept
          the empty language.

(c)
 - r+ : r, rr, rrr, rrrr, ...
 - r*r: r, rr, rrr, rrrr, ...
 guess: these look the same.
 proof: the first generates all and only non-empty strings of r's.
        the second generates all and only non-empty strings of r's.
        these languages are the same.
        alternatives:
        - derive DFAs L and R and show DFAs for L \ R and R \ L accept
          the empty language

Based on the above, the most correct answer would appear to be (d).

Patrick87
  • 27,682
  • 3
  • 38
  • 73
  • Being same and equivalent is diff thing ? – Riya kathil Dec 06 '17 at 17:11
  • @Riyakathil The *regular expressions* are equivalent in that they represent *the same* language. Clearly, `r(rr)*` is not *the same* as `(rr)*r`, but they are equivalent. The same basic concept applies to automata and grammars: they can be equivalent without being equal. – Patrick87 Dec 06 '17 at 18:44