Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!jato!csi!sam
From: sam@csi.jpl.nasa.gov (Sam Sirlin)
Subject: Re: what about func(a,a,a)
Message-ID: <1992Dec4.180648.23295@csi.jpl.nasa.gov>
Originator: sam@kalessin
Sender: usenet@csi.jpl.nasa.gov (Network Noise Transfer Service)
Nntp-Posting-Host: kalessin
Organization: Jet Propulsion Laboratory, Pasadena, CA
References: <1992Dec3.120841.9774@bernina.ethz.ch> <1992Dec3.170007.16358@csi.jpl.nasa.gov> <1992Dec4.111043.20054@bernina.ethz.ch>
Date: Fri, 4 Dec 1992 18:06:48 GMT
Lines: 113


In article <1992Dec4.111043.20054@bernina.ethz.ch>, hoesel@igc.ethz.ch (Frans van Hoesel) writes:
...
|> I'm writing data -processing software, and at the point of writing a completle
|> new version. (due to populary demand). Now the old version had a function
|> called fft. The user can call this with a 1D array or a multi-D array, but
...
|> calling fft(2darray, scalarsize) no problem... loop over the rows in
|>  the array
|> calling fft(1darray, 1dsize) (make a 2-d result... note this would
|> calling fft(2darray, 1dsize) (make a 3d result)

These look to me like an outer "product", in which the resulting rank
is the sum of the input ranks. APL/J would do this using an outer
product operator; in J  
   a fft / b

|> but now a function sum(int a[*], b[*]) (note the '*' indicates 1D array
|> call sum(1darr, 1darr)  no problem... 1d result (adding correspondiing elem)
|> call sum(2darr, 1darr)  no problem ... 2dresult
|> call sum(2darr, 2darr)  2d result expected (added corr. elem.) but in analogy
|> 			with fft the result would be 3d!

Here you don't seem to want the outer product, but the
element-by-element sum? The behavior you want is different, so I think
you need a different mechanism.

|> ok, but can you tell me how to order it from the netherlands. I have the 
|> doc's that came with J-6 (ftp-ed)

The docs should give you ISI's adress, but they don't seem to want to
include a current catalog and price list. I have a recent one and will
dig it up and send you the gist.

|> >
|> [deleted long, but useful example of inproduct]
|> 
|> so  inproduct(2darr, 1darr) gives a 2d result, whee as

No, though I didn't give an example of this,
       inproduct(2darr, 1darr) gives a 1d result

|>     inproduct(1darr, 2darr) gives a 1d result.

|> This may be fine for J, but strikes me when use inside a normal (?)
|> function call, and this comes back to the question what about
|> func(a,a,a)

Hmm. You are right in that the language you have doesn't seem to allow
for operators, whereas the basic syntax of APL/J does. You might look
at lisp, as their lambda-expressions might be more like "traditional"
or "normal" function calls. Though actually most languages implement
the syntax of +, *, etc as APL (do you write +(a,b) in C?), but then
don't allow you to write functions that behave this "normal" way.
APL/J make the choice of only allowing monadic or dyadic functions,
though operator syntax can allow 3 arguments as well.  Of course you
can add more arguments by passing structures, but then you must deal
with rank yourself. I suspect that this is what we want in almost all
cases, since you can't even write down the details of a function of
more than two variables on paper without resorting to strictly monadic
or dyadic functions eventually. An exception I can think of is
indexing, which is a pain in J (more traditional APL allows an
exception in this case to traditional notation). Then there's
integration I guess... 

A bastardized notation that would fit your case is
func"(rank_vector)(a,a,a), or maybe you want something like 
apply(func, rank_vector, (a,a,a)) which is more lisp-ish. The latter
lends itself you your problem as well since you can do
outer(fft,a,size), or apply(sum,rank,a,b).

|> >Of course all verbs (functions that act on nouns [numbers or
|> >characters]) have a monadic, left, and right rank, so I can actually
|> >specify these separately, for example:
|> >
|> >   m i"0 1 n
|> > 3.5       7
|> >7.75 10.3333
|> >
|> This one I didn't get sam, can you translate it in english?

Here goes. m and n are rank 2, and the inner product function i
normally treats them as such. But here I'm telling i to treat the left
argument one scalar at a time, and the right argument one vector at a
time. The result comes out as (hopefully you remember m and n). 

(1 i 0{n) (2 i 0{n)
(3 i 1{n) (4 i 1{n)

where 0{n is the first row etc. To really understand this stuff you
can read the dictionary. I usually resort to the interpreter. I
realize I didn't give an example of the result having greater rank
than the elements, so try

   m i"0 2 n
3.33333 2.75
6.66667  5.5

     10 8.25
13.3333   11

Or, using the outer operator as well as rank
   m i"0 1 /n
 3.5 2.58333
   7 5.16667

10.5    7.75
  14 10.3333

-- 
Sam Sirlin
Jet Propulsion Laboratory         sam@kalessin.jpl.nasa.gov

