#OK to post homework #Kent Mei, 9/20/20, Assignment 4 #--------------------------------- #Part 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 #Note: In the Maple Code for Lecture 4, I had to rename CheckDecomp to CheckAdd to get the desired output. #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,o,n,r},5)); #true #--------------------------------- #Part 2 #With how the OEIS works, A257 (aka the natural numbers) only appears up to n = 77 where there are 11 hits. #The smallest positive integer n that returns one hit is n = 106 where the only hit is the sequence A262530: the numbers such that digits occur at most twice in decimal representation. #--------------------------------- #Part 3 #U = {1,...,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} #Comp(U,A1) intersect Comp(U,A2) = {1,2,4,7,8,11,13,14} #|Comp(U,A1) intersect Comp(U,A2)| = 8 #A1 intersect A2 = {15} #|U|- |A1|-|A2|+ |A1 intersect A2| = 15 - 5 - 3 + 1 = 8 #|Comp(U,A1) intersect Comp(U,A2)| = |U|- |A1|-|A2|+ |A1 intersect A2| as desired. PIE2:=proc(U,A1,A2) local x, y: 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 not ((A1 subset U) and (A2 subset U)) then print(A1, `and/or`, A2, `is not a subset of`, U): RETURN(FAIL): fi: x := nops((U minus A1) intersect (U minus A2)): y := nops(U) - nops(A1) - nops(A2) + nops(A1 intersect A2): RETURN([x,y]): end: #--------------------------------- #Part 4 PIE3:=proc(U,A1,A2,A3) local x, y: 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 not type(A3, set) then print(A3, `is not a set.`): RETURN(FAIL): fi: if not ((A1 subset U) and (A2 subset U) and (A3 subset U)) then print(A1, `and/or`, A2, `and/or`, A3, `is not a subset of`, U): RETURN(FAIL): fi: x := nops((U minus A1) intersect (U minus A2) intersect (U minus A3)): y := nops(U) - nops(A1) - nops(A2) - nops(A3) + nops(A1 intersect A2) + nops(A1 intersect A3) + nops(A2 intersect A3) - nops(A1 intersect A2 intersect A3): RETURN([x,y]): end: #--------------------------------- #Part 5 PIE4:=proc(U,A1,A2,A3,A4) local x, y: 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 not type(A3, set) then print(A3, `is not a set.`): RETURN(FAIL): fi: if not type(A4, set) then print(A4, `is not a set.`): RETURN(FAIL): fi: if not ((A1 subset U) and (A2 subset U) and (A3 subset U) and (A4 subset U)) then print(A1, `and/or`, A2, `and/or`, A3, `and/or`, A4, `is not a subset of`, U): RETURN(FAIL): fi: x := nops((U minus A1) intersect (U minus A2) intersect (U minus A3) intersect (U minus A4)): y := nops(U) - nops(A1) - nops(A2) - nops(A3) - nops(A4) + nops(A1 intersect A2) + nops(A1 intersect A3) + nops(A1 intersect A4) + nops(A2 intersect A3) + nops(A2 intersect A4) + nops(A3 intersect A4) - nops(A1 intersect A2 intersect A3) - nops(A1 intersect A2 intersect A4) - nops(A1 intersect A3 intersect A4) - nops(A2 intersect A3 intersect A4) + nops (A1 intersect A2 intersect A3 intersect A4): RETURN([x,y]): end: