WolframAlpha miscalculates a simple arithmetic expression

In summary: When you give two decimal numbers as input, WolframAlpha will try to give the result in machine precision (i.e. with as many digits as there are in the input). If the two decimal numbers are not exactly equal to each other, then the result will be rounded to the nearest machine precision number.In summary, there is a 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
  • #1
cryptist
121
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
  • #2
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 scottdave
  • #3
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!
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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.
 
  • #8
When I wrote Floor[Sqrt[1144/100 - 10.]/(2/10)] it gives 5 again. (With dot next to 10).
 
  • #9
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 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!
 

Related to WolframAlpha miscalculates a simple arithmetic expression

1. Why did WolframAlpha miscalculate my arithmetic expression?

There could be several reasons why WolframAlpha miscalculated your expression. It could be due to a typo or incorrect input, the expression may be too complex for the program to handle, or there could be an error in the program itself.

2. How accurate is WolframAlpha's arithmetic calculations?

WolframAlpha prides itself on being extremely accurate in its calculations. However, like any program, it is not perfect and may occasionally make mistakes. It is always a good idea to double check your results and report any discrepancies to the WolframAlpha team.

3. Can I report a miscalculation to WolframAlpha?

Yes, WolframAlpha has a feedback feature where you can report any miscalculations or errors you encounter. This helps improve the program for future use.

4. Is WolframAlpha's miscalculation a common occurrence?

No, miscalculations in WolframAlpha are not common. The program is constantly updated and maintained to ensure accuracy. However, as with any technology, errors can occur, so it is always important to double check your results.

5. How can I avoid miscalculations when using WolframAlpha?

To avoid miscalculations, make sure to double check your input and use proper mathematical notation. Also, be aware that WolframAlpha may not be able to handle extremely complex expressions, so it is best to break them down into smaller parts if possible.

Similar threads

  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • Math Proof Training and Practice
2
Replies
67
Views
10K
  • Linear and Abstract Algebra
Replies
2
Views
5K
Back
Top