The Museum of HP Calculators

HP Forum Archive 21

 Entry MethodsMessage #1 Posted by dbatiz on 29 Mar 2012, 2:36 a.m. One of my technicians brought a math problem to me yesterday. He was working a total harmonic distortion issue, and his numbers weren't what he expected. In the end, he was having an order of operations problem. While resolving his problem, I noticed some interesting disparities between technologies: Here are the results from a TI 83+ 10^(-2)^2 = .0001 From Wolfram Alpha: 10^(-2)^2 = 10,000 On the HP35s, in algebraic mode I got: 10^(-2)^2 = .0001 On the HP50g '10^(-2)^2' evaluates to 10,000 While I do appreciate the power of a machine that addresses the order of operations, I've yet to encounter enough consistency in application to allow me to be comfortable trusting this process completely to my hand held device. I cannot find consensus even within the HP handheld with built-in algebraic entry. My rational for preferring RPN/L to any other entry method is: I like my devices to do the arithmetic while I do the math. This is simply my opinion, and other opinions are always welcome, Very respectfully, David

 Re: Entry MethodsMessage #2 Posted by Walter B on 29 Mar 2012, 2:48 a.m.,in response to message #1 by dbatiz I fullheartedly concur.

 Re: Entry MethodsMessage #3 Posted by Alexander Oestert on 29 Mar 2012, 2:57 a.m.,in response to message #1 by dbatiz What is the correct way then: from inside out or from outside in?

 Re: Entry MethodsMessage #4 Posted by dbatiz on 29 Mar 2012, 3:36 a.m.,in response to message #3 by Alexander Oestert I don't have a reference to site, but I think you almost have to work from the inside out. If you try to work from the outside, you end up with a lot of, "But I got to do this first"... until you end up smack dab in the middle crunching your way out. I'm sure there is a more technical way of saying that, but that's how it adds up, no pun intnended, in my head, Very respectfully, David

 Re: Entry MethodsMessage #5 Posted by C.Ret on 29 Mar 2012, 4:32 a.m.,in response to message #3 by Alexander Oestert We have to be very carefull when writing in-line algebraic expression. `10^(-2)^2` is as much ambigus as `3/2(1+3)` because incomplete notation can lead to a bunch of different interpretations. Only correct practices may guard from ambigus interpretation. Whatever the way from inside out or from outside in, a correct written expression will lead to the same result. If you have to consider the way to sparse data, you no more in the world of algebra, you already are in the word data processing environement. `10^(-2)^2 = ? ? ?` ? Edited: 29 Mar 2012, 4:36 a.m.

 Re: Entry MethodsMessage #6 Posted by fhub on 29 Mar 2012, 5:27 a.m.,in response to message #5 by C.Ret Quote: We have to be very carefull when writing in-line algebraic expression. `10^(-2)^2` is as much ambigus as `3/2(1+3)` because incomplete notation can lead to a bunch of different interpretations. I don't see any ambiguity in both expressions - there are clearly defined rules of precedence: 1) expressions in parentheses (...) first 2) operations with higher priority first (i.e. ^ before *,/ before +,-) 3) operations with the same priority from left to right (with one exception: ^ from right to left, i.e. a^b^c = a^(b^c)) So 10^(-2)^2 is definitely 10^((-2)^2)=10^4=10000 and 3/2(1+3)=(3/2)*(1+3)=1.5*4=6 Edited: 29 Mar 2012, 5:28 a.m.

 Re: Entry MethodsMessage #7 Posted by Alexander Oestert on 29 Mar 2012, 6:48 a.m.,in response to message #6 by fhub Quote: (with one exception: ^ from right to left) Actually, I also only just found out, that the double up-arrow operator defined by Donald Knuth (the TeX guy) is another exception in being right-assoziative as well.

 Re: Entry MethodsMessage #8 Posted by C.Ret on 29 Mar 2012, 4:28 p.m.,in response to message #6 by fhub Quote: I don't see any ambiguity in both expressions - there are clearly defined rules of precedence: 1) expressions in parentheses (...) first 2) operations with higher priority first (i.e. ^ before *,/ before +,-) 3) operations with the same priority from left to right (with one exception: ^ from right to left, i.e. a^b^c = a^(b^c)) So 10^(-2)^2 is definitely 10^((-2)^2)=10^4=10000 and 3/2(1+3)=(3/2)*(1+3)=1.5*4=6 I am sorry not to agree with you. But, this will not prove you are wrong. Au contraire ! By following your rules I have understand why you don't see any ambiguity. Especially rule 3) is of great help to resolve the ambiguity I saw. But, I am no computer scientist. The rules I use in algebra expression are a bit older than yours. There is no general direction in case of operator of the same priority. In the rule I was instructed to follow, the sentences only specify that, in the case of equal priority operators, a vinculum have to be used in order to dissolve any ambiguity. Quote: Priority rules I was instructed to follow in publications are: 1. The calculations contained in parentheses (or brackets) take precedence over the calculations outside of the parentheses. The fraction bar or the square root bar act as a pair of parenthesis; 2. The exponent takes priority over multiplication, division, addition and subtraction; 3. The multiplication and division take priority over addition and subtraction; 4. Any ambiguity has to be removed by the use of a delimiter (the vinculum, the point or parenthesis) and a spatial organization of the expression. As more and more algebra are type in computer and calculator, these old style rules of algebra and mathematics’ publications have been supplanted by ‘Data Processing Rules’ style or fashion. But having a specific direction of evaluating expression from right to left (or inversely from left to right), or from inside – out (or inversely from outside – in) has never been a commonly accepted or applied universal convention. In contrary, the purpose of the most universally followed rules in paper publications is that, whatever are the way (the direction) the reader process, he will get the same result or expression. Oppositely it is a really common, quite universal, in most of programming languages to have a rule indicating in which way (direction)the expression have to be process or evaluated. In conclusion, I am not surprise that today well computer educated peoples from this actual millennium encounter or see no ambiguity at all in the abscond and badly delimited expressions such a as the above 10^(-2)^2 or 5/2(3+1). Whereas an old fashion XXth century scientist will find these expression ambiguous and badly formatted.

 Re: Entry MethodsMessage #9 Posted by bill platt on 30 Mar 2012, 11:44 a.m.,in response to message #8 by C.Ret You are correct, both from the standpoint that these are data processing issues not algebra issues and secondly but no less importantly, hat data processing rules are now being confounded with the rules of algebra! For anyone suffering from ambiguity of a written expression, I recommend reading a maths textbook, not a calculator manual--and then when dealing with a calculator, RTFM41 that manual!

 Re: Entry MethodsMessage #10 Posted by dbatiz on 30 Mar 2012, 7:05 a.m.,in response to message #5 by C.Ret In my opinion, the "in-line algebraic expression" is the culprit here. While orders of operation, left to right, right to left, out-side in, in-side out can vary depending on application; I believe there is little ambiguity when an the expression is re-written as such: 10(-2)2 Which, coincidently, is exactly what the HP50g displays in the stack when I enter '10^(-2)^2' On my first attempt to demonstrate this to my co-worker, I entered '10^-2^2' which put the following on the stack: 10(-22) Some may say there is still ambiguity in the notation above (whether it means minus 2 squared or the square of negative 2), but it agrees with the instruction I received in school and still subscribe to. I did have to do a double take, but in the end I quickly saw my error. In either case, the possibility of my handheld device CAUSING an error by using a different than expected interpretation is eliminated by using the command line or the X register as a grouping symbol. I'm humbled by the thoughtful responses on this forum. I've never read a thread and failed to learn something, Very respectfully, David

 Re: Entry MethodsMessage #11 Posted by hpnut on 29 Mar 2012, 10:31 a.m.,in response to message #3 by Alexander Oestert With RPN, it's always working from inside to outside. parenthesis- free.

 Re: Entry MethodsMessage #12 Posted by Nick_S on 29 Mar 2012, 4:50 a.m.,in response to message #1 by dbatiz I gave a similar comparison in this thread here: http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/archv021.cgi?read=214739#214739 It turns out that there are even differences within the RPL family with your example, the HP-28s and 48GX calculators return a value of 0.0001 The R language on the other hand returns the result of 10000 Nick Edited: 29 Mar 2012, 4:51 a.m.

 Re: Entry MethodsMessage #13 Posted by dbatiz on 29 Mar 2012, 9:05 a.m.,in response to message #12 by Nick_S Your example hits the nail on the head. Using the stack as a vinculum eliminates all doubt about the desired operand for a desired operation. For example, -2 in the stack followed by x^2 always results in 4, not -4. Thanks to everybody for sharing their examples and perspectives, Very respectfully, David

 Re: Entry MethodsMessage #14 Posted by Luiz C. Vieira (Brazil) on 29 Mar 2012, 5:13 a.m.,in response to message #1 by dbatiz Quote:I like my devices to do the arithmetic while I do the math.Could not express this better.

 Re: Entry MethodsMessage #15 Posted by Antonio Petri (UK) on 29 Mar 2012, 9:40 a.m.,in response to message #14 by Luiz C. Vieira (Brazil) Quote: I like my devices to do the arithmetic while I do the math. That is indeed a great quote that summarise the difference of using RPN: you know what you are doing. I think actually RPN should be the only allowed in schools, as it has a lot more educational value than all those "Textbook Format Display", "Writeview", "Natural TextBook Display", "MultiView" etc.

 Re: Entry MethodsMessage #16 Posted by Luiz C. Vieira (Brazil) on 29 Mar 2012, 9:52 a.m.,in response to message #15 by Antonio Petri (UK) Ditto! I support with no restrictions. Edited: 29 Mar 2012, 9:53 a.m.

 Re: Entry MethodsMessage #17 Posted by Matt Agajanian on 29 Mar 2012, 10:36 a.m.,in response to message #15 by Antonio Petri (UK) In the tone of the Narnian Dufflepuds, "Well said! Well put!" Check out the article in Volume 5 of the HP Digest entitled "How Programmable Calculators Help Kids Learn"by Dr. John J. Wavrik. You'll find it quite a comprehensive approach to supporting RPN and using its concepts and using calculators to better grasp and understand math concepts. Edited: 29 Mar 2012, 10:37 a.m.

 Re: Entry MethodsMessage #18 Posted by Alexander Oestert on 29 Mar 2012, 7:05 a.m.,in response to message #1 by dbatiz Quote: On the HP50g '10^(-2)^2' evaluates to 10,000 The odd thing about the 50g is that it yields 10^(-2)^2 after ENTER and 10000 after EVAL. But with '10^-2^2' yields 10^(-2^2) after ENTER and 1/10000 after EVAL. Note that the - in both cases is the unary operator on the key [+/-]. I would have thought that with the unary - the parentheses would not be needed and both expressions should evaluate to the same.

 Re: Entry MethodsMessage #19 Posted by Thomas Radtke on 29 Mar 2012, 7:46 a.m.,in response to message #18 by Alexander Oestert Quote:But with '10^-2^2' yields 10^(-2^2) after ENTER and 1/10000 after EVAL. Note that the - in both cases is the unary operator on the key [+/-]. I would have thought that with the unary - the parentheses would not be needed and both expressions should evaluate to the same. The expression -2^2 reads as 0-2^2 = -4, no matter which keys were used, unless the 50G has a special character to identify this 'unary minus' concept. If not, it should automatically place parantheses around minus and the rightmost variable/number to reflect what the user probably intended. Best thing would be to forbid CHS when writing algebraic expressions.

 Re: Entry MethodsMessage #20 Posted by fhub on 29 Mar 2012, 8:16 a.m.,in response to message #19 by Thomas Radtke Quote: The expression -2^2 reads as 0-2^2 = -4 Another explanation is that -2 is in fact (-1)*2 and thus the operation ^ has priority over this (implicite) * in the expression -2^2 = (-1)*2^2.

 Re: Entry MethodsMessage #21 Posted by Thomas Radtke on 29 Mar 2012, 8:38 a.m.,in response to message #20 by fhub Quote: Another explanation is that -2 is in fact (-1)*2 and thus the operation ^ has priority over this (implicite) * in the expression -2^2 = (-1)*2^2. But: (-1) * 2 = 2 * (-1) ;-)

 Re: Entry MethodsMessage #22 Posted by fhub on 29 Mar 2012, 8:41 a.m.,in response to message #21 by Thomas Radtke Quote: But: (-1) * 2 = 2 * (-1) ;-) Hmmm? What do you want to say with this? I don't get it ... :(

 Re: Entry MethodsMessage #23 Posted by Thomas Radtke on 29 Mar 2012, 9:15 a.m.,in response to message #22 by fhub Quote: Hmmm? What do you want to say with this? I don't get it ... :( If you argue just with the higher preceedence of the exponentiation over multiplication, it stops working as soon as you commute it, i.e. 2*(-1)^2 = 4 Don't take it too serious.

 Re: Entry MethodsMessage #24 Posted by fhub on 29 Mar 2012, 9:46 a.m.,in response to message #23 by Thomas Radtke Quote: If you argue just with the higher preceedence of the exponentiation over multiplication, it stops working as soon as you commute it, i.e. 2*(-1)^2 = 4 Don't take it too serious. You're right, I really can't take this serious at all because it's just nonsense. Or would you say that a+b*c = b+a*c just because + is commutative??? It's exactly the higher precedence of * over + (or of ^ over * in the example above) why you can't apply the commutative law here.

 Re: Entry MethodsMessage #25 Posted by Thomas Radtke on 29 Mar 2012, 10:17 a.m.,in response to message #24 by fhub Calm down, Franz. This is what I refer to: Quote:Another explanation is that -2 is in fact (-1)*2 and thus the operation ^ has priority over this (implicite) * in the expression -2^2 = (-1)*2^2. Rewrite your sentence to: Quote:Another explanation is that -2 is in fact 2*(-1) [...] ... (which is equal) and you will see where you're mistaken in the following argument, which I have adapted to the above: Quote:[...] and thus the operation ^ has priority over this (implicite) * in the expression -2^2 = 2*(-1)^2.

 Re: Entry MethodsMessage #26 Posted by fhub on 29 Mar 2012, 10:35 a.m.,in response to message #25 by Thomas Radtke Quote: Calm down, Franz. Oh, I'm so calm, calmer "geht's nicht mehr". ;-) At least now I finally understand what you had in mind. Since the - sign in -2 is called Vorzeichen in German (not Nachzeichen), so I'd say (-1)*2 is more logical than 2*(-1). :-) But the true mistake on your side is the following: In -2^2 the - sign doesn't 'belong' to the first 2 but to the whole expression 2^2, so if you would really apply the commutative law then it should be -2^2=(-1)*2^2=2^2*(-1) and not (2*(-1))^2. Franz Edited: 29 Mar 2012, 10:57 a.m. after one or more responses were posted

 Re: Entry Methods-My \$0.02Message #27 Posted by John Stark on 29 Mar 2012, 10:48 a.m.,in response to message #26 by fhub To all: Interesting thread, as everyone spouts off about entry methods and math "rules". My approach would be: Which "answer" makes sense in view of the problem / question ? Just a thought from an unschooled, but active mind. Have a great day, everyone ! John

 Re: Entry Methods-My \$0.02Message #28 Posted by fhub on 29 Mar 2012, 11:06 a.m.,in response to message #27 by John Stark Quote: My approach would be: Which "answer" makes sense in view of the problem / question ? Well, take the example -2^2: Would you say that one of the two answers (4 or -4) "make more sense"? I don't think that math expressions should "make sense" other than being exact and unique, and exactly for that reason we have math rules. If not then everyone would have his own interpretation of "making sense". ;-)

 Re: Entry MethodsMessage #29 Posted by C.Ret on 29 Mar 2012, 5:06 p.m.,in response to message #26 by fhub Wieder Einmal, gibt es keine Zweideutigkeit. Sicher ? -2^2 is another one I have to add in my personal list of ambiguous expressions. Following your interpretation, -2^2 is '-(2^2)' literally "square two and change the sign”. One ambiguity I see, that may explain John's mistake, could be a badly formatted ‘(-2)^2’ / literally “square the opposite of two” / ` -2^2 -22 -2² -22` Edited: 29 Mar 2012, 5:12 p.m.

 Re: Entry MethodsMessage #30 Posted by Marcus von Cube, Germany on 29 Mar 2012, 5:19 p.m.,in response to message #29 by C.Ret The problem with -2^2 is that an interpretation as (-2)^2 is in contrast to the very similar expression 0-2^2 which isn't ambiguous at all. Many modern calculators solve the problem by introducing a special unary minus, often noted as (-), so that -2^2 becomes (-)2^2 which is, per definition ((-)2)^2.

 Re: Entry MethodsMessage #31 Posted by bill platt on 30 Mar 2012, 11:49 a.m.,in response to message #30 by Marcus von Cube, Germany ugh. EDIT. This is one of the AWFUL things about the equation list in the 32sii. And it even has a bug to boot! Look it up, you'll be shocked. I was getting screwed up results way back when I first got that machine and it all had to do with not only the unary minus (which is defined in the manual) but also with the inconsistent behavior where that unary appears at the beginning of a line. Edited: 30 Mar 2012, 3:31 p.m.

 Re: Entry MethodsMessage #32 Posted by Walter B on 30 Mar 2012, 12:53 p.m.,in response to message #30 by Marcus von Cube, Germany That's making simple things complicated. There's a very old German calculation rule "hoch vor Punkt vor Strich" covering also this case perfectly: -2^2 is identical to -(2^2) equaling -4. Unambiguous. No 'unary minus' needed! Due to deviating symbols used in the USA, this rule cannot be translated AFAIK. Sorry, folks :-( Edited: 30 Mar 2012, 12:59 p.m.

 Re: Entry MethodsMessage #33 Posted by Alexander Oestert on 30 Mar 2012, 2:06 p.m.,in response to message #32 by Walter B Quote: "hoch vor Punkt vor Strich" covering also this case perfectly: -2^2 is identical to -(2^2) equaling -4. Unambiguous. No 'unary minus' needed! You're sure? ;-) If by -(2^2) you mean (-1)*(2^2) you arrive at -4. But isn't -(2^2) also equal to (-2)*(1^2)??? So -4=-2! QED!

 Re: Entry MethodsMessage #34 Posted by fhub on 30 Mar 2012, 2:33 p.m.,in response to message #33 by Alexander Oestert Quote: But isn't -(2^2) also equal to (-2)*(1^2)??? It's really funny to see what crazy ideas people are developping for such a simple calculation ... ;-) I would say the 3 '???' at the end are the only things in your post that make sense. Edited: 30 Mar 2012, 2:38 p.m.

 Re: Entry MethodsMessage #35 Posted by bill platt on 30 Mar 2012, 3:29 p.m.,in response to message #33 by Alexander Oestert Quote: . But isn't -(2^2) also equal to (-2)*(1^2)??? So -4=-2! QED! No. 2^2 is defined as 2*2. Therefore -(2^2) can be written equivalently as -1 * 2 * 2 1^2 is defined as 1 * 1. This is not the ame as 2 * 2! You've got a logical fallacy going on there...

 Re: Entry MethodsMessage #36 Posted by Walter B on 30 Mar 2012, 4:12 p.m.,in response to message #33 by Alexander Oestert Alexander, bitte gaaanz langsam und vorsichtig noch mal die Matheregeln aus der Mittelstufe durcharbeiten. Klammern usw. HTH, Walter ;-) (For our unilingual readers: This was a friendly hint to solve this case.)

 Re: Entry MethodsMessage #37 Posted by Alexander Oestert on 30 Mar 2012, 4:27 p.m.,in response to message #33 by Alexander Oestert Quote: You're sure? ;-) fhub, Bill, Walter - please note the ;-) I thought we were already beyond being serious in this thread!

 Re: Entry MethodsMessage #38 Posted by bill platt on 30 Mar 2012, 4:46 p.m.,in response to message #37 by Alexander Oestert :-)

 Re: Entry MethodsMessage #39 Posted by Thomas Radtke on 30 Mar 2012, 3:27 a.m.,in response to message #26 by fhub Quote:But the true mistake on your side is the following: [...] There's no mistake. Read my posts again and try to understand. Enough said, I'm out here.

 Re: Entry MethodsMessage #40 Posted by bill platt on 30 Mar 2012, 11:52 a.m.,in response to message #25 by Thomas Radtke It is actually even simpler than that. There is no such thing as a "unary minus" in maths. That is a computer coding issue. X-y^2+z^3-4 We all know what the hell that is. It is no different if you do this: 3-4^2+5^3-4 Maybe I should go edit with advanced formatting but I think it works well enough... but then someone is going to ask me about: -x^3-y^2+z^3-4. Guess what. It is still the same as before. You know that you can rearrange it (commutative prop.) to: z^3-x^3-y^2-4. So pretty obvious once again that without putting parenths. around a leading minus and it's associated absolute value, you never carry the sign into the exponentiation....That's just the way it is and the goal of calculator use is to make ure that comes out correctly! Indeed, as much as I have been using the algebraic machines more often now, I am always checking and double checking this behavior becuase the really are all different! Edited: 30 Mar 2012, 11:56 a.m.

 Re: Entry MethodsMessage #41 Posted by Walter B on 30 Mar 2012, 12:57 p.m.,in response to message #40 by bill platt It's actually even simpler than that :-) Please see above.

 Re: Entry MethodsMessage #42 Posted by Marcus von Cube, Germany on 30 Mar 2012, 12:59 p.m.,in response to message #40 by bill platt Interestingly the 39gii has a unary minus but the parser treats it the same as the minus key with low priority.

 Re: Entry MethodsMessage #43 Posted by bill platt on 30 Mar 2012, 3:57 p.m.,in response to message #18 by Alexander Oestert This is NOT how the 48G behaves.

 Re: Entry MethodsMessage #44 Posted by Jorge Rodriguez on 30 Mar 2012, 6:05 a.m.,in response to message #1 by dbatiz The TI-84+ returns 10000 for the expression 10^(-2)^2. Interesting. On the HP-35s you must enter an extra set of parentheses to get 10000 thus 10^((-2)^2)). Edited: 30 Mar 2012, 6:15 a.m.

 Re: Entry MethodsMessage #45 Posted by David Hayden on 30 Mar 2012, 5:13 p.m.,in response to message #1 by dbatiz A nice side effect of RPN is that it points out ambiguities like this. Once you realize that you aren't sure which way it should go, you can investigate to figure it out. The unary minus really is there. In the expression "-x=3" there is only one value that "-" operates on, so it's unary. To say that -x is really 0-x just invites the argument that multiplication is ternary. After all, a*b is really just 1*a*b. Moving further off topic, programming languages have another issue that trips people up: order of evaluation. In an expression like a+b, order of evaluation tells you whether a is evaluated first and then b, or vice versa. The order of evaluation matters when the operands are function calls that have side effects.

Go back to the main exhibit hall