WolframAlpha miscalculates a simple arithmetic expression

Click For Summary

Discussion Overview

The discussion revolves around a perceived bug in WolframAlpha and Mathematica related to the calculation of the expression "Floor(sqrt(11.44-10)/0.2)". Participants explore issues of numerical representation in computing, particularly how base-10 numbers are converted to base-2, leading to unexpected results in arithmetic operations.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant claims that WolframAlpha incorrectly calculates "11.44-10" as approximately 1.4399999999999995 instead of exactly 1.44, leading to an incorrect final result of 5 instead of 6.
  • Another participant explains that the discrepancy arises from the conversion of base-10 numbers to base-2, suggesting that users should be aware of this limitation and consider using functions like Round instead of Floor.
  • A different participant argues that the number 11.44 is exact and should not produce such long decimal representations, asserting that this indicates a bug in the software.
  • Some participants propose alternative inputs, such as using "1144/100 - 10" to achieve the exact value of 1.44, but others report that this still yields incorrect results in their cases.
  • There is a discussion about the implications of machine precision and how it affects calculations, with some participants emphasizing the need for exact input to obtain exact output.
  • One participant expresses frustration over the issue, suggesting that Wolfram should modify their software to handle such cases better, while others speculate on the future of computing and numerical representation.
  • A participant shares a custom function for handling decimal arithmetic, which is met with appreciation from others in the thread.

Areas of Agreement / Disagreement

Participants express differing views on whether the behavior of WolframAlpha constitutes a bug or is simply a consequence of numerical representation in computing. There is no consensus on the necessity for Wolfram to address the issue, as some believe it is an inherent limitation of the system.

Contextual Notes

Participants highlight limitations related to machine precision and the representation of decimal numbers in binary systems, which may affect the outcomes of arithmetic expressions. The discussion does not resolve these limitations but emphasizes their relevance to the problem at hand.

cryptist
Messages
121
Reaction score
1
There is a crucial bug on both WolframAlpha and Mathematica. When we give the input "Floor(sqrt(11.44-10)/0.2)" it gives wrong answer. The actual answer is six (6) but wolframalpha gives five (5). The problem is Wolframalpha calculates 11.44-10 incorrectly. Although the answer is exactly 1.44, engine calculates as 1.4399999999999995.

It is suprising that this program cannot give true answer for such an elementary arithmetic equation.

See:
https://www.wolframalpha.com/input/?i=Floor(sqrt(11.44-10)/0.2)
 
Physics news on Phys.org
Actually, it is not surprising at all...it is just that you need to be aware that when working with computers, your base-10 numbers will be converted into base-2 and represented with a finite number of bits...so, often, there a "lost in translation" problem you, as a computer user, need to be aware and program around if it affects you. For example, one common problem is to attempt a boolean expression in an if statement and test if a real number is zero or some other exact integer.

In this particular case, depending on what you wanted, maybe you should use Round, instead of Floor; or Floor( sqrt(11.44-10)/0.2 + 0.5 )...depending on what you REALLY want to achieve and if you KNOW what you are doing.
 
  • Like
Likes   Reactions: scottdave
cryptist said:
Although the answer is exactly 1.44,
The answer is not exactly 1.44, it is approximately 1.44 to within machine precision. Remember, a computer uses base 2 numbers, not base 10 numbers, so not all base 10 numbers can be exactly represented in base 2.

If you want exactly 1.44 then you need to input 1144/100 - 10. That will get you 144/100, or exactly 1.44

EDIT: gsal beat me to it!
 
It is NOT related to the thing that you mentioned, because with different numbers, I get right answers. For example 20.46-10 (substraction expression) gives the right result but 11.44-10 gives wrong result. So this prooves that there is a clear bug. Besides, 11.44 is an exact number. So it should not give such long decimals..

And actually I think it is a major problem. I cannot use Round because it changes my results completely, as you may understand. I am calculating something based on Floors and Ceils and because of this wrong calculation I get wrong results and I spend many hours to see where my mistake is, but eventually I understand that it was not my mistake.
 
DaleSpam said:
If you want exactly 1.44 then you need to input 1144/100 - 10. That will get you 144/100, or exactly 1.44

No. I tried what you said and I get wrong answer again.
 
cryptist said:
with different numbers, I get right answers
That actually indicates that it is exactly what gsal and I mentioned. That is a typical consequence of this issue, in fact it is almost a defining feature.
 
cryptist said:
No. I tried what you said and I get wrong answer again.
Interesting. For me running Mathematica 10.0.0.0 on 64-bit Windows
Code:
Floor[Sqrt[1144/100 - 10]/(2/10)]
gives 6.

Edit: same code gives the same result on Wolfram Alpha.
 
When I wrote Floor[Sqrt[1144/100 - 10.]/(2/10)] it gives 5 again. (With dot next to 10).
 
I think I am getting what you say. But don't you think Wolfram team should find a solution for this? Maybe they should modify their codes, because this is the reason I get wrong answers on my study and it is clearly wrong. I am writing an exact expression, I think it should understand it before turning it into a bunch of decimals. I also reported the problem to Wolfram but I didn't get an answer yet. (It was about a month ago)
 
  • #10
Maybe one day, we will have base-10 computers or maybe one day we (humans) will drop base-10 and start counting in binary...don't know. In the mean time, you need to be aware of this and, no, Wolfram is not going to re-write any software.

To be sure, different programs provide a way to do decimal arithmetic for when it is truly necessary, for example, Python provides the decimal package:

>>> from decimal import *
>>> a = 11.44 - 10.0
>>> a
1.4399999999999995
>>> b = Decimal('11.44') - Decimal('10.0')
>>> b
Decimal('1.44')
>>>
 
  • #11
That's it! Wolfram should provide a similar package too I think. It shouldn't be so difficult.

Thanks to you all for your answers.
 
  • #12
cryptist said:
When I wrote Floor[Sqrt[1144/100 - 10.]/(2/10)] it gives 5 again. (With dot next to 10).
Yes, because then the thing inside the square root is not an exact number. It is no longer exactly equal to 1.44, but only approximately equal to within machine precision.

If you write machine precision input then at most you can get machine precision output (and usually it is less). If you need exact output then you must give exact input. The result of adding an exact number to a machine precision number is a machine precision number.
 
  • #13
cryptist said:
Wolfram should provide a similar package too I think. It shouldn't be so difficult.
Here you go.
Code:
decimal[x_?NumberQ, dig_Integer: 2] := Round[x 10^dig]/10^dig

It defaults to considering two digit input exact, but you can do a different number of digits if you want.
 
  • Like
Likes   Reactions: cryptist
  • #14
DaleSpam said:
Here you go.
Code:
decimal[x_?NumberQ, dig_Integer: 2] := Round[x 10^dig]/10^dig

It defaults to considering two digit input exact, but you can do a different number of digits if you want.

Wow! That's it. Thank you for the code!
 

Similar threads

Replies
10
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 67 ·
3
Replies
67
Views
16K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
7K
Replies
6
Views
4K