#Aniket Shah #01/27/14 #HW1 #Ok to post #A few examples from Garvan’s Maple book #1 p:= x^9-1: factor(p); simplify(3*4^(1/2)+5); simplify((x^2)^(1/2)); rationalize((1-sqrt(2))/(1+sqrt(2))); #2 #CheckPie2(A,B)(): inputs two sets of integers and #checks the inclusion-exclusion principle for two #sets: |A union B|=|A|+|B|-|A intersect B| CheckPie2:=proc(A,B) local a,b, aub, anb: a:=nops(A): b:=nops(B): aub:=nops(A union B): anb:=nops(A intersect B): if aub=a+b-anb then print(`good`): else print(`bad`): fi; end: #3 #DoNs()(): modified DoN(N) which tosses a coin with #statements and only outputs the number of coin #tosses that it took to exit with one dollar DoNs:=proc(N) local coin, c, ST, account,i,j: coin:=rand(0..1): ST:=1: account:=0: j:=0: for i from 1 to N do c:=coin(): j:=j+1: if c=1 then RETURN(j): else account:=account-ST: ST:=2*ST: fi; od: RETURN(N); end: #4 #AveDuration(N,K)(): runs DoNs(N) K times and #computes the average duration AveDuration:=proc(N,K) local i, average, totalLength: average:=0: totalLength:=0: for i from 1 to K do totalLength:=totalLength+DoNs(N): od: RETURN(totalLength/K): end: #I got 1027/500 for AveDuration(100,1000) #5 #limit of the expected value of AveDuration(N,K) #as N,K->infinity will be the sum of n/2^n as n #goes to infinity, which is 2. If the probability #is p, then the expected value is 1/p.