Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precedence of transposition operator ' #15858

Closed
nalimilan opened this issue Apr 13, 2016 · 7 comments
Closed

Precedence of transposition operator ' #15858

nalimilan opened this issue Apr 13, 2016 · 7 comments
Labels
docs This change adds or pertains to documentation parser Language parsing and surface syntax
Milestone

Comments

@nalimilan
Copy link
Member

Though not terrible, this is a bit unfortunate:

julia> :(1:4')
:(1:(4)')

I can't find a case where one could want to create a range from a transposed last element. OTC, creating a row-matrix from a range can sometimes be useful.

Maybe we could change this? Or would it break something else?

Also, ' isn't listed in the table about operator precedence.

@stevengj stevengj added breaking This change will break code julep Julia Enhancement Proposal parser Language parsing and surface syntax labels Apr 13, 2016
@stevengj
Copy link
Member

Theoretically, this would be a breaking change, although it's hard to imagine it affecting real code.

@TotalVerb
Copy link
Contributor

Currently transposition has higher precedence than multiplication and addition, and that's probably a good thing: A + B' should probably mean A + (B'), not (A + B)'.

But range has lower precedence than both: 1:10*10 is 1:(10*10). This change would have to break that behaviour. Especially concerning is this:

1:length(A)-1

which I think is likely quite common.

@timholy
Copy link
Member

timholy commented Apr 14, 2016

Seems like the easiest way to solve this is to make 4' an error. Currently ctranspose is recursive (to handle arrays-of-arrays) and on numbers it computes conj. But perhaps we could make ctranspose recurse to _ctranspose (non-exported), and restrict ctranspose to AbstractVecOrMat.

@stevengj
Copy link
Member

@TotalVerb, good point, we can't make ' lower precedence than : without breaking the relationship with + (or breaking the partial ordering of precedences).

@timholy, please no. ' is adjoint, and making the adjoint of a number equal to its conjugate is extremely well established mathematics. It seems crazy to break that (making it harder to write generic code that works with both matrices and numbers) just to give a syntax error for odd mistakes with colons.

@nalimilan
Copy link
Member Author

I don't think there really a problem here. I was just wondering whether we could make this slightly more convenient without making anything more painful.

I'm inclined to close this issue. But I am right that ' should be added to the operator precedence table? We can turn it into a docs issue.

@TotalVerb
Copy link
Contributor

I think implicit multiplication (which binds quite strongly, but not as strong as exponentiation) is also missing from that table, along with probably many other common ones. All the unicode ones are missing too, but those can probably be left out.

@JeffBezanson JeffBezanson added this to the 1.0 milestone May 2, 2017
@JeffBezanson JeffBezanson added docs This change adds or pertains to documentation and removed breaking This change will break code julep Julia Enhancement Proposal labels May 2, 2017
@JeffBezanson
Copy link
Member

This doesn't seem to be solvable with transitive operator precedence. : has lower precedence than +, but transpose has to have higher precedence than +. #18714 would be the change we could make here if anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

5 participants