Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn!cs.utexas.edu!uunet!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: J table question
Message-ID: <1992Jul25.053558.15013@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <qmdbms.711902900@gsusgi1.gsu.edu>
Date: Sat, 25 Jul 92 05:35:58 GMT
Lines: 44

Brian Schott writes:

> I am trying to create a table which has the result 1 if x is 0
> and the lesser of 1 and y%x otherwise.  My scheme is to set this
> up as an agenda construct with the selection of the index
> determined by whether the left argument x equals 0.  So my idea is
>    gerund @. selection    where "selection" is [/ .
 
> But I am running into a problem because the result of x [/ y
> is a vector, not a table.  That surprises me since x */ y
> is a table.  Is this as it should be in J?
 
> BTW my vector arguments are all fractions  0<=x,y<=1.
 
The overall problem can be solved without agenda, viz., 1<.y%x+y*0=x ;
with agenda, x (1&<.@%~)`1:@.(0&=@[)"0 y .
 
Regarding the dyad u/ :  The result on vector arguments need not be a table.
For the familiar "scalar" functions, the dyad u/ on vector arguments does
produce a table, but for an arbitrary u may produce an array of any rank.
x u/ y is defined to be x u"(lu,_) y where lu is the left rank of u.
The effect is to (conceptually) divide x into an array of argument cells;
these cells are each applied against y in toto.  This is a generalization 
of the outer product of scalar functions in APL, for which lu=0 and the 
left argument cells are scalars.
 
Since [ has infinite ranks, [/ is the same as [ per se.
 
The following examples may be helpful in elucidating u/ :
 
   a=.i.2 3 [ b=.100+i.3 2 4
 
   a ,"0/b        a <@,"0 /b
   a ,"1/b        a <@,"1 /b
   a ,"2/b        a <@,"2 /b
 
And mental gymnastics:
 
   f =. (i. {"1/~) @ (i.@! A. i.)
   f 3

------------------------------------
Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
Phone: (416) 925 6096;  Fax: (416) 488 7559
