[comp.lang.apl] Rank 0 catenation.

ljdickey@watmath.waterloo.edu (L.J.Dickey) (06/24/91)

Someone wrote recently asking about how to glue some given
arrays together to create certain specified results.
Here is the question.

 ========================= ========================== =========================
Suppose one is given the three arrays:

   a =. < " 0  m =. i. 2 3
   b =. < "(0) m + 12
   c =. < "(0) m + 24

How does one use these to create arrays d and e, whose displays are

   d
+----+----+----+
|0 12|1 13|2 14|
+----+----+----+
|3 15|4 16|5 17|
+----+----+----+
   e
+-------+-------+-------+
|0 12 24|1 13 25|2 14 26|
+-------+-------+-------+
|3 15 27|4 16 28|5 17 29|
+-------+-------+-------+
 ========================= ========================== =========================
   
I found that these expressions do the job:

   d =. a   ,"0  &. > b
   e =. d (,,"0) &. > c
  
My question is, do you know other ways of doing this?


-- 
Prof L.J. Dickey, Faculty of Mathematics, U of Waterloo, Canada N2L 3G1
internet:       ljdickey@watmath.UWaterloo.ca	BITNET/EARN:	ljdickey@watdcs
obsolescent?:	ljdickey@watmath.waterloo.edu
UUCP:		ljdickey@watmath.UUCP	..!uunet!watmath!ljdickey

rockwell@socrates.umd.edu (Raul Rockwell) (06/25/91)

L. J. Dickey (paraphrased, slightly):
   Suppose one is given the three arrays:
      c =. 12+&.> b =. 12+&.>  a=. <"0 i. 2 3

   How does one use these to create arrays d and e, whose displays are
      d                              e                     
   +----+----+----+	          +-------+-------+-------+
   |0 12|1 13|2 14|	          |0 12 24|1 13 25|2 14 26|
   +----+----+----+	          +-------+-------+-------+
   |3 15|4 16|5 17|	          |3 15 27|4 16 28|5 17 29|
   +----+----+----+	          +-------+-------+-------+

   I found that these expressions do the job:
      d =. a   ,"0  &. > b
      e =. d (,,"0) &. > c
   My question is, do you know other ways of doing this?

======================================================================

How about:
     d =. a ,&.> b
     e =. ,&.>/ a,b,c

?

CAUTION: I don't have a working copy of J on my system so I honestly
don't know if that will even work.

-- 
Raul <rockwell@socrates.umd.edu>

rockwell@socrates.umd.edu (Raul Rockwell) (06/25/91)

I wrote:
	e =. ,&.>/ a,b,c

but that won't work.  This should work:
   e =. a ,&.> b ,&.> c
or
   e =. d ,&.> c            NB.  ,&.>  is associative

-- 
Raul <rockwell@socrates.umd.edu>

hui@yrloc.ipsa.reuter.COM (Roger Hui) (06/25/91)

Article <1991Jun24.161151.12366@watmath.waterloo.edu> ljdickey@watmath.waterloo.edu (L.J.Dickey):

Lee, here are some other ways to generate the desired results:

   d =. a ,&.> b
   e =. d ,&.> c
   e =. a ,&.> b ,&.> c

   d =. <"1 (i.2 3)+/0 12
   e =. <"1 (i.2 3)+/0 12 24

   d =. (<0 12) +&.> i.2 3
   e =. (<0 12 24) +&.> i.2 3

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

hui@yrloc.ipsa.reuter.COM (Roger Hui) (06/25/91)

Article <ROCKWELL.91Jun24223131@socrates.umd.edu> by rockwell@socrates.umd.edu (Raul Rockwell):
>I wrote:
>	e =. ,&.>/ a,b,c
>
>but that won't work.     [more stuff]

   e =. ,&.> / a,b,:c
   d =. ,&.> / a,:b

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

rjfrey@kepler.com (Robert J Frey) (06/25/91)

In article <1991Jun24.161151.12366@watmath.waterloo.edu> ljdickey@watmath.waterloo.edu (L.J.Dickey) writes:
>
>Suppose one is given the three arrays:
>
>   a =. < " 0  m =. i. 2 3
>   b =. < "(0) m + 12
>   c =. < "(0) m + 24
>
>How does one use these to create arrays d and e, whose displays are
>
>   d
>+----+----+----+
>|0 12|1 13|2 14|
>+----+----+----+
>|3 15|4 16|5 17|
>+----+----+----+
>   e
>+-------+-------+-------+
>|0 12 24|1 13 25|2 14 26|
>+-------+-------+-------+
>|3 15 27|4 16 28|5 17 29|
>+-------+-------+-------+
>   
>I found that these expressions do the job:
>
>   d =. a   ,"0  &. > b
>   e =. d (,,"0) &. > c
>  
>My question is, do you know other ways of doing this?
>
>
>-- 
Well, I wouldn't do that way ;-)! But given your original definition of a, b 
and c, you can also do:

	each =. '&.>':1

	a=. <"0 i.2 3
	b=. 12 +each a
	c=. 24 +each a

then:

	e=. a ,each b ,each c

Also, if list is a vector of boxed arrays of boxes:

	list=. (<a),(<b),<c

then this works:


	e=. >,each each/list


note that '$each e' is:

	+-+-+-+
	|3|3|3|
	+-+-+-+
	|3|3|3|
	+-+-+-+

as expected.

In the case of J I would defer the use of arrays of boxes until the 'last' 
step:

	a=. i.2 3
	b=. a+12
	c=. b+24

	e=. <"1&.|:a,b,:c

I think that a comparison of the two approaches suggests that the latter is 
probably a better way to do it.

I was more familiar with APL2ish APL rather than Sharpish APL, so I tended to
use a lot each's on boxed nouns when I first started using J. Because J
treats a boxed noun as a reference to data, rather than as the data themselves,
that often led to some pretty convolved sentences on my part.

Does anyone know why people seem to feel that "data nesting" as in APL2
enclosed variables and "data referencing" as in J boxed nouns are incompatible
with one another? They are probably implemented pretty much the same way as a
data structure, the difference being the way the various verbs/functions of
the language deals with them.

A rank operator would be great to have in APL2 instead of all that function 
with axis stuff, and a foreach adverb and depth verb would be great to have 
in J (sometimes the way J pads out ragged results with zeroes/blanks/empty 
boxes makes me nervous).

All that being said, I'm finding J extremely interesting. I'm quickly becoming
one of the converted.

weg@convx1.ccit.arizona.edu (Eythan Weg) (06/26/91)

In article <ROCKWELL.91Jun24223131@socrates.umd.edu> rockwell@socrates.umd.edu (Raul Rockwell) writes:


   I wrote:
	   e =. ,&.>/ a,b,c

   but that won't work. [...]

but this would (I think):
e=.,&.>/a,b,:c

Any time I start playing with this toy I find new ways to recombine
its constituents.  Is it the language equivalent to Lego?  I am
confident that this is a common experience.  But here is a point that
puzzles me.  I wish J to possess a regular expression automaton to be
used in much the same way as it is used in unix utilities.  Is there
anything wrong with this desire?  I thought it might be used with E.
for example.

Any comments? 

Eythan

wdr@wang.com (William Ricker) (06/27/91)

rockwell@socrates.umd.edu (Raul Rockwell) writes:
>	e =. ,&.>/ a,b,c
>but that won't work.  This should work:
>   e =. a ,&.> b ,&.> c

Nope.  That also gives 
+---------------+---------------+---------------+
|0 3 12 15 24 27|1 4 13 16 25 28|2 5 14 17 26 29|
+---------------+---------------+---------------+
 
To insert (,&.>) between three arrays of similar size, you can
   ]    e =. ,&.> /   >  a;b;<c

which has the desired result of 

+-----------------------+
|0 12 24|1 13 25|2 14 26|
+-------+-------+-------|
|3 15 27|4 16 28|5 17 29|
+-----------------------+

(The close or box < on c is needed since c is alread boxed, and thus
 won't get the extra layer needed for symmetry from ; for free; we
 then discard one layer of box  and work under the other.)

-- 
/s/ Bill Ricker                wdr@wang.wang.com 
"The Freedom of the Press belongs to those who own one."
*** Warning: This account is not authorized to express opinions. ***

ljdickey@watmath.waterloo.edu (L.J.Dickey) (06/27/91)

In article <594@kepler1.kepler.com> rjfrey@kepler1.UUCP (Robert J Frey) writes:
> ...
> 
>Does anyone know why people seem to feel that "data nesting" as in APL2
>enclosed variables and "data referencing" as in J boxed nouns are incompatible
>with one another? They are probably implemented pretty much the same way as a
>data structure, the difference being the way the various verbs/functions of
>the language deals with them.

They need not be incompatible.  I would refer you to the programming
language APL90, designed by Jean-Jacques Girardot, of the School of
Mines in St-Etienne, France, and to papers by Girardot.   With APL90,
which runs only on Macintosh computers, one may have both types of
generalized arrays in your workspace at the same time.

It was Girardot who made at the conference APL90 what is, I believe,
the first public observation that boxed arrays behave very much like
pointers to arrays.  In his paper, "Arrays and References", there is
a section called "A comparison of nested arrays, boxed arrays and
references" in which he notes a profound analogy between boxed arrays
and References.

Girardot may be reached at  girardot@cambur.emse.fr .  I don't know
if he reads this news group.

						Lee Dickey

-- 
Prof L.J. Dickey, Faculty of Mathematics, U of Waterloo, Canada N2L 3G1
internet:       ljdickey@watmath.UWaterloo.ca	BITNET/EARN:	ljdickey@watdcs
obsolescent?:	ljdickey@watmath.waterloo.edu
UUCP:		ljdickey@watmath.UUCP	..!uunet!watmath!ljdickey

weg@convx1.ccit.arizona.edu (Eythan Weg) (06/27/91)

In article <b7mykb.n3a@wang.com> wdr@wang.com (William Ricker) writes:


   rockwell@socrates.umd.edu (Raul Rockwell) writes:
   >	e =. ,&.>/ a,b,c
   >but that won't work.  This should work:
   >   e =. a ,&.> b ,&.> c

   Nope.  That also gives 
   +---------------+---------------+---------------+
   |0 3 12 15 24 27|1 4 13 16 25 28|2 5 14 17 26 29|
   +---------------+---------------+---------------+

Yes, it does work, at least on J/pc version 3.0.  
And should, by the dictionary.

Eythan

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

In article <WEG.91Jun25125303@convx1.convx1.ccit.arizona.edu> weg@convx1.ccit.arizona.edu (Eythan Weg) writes:

>    [stuff]
>
> Any time I start playing with this toy I find new ways to recombine
> its constituents.  Is it the language equivalent to Lego?  I am
> confident that this is a common experience.  But here is a point that
> puzzles me.  I wish J to possess a regular expression automaton to be
> used in much the same way as it is used in unix utilities.  Is there
> anything wrong with this desire?  I thought it might be used with E.
> for example.

a) It is not so unusual that the same nontrivial idea can be expressed
in more than one way.  One can say "to be or not to be" or "what now?"
as appropriate; does that make English a Lego language? :-)
 
b) If the regular expression automaton in UNIX is to your liking,
you can invoke it from within J by 0!:0 or by using LinkJ.
 
I have some epsilon-baked ideas on how a FSM can be introduced.
A gerund is an array of atomic representations of verbs.
The conjunction ` returns gerund results, for example, +`-`*`(+/)
is a 4-element gerund; and the conjunction g`:n defined various
verbs from a gerund.  (See Bernecky & Hui, APL91.)
 
If g is a gerund matrix, one can define:  fsm =. g`:57
fsm is applied to successive elements of an integer vector of inputs.
The initial state is 0.  If the current state is i and the current input
is j, then the verb represented by  (<i;j){g  is applied to i and j,
resulting in the pair (newstate;output).  The result of fsm is the
collection of the outputs.

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

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

(Whoever posted this...) 

>use a lot each's on boxed nouns when I first started using J. Because J
>treats a boxed noun as a reference to data, rather than as the data themselves,
>that often led to some pretty convolved sentences on my part.
>
>Does anyone know why people seem to feel that "data nesting" as in APL2
>enclosed variables and "data referencing" as in J boxed nouns are incompatible
>with one another? They are probably implemented pretty much the same way as a
>data structure, the difference being the way the various verbs/functions of
>the language deals with them.

They are NOT incompatible. Perhaps my evil twin, xxx xxxxx, from IBM, 
has been passing such rumours around. APL2 arrays are a proper subset of
SHARP APL arrays, and anyone  who can't see that will  deserve all theyget...

1. I doubt if they are even close in terms of a naive implementation.
   As the original implemenetor of boxes arrays on SHARP APL, and 
   as one with at least ne appendage on the pulse of APL implementations
   around this planet, I doubt if they are close at all:
     a. SAPL stuff tends to work on the underlying primitive without 
        bothering to call a function to bust it up, in common rank
        and similar expressions. Oddball ones, which are rarely used,
        such as reshape with a left argument rank specification, ARE
        done in a brute force manner. At least, they were when I worked
        there, and I sorta soubt, but cannot prove, that things have changed
        in that area.
     b. A lot of the functions with rank can be implemented by either 
        introducing another level of looping, or altering the extant
        loop structure, in a rather obvious fashion:pass the rank
         expression to the primitive as Yey-Another_argument. 
        It's not clear to me how this would work with apl2 and the world
        of eachness.

2. Beata hell outa me what (2) was. Perhaps the tail end of 1b?

3. A lot of the stuff with J  (or SAPL) vs APL2 is that the each/
enclose-along-axis stuff , is that a naive implementation can do MUCH
better with rank than with each/enclose with axis. Far fewer operations
involving storage management, data movement, and so on. 

In SHARP APL, we observed speedups of typcally 5-500 when primitives
included rank adverb support directly. 

   Bob
>
>A rank operator would be great to have in APL2 instead of all that function 
>with axis stuff, and a foreach adverb and depth verb would be great to have 
>in J (sometimes the way J pads out ragged results with zeroes/blanks/empty 
>boxes makes me nervous).

I also have to admit to being disturbed by J's lack of errors, both in
the padding of ragged arrays, and in the tolerance for negative elements
in index expressions. Life's tough that way...

Robert Bernecky      rbe@yrloc.ipsa.reuter.com  bernecky@itrchq.itrc.on.ca 
Snake Island Research Inc  (416) 368-6944   FAX: (416) 360-4694 
18 Fifth Street, Ward's Island
Toronto, Ontario M5J 2B9 
Canada

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

In article <1991Jun27.052421.809@yrloc.ipsa.reuter.COM> hui@yrloc.ipsa.reuter.COM (Roger Hui) writes:

>I have some epsilon-baked ideas on how a FSM can be introduced.
>A gerund is an array of atomic representations of verbs.
>The conjunction ` returns gerund results, for example, +`-`*`(+/)
>is a 4-element gerund; and the conjunction g`:n defined various
>verbs from a gerund.  (See Bernecky & Hui, APL91.)

If you want to see some earlier work that sets the stage for ROger and my
APL91 paper (which won't appear until August-ish), see my earlier
work in APL84: 
"Function Arrays".

Bob

Robert Bernecky      rbe@yrloc.ipsa.reuter.com  bernecky@itrchq.itrc.on.ca 
Snake Island Research Inc  (416) 368-6944   FAX: (416) 360-4694 
18 Fifth Street, Ward's Island
Toronto, Ontario M5J 2B9 
Canada