# Daniel Yang, Due Sept. 13, 9:00pm # OK to post Homwork # 1) diff(x^3,x); int(x^2,x=-1...1) sin(x)+1 # 2) # F(6) = {[1,1,1,1,1,1],[1,1,1,1,2],[1,1,1,2,1],[1,1,2,1,1],[1,2,1,1,1],[2,1,1,1,1],[2,2,1,1],[2,1,2,1],[2,1,1,2],[1,2,2,1],[1,2,1,2],[1,1,2,2],[2,2,2]} # 3) # -Given list L1:=[Mercury, Venus, Earth], we can append Mars to L1 and Get L2 by # L2:=[op(l1), Mars] # Assuming the next two questions are discussing the reason of including # if m<0 or n<0 then # RETURN({}): # fi: # if m=0 and n=0 then # RETURN({[]}): # fi: #in the functions: #-The reason why we initialize Walks(m,n) with either m, or n is to dealwith # terminating the recursive function. Specifically for this case and due to the # nature of the function Walks, we know for a fact that when either m or n is # greater than zero (i.e. exclusively some function call Walks(m,0) or Walks(0,n)), # the number of possible walks is always zero, thus when the recursive call reduces # to some Walks(m,0) or Walks(0,n) we can just return with the leftover possibility. # Similarly, if either m or n is negative, we get that it becomes impossible to # reach the desired target with only positive movesets, thus we terminate with the # function as no more possible moves can be made to reach the target. #-For similar reason why we initialize Walks(m,n) with the set {[]} when m and n # is zero is due to the fact that no more moves are necessary to reach (0,0), thus # the only possible move set possible is the empty set, or zero moves. # 4/5/6) (Same/ish problem) #hw1DanielYang.txt: Homework 1 Help:=proc():print(`F(n), NuF(n)`): end: #F(n) : inputs one non-negative integer n #and outputs the Set of all combinations of sums of n #using integers 1 and 2 F := proc(n) local W1, W2, w1, w2; option remember: if n < 0 then RETURN({}): fi: if n = 0 then RETURN({[]}): fi: W1 := F(n - 1): W2 := F(n - 2): {seq([op(w1), 1], w1 in W1), seq([op(w2), 2], w2 in W2)}; end: #NuF(n) : inputs one non-negative integer n #and outputs the number of sets made from the set #of all combinations of sums of n using integers 1 and 2 NuF := proc(n) local W1, W2, w1, w2; option remember: if n < 0 then RETURN(0): fi: if n = 0 then RETURN(1): fi: W1 := NuF(n - 1): W2 := NuF(n - 2): W1+W2; end: #NuF(1000) = #70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501 # Maple would complain about trying to do nops(F(1000)) as it would try to do every # single recurssive step, which would add up to trying to find all NuF(1000) iterations of recurssion.