> # Weiji Zheng, 09/15/2020, Assignment 1 > # OK to post Homwork ; > #Part 1 - Random Lines ; > ; > 100+300+500; 900 ; > 500-200-100; 200 ; > 500-100000; -99500 ; > diff(x^6 + x*y^7*z^4, x); y^7*z^4+6*x^5 ; > factor(x^3 + 2*x*y + 3*x^5); x*(3*x^4+x^2+2*y) ; > isprime(17); true ; > s := 1,640,454: s[3]; 454 ; > ; > #Part 2 - Human Problem ; > #F(6) = {[1,1,1,1,1,1],[2,1,1,1,1],[1,2,1,1,1],[1,1,2,1,1],[1,1,1,2,1],[1,1,1,1,2],[2,2,1,1],[2,1,2,1],[2,1,1,2],[1,1,2,2],[1,2,1,2],[1,2,2,1]} ; > ; > #Part 3 ; > #1.To covert L1:=[Mercury,Venus,Earth] to L2:=[Mercury,Venus,Earth,Mars], Use L->[op(L),a] where a = Mars ; > #Code: > L1 := [Mercury,Venus,Earth]; L1 := [Mercury, Venus, Earth] ; > L2 := [op(%),Mars]; L2 := [Mercury, Venus, Earth, Mars] ; > #2. ; > #Because the function Walks(m, n) is used to calculate all the sets of possible routes from (0, 0) to (m, n) by using North and East.Thus, if either m or n or both are negative, there is no route will show up, which makes Maple shows an empty set denotes null answer. ; > #3 ; > #There is still a route from (0,0) to (0,0), which is an initial condition. So we use set {[]} to show this route. ; > ; > #Part 4 ; > 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: > F(6); {[2, 2, 2], [1, 1, 2, 2], [1, 2, 1, 2], [1, 2, 2, 1], [2, 1, 1, 2], [2, 1, 2, 1], [2, 2, 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], [1, 1, 1, 1, 1, 1]} ; > #Same output as the handwrite answer ; > ; > #Part 5 ; > > 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: > #check equal ; > evalb(seq(nops(F(n)),n=0..10)=seq(NuF(n),n=0..10)); true ; > NuF(1000); 70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501 ; > #nops(F(1000)) ; > #this gonna be a large calculation which waste too much resources, so Maple complains. ;