#C17.txt, Nov. 3, 2016, Math640, Rutgers University, Fall 2016 (Dr. Z.'s Experimental Mathematics) #voting Help:=proc(): print(`Com(n,k), COn1(L) , Con(L),ConS(n) , OddSeq(N), CP(n) , ProbC(n) , RV()`): print(`Rcomp(n) , MCcon(n, N) `): end: #Com(n,k): the set of lists of length k of non-neg. integer that add-up to n Com:=proc(n,k) local S,S1,i,s1: option remember: if k=0 then if n=0 then RETURN({[]}): else RETURN({}): fi: fi: S:={}: for i from 0 to n do S1:=Com(n-i,k-1): S:=S union {seq([op(s1), i], s1 in S1)}: od: S: end: #Inputs a composition,L of n into non-neg. integers of size 6 #[123,132,213,231,312,321], decides whether 1->2->3->1 Con1:=proc(L) evalb( #1->2 (L[1]+L[2]+L[5])-(L[3]+L[4]+L[6])>0 and #2->3 (L[1]+L[3]+L[4])- (L[2]+L[5]+L[6])>0 and #3->1 (L[4]+L[5]+L[6])- (L[1]+L[2]+L[3])>0 ): end: #Inputs a composition,L of n into non-neg. integers of size 6 #[123,132,213,231,312,321], decides whether 1->3->2->1 Con2:=proc(L) evalb( #1->2 (L[1]+L[2]+L[5])-(L[3]+L[4]+L[6])<0 and #2->3 (L[1]+L[3]+L[4])- (L[2]+L[5]+L[6])<0 and #3->1 (L[4]+L[5]+L[6])- (L[1]+L[2]+L[3])<0 ): end: #Con(L): Is L a Condorect paradox example? Con:=proc(L): Con1(L) or Con2(L) : end: #ConS(n): inputs n (the number of voters each randking three candidates) outputs #the set of all vectors of length 6 that sum up to n and exhibit the Condorect paradox ConS:=proc(n) local S,G,s: S:=Com(n,6): G:={}: for s in S do if Con(s) then G:=G union {s}: fi: od: G: end: #OddSeq(N): the the sequence counting the Condorect scenarios for n=1..2*N-1 for odd n OddSeq:=proc(N) local n: [seq(nops(ConS(2*n-1)),n=1..N)]: end: CP:=proc(n) factor(subs(n=n-1,1/60*n^5+ 1/6*n^4+ 7/12*n^3+5/6*n^2+ 2/5*n)): end: ProbC:=proc(n): factor(CP(n)/expand(binomial(2*n+4,5))): end: #RV(): generates one of [1,0$5], ..., [0$5,1] each with prob. 1/6 RV:=proc() local i: i:=rand(1..6)(): [0$(i-1),1,0$(6-i)]: end: Rcom:=proc(n) local i: add(RV(),i=1..n): end: #an estimate for the prob. of the Condorcet scenario using n voters with N elections MCcon:=proc(n,N) local L,c,i: c:=0: for i from 1 to N do L:=Rcom(n): if Con(L) then c:=c+1: fi: od: evalf(c/N): end: