Well... of course, you can express matrix multiplication *using* rank:

   (1+i.4 3) +/@:*"1 _(1+i.3 4)
 38  44  50  56
 83  98 113 128
128 152 176 200
173 206 239 272

And, conceptually, all verbs in J have rank, so that always gets used.

But, I guess you are asking how to avoid the rank conjunction -- which
would be: how can you use just the implicit ranks (and, presumably,
other adverbs and conjunctions).

And, that can be done, but I don't think it's elegant.

For example:

   +/(1 2;0;3)|:(1+i.4 3) */ (1+i.3 4)
 38  44  50  56
 83  98 113 128
128 152 176 200
173 206 239 272

Basically, you probably want a rank 1 operation in there, somewhere,
to merge the rightmost dimension of the left argument with the
leftmost dimension of the right argument... But there aren't that many
operations in J which are rank 1, and getting them to do multiply is
not likely to be straightforward (though I might be overlooking
something).

You might be able to use #. for example, but the approach would be convoluted.

Does any of this help?

-- 
Raul

On Tue, Jul 12, 2022 at 11:09 PM Thomas McGuire <tmcguir...@gmail.com> wrote:
>
> Devon had shared a kx example of performing matrix multiplication backing out 
> the loops from a wikipedia pseudocode. Providing an elegant solution in K.
>
> You can see it in the NYCJUG notes here: 
> https://code.jsoftware.com/wiki/NYCJUG/2022-07-12 
> <https://code.jsoftware.com/wiki/NYCJUG/2022-07-12>
>
> The Kx solution is as follows:
>
> matmul: {x{+/x*y}/:\:+y}
>
> The each right (/:) and each left operators (\:) in sequence appear to 
> perform in a similar way to Jā€™s table operator ā€˜/ā€˜.
>
> After some messing around with rank I came up with the following J equivalent:
>
> matmul =: {{x {{+/x*y}}ā€1 1/ |:y}}
>
>     (1+i. 4 3) matmul 1+i. 3 4
>  38  44  50  56
>  83  98 113 128
> 128 152 176 200
> 173 206 239 272
>    (1+i. 4 3) +/ . * 1+i. 3 4
>  38  44  50  56
>  83  98 113 128
> 128 152 176 200
> 173 206 239 272
>
> By transposing the y operand I deliver columns of y to rows of x which gets 
> operated on by the inner anonymous dfns. Wondering if there is a more elegant 
> way that does not play around with rank?
>
> Tom McGuire
> ----------------------------------------------------------------------
> 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