Help17:=proc(): print(`Comps(N,k), IsCond123(V), Cond123(N), GP1(L,n,d), GP(L,n) `):end: with(combinat): #Comps(N,k): all the vectors of length k that add-up to N Comps:=proc(N,k) local S,S1,a,s: 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([a,op(s)],s in S1)}: od: S: end: #IsCond123(V): Given a voting score outcomes with 6components where V[i] is the number of voters that have rank permute(3)[i] #whether it the condorcet cycle 1->2->3->1 #IsCond123([1,1,1,1,1,1,1]); IsCond123:=proc(V) local T,P,i: P:=permute(3): for i from 1 to nops(P) do T[P[i]]:=V[i]: od: if T[[1,2,3]]+T[[1,3,2]]+T[[3,1,2]]> T[[2,1,3]]+T[[2,3,1]]+T[[3,2,1]] and T[[1,2,3]]+T[[2,1,3]]+T[[2,3,1]]> T[[1,3,2]]+T[[3,1,2]]+T[[3,2,1]] and T[[2,3,1]]+T[[3,2,1]]+T[[3,1,2]]> T[[2,1,3]]+T[[1,2,3]]+T[[1,3,2]] then true: else false: fi: end: #Cond123(N): the set of ballots with N voters and three candidates that lead to the 1->2->3->1 cycle Cond123:=proc(N) local S,V,C: S:=Comps(N,6): C:={}: for V in S do if IsCond123(V) then C:=C union {V}: fi: od: C: end: #GP1(L,n,d): guesses a polynomial P in n of degree d such that P[i]=L[i] GP1:=proc(L,n,d) local P, a,i,eq,var: if nops(L){0} then RETURN(FAIL): fi: P: end: #GP(L,n): guesses a polynomial fiting L 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: