« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Reliability
Voting Power in a Presidential Election
In[1]:=
X
pick[_, votes_, needed_] /; needed > Total[votes] := False; pick[{}, {}, _] := {{}}; pick[_, _, _?NonPositive] := {{}}; pick[states_, votes_, needed_] := Cases[Flatten[ Table[Append[#, states[[i]]] & /@ pick[states[[i + 1 ;;]], votes[[i + 1 ;;]], needed - votes[[i]]], {i, 1, Length[states]}], 1], Except[False]]
In[2]:=
X
states1804 = {CT, DE, GA, KY, MD, MA, NH, NJ, NY, NC, OH, PA, RI, SC, TN, VT, VA}; votes1804 = {9, 3, 6, 8, 11, 19, 7, 8, 19, 14, 3, 20, 4, 10, 5, 6, 24}; bexpr = Or @@ (And @@@ pick[states1804, votes1804, 89]); population = {255376, 67632, 198565, 295137, 357139, 442512, 196092, 224907, 736969, 509045, 119482, 685410, 72244, 373385, 168018, 179823, 835592};
In[3]:=
X
power = StructuralImportance[bexpr, states1804];
In[4]:=
X
labeler[_, {1, _}, ___] := None labeler[_, {2, c_}, ___] := Placed[states1804[[c]], "RadialCallout"]
In[5]:=
X
PieChart[{Labeled[population, "Population", {0, 0}], Labeled[power, "Voting Power", {0, 0}]}, SectorSpacing -> 0.1, LabelingFunction -> labeler, ImagePadding -> 20, ImageSize -> 500]
Compare the Banzhaf power index, which is another name for
StructuralImportance
, of the states in the 1804 US presidential election with their population.
Out[5]=