bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Supporting negative ranks for ⍤ operator


From: Juergen Sauermann
Subject: Re: [Bug-apl] Supporting negative ranks for ⍤ operator
Date: Fri, 06 May 2016 19:46:02 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

Hi Elias,

the ISO standard (taking the monadic case for simplicity) says:

Z ← f  ⍣ y B
...
If y is a scalar, set y1 to ,y. Otherwise set y1 to y.
If y1 is not a vector, signal domain-error.
If y1 has more than three elements, signal length-error.
If any element of y1 is not a near-integer, signal domain-error.
Set y2 to ⌽3⍴⌽y1.
Set y3 to the first-item in y2.
Set y4 to the integer-nearest-to y3.
If y4 exceeds the rank of B, set y5 to the rank of B, otherwise set y5 to y4.
If y5 is negative, set y6 to 0⌈(y5 plus the rank of B), otherwise set y6 to y5.  // () added by jsa
Apply f to the rank-y6 cells of B.

For y←¯1 that gives:

y1 = ¯1
y2 - ¯1 ¯1 ¯1
y3 = ¯1
y4 = ¯1
y5 = ¯1
y6 = ¯1 + ⍴⍴B = ¯1 + 2 = +1


For y←+1 it gives:

y1 = 1
y2 - 1 1 1
y3 = 1
y4 = 1
y5 = 1
y6 = +1


Both cases give the same y6 (and hence the same results) are the same.

In Dyalog terms: for y←1 you take the rank-1-cells and for j←¯1 you take the
rank-(2+¯1)-cells which are also the rank-1-cells when the rank of B is 2.

The dyadic case is similar except that the computation above is performed independently for A and B.

/// Jürgen


On 05/06/2016 03:32 PM, Elias Mårtenson wrote:
In GNU APL, the following two expressions yield the same result:

      (+/⍤1) 3 4⍴⍳100
┏→━━━━━━━┓
┃10 26 42┃
┗━━━━━━━━┛

And:

      (+/⍤¯1) 3 4⍴⍳100
┏→━━━━━━━┓
┃10 26 42┃
┗━━━━━━━━┛

I would expect the latter to yield the following (which is what I believe Dyalog does):

┏→━━━━━━━━━━┓
┃15 18 21 24┃
┗━━━━━━━━━━━┛

Regards,
Elias

On 6 May 2016 at 21:22, Jay Foad <address@hidden> wrote:
On 6 May 2016 at 13:52, Juergen Sauermann <address@hidden> wrote:
> Except maybe for the Dyalog ¯1 case (primarily because I don't know what
> "major cells" are).

Dyalog treats ¯1 the same as the ISO standard (and therefore also GNU
APL). "Major cell" is explained on page 14 of:
http://docs.dyalog.com/14.1/Dyalog%20APL%20Programmer's%20Guide.pdf

Jay.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]