Simplex_Procedure_Line.nb
T. Ratliff, Wheaton College, Apr 5, 2016

These are several routines that you may find useful in doing calculations for 3-candidate elections

The ones most relevant are:

	weightedTally[ ]
	procedureLine[ ]
	M, the matrix used for computing the decomposition of a profile 

See the examples below for how you can use these.

tMat = Block[{y1=-Norm[{1/3,1/3,1/3}-{1/2,1/2,0}],
x1=Norm[{1/2,1/2,0}-{1,0,0}],
y2=Norm[{1/3,1/3,1/3}-{0,0,1}]},
Transpose[{ {-x1,y1},{x1,y1},{0,y2}}]];
boundaries:=Module[ {y1=-Norm[{1/3,1/3,1/3}-{1/2,1/2,0}],
x1=Norm[{1/2,1/2,0}-{1,0,0}],
y2=Norm[{1/3,1/3,1/3}-{0,0,1}],avertex,bvertex,cvertex},
avertex={-x1,y1};
 bvertex={x1,y1};
cvertex={0,y2};
Return[Graphics[{Line[{avertex,bvertex,cvertex,avertex}],
		Line[{avertex,1/2*(bvertex+cvertex)}],
		Line[{bvertex,1/2*(avertex+cvertex)}],
		Line[{cvertex,1/2*(avertex+bvertex)}]}]]
];
onSimplex[tallies_]:=1/Total[tallies] * tallies;

weightedTally[w_,profile_]:={{w[[1]],w[[1]],w[[2]],w[[3]],w[[3]],w[[2]]},
			{w[[2]],w[[3]],w[[3]],w[[2]],w[[1]],w[[1]]},
			{w[[3]],w[[2]],w[[1]],w[[1]],w[[2]],w[[3]]}}.profile;

procedureLine[profile_]:=Module[ {q0, q1, pLine,Q0,Q1},
	q0 = tMat.onSimplex[weightedTally[{1,0,0},profile]];
	q1 = tMat.onSimplex[weightedTally[{1,1,0},profile]];
	Q0= Graphics[{PointSize[ 0.015],Red,Point[q0]}];
Q1= Graphics[{PointSize[ 0.015],Blue,Point[{q1}]}];
pLine=Graphics[{Magenta,Line[{ q0,q1}]}];
Show[{boundaries,Q0,Q1,pLine,
Graphics[{PointSize[0.025],Red,Point[{0.5,0.5}]}],
Graphics[Text[Style["q0",FontSize->16],{0.6,0.5}]],
Graphics[{PointSize[0.025],Blue,Point[{0.5,0.3}]}],
Graphics[Text[Style["q1",FontSize->16],{0.6,0.3}]]
}]
]

M={{1,1,1,0,2,1},{1,0,0,1,2,0},{1,1,0,0,1,0},{1,0,1,0,0,1},{1,1,0,1,0,2},{1,0,0,0,1,2}};

Let’s define our favorite profile and determine the Borda Count tallies

p={10,0,6,6,3,6};
weightedTally[{2,1,0},p]

Or, we can calculate the tallies using weights (13,1,0)

weightedTally[{13,1,0},p]

We can draw the procedure line for p

procedureLine[p]

And we can determine the decomposition of p in terms of {K, Cy, R1, R2, B1, B2}

Inverse[M].p