<div class="gmail_quote">On 13 January 2012 20:54, Stewart Gordon <span dir="ltr"><<a href="mailto:smjg_1998@yahoo.com">smjg_1998@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 13/01/2012 13:47, Manu wrote:<br>
<snip><div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    Some people expect this:<br>
    (-10 ^^ 2)<br>
    To be 100 instead of -100<br>
</blockquote></div>
<snip><div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm fairly amazed it's not the other way around... what's the logic behind this?<br>
</blockquote>
<br></div>
It matches standard mathematical notation.  -x² means -(x²) not (-x)².<br>
<br>
This actually makes most sense when you consider that:<br>
<br>
(a) -2x² means -2(x²), because exponentiation beats multiplication.  With the precedence you're suggesting, removal of the 2 would completely change the expression.<br>
<br>
(b) 42 - x² means 42 - (x²).  With the precedence you're suggesting, removal of the 42 would completely change the expression.<br>
<br>
Both these rules play a significant part in how we write polynomial expressions.  Look at these:<br>
<br>
x³ - x² + 3<br>
   - x² + 3<br>
   -4x² + 3<br>
<br>
In all these, the coefficient of x² is negative.  It would be confusing if it were positive only in the second one.<br>
<br>
It might help to think of -Exp as syntactic sugar for 0-Exp.</blockquote><div><br></div><div>I think there's one very important point to realise in all your examples though...</div><div>We're NOT writing -4x² + 3. We write -4 * x ^^ 2 + 4. That's not a polynomial expressions, it's source code.</div>
<div>I don't know about you, but the visual similarity is just not there for me. I can't see C/D/Java/whatever code as a direct transcription of mathematical notation no matter how hard I squint at it.</div><div>I personally have the presumption that unary operators have a higher precedence than binary operators... period. I wouldn't give that a second thought, and that trumps all other logic for me.</div>
<div>Secondary to that, when looking at that statement and deciding which of the * or ^^ might have higher precedence, I would probably only then consider that '^^' *may* have higher precedence than '*', but still not certain, and I wouldn't be surprised (possibly assume) it had the same, ie. left to right, as with * and /.</div>
</div>