Professional Documents
Culture Documents
Capitulo 4
Capitulo 4
ws/Unisa
Cohen chapter 4
1. Let r1, r2, and r3 be three regular expressions. Show that the language associated with (r1
+ r2)r3 is the same as the language associated with r1r3 + r2r3. Show that r1(r2 + r3) is
equivalent to r1r2 + r1r3. This will be the same as providing a distributive law for regular
expressions.
(r1+ r2)r3:
http://wikistudent.ws/Unisa
words in which a is tripled means there is at least one triple, and possibly more.
9. Construct a regular expression for:
(i) all words that do not have the substring ab.
(ii) all words that do not have both the substrings bba and abb.
(i)
b*a*
This contains only bs or only as, or bs followed by as or /\.
(ii)
words that do not have both substrings means that words may have one or the other - just
not both (i.e. not abba or bbaabb).
So put a + between two regular expressions defining a) all words excluding bba, and b) all
words excluding abb.
Together they form a regular expression that excludes both substrings simultaneously.
a*(baa*)*b* + b*(a*ab)*a*
LHS: If theres a double b, its not followed by an a.
RHS: If theres a double b, its not preceded by an a.
10. Construct a regular expression for all strings in which the total number of as is divisible by
3 no matter how they are distributed, such as aabaabbaba.
(b*ab*ab*ab*)*
11. Construct a regular expression for:
(i) all strings in which any bs that occur are found in clumps of an odd number at a time, such
as abaabbbab.
(ii) all strings that have an even number of as and an odd number of bs.
(iii) all strings that have an odd number of as and an odd number of bs.
(i)
a*(b(bb)*aa*)*(/\ + b(bb)*)
The compulsory a after some number of odd bs is there because odd + odd = even, so it is
needed to separate these odd clumps.
(ii)
EVEN-EVEN = [aa + bb + (ab + ba)(aa + bb)*(ab + ba)]*
Divide the language into 2 groups:
a) Words that start with b (followed by even as and even bs)
b) Words that start with a (followed by odd as and odd bs)
b(EVEN-EVEN) + a[EVEN-EVEN(ab + ba)EVEN-EVEN]
(iii)
EVEN-EVEN(ab + ba)EVEN-EVEN
The smallest string is ab or ba.
Even letters can be added to the left, right, or both.