[EM] A 27 character J program to elect winners

Craig Carey research at ijs.co.nz
Thu Oct 19 12:19:16 PDT 2000


Private message from Demorep following a question for what is on the
Ballot papers of the YES/NO method. I have doubts about this YES/NO
method.


At 20:03 18.10.00 -0400 Wednesday, DEMOREP1 at aol.com wrote:
 >English language variant-
 >
 >ballot papers (U.K, N.Z) = ballot form (U.S.A.) or ballot instructions
 >----------------
 >Approval Voting (simple variant)
 >
 >Vote for one or more of your choices by putting an X next to the name of the
 >candidate(s) that you approve of.
 >
 >A.B.   [    ]
 >C.D.   [    ]
 >E.F.   [    ]
 >-------------------
 >YES/NO Voting (simple variant)
 >
 >Vote YES or NO for each candidate by putting an X in the YES or NO box next
 >to the candidate's name.
 >
 >         YES       NO
 >A.B.    [    ]   [    ]
 >C.D.    [    ]   [    ]
 >E.F.    [    ]   [    ]
 >
 >[Technically the NO is not needed but a whole lot of voters would like to
 >vote NO on lots of  candidates.]
 >-------------------
 >

Thanks for that. Interesting to see how the Approval Vote methods wasn't
a preferential voting method, like Mr Ossipoff sort of seemed to be
suggesting. I think I was somehow misled for most of the year so far,
over that.



======================================================================

Some voting theory ideas are simple and they can coded into 'one liners'.

It can be sometimes be difficult to make simple ideas seem complex.

NB. Can Demorep tell me if the "NO" votes in the method he was commenting
on, have a weight of -1, or do they have a weight of zero?. This is
assuming the "YES" votes have a weight of +1.

Here is a first attempt at Demorep's YES/NO method. I assume NO subvotes
have a weight of -1, and the YES votes have a weight of +1 (which
Demorep might have indicated to be incorrect);


           +----------------------------------------------+
           |                                              |
           |         a =. (= >./) +/ 1 _1 * +/ v          |
           |                                              |
           +----------------------------------------------+

That is just 27 bytes long. J version 4 is fast and it can process
large datasets. I suppose it could tally up 100,000 results easily.

Can Demorep write the YES/NO method as a J program allowing its
definition to be accessed?.

-------------------------------------

The program is protected by a GPL license, and improvements can be
sent to the Politicians and Polytopes mailing list.

In J (like in APL) all expressions are evaluated strictly from right
to left.

# PART A: Input the data:

# Dyadic ',.' is 'Stitch';
# Monadic ']' is 'Same' and it returns the value to the right;
# Assignment is done with '=.' 'Copula(Is, local)':

    ] v =. 1 0 ,. 0 1 ,. 0 0 ,. 1 0
1 0 0 1
0 1 0 0

# Monadic '$' is 'Shape Of', and monadic ',:' is 'Laminate':

    $ v
2 4

    $ ,: v
1 2 4

# Dyadic ',' is 'Append':

    ] v =. v , ,: 1 0 ,. 0 0 ,. 1 0 ,. 1 0
1 0 0 1
0 1 0 0

1 0 1 1
0 0 0 0

# Now the votes are in a 2x2x4 tensor (v[1..2, 1..2, 1..4]):

    $ v
2 2 4


# PART B: Process the data:

# sum over the 1st index:

    +/ v
2 0 1 2
0 1 0 0

    $ +/ v
2 4

# Dyadic '*' is the 'Times' operator. Monadic '*' is 'Signum' (sign
#  of, return -1, 0, or +1).

    1 _1 * +/ v
2  0 1 2
0 _1 0 0

    ] y =. +/ 1 _1 * +/ v
2 _1 1 2

# Greater than:
    _21 > _22
1

# Maximum of two items:
    _21 >. _22
_21

# Find the maximum of a item (apply to 1st index):

    >./ _21 _20
_20


# Test for equality:


    _20 = _21 _20
0 1

# Construct the "fork" 'v = >./ v'. (J has verb and adjectives
# and forks and various other features for gluing together
# operators without naming their arguments. This differs from
# APL).

    (= >./) _21 _20
0 1

# Here is what might or might not be the so called YES/NO method:

    ] a =. (= >./) +/ 1 _1 * +/ v
1 0 0 1

# v again:
    v
1 0 0 1
0 1 0 0

1 0 1 1
0 0 0 0

# Etc. '/:' is sort

# Is this list on preferential voting or not?. Methods that have
# ballot papers showing checkboxes are not preferential voting
# methods. Demorep has commented that methods ought be simple.
# I hope Demorep can send in a proof that methods for US citizens
# need to be simple. I am wondering if Mr Rob Lanphier ought stamp
# out low quality discussions of checkbox methods (Demorep thought
# the Approval Vote was a checkbox method, so that ought be checked).

Programming of Voting:

With just 16 characters of computer code the Borda weights can be
involved in a multiplication. (This is the theory of Donald G. Saari
of wherever, http://www.math.nwu.edu/~d_saari/index.html ).

     ] v =. 1 2 0 6 9 _2 1
1 2 0 6 9 _2 1

    $ v
7
    i. $ v
0 1 2 3 4 5 6

    |. i. $ v
6 5 4 3 2 1 0

    ] a =. (*|. at i.@$) v
6 10 0 18 18 _2 0

    ]a=.(*|. at i.@$) v
6 10 0 18 18 _2 0

# With a few more characters, an algorithm to select the wrong
# winners would be available for public use.
#
# NB. 'u at v y' is 'u v y'; '@' is 'Atop', and '*' is 'Times', and '|.'
# is 'Reverse (monadic) or 'Rotate' (dyadic).

---------------------------------------------------------------------
J version 3 is available for free, and the above was done in version
3. J is by Mr Kenneth E. Iverson. Toronto, the creator of the APL
language. Download:

ftp://watserv1.uwaterloo.ca/languages/j/index.html

http://www.jsorftware.com/

A reference manual for J's operators/vocabulary:
ftp://archive.uwaterloo.ca/languages/j/j3/jsmid.zip


Can Demorep send in proof that the US public is dumb?. If that were
done, then what?. Nothing could be made of it, and surely some
regions are brighter than others. What about Washington's more
expensive suburbs?.




G. A. Craig Carey
http://www.ijs.co.nz/ifpp.htm



More information about the Election-Methods mailing list