Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login
3 caculators = 3 different answers to one math problem (www.mathmagical.co.uk) similar stories update story
41.0 points by msredmond | karma 934 | avg karma 2.7 2012-03-30 17:29:35+00:00 | hide | past | favorite | 58 comments



view as:

Anyone have a guess to how the iPhone calculator computed 2?

Comments on the original post indicate that if you do 6/7(1+2) then you get 2 as well and the iPhone is just throwing away whatever digit is in the position of the 7.

It seems that pushing "(" doesn't push the entered value onto the stack, even though it's still visible on the screen. "6 / 2 (2 + 1)" becomes "6 / (2 + 1)".

The calculator on WP7 does the same thing, but is a little more explicit - it shows the current expression as it is being built, so you see that while the first 2 was entered, the final expression is 6 ÷ (2 + 1)

OK, I get the first two. Strictly speaking, mult and div have the same precedence (6 / 2 * 3 should be the same as 6 * 3 / 2 , both 9), but in one case, the calculator interpreted the multiplication in 2(1+2) as having higher precedence than 2*(1+2). Arguably a bug, but nothing crazy.

But ... the iPhone gives 2? I don't get it.

(FWIW, Android says 9)


My iPhone gives 9. I entered "6/2*(1+2)".

You have to test it without the explicit "*" and see if it performs the order of operations correctly.

My iPhone gives 9. I entered "6/2*(1+2)".

I don't like calling one interpretation of an ambiguous notation a bug but not the other. Either they are both possible bugs or neither are. The ambiguity comes in when we try to apply rules we learned for encoding (handwritten notation) to another encoding scheme (the calculator). Handwritten math uses positional information to encode order of operations. Calculator math can either try to mimic this (like one Casio did) or ignore this and revert to strict "all multiply and divide operations have equal precedence" (which the other Casio did) Fractions and exponents are other areas where handwritten notation and calculator notation don't overlap very well.

The iPhone ignores any input before opening a group if you don't give it an operator.

5(2) = 2

999(2+2) = 4


So it should have given 3.

'before…within the term or factor":

  2*2455(6) = 12
  2+47435)7 = 14
(according to the iPhone calculator in scientific mode)

I'm guessing you meant: 7+47435)7 = 14 for the second example?

I get 9 as written on my iPhone. The correction above gives 14.

The interesting thing to me is that the close parenthesis cause the same behavior. The consistent logic appears to be "an operator entered in error causes input to reset" or something like that. Also errors are silently ignored in the easiest way possible, perhaps internally the value never gets pushed to the stack or something along those lines.

I wonder what other 'errors' could show this behavior?


No, if you drop the number before the parenthesis you get 6/3, or 2.

6 ÷ 2 ( 1 + 2 )

6 ÷ ( 1 + 2 )

6 ÷ ( 3 )

2


Don't forget the division being done.

The iPhone appears to operate this way:

    6
    6%
    6%2
    6%(
      At this point the 2 (or any value in that slot) has been dropped
    6%(1
    6%(1+
    6%(1+2
    6%(1+2)
      and the result is processed in this order:
    6%(3)
    6%3
    2
giving the result.

It appears what most people are objecting to is that it performs an unexpected operation when it discards the value at 2 (because opening the parenthesis without giving 2 an operator has been designed to be 'invalid') but it does NOT indicate this in ANY way.

It is also interesting to note that all of his other examples had the entire formula written out, where the iPhone did not. If it had, it would have been more clear when the 2 was dropped.


Android inserts the implied multiplication symbol when you open parentheses (on Gingerbread 2.3.5).

1 ambiguous notation, 3 different interpretations. The Casios both have reasonable interpretations, but the iPhone should probably give some kind of warning that it is about to ignore entire numbers.

How is that ambiguous? PEMDAS and since multiplication and division have the same rank, you go left to right. Pretty clear if the calculators follow the basic order of operations.

All infix notations (without sufficient parentheses) require an agreement (implicit or explicit) among all concerned parties. This is nothing new. The same ambiguity occurs with the unary negation operator, as in -5^2.

While I wouldn't choose it, I don't think it's entirely unreasonable to give the "multiplication by juxtaposition" operator greater precedence than the normal multiplication and division operators.


If you write the expression as a fraction without anything beside it being multiplied, it is ambiguous as to whether (1+2) ought to go above or below the fraction bar. The fact that parentheses/brackets ought to be resolved before anything else complicates things because 6/2 * 3 could reasonably be interpreted either way. An unambiguous way to write it would be either as (6/2) * 3 or as 6/(2*3).

BEDMAS is easier to remember

There is an ambiguity if Division comes before Multiplication - although in this case you assume left->right


How is that ambiguous?

Although that was probably rhetorical:

It's ambiguous because most people[1] automatically view implicit multiplication as higher rank than both division and explicit multiplication.

--

[1]this is a wild guess with no data to back it up

edit: baddox's answer is much better


I don't think it's ambiguous in the least. Sure, if I were programming I would add another set of parentheses and the implied * symbol so that it's crystal clear and more reader friendly, but I would toss any calculator that gave me anything other than 6÷2(1+2)=9. I've never read or heard anywhere that an implied * symbol has higher priority than an explicit one. But if that is a reasonable interpretation, Casio has a responsibility to give consistent results across it's entire calculator line.

In WolframAlpha 6÷2(1+2) gives 9 but 6÷2x with x=(1+2) gives 1.

I might be remembering incorrectly, but 2x and 2(x) are totally different things in algebra.

2x would be expanded as (2 * x), whereas 2(x) expands as 2 * x.

In this case, since the equation is 2(1+2) which results in 2(3), it's final DMAS form is 6 ÷ 2 * 3 = 9, instead of 6 ÷ ( 2 * 3 ) = 1


Mentally, I perform no-written-operator multiplication first, then anything else, so I can see why the calculators (and WolframAlpha, in some cases) are getting the intention wrong:

"6 ÷ 2x" gets parsed as "6 / (2 * x)"

"6 ÷ 2 * x" gets parsed as "(6 / 2) * x"

All that's done in the equation in the article is having a pair of brackets instead of a variable, but the result is the same to my brain.


> "6 ÷ 2x" gets parsed as "6 / (2 * x)"

Edit: I'm probably wrong about precedence for 2x, which should be stronger. Which would leave 2(1+2) still really ambiguous. I guess the true lesson here is to always parenthesize explicitly or use over/under notation,

But this is wrong! Division and multiplication have the same precedence and left-to-right application order!

Hence, "6 ÷ 2x" should be parsed as "(6 ÷ 2) * x", which I admit is a bit confusing, so you probably should write out either the parenthesis or the multiplication. But, just because the notation is confusing doesn't mean the rules no longer apply.


But this makes almost everybody wrong. Going by this, you would evaluate 6x ÷ 2x to 3(x^2) rather than 3. That is clearly not the intention, so somebody is wrong here, but it's a matter of opinion whether it's the writer (for not precisely following standard notation) or the standard notation (for being counterintuitive) that deserves the blame.

Yes, this is correct and is the reason why I set implicit multiplication to a higher precedence in the calculators I've written. Obviously not everyone agrees though, but it's certainly the way it's always been interpreted in written algebra textbooks. Precedence rules are essentially arbitrary. We have to make them up. Going by most common historical use is a reasonable choice.

Why does the multiplication in "2x" have the same precedence as in "2 * x"? The previous poster is saying that the no-operator version binds stronger than the versions with operations. I agree that the no-symbol version has different rules than the explicit symbol.

Consider the expression "h-bar is h over 2 pi". That's "h = h/2p", and is definitely not the same as "(h/2) * p". This is because of the convention that you write the numerator terms and then the denominator terms. That is, if you wanted "h/2 * p" then you would tend to write it hp/2.

As another example, consider Schrödinger's equation, with (-h²/2m) * ?(r, t). There too the 'm' is well-understood as being in the denominator.


Exactly. This whole thing seems extremely artificial to me; notation is fluid and ambiguous, despite what elementary-school teachers may say. If you're calculating something, you can use whatever rules you want, and if you're reading some else's work, you can complain if they're being ambiguous.

My intuitions (astrophysics/finance background) say multiplication-by-juxtaposition is higher-precedence than multiplication-by-symbol, so "x/y(1+y)" would be "x/(y(1+y))"; interpreting it as "(x/y)(1+y)" seems wrong.

Then again, "x/y*(1+y)" already looks wrong. The solidus is too powerful. I'd write "(x/y)(1+y)" explicitly.


The way I parse it, 2x is a single unit but 2(x) is normal multiplication.

I'm happy to say my mental math and my phone's (Nexus S) math get 9.

RPN (Reverse Polish Notation) gets things done on a calculator. This article shows one reason why it's not just for finance.

You beat me to it. Enter one of

    6 [enter] 2 [enter] 1 [enter] 2 + * /
or

    6 [enter] 2 / 1 [enter] 2 + *
depending on how you prioritize the implicit *, and never have to wonder how your calculator might interpret the input.

> depending on how you prioritize the implicit *,

I believe this is the crux if the issue, RPN notwithstanding.


when i was a kid, i was told to use the BODMAS rule i.e Brackets, Orders, Division or Multiply, Addition or Substraction

After you have done "B" and "O", just go from left to right doing any "D" or "M" as you find them.

Then go from left to right doing any "A" or "S" as you find them.


I was taught the same, but with strict precedence - division comes first. Having said that, a mathematician would never write those down anyway, as it's too confusing.

Hm, Calcbot on the iPhone also returns 2 if entered without a multiplication after the first "2". Hitting the open parenthesis key removes the "2" from the calculation. Since Calcbot displays what you've entered below the answer, it's easy to see the mistake with a trivial calculation like this, but if you're not watching for it it's easy to miss. Better than the built-in calculator and PCalc, which provide no feedback and give the wrong answer, but surprising.

Math PhD student here. The issue is that people are confusing two symbols which are distinct: the solidus (/) and the obelus (÷). The latter is rather obsolete and it's not clear why exactly calculators use it. Anyway, this blog post clears up the issue better than I could hope to in a comment: http://www.matthewcompher.com/posts/trouble-with-semantics-t...

No, this is not the problem in this case at all. Read the article. Besides, both calculators use the obelus, and still give different results.

Multiplication and division have the same precedence, so you do them left-to-right as written. Like addition and substitution.

Or better yet, realise that writing it all on one line is stupid and ambiguous, and write properly.


In Microsoft Excel we get:

"Microsoft Excel found an error in your formula you entered. Do you want to accept the correction proposed below?"

=6/2*(1+2)

Which then gives 9.


I enjoyed the bit at the end where the writer managed to use the wrong (IMO) formula to arrive at the correct answer.

Using BEDMAS as I was taught, so many moons ago:

6 ÷ 2 ( 1 + 2 )

6 ÷ 2 ( 3 )

6 ÷ 2 * 3 // because 2(3) is not an exponent or algebraic construct, it's straight multiplication

3 * 3 // division and multiplication are in left-to-right order, no precedence

9


Update: after reading the article at http://www.matthewcompher.com/posts/trouble-with-semantics-t... , the writer used the ÷ as a line operator, not a natural division operation.

I would maintain that since this is not taught in any school I've ever attended, it is at least questionable. I've never seen a math textbook use the / symbol for natural division either.


I never knew about the distinction either. But if interpreted that way

    6 ÷ 2 (1 + 2)
should then translate to

    6 / (2 * (1 + 2)) = 1
I guess this only reaffirms the fact that the expression is ambiguous.

that seems wrong to me too, either I lost my math or I don’t see how he went from

   6 ÷ 2 (1 + 2)
to

   (6 * (1 + 2)) / 2

You may reorder factors arbitrarily

  *a /b *c = *a *b /c = /c *b *a  etc.

  so 6 /2 *(...) = 6 *(...) /2.

Right. Silly me. What a weird way of doing it though.

to me, elided multiplication has a higher precedence than the explicit one (and by transitivity, than the explicit division), but I don't remember in which grammar I read that (mathematica, matlab ?).

I would have expected an answer of 3 as 2(1+2) cannot mean anything else than applying the constant function 2 to the sum.

...about time we start teaching prefix notation on schools.

Legal | privacy