Help:=proc(): print(`inv(pi), des(pi), maj(pi),Cov(S,f,g)`): print(`gCov(S,ListRV, ListPowers), GF1(S,f,x) , GF1m(S,f,x) `): end: with(combinat): #inv(pi): inputs a permutation pi and outputs the number #of inversions inv:=proc(pi) local s,i,j,n: n:=nops(pi): s:=0: for i from 1 to n do for j from i+1 to n do if pi[i]>pi[j] then s:=s+1: fi: od: od: s: end: des:=proc(pi) local s,i: s:=0: for i from 1 to nops(pi)-1 do if pi[i]>pi[i+1] then s:=s+1: fi: od: s: end: maj:=proc(pi) local s,i: s:=0: for i from 1 to nops(pi)-1 do if pi[i]>pi[i+1] then s:=s+i: fi: od: s: end: #Av(S,f): The average of the function f on the set S Av:=proc(S,f) local s: add(f(s), s in S)/nops(S): end: #Cov(S,f,g): The covariance of f and g over S Cov:=proc(S,f,g) local af,ag: af:=Av(S,f): ag:=Av(S,g): add((f(s)-af)*(g(s)-ag), s in S)/ nops(S): end: #gCov(S,f,g): The covariance of f and g over S gCov:=proc(S,ListRV, ListPowers) local af,ag: af:=[ seq(Av(S,f),f in ListRV)]: add(mul( (ListRV[i](s)-af[i])^ListPowers[i],i=1..nops(ListRV)) ,s in S) / nops(S): end: #GF1(S,f,x): the sum of x^f(s) over s in S (a.k.a. g.f. of f w.r.t. x) GF1:=proc(S,f,x) local s: add(x^f(s),s in S): end: #GF1(S,f,x): Given a set S, and a LIST of functions f #and a letter x, the sum of x[1]^f[1](s)* x[2]^f[2](s) * ... GF1m:=proc(S,f,x) local s,i: add(mul(x[i]^f[i](s),i=1..nops(f)),s in S): end: