negative number raised to even power
|
05-07-2015, 12:25 PM
Post: #61
|
|||
|
|||
RE: negative number raised to even power
I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it?
In CS terms, fully parsing a numeric literal is atomic, and precedes any operations on that number. |
|||
05-07-2015, 01:39 PM
Post: #62
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 12:25 PM)Dave Britten Wrote: I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it? I tend to agree with this point of view when it is presented simply as "-2^2" but what about the case where it is part of an equation such as "10-2^2"? |
|||
05-07-2015, 02:01 PM
Post: #63
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 12:25 PM)Dave Britten Wrote: I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it? From the parser point of view: Giving unary minus high precedence to make it "stick" to the number quickly gives -2^2=4. Lowering its precedence with respect to the power will make -2^2=-(2^2). But what happens when the literal is not a number? In the first case: -X^2 = (-X)^2 = X^2 And in the second case -X^2=-(X^2) While the result of -2^2 could be debatable, I think 100% of the readers here will agree that the result of -X^2 is not X^2. On an algebraic parser, it seems (humanly) reasonable that: -X^2+3*X+4 ≠ X^2+3*X+4 -X^2+3*X+4 = -1*X^2+3*X+4 -X^2+3*X+4 = 4+3*X-X^2 In Excel (used here as an example of a parser that does -2^2=4), none of the three equations above is true. In general, a simple parser that was designed only for numeric purposes (like a non-algebraic calculator or Excel), might choose to use -2^2=4, but the more advanced algebra the device/software does, it will be forced to use -2^2=-4. I don't know of any compiler or language interpreter that would fail the 3 expressions above (using compilers/interpreters as the main example of what's state of the art in Computer Science parsers). I checked BASIC, Lua, Python and Haskell (C, Java, JavaScript are out of the question since they don't have power operator). From that point of view, Computer Science seems to agree that the way to go is -2^2=-4. While in my opinion there is no right or wrong answer, everybody (including CS) is moving towards -2^2=-4, as it allows for a more natural algebraic manipulation. |
|||
05-07-2015, 02:25 PM
Post: #64
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 01:39 PM)Steve Simpkin Wrote:(05-07-2015 12:25 PM)Dave Britten Wrote: I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it? In that case, it's a binary operation (subtraction), so the result should be 6. If it were written "10 + -2^2", then I say it should be 14. |
|||
05-07-2015, 02:43 PM
Post: #65
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 10:40 AM)Gerald H Wrote: Lotus 123, 2.4: aba Historically, this seems interesting. Visicalc (the very first mass-market spreadsheet) introduced the idea of -2^2=4 into spreadsheets. Lotus 1-2-3, despite being an "imitation", went with -2^4=-4, knowing this was breaking compatibility with Visicalc. A few years later, Excel followed the Visicalc path, even though Lotus was the market leader and the one to be "imitated", reintroducing -2^2=4 into the spreadsheet world. Quatto Pro kept the Lotus way for compatibility, but eventually MS crushed the competition and every other modern spreadsheet since then has been copying -2^2=4 to keep their precious Excel compatibility. Everything else in Wes's list agrees on -4, so it seems one bad apple turned all spreadsheets down that path. Question remains whether the bad apple was Visicalc or Excel. I'd think Excel, since at the time Lotus had already steered the world towards -4. |
|||
05-07-2015, 02:59 PM
(This post was last modified: 05-07-2015 04:14 PM by Manolo Sobrino.)
Post: #66
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 12:25 PM)Dave Britten Wrote: I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it? Wow... As has been said (to death) here, -2^2=-4 and (-2)^2=4 in standard mathematical notation, which applies to the stuff we write on blackboards, books and papers to share knowledge with people. Exponentiation has higher precedence than negation, which is on the same level of addition and subtraction (where else could it be?) If you don't know/care about this or you don't like it, well, it's better to get used to it. It's not a matter of opinion, it's the convention that won. How you represent numbers in a computer is a different thing, and how you tell the computer to perform arithmetical and order operations with those representations is another one. I don't think there's any advantage in mixing things up. Any math parser should follow standard mathematical notation, not the other way around. Doing that is a very bad idea, you end with crummy parsers like Excel's one that can't be fixed because of compatibility with legacy misdeeds and users of calculators that think mathematical expressions are sequences of calculator steps. They're not. Of course you can say that 2.5 = 2 + 0.5, if you square it it's just (2+0.5)*(2+0.5), which is what ^2 means (another notation). That's why (-2)*(-2)=(-2)^2, the same way that 2*2=2^2. The additive inverse of 4 is -4, and as 4=1+1+1+1=(1+1)*(1+1)=2*2=2^2, we can write -4 as -(2^2), or -(2*2), or -((1+1)*(1+1)), or -(1+1+1+1). Now, let's read those expressions. With the precedence rule "^" > "anything else", parentheses in the first one are redundant: -2^2=-(2^2), hence -2^2=-4. In the second one they are of no effect, as -(2*2)=(-2)*2=2*(-2) you can write it again as -2*2. The other ones have additions (lowest priority), so you keep the parentheses around those. What's so hard to accept? Why does this keep popping up? |
|||
05-07-2015, 03:33 PM
Post: #67
|
|||
|
|||
RE: negative number raised to even power
I think at the moment you are missing a very important point in your dicussion:
The prime is a pocket calulator having a (+/-)-key (Or CHS-key if you like). Therefore it pressing (-)(2) is different from pressing (CHS)(2) (== (2)(CHS)). You don't have this in EXCEL or in other PC-Programms. (But luckily the Prime has a long and a short minus sign so distinguish subtraction from negative numbers) ... as said before: Some other calculators respect this difference in a very smart way, they even make clear what will happen by adding "0-" or even brackets. |
|||
05-07-2015, 03:41 PM
Post: #68
|
|||
|
|||
RE: negative number raised to even power | |||
05-07-2015, 05:50 PM
Post: #69
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 02:59 PM)Manolo Sobrino Wrote:(05-07-2015 12:25 PM)Dave Britten Wrote: I'm of the opinion that the negation sign is a part of the number itself, not an operation, and thus -2^2 = 4. Yes, you can say that -2 = 0 - 2, but you can also say that 2.5 = 2 + .5, and 2.5^2 isn't 2.25, is it? Then I disagree with "standard mathematical notation". If -2^2=-4, then as far as I'm concened, 2.5^2=2.25 is just as valid. |
|||
05-07-2015, 06:29 PM
Post: #70
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 05:50 PM)Dave Britten Wrote: Then I disagree with "standard mathematical notation". If -2^2=-4, then as far as I'm concened, 2.5^2=2.25 is just as valid. I strongly agree with Dave. -2 is a number preceded by the unary minus operator and 0-2 is a subtraction. In "the C programming language" 1977 by Kernighan/Ritchie/ Prentice Hall, Inc. the unary minus is already defined (operators, page 54 in the german edition) and has higher priority than multiplication/division and thus also higher than exponentiation, (but as exponentiation is not an operator but a function call in C this is inherent). See also wikipedia "Operators", which differentiates also between unary minus and subtraction operator. Imagine you store the number -2 in register 0 of an RPN calculator or in a variable y in C, then Code:
or Code:
Bernhard That's one small step for a man - one giant leap for mankind. |
|||
05-07-2015, 06:41 PM
Post: #71
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 06:29 PM)PANAMATIK Wrote:(05-07-2015 05:50 PM)Dave Britten Wrote: Then I disagree with "standard mathematical notation". If -2^2=-4, then as far as I'm concened, 2.5^2=2.25 is just as valid. Personally, I wouldn't even consider the negation symbol to be a unary operator, but rather a fundamental component of the number. In other words, I don't consider it an operator any more than I would the decimal point. Thus if it's not an operator, order of operations is irrelevant, and the number should be fully parsed before carrying out any operations on it. Keep in mind I'm a CS guy, so I'm just speaking to what makes the most intuitive sense based on my knowledge of parsers and grammars and such. One could probably make perfectly rational arguments to the opposite as well, I just don't like them. |
|||
05-07-2015, 08:13 PM
Post: #72
|
|||
|
|||
RE: negative number raised to even power
I see unary negation as an operation, since it 'operates' on the location of a number on the number line. I see the decimal point as a separator, (ip.fp) which I think is a distinction WITH a difference.
We may just have to live with a dual definition for the value of -2^2, since there is rationale on either side of the argument. It may be that the definition might just 'turn' when the context is made clear: computer science (man/machine technology), or fundamental mathematics, the written legacy. It's sort of unfortunate that the computer science approach isn't universally applied across all applicable computing technologies, or that mathematics isn't able to accommodate changeable rules, and still arrive at the one correct result! |
|||
05-07-2015, 09:25 PM
Post: #73
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 08:13 PM)DrD Wrote: We may just have to live with a dual definition for the value of -2^2, since there is rationale on either side of the argument. It may be that the definition might just 'turn' when the context is made clear: computer science (man/machine technology), or fundamental mathematics, the written legacy. It's sort of unfortunate that the computer science approach isn't universally applied across all applicable computing technologies, or that mathematics isn't able to accommodate changeable rules, and still arrive at the one correct result! If a mathematician is reading an expression on paper he must parse the expression according to the rules for parsing in mathematics the same way as a compiler or CAS parser has to evaluate the expression. If this rules are ambiguous they must be refined. For the C/C++ language expressions the rules are unambiguous. What about the complex number 2i+2. It is just a number, but to my knowledge it must be written with parenthesis when used in an expression (2i+2)^2, like (-2)^2, otherwise it would be interpreted as imaginary number 2i + (2^2). There might be a rule for omitting parenthesis that a minus sign, not preceded by another number, is the unary minus operator, but this cannot be decided by an opinion, it must be officially defined. Does anybody know, whether an international committee (something like the mathematical royal society) has defined standardized rules for mathematical expressions when parenthesis are omitted, or did they allow the calculator manufacturers to define the rules? Bernhard That's one small step for a man - one giant leap for mankind. |
|||
05-07-2015, 09:36 PM
Post: #74
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 05:50 PM)Dave Britten Wrote: Then I disagree with "standard mathematical notation". If -2^2=-4, then as far as I'm concened, 2.5^2=2.25 is just as valid. OK, -2 belongs to Z, (Z;+;*) is a (unitary and commutative) ring. When I'm reading an expression and someone wrote (-2)^2, it means (-2)*(-2). They're squaring -2 ∈ Z. I get 4. When it's -2^2, it means someone squared 2 ∈ Z and then considered it's inverse for (Z;+). So I get -4. Precedence is a perfectly good way to specify what is meant. And that's all there is to it. There is no room for subjective opinions in Maths, all consistent conventions concerning well defined objects are trivially equivalent and once people agree on one there's no point in arguing or reinventing the wheel. And I'm sorry, but that "2.5^2=2.25" has nothing to do with this convention (and writing it twice is two too many. ) |
|||
05-07-2015, 09:45 PM
Post: #75
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 09:36 PM)Manolo Sobrino Wrote: Precedence is a perfectly good way to specify what is meant. What is the precedence of the unary minus operator in mathematics? Or does it only exist in the C language? I ask this because I don't know the answer. Bernhard That's one small step for a man - one giant leap for mankind. |
|||
05-07-2015, 09:57 PM
Post: #76
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 09:36 PM)Manolo Sobrino Wrote: And I'm sorry, but that "2.5^2=2.25" has nothing to do with this convention (and writing it twice is two too many. ) Sure it does. If one believes that the negation prefix is not a fundamental component of the number being represented, but rather a separate operation, then it's not a stretch to argue that the decimal point is a binary operation and draw similar conclusions about precedence based upon that. 2.5^2 vs. 2.(5^2) |
|||
05-07-2015, 09:59 PM
Post: #77
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 09:45 PM)PANAMATIK Wrote: What is the precedence of the unary minus operator in mathematics? Or does it only exist in the C language? I ask this because I don't know the answer. We're doing arithmetic with integers here, who needs unary operators? Do whatever you want with grammars for computers, I just say that it's a good idea to parse maths as maths if you want to do maths. |
|||
05-07-2015, 10:21 PM
Post: #78
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 09:59 PM)Manolo Sobrino Wrote:(05-07-2015 09:45 PM)PANAMATIK Wrote: What is the precedence of the unary minus operator in mathematics? Or does it only exist in the C language? I ask this because I don't know the answer. I found a better answer to my question here in this thread. Sorry that I missed it before. (05-04-2015 07:22 AM)Thomas Radtke Wrote: Have a look here. That's one small step for a man - one giant leap for mankind. |
|||
05-07-2015, 10:22 PM
Post: #79
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 09:57 PM)Dave Britten Wrote: Sure it does. If one believes that the negation prefix is not a fundamental component of the number being represented, but rather a separate operation, then it's not a stretch to argue that the decimal point is a binary operation and draw similar conclusions about precedence based upon that. Read my post again. -2 is a number. -(2^2) is another number, it happens to be written as -2^2 after removing the parentheses made redundant by the conventional precedence rules. "To argue that a decimal point is a binary operation", I guess you mean unary, but even that is indeed a stretch for my brains at this moment of the evening. I'd like to see the axioms for that, though. Take off the CS goggles and you'll see the point. |
|||
05-08-2015, 02:27 AM
Post: #80
|
|||
|
|||
RE: negative number raised to even power
(05-07-2015 10:22 PM)Manolo Sobrino Wrote:(05-07-2015 09:57 PM)Dave Britten Wrote: Sure it does. If one believes that the negation prefix is not a fundamental component of the number being represented, but rather a separate operation, then it's not a stretch to argue that the decimal point is a binary operation and draw similar conclusions about precedence based upon that. The point is that -2^2=-4 looks as silly to me as 2.5^2=2.25 does to you. I find it much more elegant to consider the negation prefix as an inseparable part of the number, just as with multi-digit numbers or decimal points. Irrespective of whatever the chosen standard happens to be, I find it ugly to treat it as 0 - 2^2. And I meant binary, as in two arguments, e.g. 2.5, 2 and 5. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 11 Guest(s)