[comp.lang.apl] Some General Questions about J

cbbrowne@csi.uottawa.ca (Christopher Browne (055908)) (02/24/91)

I'm in the process of trying to assimilate some sort of understanding of
the J language.  It looks like it has distinct advantages over APL,
notably in that it doesn't use "funny characters."  That makes it:

a) Easier to port to multiple machines
  i.e. - it's MUCH LESS hardware dependent.  One APL solution is to have
  a standard "character set generator" for each machine - but you still have
  to put together SOMETHING that's massively machine dependent when you use
  classical APL.

b) Nicer to use with foreign file systems.
  It uses "standard ASCII" (and EBCDIC support wouldn't be too hard to add...)
  so that files will be far easier to move between different machines &
  versions of the language.  I don't know how "classical APL" put together
  workspaces, but I'm pretty sure that the ONLY sensible way to edit it was
  by using APL (or some customized version of XEDIT...).  This adds Yet
  Another Improvement:

c) You can use ANY editor to edit programs/data.
  Old APL workspaces were ugly in MANY ways...  Being able to load vars/
  functions from files is a NICE improvement.  I can use Emacs, you can use
  Brief, someone else can use WordPerfect (ick!)...  Others may use vi...

BUT
---

There seem to be a few downsides.  Related to one of them, I have a public
question...

a) Doesn't use the "funny characters"
  That special character set WAS good in that it was easy to tell the various
  operations apart.  Now, instead of looking like strange-character gibberish,
  the code looks like punctuation gibberish...

  It'll take some work with the system to be able to figure out the operator
  set, especially since MANY have characters in common.

  This is a lose-lose situation.  There are both advantages and disadvantages
  to using either a) Special APL characters or b) Combinations of standard
  punctuation characters.

  I think that the benefits of moving to ASCII outweigh the costs, but there
  IS certainly a cost...

b) Documentation at FTP archives

  This isn't a language issue - just a distribution issue.  All I could find
  on watserv1 was a document entitled "J Implementation Status," showing the
  various verbs, adverbs, conjunctions, pronouns, copulae, and conjunctions,
  with (in most cases) not much explanation of what they're about.

  T'would be nice to have some sort of brief documenting describing:

   I)  What is J?  How did APL work lead to J?
   II) What are the major differences?
   III)What are the operators?  What do they do? (e.g. - giving a little more
         than just the operators' names.)

  I've been able to figure out many of my confusions by looking at the
  sundry tutorial files, but it would be nice to have some sort of overview
  of the system.

  I realize that there's a $24 J Reference Manual available, but I'm a
  poor grad. student who can't really afford every manual that comes
  available...   If I start using J really extensively, then maybe...

c) Matrix Referencing (the "" operation)
  This shouldn't be TOO hard...

  In original APL, one could grab part of a matrix by doing something like
  the following:

  (I'll add a little J in to substitute for those operators that are not
  in ASCII...)

  EXPENDITURES=. 2 3 6 $ 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20
  130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161

  EXPENDITURES
161 161 161 164 164 164
9 3 11 6 4 4 
10 17 22 9 11 20

130 132 184 197 163 0
1 7 9 10 5 6
21 24 8 11 17 161

  I'd then like to add things up with respect to the second index.

  I'd use the operation:
     +/[2]EXPENDITURES
getting:
180 181 194 179 179 188
152 163 201 218 185 167

In J, it's something annoying like
+/ {Ugliesomitted{MoreUglies{EXPENDITURES

Question 1)
  What should those two sets of uglies be?

Question 2)
  There must be some general J idiom for doing this sort of thing.
  What might it be?

Question 3)
  Why was this operation changed?  I can see that the new way is far more
  explicit (and may be able to do things the old way couldn't).  The square
  braces aren't used for anything in J now - they could have been used for
  the old operation.  Why not?

  (I'm sure there are good reasons for these things.  I'd just like to know
  why...)

-- 
Christopher Browne
cbbrowne@csi.uofottawa.ca
University of Ottawa
Master of System Science Program

mjab@godot.think.com (Michael J. A. Berry) (02/26/91)

   Newsgroups: comp.lang.apl
   From: cbbrowne@csi.uottawa.ca (Christopher Browne (055908))
   Keywords: n
   Nntp-Posting-Host: prgc
   Organization: CSI Dept., University of Ottawa
   Date: Sat, 23 Feb 91 23:45:05 GMT

   I'm in the process of trying to assimilate some sort of understanding of
   the J language.

    .
    .
    .

   c) Matrix Referencing (the "" operation)
     This shouldn't be TOO hard...

I'm not too sure what you mean by the "" operation.

     In original APL, one could grab part of a matrix by doing something like
     the following:

     (I'll add a little J in to substitute for those operators that are not
     in ASCII...)

     EXPENDITURES=. 2 3 6 $ 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20
     130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161

     EXPENDITURES
   161 161 161 164 164 164
   9 3 11 6 4 4 
   10 17 22 9 11 20

   130 132 184 197 163 0
   1 7 9 10 5 6
   21 24 8 11 17 161

     I'd then like to add things up with respect to the second index.

     I'd use the operation:
	+/[2]EXPENDITURES
   getting:
   180 181 194 179 179 188
   152 163 201 218 185 167

Actually, assuming an index origin of 0 as in J, that expression would be
+/[1]EXPENDITURES

   In J, it's something annoying like
   +/ {Ugliesomitted{MoreUglies{EXPENDITURES

   Question 1)
     What should those two sets of uglies be?

These are not the "uglies" you want.  In both traditional APL and J what
you are doing is not a selection of elements or "grabbing part of a matrix"
(what { does) but rather, specifying how to carve up EXPENDITURES for +/.
The confusion probably comes from the fact that square brackets were used
for both selection and axis specification in APL.  The two uses are
unrelated.

   Question 2)
     There must be some general J idiom for doing this sort of thing.
     What might it be?

In J, one would write +/"2 EXPENDITURES.  This is read "sum rank two of
EXPENDITURES"  or "apply summation to the rank-2 cells of EXPENDITURES."

The rank operator is not new with J.  It was in Dictionary APL and Sharp
APL (and maybe others as well).  The [] notation was used for several
different things in APL.  In all cases, the syntax was anomalous since a
pair of symbols was used where other APL functions and operators use a
single symbol.  Even the $24 documentation of J may not tell you all you
want to know.  If you want to read more about the rank operator, I suggest:

Berneky, Robert "An Introduction to Function Rank" in the Proceedings of
APL 88 (ACM).

To understand more of the roots of J, I suggest:

Iverson, Kenneth E. "A Dictionary of APL" APL Quote-Quad Vol. 18, Number 1,
September 1987.

The J distribution includes a file "references" with pointers to articles
on J itself.

Here is a sample J session illustrating the use of the rank operator to
solve your problem:

$ /public/j/sun4/j
J Version 2.9   Copyright (c) 1990 1991, Iverson Software Inc.

   EXPENDITURES=. 2 3 6 $ 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20 130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161

   EXPENDITURES
161 161 161 164 164 164
  9   3  11   6   4   4
 10  17  22   9  11  20

130 132 184 197 163   0
  1   7   9  10   5   6
 21  24   8  11  17 161
   
   +/"2 EXPENDITURES
180 181 194 179 179 188
152 163 201 218 185 167
   

   Question 3)
     Why was this operation changed?  I can see that the new way is far more
     explicit (and may be able to do things the old way couldn't).  The square
     braces aren't used for anything in J now - they could have been used for
     the old operation.  Why not?

All the various things which [] used to do are done in J in different ways.
The primary use of [] in APL was subscripting.  Unlike {, however, it was
impossible to write a rank-independent selection expression with the []
notation because you had to know how many semicolons to put in.

     (I'm sure there are good reasons for these things.  I'd just like to know
     why...)

   -- 
   Christopher Browne
   cbbrowne@csi.uofottawa.ca
   University of Ottawa
   Master of System Science Program
--

==============================================
Michael J. A. Berry

Internet:  mjab@think.com
uucp:      {harvard, uunet}!think!mjab
telephone: (617) 234-2056  FAX: (617) 234-4444
==============================================

rbe@yrloc.ipsa.reuter.COM (Robert Bernecky) (02/27/91)

I won't try to deal with all your concerns about J vs apl, but
here are two comments:

a. character set: The apl character set is an ONGOING problem:
   Every new editor, printer, keyboard, etc., would need special
   tinkering to support it. Ergo, we give up and go ascii.

b. hard-to-read squiggles: You get used to them, just as you got
   used to apl squiggles. For example, x#y is replicate or compression.
   $ is reshape (with slightly different semantics due to "item" 
   orientation of J.

c. (ok, so I can't count- that's why I use computers).
   how do I do reductions along specific axes, etc? Like this.
   Assume T is your rank 3 array:
     +/t   gives you first axis summation
     +/"3 t would be the same.
     +/"2 t  gives you second axis summation. Basically, it says:
            "apply plus reduction to the rank-2 objects of t".
     +/"1 t gives last axis reduction (sum each row of t).

There are two reasons for abandoning the +/[k] approach of apl:
a. brackets are syntactically anomalous, and are not functions, operators,
   or anything else that is generally applicable to apl.

b. brackets have special and unique meanings for EACH primitive. 
   You can't tell someone: foo[k] means thus and such. 

   In J, the rank adverb ("k) has a specific and CONSISTENT meaning
  for all verbs, including user defined ones: Apply the verb/function
  to the rank k objects of the argument.

Simple, straightforward, and consistent.
See my paper on "An Introduction to Function Rank" in the acm sigapl
apl88 conference proceedings (apl quote quad vol 18, no 2) for
discussion of function rank in an apl environment.

Bob Bernecky
Snake Island Research Inc.

hui@yrloc.ipsa.reuter.COM (Roger Hui) (02/27/91)

a. The special symbols APL are elegant, but they are very expensive.
You yourself outlined some of the costs, by pointing out things made
possible by eschewing the special symbols.

As to the possible disadvantages of the ASCII spelling, anything new 
will look strange at first.  The Language Summary in the dictionary is
worthy of study. You may come to appreciate that the ASCII spelling 
is no less mnemonic than the special symbols.

b. Documentation. "status.doc" is not meant to be sufficient for
learning J. It just tells you what's been implemented and what has not.
$24 buys you a printed manual called "Tangible Math and the ISI Dictionary
of J" (author: K.E. Iverson).  If you feel that you can not afford the
cost, there are alternatives:

- Hui/Iverson/McDonnell/Whitney, APL\?, APL90 Conference Proceedings.
[Introduced J, "philosophic" discussions, reasons behind design].
- K.E. Iverson, Dictionary of J, Vector (Journal of the British 
APL Association), October 1990. [This version of dictionary now 
slightly out-of-date.]
- K.E. Iverson, J, Vector, July 1990.
- The tutorial frames in the distribution package.

c. The bracket axis "operator" has been superseded by the rank (")
conjunction. See the msg from Bob Bernecky filed 1991 2 26 21 05 GMT.

Roger Hui
Iverson Software Inc.
33 Major Street, Toronto, Ontario  M5S 2K9
(416) 925 6096
 

mjab@nanna.think.com (Michael J. A. Berry) (03/01/91)

In article <1991Feb26.162714.28837@csrd.uiuc.edu> jaxon@sp27.csrd.uiuc.edu (Greg P. Jaxon) writes:
    .
    .
    .

   I was sure I understood the rank operator until I read Mike Berry's reply.  What I can't
   understand now is how the summation chose the `middle' axis.  Am I right that there are
   2 `rank-2 cells' in EXPENDITURES, and they are 3x6 arrays?  If so shouldn't summing them
   yield a 3x6 result?  Or is J's rank operator asking sum to produce a rank-2 result?, in 
   which case I want to know how it picked the axis to reduce.

   I'm just guessing here, but has +/ been changed to work by default on the leading axis
   of its argument?  Applying +/[#IO] to the rank-2 cells of EXPENDITURES would give 2
   6-element results.

Yes, that is what happened.  In J, *everything* favors the first axis.  /
does what slash-bar used to do, comma does what comma-bar used to do.  This
(I assume) is to make the rank operator more convenient to use.  

   Regards,
   Greg Jaxon  Univ. of Ill. Center for Supercomputing R&D
   jaxon@csrd.uiuc.edu

-Michael
--

==============================================
Michael J. A. Berry

Internet:  mjab@think.com
uucp:      {harvard, uunet}!think!mjab
telephone: (617) 234-2056  FAX: (617) 234-4444
==============================================

rbe@yrloc.ipsa.reuter.COM (Robert Bernecky) (03/02/91)

<... first axis operations were done... to make use of the rank operator
    easier...>

There's more to it than that. 

Consider that traditional APL had 3 (count 'em, three!) flavors of
many operations. For reduction, there was reduction along the first
axis, written as slash overstruck with minus. There was reduction along
the last axis, written as slash. And, there was reduction along axis k
written as slash leftbracket k rightbracket.

J unifies all those into a single reduction, written with slash, in which
you achieve the other axes via the rank adverb.

Because the rank adverb has consistent semantics, you only have to learn how
it works once. Because reduction has consistent semantics, ditto.
But you end up with a whole family of reductions, and REDUCE the number
of symbols required to express the notation.

So, it'
it's not just to make rank easier. Function rank is the key to simplifying
APL, and the first axis is its prophet. Oopsie. Apologies to Asimiv.
Asimov. ... the first axis enables those simplifications.

Bob Bernecky

Edward_M_Cherlin@cup.portal.com (03/03/91)

cbbrowne asked for help in understanding J and its rationale. He can find some
of the answers in the article "The Principles of J" in APL News, 22,3 (1990).
The article explains most J features with examples for the more confusing
new features, and shows the development from Sharp (or Reuter:file) APL to
J, starting from before nested arrays and including Dictionary APL. Back
issues are available from the publisher, Springer-Verlag New York, at 800-
SPRINGER or 212/460-1500.

To answer one particular question: instead of using the axis operator to
do reductions in a particular direction, J uses the rank operator. By default,
reduction in J applies along the first axis rather than the last. The rank
operator partitions an array by selecting a specified number of dimensions
from the end. So +/"n applied to an m-dimensional array reduces the (m-n)th
dimension, counting in origin 0.