Conjugate and identity

General APL language issues

Conjugate and identity

Postby JohnS|Dyalog on Sun Dec 20, 2009 7:47 am

At present in Dyalog, monadic + is an identity function for all arrays. This is about to change with the introduction of complex numbers in V13. Given a complex number argument, +⍵ will return the conjugate of ⍵, which is the same number but with its imaginary part negated.

Code: Select all
    +3j4
3J¯4

Question: in V13, should monadic + continue to accept non-numeric arguments?

My personal feeling is that, for backwards compatibility, yes it should. We can rationalise this by saying that the "conjugate" of a char or a ref is defined to be itself.

Note however, that there are clearer identity functions {⍵} and, if we implement it, a functionally identical but slicker spelling: '⊢', pronounced "dex".

Happily, monadic +, as an identity, will become self-deprecating in V13.

At present, +⍵ is implemented directly in Dyalog's parser as nothing more than the moving of a pointer. This means that it is considerably faster than, say, monadic "-":

Code: Select all
      cmpx'+1 2 3' '-1 2 3'
  +1 2 3 → 1.0E¯7 |    0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕                           
* -1 2 3 → 3.3E¯7 | +211% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕

However, with V13, the interpreter will be obliged to traverse +'s argument, looking for complex numbers and this will bring it's performance back into line with "-".

Also happily, {⍵} will continue to be a fast identity and ⊢ could be a little quicker still.
JohnS|Dyalog
 

Re: Conjugate and identity

Postby Dick Bowman on Mon Dec 21, 2009 8:01 am

My view on backward compatibility is that I'm much more interested in the code that I'll write in the future than what I wrote in the past.

Sometimes it's good to be given a reason to re-examine code that's been around a while.

If the proposal was to change something fundamental (like making dyadic + do multiplication) I'd be a bit more concerned.

Personally I think that people who write stuff like +'abc' deserve all the trouble they bring upon themselves.
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Conjugate and identity

Postby Phil Last on Tue Dec 22, 2009 9:02 am

Dick Bowman wrote:Personally I think that people who write stuff like +'abc' deserve all the trouble they bring upon themselves.


The trouble is that what they're more likely to have written is "+⍵" (or "+R" ... whatever) with some other stuff to the left that necessitates or justifies the presence of the identity.

If whatever that other stuff is is generalised code that works on all domains (there's plenty of it about) then before complex numbers became an issue, "+" would have been the obvious solution and the recommended and arguably the best, apart from "{⍵}" which is more than a trifle less elegant.
User avatar
Phil Last
 
Posts: 572
Joined: Thu Jun 18, 2009 6:29 pm

Re: Conjugate and identity

Postby Dick Bowman on Wed Dec 23, 2009 3:31 pm

That seems to be a Dyalog-centric view, just checked APL2 and NARS2000 and confirmed that both give DOMAIN ERROR for monadic + and a character argument (APL2 has complex numbers, NARS2000 doesn't). Don't have APLX or APL2000/Next/Visual/whatever, so I don't know what they do.

Perhaps we're not supposed to be promiscuous here, but I'd like for Dyalog to align itself with other APLs wherever possible.

But then, I don't think I've ever used monadic + (away from complex numbers).
Visit http://apl.dickbowman.com to read more from Dick Bowman
User avatar
Dick Bowman
 
Posts: 235
Joined: Thu Jun 18, 2009 4:55 pm

Re: Conjugate and identity

Postby Phil Last on Thu Dec 24, 2009 12:17 am

Dick Bowman wrote:That seems to be a Dyalog-centric view

It is but that's what this is all about. That it was a mistake all those years ago for Dyalog to allow and encourage monadic plus's use as an identity. There's been a need for one since compose (∘) and user define operators arrived. More so with power (⍣). As John points out above (+) will become self decrecating but my bet is that, because of it, there'll be a number of apparently inexplicable errors in long-standing, reliable code as soon as people start to use complex numbers.

APL2 introduced them from the beginning so it was never a possibility there which must be a part of the reasoning behind the difference in operand and vector binding strengths between Dyalog and APL2.

It's a shame they didn't both introduce dex (⊢) back then.
User avatar
Phil Last
 
Posts: 572
Joined: Thu Jun 18, 2009 6:29 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest