Re: An arithmetic puzzle, equality of numbers.
- To: mathgroup at smc.vnet.net
- Subject: [mg103094] Re: An arithmetic puzzle, equality of numbers.
- From: Szabolcs HorvÃt <szhorvat at gmail.com>
- Date: Tue, 8 Sep 2009 05:55:41 -0400 (EDT)
- References: <h829m8$3ue$1@smc.vnet.net> <4AA4BA87.3020500@gmail.com>
2009/9/7 Richard Fateman <fateman at cs.berkeley.edu>: > Szabolcs Horv=C3=A1t wrote: >> >> On 2009.09.07. 8:36, Richard Fateman wrote: >>> >>> For[i = 1.11111111111111111111, i> 0, Print[i = 2*i - i]] >>> >>> This came to my attention (again), and I thought it might amuse >>> current readers of this newsgroup. >>> >>> What looks like an infinite loop terminates with i==0 being true. also >>> i==2 is true. (Tested in Mathematica 6.0; I don't have access to 7 yet.) >>> >> >> It's because of precision loss: >> >> For[i = 1.11111111111111111111, i > 0, >> Print[i = 2*i - i, "\t", Precision[i]]] >> >> For similar results to what C/Fortran/etc. would give (no high precision >> arithmetic with precision tracking), use machine precision numbers: >> >> For[i = 1.1111111111111111, i > 0, >> Print[i = 2*i - i, "\t", Precision[i]]] > > Yes, I know. You should have mentioned it in your message then. Otherwise you just confuse beginners/newcomers, and that is not nice. > I think a design that allows one to create objects such as i > that i==0 and i==2 simultaneously is problematical. Do you agree? No, not really. I don't see how a program that supports arbitrary precision arithmetic could avoid this, and still be convenient to use. (I suppose you were referring to the lack of transitivity.) Suppose we have a system that works with decimals. We have a=0.5 with one digit precision, and b=0.51 and c=0.50 with two digit precision. Both b and c become 0.5 when rounded to 1 digit. Which of the following comparisons should give true? Which should give false? Why? a == b, b == c, a == c P.S. I am not familiar with the topic of precision tracking on computers.
- Follow-Ups:
- Re: Re: An arithmetic puzzle, equality of numbers.
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Re: An arithmetic puzzle, equality of numbers.