Ric,

As another relatively neophyte J-er, I must applaud your exposition in that
it really cleared up for me how +/ worked over square matrices. I had always
in my mind when working on problems thought of +/"1 as 'going across the
rows', and +/"2 as 'going down the columns', which of course worked, and of
course I in some sense knew (as a mantra almost)  that '+/"1 inserts +
between each rank 1 item of the noun it is applied to',  but your
explanation and example is clear enough to both make intuitive sense and be
technically accurate. Thank you :)


On 29 April 2010 22:47, Sherlock, Ric <r.g.sherl...@massey.ac.nz> wrote:

> > From: Robert O'Boyle
> >
> > I have come across a feature of J that I didn't expect. When I add
> > rows of a matrix, I use +/"1
> >
> >    a
> > 1 2 3 4
> > 1 2 3 4
> > 1 2 3 4
> >
> >    +/"1 a
> > 10 10 10
> >
> > And columns,
> >
> >   +/"2 a
> > 3 6 9 12
>
> Although the result is the same as summing the columns, I suspect you are
> misunderstanding rank in this case. Note to start with that not using rank:
>  +/ a
> 3 6 9 12
>
> Will give you the same result. The adverb insert ( / ) will place the verb
> to its immediate left between each _item_ of the noun to its right. The noun
> ( a ) is rank 2, and is therefore a list of rank 1 items. ( +/ a ) will
> place + in between each item of ( a ), i.e.
>    1 2 3 4 + 1 2 3 4 + 1 2 3 4
> 3 6 9 12
>
> You can think of the rank conjunction as a way of feeding chunks of a noun
> on its right, to the verb on the left. So ( +/"1 a ) will send rank 1 chunks
> (vectors) of ( a ) to ( +/ ). i.e. similar to:
>   (+/ 1 2 3 4) , (+/ 1 2 3 4) ,: (+/ 1 2 3 4)
> Insert will now place + between each item of the list:
>  (1+2+3+4) , (1+2+3+4) ,: (1+2+3+4)
>
> If you use ( +/"2 a ) then you are saying you want to feed ( a ) to ( +/ )
> in rank 2 chunks. Since ( a ) is only rank 2 (a matrix) this is the same as
> sending all of ( a ) to ( +/ ) at once. i.e. the same as ( +/ a ).
>
> > By chance, I happened to 'misplace' insert and got an unexpected result
>
> Note also that the sentence ( a *"1/ b ) uses dyadic / and so is "table"
> not "insert".
>
> I see Bob has replied along similar lines, I certainly endorse his
> recommendation of Henry's book!
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to