#Ok to post homework #Tifany Tong, September 20th, 2020, HW #4 # Question 1: # CP({a, b, c}, {b, c, d}) = {[a, b], [a, c], [a, d], [b, b], [b, c], [b, d], [c, b], [c, c], [c, d]} # CheckMult({1, 2}, {3, 4}) = true # CheckAdd({1, 2, 3}, {3, 4, 5}) = # {1, 2, 3}, {3, 4, 5}, have the following common elements, {3} # FAIL # member([d, o, r, o, n], Words({d, n, o, r}, 5)) = true # Question 2: # There is no sequence that will result in A27 as the only hit. When I search up the entire sequence (seq(i,i=1..77)), I still get 11 search hits. # Question 3: # Checking by hand: # U = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} # A1 = {3,6,9,12,15} # A2 = {5,10,15} # Comp(U,A1) = {1,2,4,5,7,8,10,11,13,14} # Comp(U,A2) = {1,2,3,4,6,7,8,9,11,12,13,14} # The length of (Comp(U,A1) intersect Comp(U,A2)) is the length of {1,2,4,7,8,11,13,14}, which is 8. # |U| - |A1| - |A2| + |A1 intersect A2| = 15 - 5 - 3 + (length of {15}) = 15-8+1 = 8. # Both values come out to 8, showing that these two values are equal for the given case of U,A1, and A2. Comp := proc(n, z) local S, S1, i, l, j: option remember: S := {}: l := nops(n): for i to l do if not member(n[i], z) then S := S union {n[i]}: fi: od: S: end: PIE2 := proc(U, A1, A2) local subprob1, subprob2, S, Z: if not type(U, set) then print(U, `is not a set `): RETURN(FAIL): fi: if not type(A1, set) then print(A1, `is not a set `): RETURN(FAIL): fi: if not type(A2, set) then print(A2, `is not a set `): RETURN(FAIL): fi: if nops(A1 intersect U) = nops(U) then print(A1, 'is a subset of', U): RETURN(FAIL): fi: if nops(A2 intersect U) = nops(U) then print(A2, 'is a subset of', U): RETURN(FAIL): fi: subprob1 := nops(U) - nops(A1) - nops(A2) + nops(A1 intersect A2): S := Comp(U, A1): Z := Comp(U, A2): subprob2 := nops(S intersect Z): RETURN([subprob1, subprob2]): end: