ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and -
@ 2012-11-11  6:58 boris_stitnicky (Boris Stitnicky)
  2012-11-11  8:01 ` [ruby-core:49213] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
                   ` (16 more replies)
  0 siblings, 17 replies; 20+ messages in thread
From: boris_stitnicky (Boris Stitnicky) @ 2012-11-11  6:58 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been reported by boris_stitnicky (Boris Stitnicky).

----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49213] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
@ 2012-11-11  8:01 ` alexeymuranov (Alexey Muranov)
  2012-11-11  8:44   ` [ruby-core:49214] " Matthew Kerwin
  2012-11-11  9:33 ` [ruby-core:49216] " alexeymuranov (Alexey Muranov)
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11  8:01 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


(-1) ** 0.5 should not be defined! I just tried it and it gave me (6.123233995736766e-17+1.0i) -- approximately the complex i. Why not -i ??
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32768

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49214] Re: [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  8:01 ` [ruby-core:49213] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
@ 2012-11-11  8:44   ` Matthew Kerwin
  0 siblings, 0 replies; 20+ messages in thread
From: Matthew Kerwin @ 2012-11-11  8:44 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]

It woudl never be -i.  (-1) ** 0.5 => i (or, in complex coordinates, 0+1i,
which is basically what (6.123233995736766e-17+1.0i) means.


On 11 November 2012 18:01, alexeymuranov (Alexey Muranov) <
redmine@ruby-lang.org> wrote:

>
> Issue #7328 has been updated by alexeymuranov (Alexey Muranov).
>
>
> (-1) ** 0.5 should not be defined! I just tried it and it gave me
> (6.123233995736766e-17+1.0i) -- approximately the complex i. Why not -i ??
> ----------------------------------------
> Feature #7328: Move ** operator precedence under unary + and -
> https://bugs.ruby-lang.org/issues/7328#change-32768
>
> Author: boris_stitnicky (Boris Stitnicky)
> Status: Open
> Priority: Normal
> Assignee:
> Category:
> Target version:
>
>
> I would like to ask to consider decreasing ** operator precedence just
> below that of -/+ unary operators. I know that other languages (eg. Python)
> have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the
> result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not
> worth changing, I'd like to hear this rationalized. I've asked about
> rationalization of this on SO, and nobody seems to know why this precedence
> is the way it is.
>
>
> --
> http://bugs.ruby-lang.org/
>
>


-- 
  Matthew Kerwin, B.Sc (CompSci) (Hons)
  http://matthew.kerwin.net.au/
  ABN: 59-013-727-651

  "You'll never find a programming language that frees
  you from the burden of clarifying your ideas." - xkcd

[-- Attachment #2: Type: text/html, Size: 2221 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49216] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
  2012-11-11  8:01 ` [ruby-core:49213] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
@ 2012-11-11  9:33 ` alexeymuranov (Alexey Muranov)
  2012-11-11  9:38 ` [ruby-core:49217] " alexeymuranov (Alexey Muranov)
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11  9:33 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


phluid61 (Matthew Kerwin) wrote:
> It woudl never be -i.  (-1) ** 0.5 => i (or, in complex coordinates, 0+1i,
>  which is basically what (6.123233995736766e-17+1.0i) means.
>  

What do you mean? Why (-1)^(0.5) i and not -i?  Mathematically, it is not defined.
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32772

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49217] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
  2012-11-11  8:01 ` [ruby-core:49213] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
  2012-11-11  9:33 ` [ruby-core:49216] " alexeymuranov (Alexey Muranov)
@ 2012-11-11  9:38 ` alexeymuranov (Alexey Muranov)
  2012-11-11 15:01 ` [ruby-core:49222] " trans (Thomas Sawyer)
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11  9:38 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


I have not still figured out how exactly this mailing issue tracker works, i have not managed to configure it to receive email notifications, and it seems that if i edit my comment the edited version is not what the others reply to, so i will post again the second part of my comment:

I agree that from pragmatic point of view it may be better for (-1)**0.5 to return i than nothing, but then i would prefer it written clearly as (-1) ** 0.5.

In mathematics you would put parentheses in (-a)^n.

I think that unary +/- have the same precedence as binary, at least in mathematics.

I am -1 for the change.
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32773

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49222] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (2 preceding siblings ...)
  2012-11-11  9:38 ` [ruby-core:49217] " alexeymuranov (Alexey Muranov)
@ 2012-11-11 15:01 ` trans (Thomas Sawyer)
  2012-11-11 15:40 ` [ruby-core:49223] " alexeymuranov (Alexey Muranov)
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 15:01 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


"In mathematics you would put parentheses in (-a)^n.  For example: -e^x is ... well ... -(e^x)."

I think that's the opposite of what's generally expected. Currently Ruby does:

  -2**2 #=> -4

but commonly it would be:

  -2**2 #=> 4

It's curious how Ruby got the operator precedence it has. Clearly it is based on C, which most languages seem to mimic without much consideration. Yet Ruby stuck `**` way up top. I wonder why?

----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32779

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49223] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (3 preceding siblings ...)
  2012-11-11 15:01 ` [ruby-core:49222] " trans (Thomas Sawyer)
@ 2012-11-11 15:40 ` alexeymuranov (Alexey Muranov)
  2012-11-11 16:26 ` [ruby-core:49224] " trans (Thomas Sawyer)
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11 15:40 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


trans (Thomas Sawyer) wrote:
> "In mathematics you would put parentheses in (-a)^n.  For example: -e^x is ... well ... -(e^x)."
> 
> I think that's the opposite of what's generally expected. Currently Ruby does:
> 
>   -2**2 #=> -4
> 
> but commonly it would be:
> 
>   -2**2 #=> 4
> 
> It's curious how Ruby got the operator precedence it has. Clearly it is based on C, which most languages seem to mimic without much consideration. Yet Ruby stuck `**` way up top. I wonder why?

I am sorry, i hear for the first time that commonly -2^2 would be 4 :).
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32780

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49224] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (4 preceding siblings ...)
  2012-11-11 15:40 ` [ruby-core:49223] " alexeymuranov (Alexey Muranov)
@ 2012-11-11 16:26 ` trans (Thomas Sawyer)
  2012-11-11 16:35 ` [ruby-core:49225] " alexeymuranov (Alexey Muranov)
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 16:26 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


@alexeymuranov

    -2 * -2 = 4


----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32782

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49225] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (5 preceding siblings ...)
  2012-11-11 16:26 ` [ruby-core:49224] " trans (Thomas Sawyer)
@ 2012-11-11 16:35 ` alexeymuranov (Alexey Muranov)
  2012-11-11 16:46 ` [ruby-core:49226] " trans (Thomas Sawyer)
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11 16:35 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


trans (Thomas Sawyer) wrote:
> @alexeymuranov
> 
>     -2 * -2 = 4

This is not the same, and I do not agree with this either.  In my opinion, "-2 * -2" is not a legal syntax (the "*-" part), it should be (-2)*(-2) or -2*(-2) = - (2*(-2)).

Tomas, can you find a printed or otherwise confirmed example where an expression with parentheses like "-(2^2)" or "-(e^x)" or "-(x^2)" is used?
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32783

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49226] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (6 preceding siblings ...)
  2012-11-11 16:35 ` [ruby-core:49225] " alexeymuranov (Alexey Muranov)
@ 2012-11-11 16:46 ` trans (Thomas Sawyer)
  2012-11-11 16:59 ` [ruby-core:49227] " alexeymuranov (Alexey Muranov)
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 16:46 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


"In my opinion, "-2 * -2" is not a legal syntax (the "*-" part), it should be (-2)*(-2) or -2*(-2) = - (2*(-2))."

I don't understand this. Type `-2*-2` in Ruby and it produces `4`.

"Can you find a printed or otherwise confirmed example where an expression with parentheses like "-(2^2)" or "-(e^x)" or "-(x^2)" is used?"

I stand corrected on this. I was thinking in terms of just then numerical value. Sorry.

----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32784

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49227] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (7 preceding siblings ...)
  2012-11-11 16:46 ` [ruby-core:49226] " trans (Thomas Sawyer)
@ 2012-11-11 16:59 ` alexeymuranov (Alexey Muranov)
  2012-11-11 17:02 ` [ruby-core:49228] " trans (Thomas Sawyer)
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11 16:59 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


trans (Thomas Sawyer) wrote:
> "In my opinion, "-2 * -2" is not a legal syntax (the "*-" part), it should be (-2)*(-2) or -2*(-2) = - (2*(-2))."
> 
> I don't understand this. Type `-2*-2` in Ruby and it produces `4`.
> 

I was talking about writing conventions, how i learned them in elementary school.  I think it is unfortunate that Ruby allows this "shortcut": if Ruby allows `-a * -b`, this means that it first computes `-a` and `-b`, and afterwards the product. This means that if i want Ruby to compute `- a*b` in the "standard" way, i have to put the parentheses `-(a*b)`.  I consider this a bug.
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32785

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49228] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (8 preceding siblings ...)
  2012-11-11 16:59 ` [ruby-core:49227] " alexeymuranov (Alexey Muranov)
@ 2012-11-11 17:02 ` trans (Thomas Sawyer)
  2012-11-11 17:30 ` [ruby-core:49230] " trans (Thomas Sawyer)
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 17:02 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


Actually now that I think about it some more, this is similar to my problem with using power notation in my Stick project (an SI unit system for Ruby). When applying powers to units the result wasn't always the one desired --sometimes you want it to apply to the number, other times to the unit itself (e.g cubic meters). It really would be nice if `^` could be used for power too, along side `**`, and allow one to be just above unary operations and the other just below. That would provide the most flexibility.
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32786

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49230] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (9 preceding siblings ...)
  2012-11-11 17:02 ` [ruby-core:49228] " trans (Thomas Sawyer)
@ 2012-11-11 17:30 ` trans (Thomas Sawyer)
  2012-11-11 18:32 ` [ruby-core:49231] [ruby-trunk - Feature #7328][Rejected] " marcandre (Marc-Andre Lafortune)
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 17:30 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


@alexeymuranov Okay, I see what you are saying. But I think the problem really is that mathematical notation tends to be a little too conventional and variant for a programming language, which needs to be more precise. In equations, the negative sign tends to either negate the whole, or is used to mean subtraction. It rarely occurs in the middle somewhere as a negation because it gets factored out to the whole. So it just rarely an issue.

For programming however, it would kind of suck is `* -2` was an error b/c `*` is applied before `-`. And it could get rather complicated if Ruby tried to apply one order in one case and another order in another.



----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32787

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49231] [ruby-trunk - Feature #7328][Rejected] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (10 preceding siblings ...)
  2012-11-11 17:30 ` [ruby-core:49230] " trans (Thomas Sawyer)
@ 2012-11-11 18:32 ` marcandre (Marc-Andre Lafortune)
  2012-11-11 18:33 ` [ruby-core:49232] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-11-11 18:32 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Rejected

Quoting Matz from http://www.ruby-forum.com/topic/87126#163398:

> People with mathematical background demand precedence for ** being
> higher than that of unary minus.  That's the reason.

Thomas: Please check your facts, e.g. http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32788

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49232] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (11 preceding siblings ...)
  2012-11-11 18:32 ` [ruby-core:49231] [ruby-trunk - Feature #7328][Rejected] " marcandre (Marc-Andre Lafortune)
@ 2012-11-11 18:33 ` alexeymuranov (Alexey Muranov)
  2012-11-11 19:01 ` [ruby-core:49233] " trans (Thomas Sawyer)
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-11 18:33 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


In mathematical notation, when possible, the "minus operation" is usually introduced as the unary negation, and "a - b" is usually defined as a shorthand notation for "a + (-b)".  To avoid any ambiguity, as far as i know (but i do not have a reference), the minus and the plus, both binary and unary, have all the same precedence.  To the best of my knowledge, the expression "a * - b" is not a valid syntax in mathematics, at least in languages i am familiar with.

trans (Thomas Sawyer) wrote:
> @alexeymuranov Okay, I see what you are saying. But I think the problem really is that mathematical notation tends to be a little too conventional and variant for a programming language, which needs to be more precise. In equations, the negative sign tends to either negate the whole, or is used to mean subtraction. It rarely occurs in the middle somewhere as a negation because it gets factored out to the whole. So it is rarely an issue.
> 
> For programming however, it would kind of suck if `* -2` was an error b/c `*` is applied before `-`. And it could get rather complicated if Ruby tried to apply one order in one case and another order in another.


----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32789

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49233] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (12 preceding siblings ...)
  2012-11-11 18:33 ` [ruby-core:49232] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
@ 2012-11-11 19:01 ` trans (Thomas Sawyer)
  2012-11-11 20:37 ` [ruby-core:49234] " marcandre (Marc-Andre Lafortune)
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: trans (Thomas Sawyer) @ 2012-11-11 19:01 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by trans (Thomas Sawyer).


"Thomas: Please check your facts, e.g. http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard"

1) I did not make this issue.
2) If you read #9 you will see that I did check my facts.
3) Some consideration of #11 would at least be nice.

----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32790

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49234] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (13 preceding siblings ...)
  2012-11-11 19:01 ` [ruby-core:49233] " trans (Thomas Sawyer)
@ 2012-11-11 20:37 ` marcandre (Marc-Andre Lafortune)
  2012-11-11 21:38   ` [ruby-core:49235] " Matthew Kerwin
  2012-11-12  2:50 ` [ruby-core:49240] " boris_stitnicky (Boris Stitnicky)
  2012-11-12  8:56 ` [ruby-core:49251] " alexeymuranov (Alexey Muranov)
  16 siblings, 1 reply; 20+ messages in thread
From: marcandre (Marc-Andre Lafortune) @ 2012-11-11 20:37 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by marcandre (Marc-Andre Lafortune).


Hi,

trans (Thomas Sawyer) wrote:
> "Thomas: Please check your facts, e.g. http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard"
> 
> 1) I did not make this issue.

My understanding is that the original poster was wondering why the precedence was like that and that he would have preferred it the other way. Alexey answered correctly that the reason was because of the order or operations in mathematics.

I only wanted to suggest that before contradicting someone it was a good idea to check the facts, in particular if one isn't extremely familiar with the field. I didn't mean to offend and I'm sorry if I did.

----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32791

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49235] Re: [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11 20:37 ` [ruby-core:49234] " marcandre (Marc-Andre Lafortune)
@ 2012-11-11 21:38   ` Matthew Kerwin
  0 siblings, 0 replies; 20+ messages in thread
From: Matthew Kerwin @ 2012-11-11 21:38 UTC (permalink / raw
  To: ruby-core

[-- Attachment #1: Type: text/plain, Size: 2051 bytes --]

Can I just point out that everyone is using asterisks and carets and
arguing about standard mathematical notation?

I reckon the biggest factor driving this discussion should be existing
behaviour. Changing how operators behave is probably the single biggest
thing that defines and thus changes a language.

If you were writing a new language, however, I'd find this disussion and
its outcome fascinating.
On Nov 12, 2012 6:37 AM, "marcandre (Marc-Andre Lafortune)" <
ruby-core@marc-andre.ca> wrote:

>
> Issue #7328 has been updated by marcandre (Marc-Andre Lafortune).
>
>
> Hi,
>
> trans (Thomas Sawyer) wrote:
> > "Thomas: Please check your facts, e.g.
> http://en.wikipedia.org/wiki/Order_of_operations#Exceptions_to_the_standard
> "
> >
> > 1) I did not make this issue.
>
> My understanding is that the original poster was wondering why the
> precedence was like that and that he would have preferred it the other way.
> Alexey answered correctly that the reason was because of the order or
> operations in mathematics.
>
> I only wanted to suggest that before contradicting someone it was a good
> idea to check the facts, in particular if one isn't extremely familiar with
> the field. I didn't mean to offend and I'm sorry if I did.
>
> ----------------------------------------
> Feature #7328: Move ** operator precedence under unary + and -
> https://bugs.ruby-lang.org/issues/7328#change-32791
>
> Author: boris_stitnicky (Boris Stitnicky)
> Status: Rejected
> Priority: Normal
> Assignee:
> Category:
> Target version:
>
>
> I would like to ask to consider decreasing ** operator precedence just
> below that of -/+ unary operators. I know that other languages (eg. Python)
> have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the
> result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not
> worth changing, I'd like to hear this rationalized. I've asked about
> rationalization of this on SO, and nobody seems to know why this precedence
> is the way it is.
>
>
> --
> http://bugs.ruby-lang.org/
>
>

[-- Attachment #2: Type: text/html, Size: 2687 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49240] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (14 preceding siblings ...)
  2012-11-11 20:37 ` [ruby-core:49234] " marcandre (Marc-Andre Lafortune)
@ 2012-11-12  2:50 ` boris_stitnicky (Boris Stitnicky)
  2012-11-12  8:56 ` [ruby-core:49251] " alexeymuranov (Alexey Muranov)
  16 siblings, 0 replies; 20+ messages in thread
From: boris_stitnicky (Boris Stitnicky) @ 2012-11-12  2:50 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by boris_stitnicky (Boris Stitnicky).


I am pleased by this discussion and I thank Tom Sawyer for showing me that I am not alone who has feelings of surprise at -2 ** 2 behaviour. However, SO people finally found this link (http://www.ruby-forum.com/topic/87126#163398) in which Matz has already rationalized ** behaviour. For this reason, I rescind this feature request (which has already been changed to 'Rejected' status by the time I am writing this), and also for the reasons of stability as per phluid61. Just like Alex Muranov, I do dislike the current result of (-1) ** 0.5, which is (6.123233995736766e-17+1.0i), but that would be another issue, which I don't feel like opening at the moment.
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32798

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [ruby-core:49251] [ruby-trunk - Feature #7328] Move ** operator precedence under unary + and -
  2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
                   ` (15 preceding siblings ...)
  2012-11-12  2:50 ` [ruby-core:49240] " boris_stitnicky (Boris Stitnicky)
@ 2012-11-12  8:56 ` alexeymuranov (Alexey Muranov)
  16 siblings, 0 replies; 20+ messages in thread
From: alexeymuranov (Alexey Muranov) @ 2012-11-12  8:56 UTC (permalink / raw
  To: ruby-core


Issue #7328 has been updated by alexeymuranov (Alexey Muranov).


Since #7331 is rejected, i do not think anymore it is nonsense to treat unary `-` specially and give it the highest precedence.  Otherwise

1. it is stuck between `*` and `**`
2. even with respect to `**` its behavior is not consistent: the expression `-2 ** -2` does not raise an error, but evaluates to (-1/4).
----------------------------------------
Feature #7328: Move ** operator precedence under unary + and -
https://bugs.ruby-lang.org/issues/7328#change-32812

Author: boris_stitnicky (Boris Stitnicky)
Status: Rejected
Priority: Normal
Assignee: 
Category: 
Target version: 


I would like to ask to consider decreasing ** operator precedence just below that of -/+ unary operators. I know that other languages (eg. Python) have ** operator bind tighter than negation, but seeing -1 ** 0.5 give the result -1 and having to type parenthesis (-1) ** 0.5... Even if it's not worth changing, I'd like to hear this rationalized. I've asked about rationalization of this on SO, and nobody seems to know why this precedence is the way it is.


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2012-11-12  8:57 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-11  6:58 [ruby-core:49211] [ruby-trunk - Feature #7328][Open] Move ** operator precedence under unary + and - boris_stitnicky (Boris Stitnicky)
2012-11-11  8:01 ` [ruby-core:49213] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
2012-11-11  8:44   ` [ruby-core:49214] " Matthew Kerwin
2012-11-11  9:33 ` [ruby-core:49216] " alexeymuranov (Alexey Muranov)
2012-11-11  9:38 ` [ruby-core:49217] " alexeymuranov (Alexey Muranov)
2012-11-11 15:01 ` [ruby-core:49222] " trans (Thomas Sawyer)
2012-11-11 15:40 ` [ruby-core:49223] " alexeymuranov (Alexey Muranov)
2012-11-11 16:26 ` [ruby-core:49224] " trans (Thomas Sawyer)
2012-11-11 16:35 ` [ruby-core:49225] " alexeymuranov (Alexey Muranov)
2012-11-11 16:46 ` [ruby-core:49226] " trans (Thomas Sawyer)
2012-11-11 16:59 ` [ruby-core:49227] " alexeymuranov (Alexey Muranov)
2012-11-11 17:02 ` [ruby-core:49228] " trans (Thomas Sawyer)
2012-11-11 17:30 ` [ruby-core:49230] " trans (Thomas Sawyer)
2012-11-11 18:32 ` [ruby-core:49231] [ruby-trunk - Feature #7328][Rejected] " marcandre (Marc-Andre Lafortune)
2012-11-11 18:33 ` [ruby-core:49232] [ruby-trunk - Feature #7328] " alexeymuranov (Alexey Muranov)
2012-11-11 19:01 ` [ruby-core:49233] " trans (Thomas Sawyer)
2012-11-11 20:37 ` [ruby-core:49234] " marcandre (Marc-Andre Lafortune)
2012-11-11 21:38   ` [ruby-core:49235] " Matthew Kerwin
2012-11-12  2:50 ` [ruby-core:49240] " boris_stitnicky (Boris Stitnicky)
2012-11-12  8:56 ` [ruby-core:49251] " alexeymuranov (Alexey Muranov)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).