我有这个家庭作业问题。
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)
我被告知答案是(d)
。我认为(b)
和(c)
也应该是答案。有人可以为我澄清一下吗?
答案 0 :(得分:1)
你应该尝试的第一件事是在每种语言中写出一些简单的字符串。如果你发现一个是RE的语言,而不是另一个,你可以检查以确定,如果是,你就完成了。以下是这些的结果:
(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
基于以上所述,最正确的答案似乎是(d)。