Extended Inner Product

General APL language issues

Extended Inner Product

Postby mikepowell on Wed Jan 22, 2020 4:06 pm

I need some help with what I call an extension to inner product. It goes like
this.

xip is an operator taking a number n of axes as its left argument. It produces
a dyadic function which behaves like an inner product, but rather than acting on
vectors, it acts on arrays of greater rank n. For example:

a←?3 2 4⍴9
b←?2 4 5 6⍴9
⍴a(2 xip)b
3 5 6

One way I'm familiar with is to do a full outer product followed by appropriate
tensor contractions. That's a bit wasteful. An approach I'd prefer is to ravel on
the last n axes of a and the first n axes of b, followed by a regular matrix
multiplication. Something like:

xip←{(,⍤⍺⍺⊢⍺)+.×,[⍺⍺↑⍳⍴⍴⍵]⍵}

Is there a way I can avoid the ravel with axis specification and instead use the
rank operator?

Mike
mikepowell
 
Posts: 4
Joined: Thu Dec 05, 2013 8:01 pm

Re: Extended Inner Product

Postby Phil Last on Wed Jan 22, 2020 8:48 pm

I believe that
      ,[⍳⍺]⍵ ←→ ⍉,⍤⍺⊢⍉⍵
but would find it hard to prove. Also I'm not at all sure it improves either readability or efficiency.
User avatar
Phil Last
 
Posts: 549
Joined: Thu Jun 18, 2009 6:29 pm

Re: Extended Inner Product

Postby Phil Last on Mon Jan 27, 2020 11:20 am

I suggested that
      ,[⍳⍺]⍵ ←→ ⍉,⍤⍺⊢⍉⍵
It wasn't. But
      ,[⍳⍺]⍵ ←→ (1⌽⍳⍴⍴z)⍉z←,⍤⍺⊢((-⍺)⌽⍳⍴⍴⍵)⍉⍵
certainly seems to be for from 1 to rank 'though it's even less readable and probably far more expensive.
User avatar
Phil Last
 
Posts: 549
Joined: Thu Jun 18, 2009 6:29 pm

Re: Extended Inner Product

Postby Bob Armstrong on Sun Feb 02, 2020 5:07 pm

I posted and commented on this post to the FB group FORTH PROGRAMMING LANGUAGE 21st CENTURY , https://www.facebook.com/groups/PROGRAM ... 1030236918 , as an example of " APL thinking " .

The Forth community generally works and thinks at the very minimal and direct hardware level and has a strong tendency to think that's all they need even for complex problems . They'll just build vocabulary to deal with it .

Only some understand the value of general vocabulary at a high level of abstraction and structural discipline such as APLs provide .
User avatar
Bob Armstrong
 
Posts: 16
Joined: Wed Dec 23, 2009 8:41 pm
Location: 39.038681° -105.079070° 2500m

Re: Extended Inner Product

Postby mikepowell on Fri Feb 07, 2020 2:02 am

Phil,
Thanks for the offerings. I'll go with the original, even it does look like there's something wrong with the language.

Bob,
I no longer do Facebook in any form, but it's good to know that others are thinking along these lines.

Mike
mikepowell
 
Posts: 4
Joined: Thu Dec 05, 2013 8:01 pm

Re: Extended Inner Product

Postby Phil Last on Fri Feb 07, 2020 9:25 am

Sorry but the former is definitely and definitively wrong for combining two axes or more. Monadic transpose is equivalent to {(⌽⍳⍴⍴⍵)⍉⍵} so two or more leading axes shifted to the end will themselves be transposed prior to the ravel then returned to the front as {⍉,⍉⍵}.

The latter algorithm merely shifts them to the end without disturbing their internal order. Then back to the front after ravel.
User avatar
Phil Last
 
Posts: 549
Joined: Thu Jun 18, 2009 6:29 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest