The only common monadic uses of  .  seem to be

   determinant=: -/ . *
   permanent=:   +/ . *

(see e.g.  .  from the J help vocabulary page).  However, I recently
wanted to check that a set of n boolean vectors of length n are
linearly independent over the finite field GF(2) (i.e. 0 & 1 multiply
as normal, and addition is mod 2).  This can be verified by

   det2=: ~:/ . *.

which is 1 when the (n x n) argument y has linearly independent rows.
At least I think it is!  Possible applications include binary codes
and Zobrist hashing (using e.g. the first several columns as hash key
and the remaining columns to disambiguate collisions).

Note that det2 is very slow on a 10x10 matrix or larger
(like permanent, time is roughly proportional to !#y).


NB.============================== J script ==============================

hashmat=: 3 : 0             NB. hack to give "random-looking"
m=. m0=. ?. (2#y)$2         NB. invertible yxy matrix over GF(2)
for_i. i. y do.
 if. -. (ii=. <i,i){m do.
  m=. 1 ii}m
  m0=. (-. ii{m0) ii} m0
 end.
 m=. m ~: (i{"1 m) *./ i{m
end.
m0
)

det2=: ~:/ . *.             NB. Determinant for GF(2)

hammdist=: ([: +/ ~:)"1/~   NB. Hamming distance

NB.============================== example ===============================

   ] H8=: hashmat 8
1 1 0 1 1 1 0 0
0 1 0 1 0 0 1 0
0 0 1 0 1 1 1 0
0 0 0 1 1 1 0 1
1 0 0 1 1 0 1 0
1 0 0 0 0 0 0 1
0 0 1 0 0 1 0 0
1 0 0 1 0 1 0 0
   det2 H8
1
   hammdist H8
0 4 5 3 3 5 5 2
4 0 5 5 3 5 5 4
5 5 0 4 4 6 2 5
3 5 4 0 4 4 4 3
3 3 4 4 0 4 6 3
5 5 6 4 4 0 4 3
5 5 2 4 6 4 0 3
2 4 5 3 3 3 3 0

NB.============================== end ===================================


J.E.H.Shaw   [Ewart Shaw]      [EMAIL PROTECTED]    TEL: +44 2476 523069
  Department of Statistics,  University of Warwick,  Coventry CV4 7AL,  UK
  http://www.warwick.ac.uk/statsdept            http://www.ewartshaw.co.uk
Will read usenet posts up to the first insult (which may be in the Subject)

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to