#OK to post homework #Ariana Yousafzai, 9/20/2020, Assignment 4 #Question 1 CP := proc(A, B) local a, b; {seq(seq([a, b], a in A), b in B)}; end proc; 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 := proc(A, B) evalb(Mynops(CP(A, B)) = Mynops(A)*Mynops(B)); end proc; CheckMult({1, 2}, {3, 4}); false CheckDecomp := proc(A, B) if not type(A, set) then print(A, `is not a set `); RETURN(FAIL); end if; if not type(B, set) then print(B, `is not a set `); RETURN(FAIL); end if; if A intersect B <> {} then print(A, B, `have the following common elements `, A intersect B); RETURN(FAIL); end if; evalb(Mynops(A union B) = Mynops(A) + Mynops(B)); end proc CheckDecomp({1, 2, 3}, {3, 4, 5});{1, 2, 3}, {3, 4, 5}, have the following common elements , {3} FAIL Words := proc(A, n) local W1, w, a; option remember; if n = 0 then RETURN({[]}); else W1 := Words(A, n - 1); RETURN({seq(seq([op(w), a], a in A), w in W1)}); end if; end proc; member([d, o, r, o, n], Words({d, n, o, r}, 5)); True #Question 2 n = 100 #Question 3 |Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2| = {1,...,15} - [3, 6, 9, 12, 15] - [5, 10, 15] + [15] = 1, 2, 4, 7, 8, 11, 13, 14, 15