#Question 1 #Carefully study the Maple code for lecture 4 and find #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)) = false #Question 2 #[I did not do it myself, and would like to know] In class we searched Neil Sloane's amazing On-Line Encyclopedia of Integer Sequences for 1,2,3,4,5,6,7,8,9 and found 2904 hits. Find the smallest positive integer n such that 1, 2, 3, ....., n (in Maple: seq(i,i=1..n) ) only returns ONE hit, namely A27 [Typo corrected thanks to Tifany Tong] #Answer to 2 So when n is 23 we get 8 hits and when n is 24 we get no hits so there is no n when there is only one hit. #Question 3 #The Principle of Inclusion-Exclusion (that we will discuss in Lecture 5) for TWO sets says that that given a UNIVERSAL set U, and subsets A1, A2, defining the COMPLEMENT of a subset A of U by Comp(U,A), |Comp(U,A1) intersect Comp(U,A2)|= |U|- |A1|-|A2|+ |A1 intersect A2| Do the following Check it by hand for U={1,..., 15}, A1= subset of U that are multiples of 3, A2=subsets of U that are multiples of 5 Write a Maple procedure PIE2(U,A1,A2) that inputs three sets U, A1, A2. After checking that U, A1,A2, are indeed sets (return FAIL if they are not) AND that A1 or A2 are NOT subsets of U (return FAIL if they are not), computes it in two ways. The first way by directly finding |Comp(U,A1) intersect Comp(U,A2)| and the second way by using the above formula, namely |U|- |A1|-|A2|+ |A1 intersect A2| For example the output of PIE2({1,2,3,4,5},{1,2,3},{2,3,5}) should be [1,1] #Answer to question 3 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) intersect Comp(U,A2)| = 8 |U|-|A1|-|A2|+|A1 intersect A2| 15-5-3+1 = 8 Our conjecture holds up Maple Procedure: Comp := proc(U, A1) local i, ans; ans := {}; for i in U do if not member(i, A1) then ans := {op(ans), i}; end if; end do; ans; end proc PIE2 := proc(U, A1, A2) local ans; ans := []; ans := [nops(Comp(U, A1) intersect Comp(U, A2))]; ans := [op(ans), nops(U) - nops(A1) - nops(A2) + nops(A1 intersect A2)]; end proc