re: Accuracy and Precision
- To: mathgroup at smc.vnet.net
- Subject: [mg37130] re: Accuracy and Precision
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Sat, 12 Oct 2002 05:04:56 -0400 (EDT)
- References: <200210110758.DAA01962@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Peter Kosta wrote: > [...] This subthread gets difficult to follow with all the indenting and the like so I will edit a bit for clarity. Here is some input. f = SetPrecision[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]; One question that arose is, as best I can phrase it, "How might I set values for a and b and retain 100 digits of precision (or perhaps accuracy)? There are a few answers and which you like will depend on what you really want to do. (i) You can use a = SetPrecision[77617.,100]; b = SetPrecision[33096.,100]; As has been pointed out a few times, this will give a number with 100 digits of precision. But that number will not resemble: Clear[a,b] a = SetPrecision[77617,100]; b = SetPrecision[33096,100]; 33375/100*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 11/2*b^8 + a/(2*b) or any of the equivalent variations that have been presented in this thread. (ii) You can make input exact before doing any approximate arithmetic wherein canellation error might arise. Using Rationalize, I show this below. Clear[a,b] f = 333.75*b^6 + a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) f = Rationalize[f] In[39]:= Precision[N[f /. {a->77617,b->33096}, 100]] Out[39]= 100. (iii) You cannot do what you want because you work with low precision input and want a high precision result. > 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. I am curious to know how exactly you defined I[...]. It involves a protected symbol. In[54]:= I[a_] := a^2 SetDelayed::write: Tag Complex in I[a_] is Protected. Out[54]= $Failed As for obtaining requested accuracy or precision, I gave no such advice. If you begin with exact input this can be done via N as per response (ii) above. I did not do any experimenting but simply directed N[] to find the result to 100 digits precision. > Dan, you simply advocate to do MANUAL WORK that should > be done by machine. See my above remark. > 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.827396059946821368141165095479816291999033115784384819917814841672467988`\ > 59.9177 > > Oops, it did not work (as expected). Actually it did. You have 59.9177 digits of precision. If you check you will find that you have 60. digits of accuracy as you had requested. > [...] > Dan, is there any simple way to get what I want? If what you wanted was a number with 60 digits accuracy (which certainly was what you requested), then indeed you got it. > 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 First I must request references since I am not certain what exactly you have in mind that the software will do. Then I'll comment on what, as best I can assess, you seem to want the software to do. Based on prior notes from you in this thread, it appears that you want it to treat a number such as 1.2 as an exact entity 5/6. This can be done by exact methods, e.g. preprocessing so that all numbers get rationalized. It cannot be done by our numerical engine (or any other), as that will not rationalize for you. It can also be done by you working with exact input. This would be a simple expedient, but quite effective. I would consider it to be a terrible idea to automatically rationalize every approximate number input and then to work with exact arithmetic. While I am not certain this is what you advocate, it is the only interpretation I can find with would allow for the sort of result you seem to expect. It is a terrible idea because it bypasses solid numerical methods that have been developed over several decades for handling computations accurately and reliably (subject to appropriate input!), and in reasonable time. It would entirely disable any functionality for which no exact methods are known, e.g. solving many ODEs, optimization, and the like. I could go on for a while but I my four typing fingers will get sore. I'll just finish by noting that it is a terrible idea because it would punish all users of numeric computation in Mathematica. I fail to see any useful purpose in that. Mind you, while I regard it as a terrible idea, I am still not certain that this was in fact what you propose. Again, it would be helpful to clarify the matter by posting some reference (textbook, article, software) so I can see what it is you really want. Daniel Lichtblau Wolfram Research
- Follow-Ups:
- Re: re: Accuracy and Precision
- From: "Mark Coleman" <mark@markscoleman.com>
- Re: re: Accuracy and Precision