Solution Chapter – 1 Introduction to the Theory of Computation Exercise 1.1 1. With πΊπ = {π, π, π, π}, πΊπ = {π, π, π, π, π}, πππ πΌ = {π βΆ ππ}, compute πΊπ ∩ πΊπ = { π | π ∈ πΊπ πππ π ∈ πΊπ } = { π, π } SOLUTION The set S1 ∩ S2 contains all the elements that are common in both sets S1 and S2. In this case, the elements 2 and 5 are in both sets π1 and π2 , so they are in the intersection of the two sets. π1 π π2 = { π₯ | π₯ ∈ π1 ππ π₯ ∈ π2 } = { 2, 3, 4, 5, 7, 8, 9 } The set π1 π π2 is the union of the sets π1 πππ π2 , containing all the elements that are in either set. π1 ∪ π = { π₯ | π₯ ∈ π1 ππ π₯ ∈ π } = { 1, 2, 3, 5, 7, 10 } The set π1 ∪ π is the union of the sets π1 πππ π. It contains all elements in set π1 and all element in set π. π2 ∪ π = { π₯ | π₯ ∈ π2 ππ π₯ ∈ π } = { 1, 2, 4, 5, 8, 9, 10 } The set π2 ∪ π is the union of the sets π2 and U. It contains all elements in set π2 and all element in set π. 2. With πΊπ = {π, π, π, π} and πΊπ = {π, π, π, π, π}, compute πΊπ × πΊπ and πΊπ × πΊπ. Solution: First, we need to understand what the Cartesian product of two sets is. The Cartesian product of two sets is the set of all possible ordered pairs that consist of one element from each set. Each ordered pair (π₯, π¦) in the Cartesian Product π1 × π2 , represents an element x from set S1 and an element y from set S2. Given the sets π1 = {2, 3, 5, 7} and π2 = {2, 4, 5, 8, 9}. To compute the Cartesian Product π1 × π2 , we need to form all possible ordered pairs (x, y) where x is an element of set π1 and π¦ is an element of set π2 . In this case, we have 4 elements in set π1, which are 2, 3, 5, 7, πππ 5 elements in set π2 , which are 2, 4, 5, 8, 9. So, there are 4 × 5 = 20 possible ordered pairs that can be formed by combining elements of set π1 and set π2 . The result of the Cartesian Product π1 × π2 , will be a set containing all 20 of these ordered pairs: { (2, 2), (2, 4), (2, 5), (2, 8), (2, 9), (3, 2), (3, 4), (3, 5), (3, 8), (3, 9), (5, 2), (5, 4), (5, 5), (5, 8), (5, 9), (7, 2), (7, 7, 4), (7, 5), (7, 8), (7, 9) } Similarly, To compute the Cartesian Product π2 × π1 , we need to form all possible ordered pairs (π₯, π¦) where π₯ is an element of set π2 and π¦ is an element of set π1. The result of the Cartesian Product π2 × π1 will be a set containing all 20 of these ordered pairs: { (2, 2), (2, 3), (2, 5), (2, 7), (4, 2), (4, 3), (4, 5), (4, 7), (5, 2), (5, 3), (5, 5), (5, 7), (8, 2), (8, 3), (8, 5), (8, 7), (9, 2), (9, 3), (9, 5), (9, 7) } It's important to note that the order of the sets is important for Cartesian Product, since the result will be different if we change the order of the sets. As you can see from the above, π2 × π1 is different from π2 × π1 . Also, we can observe that Cartesian product of two sets is commutative and the number of ordered pairs in the Cartesian Product of two sets is the product of number of elements in the two sets. 3. For S = {2, 5, 6, 8} and T = {2, 4, 6, 8}, compute |S ∩ T| + |S ∪ T|. To compute the size of the intersection of two sets S and T, we use the notation |S ∩ T|. The intersection of two sets is the set of elements that are common to both sets. To compute the size of the union of two sets S and T, we use the notation |S ∪ T|. The union of two sets is the set of elements that are in either S or T or both. For the given sets S = {2, 5, 6, 8} and T = {2, 4, 6, 8}, we can compute their intersection and union as follows: S ∩ T = {2, 6, 8} (elements that are in both S and T) S ∪ T = {2, 4, 5, 6, 8} (elements that are in either S or T or both) So, |S ∩ T| = 3 (size of the intersection set) and |S ∪ T| = 5 (size of the union set) Now we can compute the final expression: |S ∩ T| + |S ∪ T| = 3 + 5 = 8 So the final result is 8 4. What relation between two sets S and T must hold so that |S∪T| = |S|+|T|? For two sets S and T, the relation between them that must hold so that |S ∪ T| = |S| + |T| is that they must be disjoint sets. Disjoint sets are sets that have no elements in common, meaning that the intersection of the sets is the empty set. When two sets are disjoint, there are no elements that belong to both sets, so all elements in the union of the sets belong to either S or T. As a result, the size of the union of the sets is equal to the size of set S plus the size of set T, which can be represented as |S ∪ T| = |S| + |T|. We can also prove this by using the Identity law of Set theory : |A| + |B| = |A∪B| + |A∩B| Since the sets are disjoint, the intersection of the sets is an empty set, |A∩B| = 0 Therefore, |A| + |B| = |A∪B| + 0 = |A∪B| So if we have two disjoint sets, their union is the sum of the size of the individual sets. 5. Show that for all sets S and T, S − T = S ∩ T. To prove that S − T = S ∩ T for all sets S and T, we can start by examining the definitions of the set difference and set intersection operations. ο· The set difference of S and T, denoted as S − T, is the set of elements that belong to S but not to T. In other words, it is the set of elements that are in S but not in T. ο· The set intersection of S and T, denoted as S ∩ T, is the set of elements that belong to both S and T. In other words, it is the set of elements that are in both S and T. From the definitions above, we can see that the elements of S − T are the elements that are in S but not in T. At the same time, we can see that the elements of S ∩ T are the elements that are in both S and T. Therefore, we can conclude that S − T = S ∩ T, since they both represent the same set of elements, the elements that belong to S but not to T. We can also prove this by contradiction. Assume that S − T ≠ S ∩ T, then there will be some elements in S − T which are not in S ∩ T or vice versa. But this contradicts the definition of set difference and set intersection as we have discussed earlier. Therefore, S − T = S ∩ T for all sets S and T. 6. Prove DeMorgan’s laws, Equations (1.2) and (1.3), by showing that if an element x is in the set on one side of the equality, then it must also be in the set on the other side of the equality. DeMorgan's laws are two important laws in set theory that relate the complements of sets to the intersections and unions of sets. They are given by the following equations: (1.2) ~(S ∪ T) = ~S ∩ ~T (1.3) ~(S ∩ T) = ~S ∪ ~T To prove these laws, we can show that if an element x is in the set on one side of the equality, then it must also be in the set on the other side of the equality. Let's start with equation (1.2): ~(S ∪ T) = ~S ∩ ~T If x is in ~(S ∪ T), then it means that x is not in the union of S and T. This means that x is not in S and x is not in T. Therefore, x is in the complement of S, ~S, and x is in the complement of T, ~T. So x is in the intersection of ~S and ~T, which is ~S ∩ ~T. Conversely, if x is in ~S ∩ ~T, then it means that x is not in S and x is not in T. This means that x is not in the union of S and T. Therefore, x is in the complement of the union of S and T, ~(S ∪ T). So we have shown that if x is in the set on one side of the equation, then it must also be in the set on the other side of the equation. Let's move to equation (1.3): ~(S ∩ T) = ~S ∪ ~T If x is in ~(S ∩ T), then it means that x is not in the intersection of S and T. This means that x is not in S or x is not in T. Therefore, x is in the complement of S or x is in the complement of T, ~S or ~T. So x is in the union of ~S and ~T, which is ~S ∪ ~T. Conversely, if x is in ~S ∪ ~T, then it means that x is not in S or x is not in T. This means that x is not in the intersection of S and T. Therefore, x is in the complement of the intersection of S and T, ~(S ∩ T). So we have shown that if x is in the set on one side of the equation, then it must also be in the set on the other side of the equation. By showing that if an element x is in the set on one side of the equality, then it must also be in the set on the other side of the equality, we have proven DeMorgan's laws, equations (1.2) and (1.3), which relate the complements of sets to the intersections and unions of sets. 7. Show that if S1 ⊆ S2, then S2 ⊆ S1. It is not true that if S1 ⊆ S2, then S2 ⊆ S1. The symbol ⊆ means subset, which means that all elements of set S1 are also present in set S2, but set S1 may have other elements that are not in set S2. For example, let S1 = {1, 2, 3} and S2 = {1, 2}. We can see that S1 ⊆ S2, because all elements of S1 are in S2. But S2 is not a subset of S1 because not all elements of S2 are in S1. Another example is let S1 = {1, 2} and S2 = {1, 2, 3}. Here we can see that S1 ⊆ S2, but S2 is not a subset of S1 because not all elements of S2 are in S1. So we can conclude that if S1 ⊆ S2, it does not imply that S2 ⊆ S1. 8. Show that S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2. We can show that S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2 using the following logical equivalences: ο· S1 = S2 if and only if S1 ⊆ S2 and S2 ⊆ S1 ο· S1 ⊆ S2 if and only if S1 ∪ S2 = S2 ο· S2 ⊆ S1 if and only if S1 ∩ S2 = S2 From 1, we have: S1 = S2 if and only if (S1 ⊆ S2 and S2 ⊆ S1) From 2 and 3, we have: S1 ⊆ S2 if and only if S1 ∪ S2 = S2 and S2 ⊆ S1 if and only if S1 ∩ S2 = S2 Combining these equivalences, we get: S1 = S2 if and only if (S1 ∪ S2 = S2) and (S1 ∩ S2 = S2) Since S2 is a subset of S1 and S1, it means S1 ∪ S2 = S2 and S1 ∩ S2 = S2, so we can write: S1 = S2 if and only if S1 ∪ S2 = S1 ∩ S2 In other words, two sets are equal if and only if their union and intersection are equal. Exercise 1.2 1. How many substrings πππ are in πππΉ π, where π = ππππππ? Solution: A substring is a sequence of characters that appear in a string in a consecutive manner. In this question, we are looking for the number of substrings πππ in the string π€π€ π π€ where π€ = ππππππ. To find this, we first need to determine what the string π€π€ π π€ is. In this case, the string π€π€ π π€ is formed by concatenating the string w = ππππππ twice and then reversing the second copy. So, π€π€ π π€ = "πππππππππππππ". After that we need to look for all substring πππ in the string π€π€ π π€ Here, we can see that there are 3 such substrings "πππ" a a b Set 1 b a b a a b Set 2 b a a B Set 3 ππ π‘βπ πππ π€ππ ππ 3. 2. Use induction on n to show that |ππ | = π |π| for all strings π and all π. Solution: π΅ππ π πΆππ π (π = 1) When π = 1, |π’π | = |π’|. This is true because π’1 = π’, so the length of the concatenation of π’ with itself once is the same as the length of the original string π’. Inductive Step: Assume that |π’π | = π|π’| is true for some π. We will now prove that |π’^(π + 1)| = (π + 1)|π’|. We know that |π’(π+1) | = |π’π π’|. By the induction hypothesis, we know that |π’^π| = π|π’|. Since we are concatenating π’π with π’, |π’π π’| = (π|π’|) + |π’| = π|π’| + |π’| = (π + 1)|π’|. Therefore, by mathematical induction, we have shown that |π’π | = π|π’| for all strings π’ and all π. In simple words, the length of the concatenation of a string π’ with itself n times is equal to the length of the original string multiplied by π. 3. The reverse of a string, introduced informally above, can be defined more precisely by the recursive rules ππ = π, (π€π)π = ππ€π , πππ πππ π ∈ π΄, π€ ∈ π΄ ∗. ππ π π‘βππ π‘π ππππ£π π‘βππ‘ (π’π£)π = π£π π’π , πππ πππ π’, π£ ∈ π΄ +. Solution: The question is asking to prove that for any two strings u and v in the set of non-empty strings Σ+, the reverse of the concatenation of those strings (uv) is the concatenation of the reverse of those strings (vR uR). We can use the recursive definition of string reversal to prove this statement. First, we'll define some notation for the problem. Let Σ be the set of all characters, and let Σ* be the set of all strings, including the empty string. Then, let Σ+ be the set of all non-empty strings. With this notation, we can state the problem as: 4. Prove that for all u, v ∈ Σ+, (uv)R = vR uR To prove this statement, we'll use the recursive definition of string reversal, which is defined by the following two rules: ο· aR = a for all a ∈ Σ (the reverse of a single character is itself) ο· (wa)R = awR for all a ∈ Σ and w ∈ Σ* (the reverse of a string w followed by a character a is the reverse of a followed by the reverse of w) Using these rules, we can prove the statement by induction on the length of the string u. Base case: If the length of u is 1 (u ∈ Σ), then (uv)R = (u(vR))R. Using the second rule, we can reverse the string u(vR) by reversing the string vR and then reversing the string u. So, (uv)R = (vR) (uR) = vR uR. Inductive step: Assume that the statement is true for all strings u with a length of n, where n > 1. Now, let u be a string with a length of n+1. Then, we can write u as u'a for some string u' and some character a. By the definition of concatenation, we can write (uv) as (u'av). Then, we can reverse this string by reversing the string v and then reversing the string u'a. Using the second rule, we can reverse the string u'a by reversing the character a and then reversing the string u'. And, by the induction hypothesis, we know that (u'R) aR = u'Ra. Now, we can reverse the string vR and then reverse the string u'Ra, to get (uv)R = (vR) (u'Ra) = (vR) (u'R) aR = vR (u'R) aR = vR u'RaR = vR u'R aR = vR u'R a = vR (u'Ra) = vR uR. So, by induction, we've proven that the statement holds for all u, v ∈ Σ+. Finally, we have used the recursive definition of string reversal to prove that for any two strings u and v in the set of non-empty strings Σ+, the reverse of the concatenation of those strings (uv) is the concatenation of the reverse of those strings (vR uR) 5. To prove that (WR)R = w for all w ∈ Σ*, we can use the recursive definition of string reversal, which is defined by the following two rules: ο· aR = a for all a ∈ Σ (the reverse of a single character is itself) ο· (wa)R = awR for all a ∈ Σ and w ∈ Σ* (the reverse of a string w followed by a character a is the reverse of a followed by the reverse of w) We can prove this statement by induction on the length of the string w. Base case: If the length of w is 0 (w is the empty string), then (WR)R = (RR) = R = w. Inductive step: Assume that the statement is true for all strings w with a length of n, where n > 0. Now, let w be a string with a length of n+1. Then, we can write w as wa for some string w' and some character a. Then, we can reverse the string (wa)R by reversing the string a and then reversing the string w', using the second rule. Then, we can reverse the reversed string (wa)R by reversing the string w' and then reversing the character a. So, (wR)R = (w'aR)R = (aw'R)R = waR = w. So, by induction, we've proven that the statement holds for all w ∈ Σ*. Overall, we have used the recursive definition of string reversal to prove that for any string w in Σ*, (WR)R = w. 6. Given the language L = {ab, aa, baa}, the following strings are in L*: πππππππππππ: This string can be formed by concatenating the string "ab" with itself 3 times. ο· πππππππππ: This string can be formed by concatenating the string "aa" with itself 3 times and concatenating it with "ab" ο· ππππππππππππ: This string can be formed by concatenating the string "baaa" with itself and concatenating it with "ab" ο· πππππππππ: This string can be formed by concatenating the string "baaa" with itself and concatenating it with "aa" A language L^n (L to the power of n) is the set of all possible strings that can be formed by taking n concatenations of the strings in the original language L. Given the language L = {ab, aa, baa}, the following strings are in L^4: ππππππππ: This string can be formed by concatenating the string "ab" with itself 4 times. πππππππππππππππππππ: This string can be formed by concatenating the string "aa" with itself 4 times and concatenating it with "abab" ππππππππππππππππππππππππππππ: This string can be formed by concatenating the string "baaa" with itself 3 times and concatenating it with "abaa" πππππππππππππππππππππππππππππ: This string can be formed by concatenating the string "baaa" with itself 4 times. Note that the set of strings in L^n can be infinite, and this are just some examples of the possible strings in L^4.