#Pi Day, 2013 C314159.txt Help:=proc(): print(`GL(N), JG(N), WZpi(n) , CoinToss(N)`): print(`MetaCoinToss(N), IsUD(N) , AndreS(n), AndreF(n) `): end: #Pi is NOT a number it is (much better!) a game -Joey Reichert #Possibly one of the slowest ways to appx. Pi GL:=proc(N) local i: 4*add((-1)^i/(2*i+1),i=0..N): end: #Possibly one of the fastest ways to appx. Pi JG:=proc(N) local n: add((-1)^n*(6*n)!/n!^6/2880^(3*n)*(5418*n^2+693*n+29),n=0..N), 128*sqrt(5)/Pi^2: end: WZpi:=proc(n) local albert: albert:=int(x^(4*n)*(1-x)^(4*n)/(1+x^2),x=0..1): -coeff(albert,Pi,0)/coeff(albert,Pi,1): end: #CoinToss(N) the outcome of tossing a fair coin #randomly N times winning a dollar with Heads #and losing with Tails CoinToss:=proc(N) local i,ra: ra:=rand(0..1): #Jake's (possibly minor, but nevertheless clever) improvement 2*add(ra(),i=1..N)-N: end: #MetaCoinToss(N,K): The number of times of breaking even #if you "toss a coin N times" every day for K days MetaCoinToss:=proc(N,K) local x,i: coeff(add(x[CoinToss(N)],i=1..K),x[0],1)/K , binomial(N,N/2)/2^N: end: #IsUD(pi): Is the permutation pi Up down #pi[1]pi[3] ... IsUD:=proc(pi) local i: for i from 1 to nops(pi)/2 do if not pi[2*i-1]pi[2*i+1] then RETURN(false): fi: od: true: end: with(combinat): #AndreS(n): The number of Up-Down perms of length n AndreS:=proc(n) local S,x,pi: S:=permute(n): coeff(add(x[IsUD(pi)], pi in S), x[true],1): end: #AndreF(n): Fast way AndreF:=proc(n) local x: n!*coeff(taylor(sec(x)+tan(x),x=0,n+1),x,n): end: