Help:=proc(): print(`inv(pi), des(pi), maj(pi),Cov(S,f,g)`):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: