问题
I have this confusion related to regular expression. If there are two sets A
and B
then
is (AB)* = A*B*
?
回答1:
IN CONTEXT OF REGULAR EXPRESSION: is (AB)* = A*B*?
No, (AB)* is not equals to A*B*
(AB)* means ABABABABAB......AB
A sequence of AB (any number of time).A*B* means AAAA.....BBB......
Any number of A's followed by any number of B's. And A can't appear after B's.
Intersection - Both includes { NULL string, AB }
only
Example:
Suppose: A = xy
, and B = z
(AB)* = xyzxyz.....xyz
A*B* = xyxyxyxy....zzzz....z
Intersection - Both includes { NULL string, xyz}
only.
Example:
Suppose -
A = {a, b},
B = {c, d}
Then,
(AB)* = ((a + b)(c + d))* , Its language
L = { ac, ab, acbd, acac, .....}
NOTE: All string in this language are of even length!
And
A*B* = (a + b)* (c + d)* , Its language
L = { a, b, c, d, ac, ad, bc, bd, acbd, addb,.........}
NOTE: Also contains odd length strings.
回答2:
(AB)* = A*B* ?
No. The first is the language
{void, ab, abab, ababab, ...}
the second is the language
{void, a, b, aa, ab, bb, aaa, ...}
来源:https://stackoverflow.com/questions/13355710/confusion-related-to-regular-expression