Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What are the APL Kernel operations?

151 views
Skip to first unread message

davi...@gmail.com

unread,
Mar 19, 2013, 2:58:59 PM3/19/13
to
Hi,

I'm just getting into J, and I'm using it primarily to try to come up with an arithmetic system for the arrays in my language. The FAQ mentions that there are "over 100 operations" in an APL implementation (I figure J is the same). Is there an analysis of what the 'kernel of the kernel' is? In other words, what are the "simplest" core of operations with which the entire 100+ suite of commands can be implemented? Or perhaps all 100+ are orthogonal (I'm pretty sure I can already disprove that)? I suspect that this analysis has been done by compiler implementers but... I haven't gone that deep.

And, if I can take it one step further, any suggestions for a small, effective core for array operations (that can be used to implement basic multivariate algebra, as well as more general array ops)? I'm specifically looking for combinator-style (vs lambda-style, as MATLAB seems to be).

Thanks.

Björn Helgason

unread,
Mar 21, 2013, 8:55:57 AM3/21/13
to
I am not sure what you are after but if you want to use J operations it is possible to call J from other languages like python an let J do the job and return the results.

W. LeRoy Davis

unread,
Mar 21, 2013, 9:22:08 AM3/21/13
to
Hi (also),

If, by "simplest" core of operations, you mean that MULTIPLY is a programmed
ADD so ADD is "core" then you will end up with:
- SHAPE (create)
- ASSIGN
- ADD
- INVERT

Everything can be "programmed" from this core, and short-cuts like LOGARITHM
and MATRIX-DIVIDE become callable subroutines.

<davi...@gmail.com> wrote in message
news:9175556a-23bb-49a6...@googlegroups.com...

davi...@gmail.com

unread,
Mar 21, 2013, 10:38:23 AM3/21/13
to
Thanks for the replies. The list of four operations (SHAPE, ASSIGN, ADD, INVERT) may be the answer that I was looking for but there must be finer points that I am after. In testing your answer, for example, I don't see how you would implement the 'each' operator (¨) using just those four operations. None of these seem to offer the needed iteration/folding behavior (although maybe I'm missing some slicing capability of ASSIGN that can be "abused"?)

W. LeRoy Davis

unread,
Mar 21, 2013, 12:23:09 PM3/21/13
to
Just as !3 is a short-cut for 3 x 2 x 1 (which is a short-cut for 1+1
+ 1+1 + 1+1 ), the EACH function is a programming short-cut for repition.

1 2 3 ?" 5
is the same as
1 2 3 ? 5 5 5 5 5 5


<davi...@gmail.com> wrote in message
news:af5e216e-76a4-4f10...@googlegroups.com...

Rav

unread,
Mar 21, 2013, 1:55:33 PM3/21/13
to
Perhaps you didn't mean that example literally, but < 1 2 3?5 5 5 5 5 >
signals a LENGTH ERROR. The following (repetitive) example would
produce the exact same result as the EACH example:

⌽(3?5)(2?5)(1?5)

(Note that I reversed the order of the left argument elements, and then
reversed the strand result, so that the exact same seed would be used
for each invocation of ? as in the EACH example.)

p

W. LeRoy Davis

unread,
Mar 21, 2013, 2:03:37 PM3/21/13
to
Okay, so the "computers" between here and there swapped the RHO for a ROLL
...

Oops!

"Rav" <Pa...@cais.com> wrote in message news:kifhdg$i3t$1...@dont-email.me...
> Perhaps you didn't mean that example literally, but < 1 2 3?5 5 5 5 5 >
> signals a LENGTH ERROR. The following (repetitive) example would produce
> the exact same result as the EACH example:
>
> ?(3?5)(2?5)(1?5)

Rav

unread,
Mar 21, 2013, 2:16:09 PM3/21/13
to
Oh, I see. But I also don't think you're not saying that < 1 2 3⍴¨5 >
is the same as < 1 2 3⍴5 5 5 5 5 5 > .

Rav

unread,
Mar 21, 2013, 2:18:12 PM3/21/13
to
Whoops ... meant to say "don't think you're saying ..."

davi...@gmail.com

unread,
Mar 21, 2013, 2:36:51 PM3/21/13
to
OK. I think I see where you are going. The shape of the operand could be extracted with SHAPE, then expanded into another array of the right shape using some other operations to expand the expression as you have done by hand. I can't seem to make an EACH routine that works for any shape, N-dimensional arrays this way.

Is there a reference that talks about the four basis functions? As with most bases, I'm sure there are cool tricks for building the complex behavior from basic. A reference, especially one with an example or two, would be a huge help if you've got one.

I'm especially concerned about getting general N-D behavior as its the problem in my own mathematical notation that drove me here. I'm in a situation where I can come up with implementations for any fixed-dimensional case (like your 1-D example) but I can't generalize to N-D using the four base operations. I have a feeling that a solution that works in this case would work for me.




On Thursday, March 21, 2013 9:23:09 AM UTC-7, W. LeRoy Davis wrote:
> Just as !3 is a short-cut for 3 x 2 x 1 (which is a short-cut for 1+1
>
> + 1+1 + 1+1 ), the EACH function is a programming short-cut for repition.
>
>
>
> 1 2 3 ?" 5
>
> is the same as
>
> 1 2 3 ? 5 5 5 5 5 5
>
>
>
>
>
> <davi...@gmail.com> wrote in message
>
> news:af5e216e-76a4-4f10...@googlegroups.com...
>
> Thanks for the replies. The list of four operations (SHAPE, ASSIGN, ADD,
>
> INVERT) may be the answer that I was looking for but there must be finer
>
> points that I am after. In testing your answer, for example, I don't see
>
> how you would implement the 'each' operator (?) using just those four

W. LeRoy Davis

unread,
Mar 21, 2013, 5:49:50 PM3/21/13
to
Your answers might be found here:
http://www.softwarepreservation.org/projects/apl/
In the "BOOKS" folder are several manuals for various mainframe
implimentations of APL. Possibly "A Source Book in APL" will give you the
insight you need.
There is also Source Code in the "APL SOFTWARE REPOSITORY" folder.
Finally, in the "PAPERS" folder is a paper on YAT (Compiling APL: The
Yorktown APL Translator) that might have what you're looking for.

As for the "kernal functions" -- you need to look for studies on Axiomatic
Theory.

The reason I like APL is that a function (like DOMINO or matrix-divide) is
the same for 2-D as it is for D-26, but our (human) definition of constructs
like spacetime include combining real & imaginary "dimensions" and the
"simple" matrix manipulations need to be "enhanced." Hence, this is also
the reason I don't like APL. I want a language that knows what I MEAN, not
necessarily what I say...

It sounds like you have quite a challenging task at hand -- good luck!

<davi...@gmail.com> wrote in message
news:c50659d5-abbf-40ba...@googlegroups.com...

davi...@gmail.com

unread,
Mar 21, 2013, 8:50:13 PM3/21/13
to
Many thanks for the link. Its got some great references, including a legible version of Iverson's Turing Award lecture, which I'd had no luck tracking down. Very helpful.

In looking over the Yorktown APL paper, it looks like their concern is primarily performance (so they aren't too interested in inefficient reductions that are mostly only useful for mathematical analysis). Indeed, on p.585, they mention that they require variable array rank to be explicitly knowable to the compiler -- I bet they ran into the same situation. Still, this is a great deal of potentially on-point info that I didn't have before.

I'm with you on the value of being able to operate without explicitly knowing dimensions, although when I searched this list before posting, I read an old thread where it was argued that not knowing the rank of your operands is rare so the value is little. Obviously, I wasnt completely convinced.

The thread was here:
https://groups.google.com/forum/?fromgroups=#!searchin/comp.lang.apl/kernel/comp.lang.apl/rpFduIegWpw/TgCaGOEutzoJ

What brought me here was that I am trying to embed a notation for multivariate algebra in a synchronous language. I have five combinators in my language that work generically for all arrays but I was going to need a 6th (a 'duplicate' operator like your example, in fact) just to enable N-D outer product. I figured there may have already been work on what the minimum amount of work to implement APL would be. An interpreter that performs only SHAPE, ASSIGN, ADD and INVERT could probably be done in a few pages of code, like a class assignment. But I don't think that interpreter could do most APL operations.

And I'm also with you on the language understanding the context. Synchronous programming is most appropriate for interactive software so the math is mostly about simple 2-D and 3-D algebra and geometry. I could probably have gotten away with a little more than linear algebra (initial inspirations were Ricci and Einstein notation). But I wanted something a little more powerful, yet less intimidating than APL.

W. LeRoy Davis

unread,
Mar 22, 2013, 5:48:47 PM3/22/13
to
After re-reading my message and looking at the EACH function, you're right.
One results in a two dimensional vector and the other in a three dimensional
array.

< 1 2 3?�5 >
should be the comparable to
< 1?5 2?5 5 3?5 5 5 >

Still, just a "short-cut" bit of programming on the language's part.


"Rav" <Pa...@cais.com> wrote in message news:kifins$i3t$3...@dont-email.me...
> Whoops ... meant to say "don't think you're saying ..."
>
> On 3/21/2013 2:16 PM, Rav wrote:
>> Oh, I see. But I also don't think you're not saying that < 1 2 3?�5 >
>> is the same as < 1 2 3?5 5 5 5 5 5 > .

David Liebtag

unread,
Apr 24, 2013, 3:01:44 PM4/24/13
to
In my opinion, the APL2 Language Reference manual is the best resource for
understanding the APL primitives. Of particular interest to you may be the
fact that most of the more complex primitives are defined in terms of
simpler primitives. You can get the APL2 LRM here:

http://www.ibm.com/software/awdtools/apl/library.html

David Liebtag

0 new messages