RE: Re: Re: Accuracy and Precision
- To: mathgroup at smc.vnet.net
- Subject: [mg37090] RE: [mg37076] Re: [mg37058] Re: Accuracy and Precision
- From: "DrBob" <drbob at bigfoot.com>
- Date: Wed, 9 Oct 2002 05:25:39 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
Let's be realistic. If you want 60 digits of precision, too bad! -- in the real world. There's nothing we can measure that closely. Drug concentrations in clinical trials are generally measured within 15%, for instance. Even machine precision is more than can be realistically expected in any application I can think of. Even getting a satellite to Jupiter probably involves more error in the final result than machine precision. (If not, it's because we rely on ongoing corrections and natural factors that put the satellite where it should be, such as gravity drawing it toward each rendezvous -- not on that kind of precision in propulsion or guidance.) So... unless all numerics in a problem have a theoretical origin, and could be represented in Mathematica as Infinite precision expressions... all this talk of higher-precision computation seems futile. The realistic question is this: given that I have confidence, say, in 6 digits of precision for the inputs of an expression, how many digits can I trust in the end result? Giving inputs MORE precision than they deserve isn't the best way to answer that question. Here are two methods of answering it in Mathematica. One uses "bignums" and the other uses Intervals. Repetitious trial and error are NOT required either way. BIGNUMS: ClearAll[a, b, f, x, y] f = x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b); a = SetPrecision[77617, 6]; b = SetPrecision[33096, 6]; x = SetPrecision[33375/100, 6]; y = SetPrecision[55/10, 6]; InputForm[f] -4.1396`-12.5121*^19 Several previous solutions have set the precision or accuracy of f before giving a and b (and possibly x and y) values. That results in making the exponents imprecise along with all coefficients (not just x and y), which may or may not be what we want. INTERVALS: I'll first digress to figure out what Interval is equivalent to 6-digit precision. You might not actually do this if you like the Interval method, but you have to decide SOMEHOW what Interval width to use. nums = {77617, 33096, 33375/100, 55/10}; (Interval[SetPrecision[#1, 6]] & ) /@ nums /. Interval[{a_, b_}] :> 2*((b - a)/(b + a)); InputForm[%] {3.2209438653903`0.207*^-6, 3.7768914672467`0.2761*^-6, 2.9260299625467`0.1652*^-6, 2.7743252840909`0.1421*^-6} For these numbers, # + Interval[{-1,1}]*#/630000& gets us very close, so I'll use that. The second method therefore is: g = #1 + Interval[{-1, 1}]*(#1/630000) & ; a = g[77617]; b = g[33096]; x = g[333.75]; y = g[5.5]; f = x*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + y*b^8 + a/(2*b) (Min[f] + Max[f])/2 Interval[{-2.136361928005054*^32, 2.1363651195928296*^32}] 1.5957938878075177*^26 Either method shows the answer has no trustworthy digits, but I think the second result is far easier to interpret. Here's another example, using the Sin function, whose derivative is Cos, whose magnitude is bounded by one. The precision of the Sin of a number should be GREATER than the precision of the number itself, especially when Cos is small. a = SetPrecision[Pi/2, 6]; InputForm[Sin[a]] 0.9999999999990905052982256654`11.6078 a = g[N[Pi/2]]; Sin[a] - 1 Interval[{-3.1084024243455137*^-12, 0}] I hope this was worthwhile to someone. DrBob -----Original Message----- From: Peter Kosta [mailto:pkosta2002 at yahoo.com] To: mathgroup at smc.vnet.net Subject: [mg37090] [mg37076] Re: [mg37058] Re: Accuracy and Precision --- Daniel Lichtblau <danl at wolfram.com> wrote: > Peter Kosta wrote: > > > > Andrzej Kozlowski <andrzej at tuins.ac.jp> wrote in > message news:<anp065$qtb$1 at smc.vnet.net>... > > > On Friday, October 4, 2002, at 06:01 PM, DrBob > wrote: > > > > > >[...] > > > > > > I would say this is correct and show that > SetPrecision is very useful > > > indeed. It tells you (what of course you ought > to already know in this > > > case anyway) that machine precision will not > give you a realiable > > > answer in this case. If you know your numbers > with a great deal of > > > accuracy you can get an accurate answer: > > > > > > In[24]:= > > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - > b^6 - > > > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > > > a=SetPrecision[77617.,100]; b = > SetPrecision[33096.,100]; > > > > > > > > > In[26]:= > > > {f, Precision[f]} > > > > > > Out[26]= > > > > {-0.82739605994682136814116509547981629199903311578438481991\ > > > 781484167246798617832`61.2597, 61} > > > > > > > Congratulations! You just requested accuracy of > 100 for f and got 61 ( > > to convince yourself add Accuracy[f] to In[26]). > If In[24] one > > replaces SetAccuracy by SetPrecision the result is > similar. > > > > PK > > [...] > > One has (initially) an accuracy of 100 for an > expression that contains > variables. > > In[25]:= Clear[a,b,f] > > In[26]:= f = SetAccuracy[333.75*b^6 + > a^2*(11*a^2*b^2 - b^6 - > 121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100]; > > In[27]:= Accuracy[f] > Out[27]= 100. > > Now we assign values to some indeterminants in f. > > In[28]:= a = SetPrecision[77617.,100]; b = > SetPrecision[33096.,100]; > > In[29]:= {f, Precision[f], Accuracy[f]} > Out[29]= > {-0.8273960599468213681411650954798162919990331157843848199178148, > > 61.2599, 61.3422} > > The precision and accuracy has dropped. This is all > according to > standard numerical analysis regarding cancellation > error. You'll find it > in any textbook on the topic. > Assume that I want accuracy and precision of 100 for f. You advice me to make experiments to find out, what should be the initial precision and accuracy of a and b to reach the requested accuracy and precision for f. Notice, that you cannot just repeat I[26], we saw already what happens. I have to re-type I[24], I[25], I[26], I[27], I[28], and I[29] as many times as needed to get f with accuracy and precision 100. Dan, you simply advocate to do MANUAL WORK that should be done by machine. Let's suppose that in the above example I just want 60 digits not 61. Precisely, I want 60 digits and nothing or zeros afterwards. Let's see if I could use SetAccuracy. In[30]:= SetAccuracy[%, 60] Out[30]= -0.82739605994682136814116509547981629199903311578438481991781 In[31]:= % // FullForm Out[30]//FullForm= -0.827396059946821368141165095479816291999033115784384819917814841672467 988`\ 59.9177 Oops, it did not work (as expected). Let's highlight with mouse the expression in Out[30] and copy to a new cell. Oops, we got -0.827396059946821368141165095479816291999033115784384819917814841672467 988`\ 59.9177 again. Let's change Out[30] to a text cell and then copy. In[31]:= -0.82739605994682136814116509547981629199903311578438481991781 Out[31]= -0.82739605994682136814116509547981629199903311578438481991781 Success? Not so fast. In[32]:= % // FullForm Out[32]//FullForm= -0.827396059946821368141165095479816291999033115784384819917809999999999 998635\ 08`59.2041 Dan, is there any simple way to get what I want? As I repeated already number of times, at this stage of the development of computer technology, software should do it for me (!). We both know that this is doable. Some of the textbooks that you just advised me to read describe it. As a developer of Mathematica, tell us why do you consider this to be a bad idea? Peter Kosta > As for what happens when you artificially raise > precision (or accuracy) > of machine numbers far beyond that guaranteed by > their internal > representation, that falls into to category of > garbage in, garbage out. > It is, howoever, valid to use SetPrecision to raise > precision in > (typically iterative) algorithms where significance > arithmetic might be > unduly pessimistic due to incorrect assumptions > about uncorollatedness > of numerical error. Examples of such usage have > appeared in this news > group. > > > Daniel Lichtblau > Wolfram Research __________________________________________________ Do you Yahoo!? Faith Hill - Exclusive Performances, Videos & More http://faith.yahoo.com
- Follow-Ups:
- Re: RE: Re: Re: Accuracy and Precision
- From: Selwyn Hollis <selwynh@earthlink.net>
- Re: RE: Re: Re: Accuracy and Precision