Re: [Jprogramming] multiply two multidimensional matrices

2020-02-08 Thread R.E. Boss
Rudolf Sykora > Verzonden: vrijdag 7 februari 2020 22:37 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] multiply two multidimensional matrices > > > R.E. Boss writes: > > > What I did was translate your > > > > C_ijlmnop = sum_k A_ijkl

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-08 Thread bill lam
Certainly. It is the dictionary of j https://www.jsoftware.com/help/dictionary/contents.htm On Sat, Feb 8, 2020, 3:58 PM Tarik ÖZKANLI wrote: > Hello, > Is there a formal specification or standard for the J language? > > Thank you. > > Tarık Özkanlı > > 8 Şub 2020 Cmt 02:40 tarihinde Marshall

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Tarik ÖZKANLI
Hello, Is there a formal specification or standard for the J language? Thank you. Tarık Özkanlı 8 Şub 2020 Cmt 02:40 tarihinde Marshall Lochbaum şunu yazdı: > If you're enjoying learning J, I would say it's certainly worth it. Many > of the ideas, like copy or the prefix operator, are incredib

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Marshall Lochbaum
If you're enjoying learning J, I would say it's certainly worth it. Many of the ideas, like copy or the prefix operator, are incredibly powerful tools you won't find anywhere else. And learning how these concepts work in J will help you recognize when to use them in other languages, even if they ca

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Rudolf Sykora
R.E. Boss writes: > What I did was translate your > > C_ijlmnop = sum_k A_ijkl * B_mknop > > in J-terms. If that's not what you want, then your specs are imprecise. > > Perhaps what you want to do (with thanks to Lochbaum), is > > (('ijkl i. ijlk')|: A_ijkl ) (+/ . *) ('mknop i. kmnop')|: B_mkno

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread R.E. Boss
7 februari 2020 15:43 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] multiply two multidimensional matrices > > > R.E. Boss writes: > > > a =. i. 2 3 4 5 > > b =. i. 2 4 3 5 6 > >$a *"0 _ b > > 2 3 4 5 2 4 3 5 6 > >

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Rudolf Sykora
Mike Powell writes: > if you wish > the result to also be a tensor, you must choose one contravariant and > one covariant index. So when Ruda writes A_ijkl*B_mknop, my guess is > that the two uses of the k index have different tensor types. In principle and generality yes, but for the purely tec

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Mike Powell
Ken Iverson dealt with tensor contraction in his APL 79 paper "The Derivative Operator". He suggested an operator (a J adverb) which today can just be an APL function (a J verb). This took an array as its left argument and an even-numbered vector of indices as its right argument. It performed ze

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Raul Miller
Yes, a way of describing this issue here is that when you use an outer product to form a matrix product, you want to sum along a diagonal (and discard non-diagonal elements). For example: 2{"2+//."3 (i.2 3)*/|.i.3 4 20 23 26 29 56 68 80 92 is equivalent to (i.2 3)+/ .*i.3 4 20 23 26 29 56

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Brian Schott
I am troubled by the apparent inequality suggested below. a =. i. 2 3 4 5 b =. i. 2 4 3 5 6 ( (2 |: a) +/ . * ((|:~ 1 -.~ i.@(#@$)) b))-:+/"6 +/"4 a *"0 _ b 0 ( (2 |: a) +/ . * ((|:~ 1 -.~ i.@(#@$)) b))(;&$)+/"6 +/"4 a *"0 _ b ┌─┬─┐ │2 3 5 2 3 5 6│2 3 5

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Roger Hui
I think this is a weak point for J's array programming style. Just like tacit code works well for small manipulations but gets confusing and difficult as the number of arguments increases, J primitives like rank, transpose, and inner product are excellent for a few axes, but don't work so well when

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Rudolf Sykora
Dear Marshall and Henry, Marshall Lochbaum writes: > Although a matrix product will execute faster, if I want to write tensor > code that is straightforward, and extends to multiple contracted axes, I > would transpose the contracted axes to the end and combine them with > (+/@:*"1). This is ex

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread Rudolf Sykora
R.E. Boss writes: > a =. i. 2 3 4 5 > b =. i. 2 4 3 5 6 >$a *"0 _ b > 2 3 4 5 2 4 3 5 6 >$+/"6 +/"4 a *"0 _ b > 2 3 5 2 3 5 6 This is an interesting take on the subject. If I understand, the first part does an outer product, P, P_ijklmnopq = A_ijkl * B_mnopq . And I believe

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-07 Thread R.E. Boss
> Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] multiply two multidimensional matrices > (...) > > C_ijlmnop = sum_k A_ijkl * B_mknop > > means I have C with rank 7, A with rank 4 and B with rank 5. > C_ijlmnop is a *number*, the same with A_ijkl and B_mknop (for a

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread Henry Rich
+/ . * is so much faster than (+/@:(*"1 _)) that even if you were given a notation for selecting an axis, the implementation would do the transpose so that it could use the faster product. +/@:*"1  is pretty fast for small arguments but for big ones its cache characteristics mean you end up li

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread rsykora
February 6, 2020 11:00 PM, "Henry Rich" wrote: > It's not so simple to describe. In fact, you haven't described it. > Your example seems to have a rank-4 array times a rank-5 array producing > a rank-7 array. Is this result the sum of rank-7 arrays created by > multiplying rank-3 times rank

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread Marshall Lochbaum
Here is a way to permute the axes of an array that you might find easier to work with: A =. i. 2 3 4 5 $ ('ijkl'i.'ljik') |: A 5 3 2 4 The idea is that we start with A, which has axes ijkl, and want to shuffle them around to get ljik. So we look up each of the letters ljik in ijkl, which gi

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread Raul Miller
It's simple mathematically, because you've already learned that and because you are willing to elide discussion of various mechanical details. Personally, I had to read your question a couple of times, and then Henry's response and then your question again to resolve some of the ambiguities. The

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread Henry Rich
It's not so simple to describe.  In fact, you haven't described it.  Your example seems to have a rank-4 array times a rank-5 array producing a rank-7 array.  Is this result the sum of rank-7 arrays created by multiplying rank-3 times rank-4?  I don't know how to make that jibe with 'the usual

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread rsykora
Henry Rich writes: > It depends on what the '*' means in the definition of the product. >> C_ijlmnop = sum_k A_ijkl * B_mknop I really mean the usual multiplication (of numbers). > Have a look at > > a =. i. 2 3 4 5 > b =. i. 2 4 3 5 6 > $ (2 |: a) +/ . * ((|:~ 1 -.~ i.@(#@$)) b) > 2 3 5 2 3

Re: [Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread Henry Rich
It depends on what the '*' means in the definition of the product.  Have a look at    a =. i. 2 3 4 5    b =. i. 2 4 3 5 6    $ (2 |: a) +/ . * ((|:~   1 -.~ i.@(#@$)) b) 2 3 5 2 3 5 6 Henry Rich On 2/6/2020 2:46 PM, rsyk...@disroot.org wrote: Dear list, having two multidimensional matrices

[Jprogramming] multiply two multidimensional matrices

2020-02-06 Thread rsykora
Dear list, having two multidimensional matrices A and B, with some indices, say, A_ijkl and B_mknop, how can I obtain a matrix C, where C_ijlmnop = sum_k A_ijkl * B_mknop ie., C has all indices of A and B but for the index k, which was summed over. Thanks for your suggestions. Best regards Rud