Pease help with J's rank conjunction, " 
Author Message
 Pease help with J's rank conjunction, "

J Programmers,

I hope I'm writing to the appropriate newsgroup - there doesn't appear to be one
specifically for J.

I've recently taken up teaching myself J and I am so far extremely impressed
with what has been achieved here.

I was working through the primer, however, and realised that I could go no
further without fully understanding how ranks work. I couldn't quite follow the
explanation in the primer no matter how many times I read it and so it's time to
ask an expert.

Could someone please explain ranks to me - in particular as applied to a monadic
or a dyadic verb of defined rank. Alternatively could someone point me to
documentation other that the primer where a thorough explanation is given.

The use of the rank conjunction, for example, seems to work contrary to how I'd
expect it would for the +/ monad. What I would expect is that if I have the 3D
noun A with indices ijk (and shape Ni Nj Nk) - one for each axis - so that I can
represent it by Aijk, then summing over index i should be expressed by
B =. +/"0 A - sum over the first dimension, i -> result is of shape Nj Nk
summing over index j by
C =. +/"1 A - sum over the second dimension, j -> result is of shape Ni Nk
and summing over index k by
D =. +/"2 A - sum over the third dimension, k -> result is of shape Ni Nj
But this is not the case.

how would I be able to work out what the result should be for something like
Aijk (+/"n m) Ei
Aijk (+/"n m) Eij
Aijk (+/"n m) Eijk
or
Aijk (,"n m) Ei
Aijk (,"n m) Eij
Aijk (,"n m) Eijk
where n m are integers?

Thank You in advance,
Regards,
Robert.



Fri, 16 Jul 2004 18:26:55 GMT  
 Pease help with J's rank conjunction, "
First, to subscribe to the J forum go to
http://www.jsoftware.com/j_forum.htm to find out how to register. It's
not really a newsgroup. When you subscribe you are added to a mailing
list. Also look at http://www.jsoftware.com/ for more information on J.

There are three things to keep in mind when working with rank - frames,
cells and items. When specifying a rank you are specifying a division as
what is the frame and what is cells to the verb (function). For example:
specifying rank 2 on a 3 dimensional array divides it into a list
(vector) of tables (matrices). The list is the frame and each table in
the list is a cell. The cells are processed in a manner very similar to
the way the each operator of APL works - the verb appears to be repeated
on each cell in the frame. The J documentation goes to great lengths to
explain how cells are replicated when the shapes of the frames of the
arguments of a dyadic verb differ. By the way, J also has the "under"
conjunction (&.) which is a generalization of the APL "each".

Now, for the verb execution, ignore the frame and concentrate only on
the cell. That's all the verb will see. A cell is not necessarily
atomic. In the example above each cell is a table. The first dimension
of a cell is special. It divides the cell into items. In the case of
+/i.3 3 sees the array as one cell. That cell consists of three items -
0 1 2, 3 4 5 and 6 7 8.  It adds the items as 0 1 2+3 4 5+6 7 8.

   +/i.3 3
9 12 15

Now consider +/"1. Now the cells make up only the last dimension of the
array. The frame consists of three cells 0 1 2, 3 4 5 and 6 7 8. +/"1
appears to be executed three times, once for each cell or
(0+1+2),(3+4+5),(6+7+8).

   +/"1 i.3 3
3 12 21

Following the same logic:

   +/"0 i.3 3
0 1 2
3 4 5
6 7 8

Each cell consists only of a scalar. Each cell only contains one item
and its reduction sum is itself.

Now, there are two things to consider - using a verb with rank and
writing a user defined verb with rank. Explicit verb definitions in J
are of infinite rank, just like APL. You can give a defined verb rank,
but you're not changing it's rank you are creating another verb which
refers to your defined verb. Therefore, from the view of the verb, you
can create a verb of reduced rank, but you cannot increase it.

   plus=: 4 : 0
save=:x.;y.
x.+y.
)
   plus/i.3 3
9 12 15
   save
+-----+-------+
|0 1 2|9 11 13|
+-----+-------+
   plus/"1 i.3 3
3 12 21
   save
+-+--+
|6|15|
+-+--+
   plus2=:plus"0
   plus2/i.3 3
9 12 15
   save
+-+--+
|2|13|
+-+--+
   plus=:4 : 0"0
save=:x.;y.
x.+y.
)
   plus2=:plus"_
   plus2/i.3 3
9 12 15
   save
+-+--+
|2|13|
+-+--+
   plus2 f.
+-----------------------+-+-+
|+-----------------+-+-+|"|_|
||+-+-+-----------+|"|0|| | |
|||4|:|save=:x.;y.|| | || | |
||| | |x.+y.      || | || | |
||+-+-+-----------+| | || | |
|+-----------------+-+-+| | |
+-----------------------+-+-+

On the using view conjunctions and adverbs inherit rank from the
associated verbs. In this case, you can think of creating verbs of
increased rank.

You should be aware that J assumes that defined verbs are well behaved,
that is, you should not assume the order in which a verb is run against
cells, or even how many times it is run against a given cell. In other
words - be careful if you assign global variables within a verb that is
run repeatedly.

Quote:

> J Programmers,

> I hope I'm writing to the appropriate newsgroup - there doesn't appear to be one
> specifically for J.

> I've recently taken up teaching myself J and I am so far extremely impressed
> with what has been achieved here.

> I was working through the primer, however, and realised that I could go no
> further without fully understanding how ranks work. I couldn't quite follow the
> explanation in the primer no matter how many times I read it and so it's time to
> ask an expert.

> Could someone please explain ranks to me - in particular as applied to a monadic
> or a dyadic verb of defined rank. Alternatively could someone point me to
> documentation other that the primer where a thorough explanation is given.

> The use of the rank conjunction, for example, seems to work contrary to how I'd
> expect it would for the +/ monad. What I would expect is that if I have the 3D
> noun A with indices ijk (and shape Ni Nj Nk) - one for each axis - so that I can
> represent it by Aijk, then summing over index i should be expressed by
> B =. +/"0 A - sum over the first dimension, i -> result is of shape Nj Nk
> summing over index j by
> C =. +/"1 A - sum over the second dimension, j -> result is of shape Ni Nk
> and summing over index k by
> D =. +/"2 A - sum over the third dimension, k -> result is of shape Ni Nj
> But this is not the case.

> how would I be able to work out what the result should be for something like
> Aijk (+/"n m) Ei
> Aijk (+/"n m) Eij
> Aijk (+/"n m) Eijk
> or
> Aijk (,"n m) Ei
> Aijk (,"n m) Eij
> Aijk (,"n m) Eijk
> where n m are integers?

> Thank You in advance,
> Regards,
> Robert.



Sat, 17 Jul 2004 00:37:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. re please help with j's rank conjunction

2. Help - why doesn't this conjunction work?

3. Need conjunction for 'apply to cells above rank k'

4. ADS FIVEWIN NT WS AND NOVELL - HELP PEASE

5. Language "ranking" based on posts to

6. gfortran and "Type/rank mismatch"

7. LabView 5.1.1, 'Failure: "linker.c", line 1825': Please Help

8. JS-EAI with *JS*-callback

9. python -c "help('while')"

10. js.exception 3279.js

11. rank of fork versus rank of sentence

12. Second CFP: International Workshop on Component-Oriented Programming (in conjunction with ECOOP'97)

 

 
Powered by phpBB® Forum Software