#OK to post homework #TaerimKim,9/20/2020,Assignment 4 #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 #2. #For A27, the value for n was 77, but there were 22 total results from seq(i,i=1..77) #To get the smallest n with only 1 hit, the answer for n = 106. #seq(i,i=1..106) in oeis gave only 1 result of A262530(Numbers such that digits occur at most twice in decimal representation.) #3. #3-1. Doing so by hand, #Given U={1,..,15}, #A1={3,6,9,12,15} #A2={5,10,15} #A1 intersect A2 ={15} #|Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2| #={1,2,4,7,8,11,13,14}, total of 8 #3-2. Formulating the maple code, #1st Method Comp := proc(U, A): U minus A; end; PIE2 := proc(U, A1, A2): if not type(U, set) then RETURN(FAIL); end if; if not type(A1, set) then RETURN(FAIL); end if; if not type(A2, set) then RETURN(FAIL); end if; if A1 intersect U = {} or A2 intersect U = {} then RETURN(FAIL); end if; nops(Comp(U, A1) intersect Comp(U, A2)); end proc; #Check by comparing with answers by hand PIE2({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {3, 6, 9, 12, 15}, {5, 10, 15}); 8 #3-2. THe 2nd Method PIE2 := proc(U, A1, A2): if not type(U, set) then RETURN(FAIL); end if; if not type(A1, set) then RETURN(FAIL); end if; if not type(A2, set) then RETURN(FAIL); end if; if A1 intersect U = {} or A2 intersect U = {} then RETURN(FAIL); end if; nops(U) - nops(A1) - nops(A2) + nops(A1 intersect A2): end: #check PIE22({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {3, 6, 9, 12, 15}, {5, 10, 15}); 8 #4. optional Challenge PIE3 := proc(U, A1, A2,A3): if not type(U, set) then RETURN(FAIL); end if; if not type(A1, set) then RETURN(FAIL); end if; if not type(A2, set) then RETURN(FAIL); end if; if not type(A3, set) then RETURN(FAIL); end if; if A1 intersect U = {} or A2 intersect U = {} or A3 intersect U = {} then RETURN(FAIL); end if; 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): end: #check PIE3({1, 2, 3, 4, 5, 6}, {1, 2, 3}, {2, 3, 5}, {5, 6}); 1