Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn!utcsri!rpi!zaphod.mps.ohio-state.edu!uunet.ca!geac!itcyyz!yrloc!hui
From: hui@yrloc.ipsa.reuter.COM (Roger Hui)
Subject: Re: J table question
Message-ID: <1992Jul27.145959.10128@yrloc.ipsa.reuter.COM>
Organization: Iverson Software Inc.
References: <qmdbms.711902900@gsusgi1.gsu.edu> <1992Jul25.053558.15013@yrloc.ipsa.reuter.COM> <qmdbms.712075408@gsusgi1.gsu.edu>
Date: Mon, 27 Jul 92 14:59:59 GMT
Lines: 65

Brian Schott:
> 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. ... 0<=x,y<=1.
 
Raul Deluth-Miller Rockwell:
> Note that 1 <. y % x will do what you want except for the case where
> both x is zero and y is less than or equal to zero.  [At least, for
> versions 4 and 5 of J.]  If this qualification matches your data, I'd
> recommend using the simple expression.
 
Brian Schott:
> Yes, I thought of that, but the 0%0 case messes things up for me; I need
> 1, not 0.
 
Roger Hui:
>The overall problem can be solved without agenda, viz., 1<.y%x+y*0=x ;
>with agenda, x (1&<.@%~)`1:@.(0&=@[)"0 y .
 
Brian Schott:
> I had some difficulty implementing this non-agenda solution since my
> left and right vectors are not necessarily of same shape.
 
I guess I was misled by the original problem description.  In any case, 
if f is a solution to the elementwise problem, then f"0/ is a solution 
to the table problem.  Thus:
 
   f =. (] + 0&=@+) 1&<.@% [ + 0&=@[ * ]    NB. 1<.(y+0=x+y)%x+(0=x)*y
   g =. 1&<.@%~`1:@.(0&=@[)"0
 
   ] x =. (i.6)%5
0 0.2 0.4 0.6 0.8 1
   ] y =. (i.8)%7
0 0.142857 0.285714 0.428571 0.571429 0.714286 0.857143 1
 
   x f |.x
1 1 1 0.666667 0.25 0
   x f"0/y
1        1        1        1        1        1        1 1
0 0.714286        1        1        1        1        1 1
0 0.357143 0.714286        1        1        1        1 1
0 0.238095  0.47619 0.714286 0.952381        1        1 1
0 0.178571 0.357143 0.535714 0.714286 0.892857        1 1
0 0.142857 0.285714 0.428571 0.571429 0.714286 0.857143 1
   (x f |.x) -: x g |.x
1
   (x f"0/y) -: x g/y      NB. g"0 <-> g
1
 
Brian Schott:
>    gog =. 1&<.@%~/ ` 1: @. (0&=@(]"0))/
>      ...
> I would be interested in your comments regarding the **2** table
> operations (?) in this solution.  My solution resulted from a mistake
> and other experimentations.  The mistake was that I thought the right-
> most / operating only on the righthand argument of @. , but it applies
> to the whole structure.  But that's not enough.  The lefthand portion
> of the gerund also requires its own / .
 
The first (leftmost) / in gog is redundant (gog produces the same result if 
it is removed).  The result of gog differs from those of f"0/ and g/ because 
gog keys on 0=y whereas f"0/ and g/ key on 0=x, per the original description.

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