#OK to post #Soham Palande, Assignment 4, 09/19/2020 #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 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 # 106 is the smallest positive integer such that 1, 2, 3, ....., n (in Maple: seq(i,i=1..n) ) only returns ONE hit #PART 3 # U={1,..., 15}, A1= subset of U that are multiples of 3, A2=subsets of U that are multiples of 5 # A1={3,6,9,12,15} # A2={5,10,15} # A1^ = Complement of A1={1,2,4,5,7,8,10,11,13,14} # A2^ = COmplement of A2={1,2,3,4,6,7,8,9,11,12,13,14} # A1^ intersect A2^ = {1,2,4,7,8,11,13,14} , |A1^ intersect A2^|= 8 # A1 intersect A2 = {15}, |A1 intersect A2|= 1 #Verifying Formula: |Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2| # 8 = 15 - 5 - 3 + 1 # It works! #PIE2(U,A1,A2): |Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2| PIE2:=proc(U,A1,A2) local n1,n2,A1comp, A2comp: 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 A2 subset U then print(A2, `is not a subset of universal set`): RETURN(FAIL): fi: if not A1 subset U then print(A1, `is not a subset of universal set`): RETURN(FAIL): fi: #FIRST WAY A1comp:=U minus A1: A2comp:=U minus A2: n1:=numelems(A1comp intersect A2comp): #SECOND WAY n2:=numelems(U)-numelems(A1)-numelems(A2)+numelems(A1 intersect A2): print(n1): print(n2): end: #EXAMPLE U:={seq(i,i=1..15)} U := {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} A1:={3,6,9,12,15} A1 := {3, 6, 9, 12, 15} A2:={5,10,15} A2 := {5, 10, 15} PIE2(U,A1,A2) 8 8 #PART 4 #PIE3(U,A1,A2,A3): PIE3:=proc(U,A1,A2,A3) local n1,n2,A1comp, A2comp,A3comp: 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 A2 subset U then print(A2, `is not a subset of universal set`): RETURN(FAIL): fi: if not A1 subset U then print(A1, `is not a subset of universal set`): RETURN(FAIL): fi: if not A3 subset U then print(A3, `is not a subset of universal set`): RETURN(FAIL): fi: #FIRST WAY A1comp:=U minus A1: A2comp:=U minus A2: A3comp:=U minus A3: n1:=numelems(A1comp intersect A2comp intersect A3comp): #SECOND WAY n2:=numelems(U)-numelems(A1)-numelems(A2)-numelems(A3)+numelems(A1 intersect A2)+numelems(A1 intersect A3) + numelems(A2 intersect A3) - numelems(A1 intersect A2 intersect A3): print(n1): print(n2): end: U:={seq(i,i=1..15)} U := {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} A1:={3,6,9,12,15} A1 := {3, 6, 9, 12, 15} A2:={5,10,15} A2 := {5, 10, 15} A3:={1,2,3,4,5,6,7} A3 := {1, 2, 3, 4, 5, 6, 7} PIE3(U,A1,A2,A3) 4 4 #PART 5 #PIE4(U,A1,A2,A3,A4): PIE4:=proc(U,A1,A2,A3,A4) local n1,n2,A1comp, A2comp,A3comp,A4comp: 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 A2 subset U then print(A2, `is not a subset of universal set`): RETURN(FAIL): fi: if not A1 subset U then print(A1, `is not a subset of universal set`): RETURN(FAIL): fi: if not A3 subset U then print(A3, `is not a subset of universal set`): RETURN(FAIL): fi: if not A4 subset U then print(A4, `is not a subset of universal set`): RETURN(FAIL): fi: #FIRST WAY A1comp:=U minus A1: A2comp:=U minus A2: A3comp:=U minus A3: A4comp:=U minus A4: n1:=numelems(A1comp intersect A2comp intersect A3comp intersect A4comp): #SECOND WAY n2:=numelems(U)-numelems(A1)-numelems(A2)-numelems(A3)-numelems(A4)+numelems(A1 intersect A2)+numelems(A1 intersect A3)+numelems(A1 intersect A4)+numelems(A2 intersect A4)+numelems(A3 intersect A4) + numelems(A2 intersect A3) - numelems(A1 intersect A2 intersect A3)- numelems(A1 intersect A2 intersect A4)- numelems(A1 intersect A3 intersect A4)- numelems(A2 intersect A3 intersect A4)+numelems(A1 intersect A2 intersect A3 intersect A4): print(n1): print(n2): end: #EXAMPLE U:={seq(i,i=1..15)} U := {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} A1:={3,6,9,12,15} A1 := {3, 6, 9, 12, 15} A2:={5,10,15} A2 := {5, 10, 15} PIE4(U,A1,A2,A3,A4) 3 3 A3:={1,2,3,4,5,6,7} A3 := {1, 2, 3, 4, 5, 6, 7} A4:={2,4,6,8,10}