## Power Operator-- A Simple Question about a Simple Scalar

General APL language issues

### Power Operator-- A Simple Question about a Simple Scalar

I've always wondered why the power operator ⍣ couldn't be lax about its scalar right operand, i.e. why can't it tolerate (overlook just this once?) a single-element vector as well? I find myself doing f ⍣ (⍬⍴...)⊣⍵ (or creating a cover function pow) for use with common functions that alway return vectors, even for simple args.
Code: Select all
`  2+⍣(0=⎕NC'fred')⊣3      ⍝ Bad, yet easy on the eyes.    ⎕NC returns 1-element vectorRANK ERROR  2+⍣(⍬⍴0=⎕NC'fred')⊣3    ⍝ Good syntax, but n⍬isy!5                                            `

No doubt the interpreter is correct and certainly consistent, but those ⍬⍴ can obscure errors, e.g. when a multi-element vector is afoot, ⍬⍴ will hide the error.
petermsiegel

Posts: 58
Joined: Thu Nov 11, 2010 11:04 pm

### Re: Power Operator-- A Simple Question about a Simple Scalar

I don't know the exact reasoning, but my guess is that it goes something like this: f⍣m⊢⍵ may possibly be extended in the future to allow an array right operand, and in such extension the outer shape of the result would be the shape of that right operand. The current ⍣ should not behave in a way that forecloses future correct behavior.

The extended power operator can be modelled as follows:

Code: Select all
`      pow←{⍵⍵ ⍺⍺{⍺⍺⍣⍺⊢⍵}⍤0⊢⍵}      2+pow(0=⎕nc 'fred')⊢33      ⍴2+pow(0=⎕nc 'fred')⊢31      2+pow(⍬⍴0=⎕nc 'fred')⊢33      ⍴2+pow(⍬⍴0=⎕nc 'fred')⊢3`

An example where an array right operand is useful:

Code: Select all
`      {0.5×⍵+2÷⍵}pow(⍳8)⊢11.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 1.41421      2 - ×⍨{0.5×⍵+2÷⍵}pow(⍳8)⊢1¯0.25 ¯0.00694444 ¯0.0000060073 ¯4.51061E¯12 4.44089E¯16 4.44089E¯16           4.44089E¯16 4.44089E¯16      ⍝ currently you can't do that with ⍣      {0.5×⍵+2÷⍵}⍣(⍳8)⊢1RANK ERROR      {0.5×⍵+2÷⍵}⍣(⍳8)⊢1                ∧`
Roger|Dyalog

Posts: 139
Joined: Thu Jul 28, 2011 10:53 am

### Who is online

Users browsing this forum: No registered users and 1 guest