Re: Re: Beware of adding 0.0
- To: mathgroup at smc.vnet.net
- Subject: [mg50248] Re: [mg50237] Re: Beware of adding 0.0
- From: DrBob <drbob at bigfoot.com>
- Date: Mon, 23 Aug 2004 06:34:09 -0400 (EDT)
- References: <cg4fcn$cf5$1@smc.vnet.net> <200408220419.AAA10273@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
The range of numbers 0.0 represents (if that were the situation at all) has nothing to do with it, since even ZERO digits of precision is enough to prevent the "error" mentioned. p = SetPrecision[314159265358979323, 25] s = SetPrecision[p + 0.0`0, 25] 3.14159265358979323`25.*^17 3.14159265358979323`25.*^17 The "problem" occurs for a very different reason: because adding a machine-precision number to another number, in Mathematica, causes arithmetic to be done in machine floating point. If I write down arithmetic that involves machine-precision numbers, I expect this to occur and I probably want this to occur, because it's the fastest way to do arithmetic. p loses digits from being converted to machine precision, hence the "problem". Anyway, the problem is entirely artificial. If I know x to 25 digits and add y, where y is known to "machine precision", what is the correct precision on an arbitrary machine? Unknown, correct? (Machine precision differs from machine to machine, hence the name.) If x and y have been given specific precisions, Mathematica does the arithmetic just fine, so far as I know. That's one reason for saying the problem is artificial. A second reason is that (IMHO) there are hardly any numbers you'd ever know to 25 digits, unless you also know them PERFECTLY, either because they result from exact expressions or they're defined constants, etc. If you know a number exactly, enter it as such! That may or may not be a valid analysis for the constant p, but you clearly meant 0.0 to be exactly 0 (or why all the complaints?). So enter it that way: p = SetPrecision[314159265358979323, 25] s = SetPrecision[p + 0, 25] 3.14159265358979323`25.*^17 3.14159265358979323`25.*^17 That's at least as easy as the other way of entering it, and it gets you the answer you seem to want. Languages are allowed to have syntax, and Mathematica syntax says 0.0, 0, and 0.0`25 are three different things. Why not just get used to it? Bobby On Sun, 22 Aug 2004 00:19:48 -0400 (EDT), Richard Fateman <rfateman at sbcglobal.net> wrote: > Paul, since you are copying this from my posting to sci.math.symbolic > of August 19,2004, (yesterday) perhaps you should give me credit. > I took the example from my own paper, A Review of Mathematica, > which appeared in J. Symbolic Computation,(1992) and a version of which > is online. You might also read Mark Soufroniou's INRIA paper (1999?) > explaining why this behavior is apparently intentional, even if it is > hard to explain (shown by the responses you got). > > The idea that 0.0 should represent all numbers in [-1,1]* 2^{-precision} > is generally regarded with skepticism by computational scientists. Some > of the other consequences of this are discussed by Soufroniou and others. > RJF > > > > paul wrote: >> In Mathematica 5.0, I get a very strange result when I add 0.0 to a number, >> why is this? See below: >> >> p = SetPrecision[314159265358979323, 25] >> q = SetPrecision[314159265358979323., 25] >> r = SetPrecision[314159265358979323.00000000000000000000, 25] >> s = SetPrecision[p + 0.0, 25] >> {p == q, q == r, r == s, r == p} >> {Tan[s], N[Tan[p]], Tan[q], Tan[r]} >> >> >> \!\(3.14159265358979323`25.*^17\) >> Out[47]= >> \!\(3.14159265358979323`25.*^17\) >> Out[48]= >> \!\(3.14159265358979323`25.*^17\) >> Out[49]= >> \!\(3.14159265358979328`25.*^17\) *****NOTICE the 28 instead of 23 at the >> end, why does this happen? ******* >> Out[50]= >> {True, True, False, True} >> Out[51]= >> {1.599808, -1.12979, -1.1297927, -1.1297927} >> > > > -- DrBob at bigfoot.com www.eclecticdreams.net
- References:
- Re: Beware of adding 0.0
- From: Richard Fateman <rfateman@sbcglobal.net>
- Re: Beware of adding 0.0