Help:=proc(): print(`IsUD(pi),AnStupid(n), rf(a,k) ,SR1(M) `): print(` RtoS(a,d,k), RtoS(a,d,k) `): end: with(combinat): #IsUD(pi): Is the permutation pi Up-Down #For example IsUD([1,3,2]); is true #IsUD([1,2,3]); is false IsUD:=proc(pi) local i: evalb( {seq( evalb(pi[2*i-1]pi[2*i+1]), i=1..(nops(pi)-1)/2)}= {true}): end: #AnStupid(n): the number of up-down permutations of {1, ...,n} AnStupid:=proc(n) local co, S, pi: S:=convert(permute(n),set): co:=0: for pi in S do if IsUD(pi) then co:=co+1: fi: od: co: end: #rf(a,k):=a(a+1)(a+2)...*(a+k-1) rf:=proc(a,k) local i: mul(a+i,i=0..k-1): end: #using M terms in Ramanujan's slow formula for 2/Pi SR1:=proc(M) local k: 2/evalf(add((-1)^k*(4*k+1)*rf(1/2,k)^3/k!^3,k=0..M)): end: #RtoS(a,d,k): the list of the first k digits in the base-d #rep. of the real number a between 0 and 1 RtoS:=proc(a,d,k) local a1,L,kirsten,i: a1:=evalf(a): if a1>=1 or a1<=0 then RETURN(FAIL): fi: L:=[]: for i from 1 to k do a1:=a1*d: kirsten:=trunc(a1): L:=[op(L),kirsten]: a1:=a1-kirsten: od: if add(L[i]/d^i,i=1..k)-evalf(a)>1/d^(k-1) then RETURN(FAIL): else RETURN(L): fi: end: