Help17:=proc(): print(`Comps(n,k), GP1(L,n,d), GP(L,n) , IsCond3(C) `):end: with(combinat): #Comps(n,k): The set of all compositions of n into exactly k parts (with non-negative entrties) Comps:=proc(n,k) local S,a,S1,s: option remember: if k=0 then if n=0 then RETURN({[]}): else RETURN({}): fi: fi: S:={}: for a from 0 to n do S1:=Comps(n-a,k-1): S:=S union {seq([op(s),a],s in S1)}: od: S: end: #GP1(L,n,d): Inputs a list of numbers L and a variable n and a non-neg. d outputs the polynomial of degree d #P(n), such that P(i)=L[i], for all i from 1 to nops(L). OR FAIL #nops(L)>=d+2 GP1:=proc(L,n,d) local a,i,P,eq,var: if nops(L){0} then RETURN(FAIL): fi: P: end: #GP(L,n): Inputs a list of numbers L and a variable n and outputs the polynomial of degree <=nops(L)-2 #P(n), such that P(i)=L[i], for all i from 1 to nops(L). OR FAIL #nops(L)>=d+2 GP:=proc(L,n) local d,P: for d from 0 to nops(L)-2 do P:=GP1(L,n,d): if P<>FAIL then RETURN(P): fi: od: FAIL: end: #IsCond3(C): inputs a vote-count profile outputs true iff 1->2->3->1, IsCond3:=proc(C) local i,v,P,T: P:=permute(3): v:=add(C): for i from 1 to nops(C) do T[P[i]]:=C[i]: od: #1->2->3->1 if T[[1,2,3]]+T[[1,3,2]]+T[[3,1,2]]>v/2 and T[[1,2,3]]+T[[2,1,3]]+T[[2,3,1]]>v/2 and T[[2,3,1]]+T[[3,2,1]]+T[[3,1,2]]>v/2 then true: else false: fi: end: