Why does -2^2 compute to -4 on my HP Prime? - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Why does -2^2 compute to -4 on my HP Prime? (/thread-21262.html) Pages: 1 2 |
Why does -2^2 compute to -4 on my HP Prime? - KenL - 02-08-2024 04:56 AM If I ask my prime to give me the answer to -2 squared it says the answer is -4 ? Why is this happening? procedure ====== press +/- press 2 press x^2 press Enter result shows as -4 Both Home & CAS modes provide same result Why? RE: Why does -2^2 compute to -4 on my HP Prime? - Arno K - 02-08-2024 01:43 PM You may be interested in this thread. Hth Arno RE: Why does -2^2 compute to -4 on my HP Prime? - KenL - 02-08-2024 02:17 PM Awesome! Thanks for the explanation OK ..note to self.. (-2)^2=4 properly. Whew! Now I know Lol! RE: Why does -2^2 compute to -4 on my HP Prime? - KeithB - 02-08-2024 02:22 PM What happens if you press +/- *after* entering 2? RE: Why does -2^2 compute to -4 on my HP Prime? - KenL - 02-08-2024 03:28 PM (02-08-2024 02:22 PM)KeithB Wrote: What happens if you press +/- *after* entering 2? Same issue. Apparently HP considers the +/- key as an operation rather than a declaration I think this is nuts. RE: Why does -2^2 compute to -4 on my HP Prime? - Albert Chan - 02-08-2024 04:12 PM (02-08-2024 03:28 PM)KenL Wrote: Apparently HP considers the +/- key as an operation rather than a declaration HP does the correct way to parse a number. Negative sign is not part of number. Do it the other way, we get into weird parsing situation. (note: this is a Prolog bug) (12-23-2020 03:14 AM)robve Wrote: Parsers should not consider the - to be part of the number to avoid this flaw. RE: Why does -2^2 compute to -4 on my HP Prime? - KenL - 02-08-2024 05:08 PM (02-08-2024 04:12 PM)Albert Chan Wrote: Negative sign is not part of number. I had no idea. Do I need to add parenthesis around my negative numbers from now on? -2^2 = wrong result (-2)^2 = always correct result RE: Why does -2^2 compute to -4 on my HP Prime? - dg1969 - 02-08-2024 05:30 PM (02-08-2024 05:08 PM)KenL Wrote: I had no idea. With paper and pencil : -2^2 = -4 is a correct answer from my point of view… RE: Why does -2^2 compute to -4 on my HP Prime? - chromos - 02-08-2024 05:53 PM 1) What is the result of the expression 0-2^2? Answer: -4 (nobody doubts that). Now we will remove the zero, because, as you know, it is completely useless there: 2) What is the result of the expression -2^2? Expecting a positive result is somewhat contrary to point 1). RE: Why does -2^2 compute to -4 on my HP Prime? - KeithB - 02-08-2024 05:59 PM However, and I seem to be the one that always points this out: Prime has *two* minus operators. There is unary negation which should yield (-2)^2 and the minus operator which should yield -(2^2) I don't have my Prime with me, so I can't tell which is being used in this case. If you look in the algebraic view, the unary minus is tinier and shifted up a bit, while the other is larger and justified to the middle of the number. RE: Why does -2^2 compute to -4 on my HP Prime? - David Hayden - 02-08-2024 06:45 PM In general, this is a problem with our common notation. "-" has at least three different meanings in math:
None of this confusion would exist if we had separate symbols for all three operations. In the meantime, I think it's useful to recognize the cause. RE: Why does -2^2 compute to -4 on my HP Prime? - Joe Horn - 02-08-2024 08:35 PM (02-08-2024 03:28 PM)KenL Wrote:(02-08-2024 02:22 PM)KeithB Wrote: What happens if you press +/- *after* entering 2? Wolfram Alpha agrees with HP: https://www.wolframalpha.com/input?i=-2%5E2 RE: Why does -2^2 compute to -4 on my HP Prime? - Albert Chan - 02-08-2024 09:12 PM (02-08-2024 05:59 PM)KeithB Wrote: However, and I seem to be the one that always points this out: Are they (− vs -) really the same thing? If Yes, why 2 minus operators? If No, what is the difference? RE: Why does -2^2 compute to -4 on my HP Prime? - KenL - 02-08-2024 09:15 PM I must concede. The graph of -x^2 is indeed upside down Lol! RE: Why does -2^2 compute to -4 on my HP Prime? - KeithB - 02-08-2024 09:58 PM (02-08-2024 09:12 PM)Albert Chan Wrote:(02-08-2024 05:59 PM)KeithB Wrote: However, and I seem to be the one that always points this out: No, I don't have my prime here, but this is in the catalog section of the manual: [attachment=13257] [attachment=13258] RE: Why does -2^2 compute to -4 on my HP Prime? - KeithB - 02-08-2024 10:00 PM And I seem to have been bit by it here: https://www.hpmuseum.org/forum/thread-12460.html RE: Why does -2^2 compute to -4 on my HP Prime? - Steve Simpkin - 02-08-2024 11:40 PM The order of precedence used by algebraic scientific calculators has changed over the years. Early Texas instruments (TI) models like the SR-50 (Sum of Products logic) and TI-52/TI-30/TI-57/TI-58/TI-59, etc (AOS logic) would square the number in the display immediately after pressing the X^2 key (like RPN calculators). This would treat the sign of the number as an integral part of the number so -2^2 would equal 4. This is identical to the way HP RPN models calculated this type of problem. For Texas Instruments, the change in logic occured around 1990 with the TI-81 (EOS logic). Theses and later models would treat the - as a negation operator with a lower precedence than the ^2 function so -2^2 would equal -4 on these models. This is described in more detail on the Datamath site: http://www.datamath.org/Sci/WEDGE/SR-52_AOS.htm#Algebraic_Operating_System: RE: Why does -2^2 compute to -4 on my HP Prime? - john gustaf stebbins - 02-09-2024 01:34 AM The Prime is inconsistent with how it applies precedence for - and ^. Or maybe better said, when it imposes parentheses. - 2 ^ 2 => -4 - 2 enter ^ 2 => 4 - 2 enter (copy from history) ^ 2 => -4 ANS seems to imply parentheses. I've learned to be generous with the use of explicit parentheses when working on the Prime. It really isn't worse than other algebraic or textbook calculators, but I can do much more complex things with the Prime, so I get into subtler problems. Having a truly usable RPN mode would be nice. RE: Why does -2^2 compute to -4 on my HP Prime? - Albert Chan - 02-09-2024 01:30 PM (02-08-2024 05:53 PM)chromos Wrote: 1) What is the result of the expression 0-2^2? If we add MOD operator to the mix, zero make a difference. Unary minus has higher precedence than binary minus, with MOD in-between. >>> 0-10%7, -10%7 (-3, 4) lua> 0-10%7, -10%7 -3 4 (02-09-2024 01:34 AM)john gustaf stebbins Wrote: I've learned to be generous with the use of explicit parentheses when working on the Prime. That's a good advice! For clarity, -10%7 should really be written as (-10)%7 Practical C Programming preface Wrote:This book stresses simple, practical rules. RE: Why does -2^2 compute to -4 on my HP Prime? - KeithB - 02-09-2024 03:23 PM As the "Elements of Programming Style" puts it: "Parenthesize to avoid ambiguity" But I am afraid I was wrong - on teh internet! powers have higher precedence than unary negation: [attachment=13262] |