Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!torsqnt!jtsv16!blister!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: implementing @:
Message-ID: <1991Apr21.182401.10670@yrloc.ipsa.reuter.COM>
Reply-To: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Organization: Iverson Software Inc.
References: <19APR91.00433381@uc780.umd.edu>
Date: Sun, 21 Apr 91 18:24:01 GMT

Raul Rockwell writes:
 
> With that out of the way, I'd like to bring up a tiny algorithm.
> Consider  @: v
> where v is a numeric vector (not boxed)
>
> I think that what J is doing for this case is building a table of all
> permutations of i.#v, and using a transitive i. to find the row which
> matches v.  This is nice and concise, but seems slow in the current
> incarnation of J.

There is **no way** I would implement @:y with an order !n=.#y algorithm.
FYI this is a model of the current implementation of @: , computing the
atomic representation of a permutation p (possibly in nonstandard form):
 
   ord  =. >:@(>./)
   std  =. ((i.@ord -. ]) , ]) @ (ord | ])
   rfd  =. +/@({.>}.)\."1
   base =. (- i.)@ord
   ar   =. base #. rfd@std
 
ord computes the order of a permutation, possibly in nonstandard form.
 
std converts a permutation into standard form.  std is equivalent to
'((i.n)-.n|y.),n|y. ] n=.1+>/y.' : ''
 
rfd computes the reduced representation of a permutation from its
direct (standard) representation.  rfd and its inverse dfr were
written by E.E. McDonnell, Iverson Software PARC:
   dfr =. /:^:2@,/"1
   rfd =. +/@({.>}.)\."1
 
base computes the value n-i.n .
 
ar p computes @:p, the value of the reduced representation of p in the
base (n-i.n) numbering system.

-----------------------------------------------------------------
Roger Hui
Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
(416) 925 6096

