Newsgroups: comp.lang.apl
Path: watmath!watserv1!torn!cs.utexas.edu!uunet!gatech!gsusgi1.gsu.edu!gsusgi1.gsu.edu!qmdbms
From: qmdbms@gsusgi2.gsu.edu (Brian Schott)
Subject: Re: J table question
Message-ID: <qmdbms.712075408@gsusgi1.gsu.edu>
Organization: Georgia State University
References: <qmdbms.711902900@gsusgi1.gsu.edu> <1992Jul25.053558.15013@yrloc.ipsa.reuter.COM>
Date: Sat, 25 Jul 1992 14:43:28 GMT
Lines: 65

hui@yrloc.ipsa.reuter.COM (Roger Hui) writes:

>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 .
I had some difficulty implementing this non-agenda solution since my
left and right vectors are not necessarily of same shape.

I tried the agenda version and had considerable fun figuring where
to put the table adverb and where not to.  The solution I am working
with for now is listed below.

   ]u =. 5%~ i. 6
0 0.2 0.4 0.6 0.8 1
   ]v =. }:u
0 0.2 0.4 0.6 0.8
   gog =. 1&<.@%~/ ` 1: @. (0&=@(]"0))/
   v gog u
1        1        1    1 1 1
1        1        1    1 1 1
1      0.5        1    1 1 1
1 0.333333 0.666667    1 1 1
1     0.25      0.5 0.75 1 1
   gog
+----------------------------------------------------+-+
|+---------------------------+--+-------------------+|/|
||+----------------------+--+|@.|+-------+-+-------+|| |
|||+------------------+-+|1:||  ||+-+-+-+|@|+-+-+-+||| |
||||+--------------+-+|/||  ||  |||0|&|=|| ||]|"|0|||| |
|||||+--------+-+-+|~|| ||  ||  ||+-+-+-+| |+-+-+-+||| |
||||||+-+-+--+|@|%|| || ||  ||  |+-------+-+-------+|| |
|||||||1|&|<.|| | || || ||  ||  |                   || |
||||||+-+-+--+| | || || ||  ||  |                   || |
|||||+--------+-+-+| || ||  ||  |                   || |
||||+--------------+-+| ||  ||  |                   || |
|||+------------------+-+|  ||  |                   || |
||+----------------------+--+|  |                   || |
|+---------------------------+--+-------------------+| |
+----------------------------------------------------+-+
   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 / .


-- 
Brian Schott/Decision Sciences Dept.             qmdbms@gsusgi2.gsu.edu
College of Business Administration                         404-651-4070
Georgia State University                  interests: approx. reasoning,
Atlanta, Georgia USA 30303-3083     (B=)       decision support systems
