Sie sind auf Seite 1von 2

http://wikistudent.

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. The first expression can be either r1 or r2. The second expression is always r3. There are two possibilities for this language: r1r3 or r2r3. r1(r2 + r3): The first expression is always r1. It is followed by either r2 or r3. There are two possibilities for this language: r1r2 or r1r3. 2. Construct a regular expression for all words in which a appears tripled, if at all. This means that every clump of as contains 3 or 6 or 9 or 12 as. (aaa + b)* or (b + aaa)* or ((aaa)*b*)* or (b*(aaa)*)* 3. Construct a regular expression for all words that contain at least one of the strings s1, s2, s3, or s4. (s1 + s2 + s3 + s4)(s1 + s2 + s3 + s4)* 4. Construct a regular expression for all words that contain exactly two bs or exactly three bs, not more. a*ba*ba* + a*ba*ba*ba* or a*(b + /\)a*ba*ba* Note: Nothing was said about clumps of bs, so provide for as in between. 5. Construct a regular expression for: (i) all strings that end in a double letter. (ii) all strings that do not end in a double letter. (i) (a + b)*(aa + bb) (ii) (a + b)*(ab + ba) + a + b + /\ Note: Provide for strings containing zero or one letter too! 6. Construct a regular expression for all strings that have exactly one double letter in them. (b + /\)(ab)*aa(ba)*(b + /\) + (a + /\)(ba)*bb(ab)*(a + /\) exactly one double letter implies two equal touching letters; triples etc are excluded. 7. Construct a regular expression for all strings in which the letter b is never tripled. This means that no word contains the substring bbb. (/\ + b + bb)(a + ab + abb)* Words can be empty and start and end with a or b. A compulsory a is inserted between all repetitions of bs. 8. Construct a regular expression for all words in which a is tripled or b is tripled, but not both. This means each word contains the substring aaa or the substring bbb but not both. (/\ + b + bb)(a + ab + abb)*aaa(/\ + b + bb)(a + ab + abb)* + (/\ + a + aa)(b + ba + baa)*bbb(/\ + a + aa)(b + ba + baa)* (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.

Das könnte Ihnen auch gefallen