maksl has asked for the wisdom of the Perl Monks concerning the following question:
dear monks;
i have to deal with numeric limits in perl. not exactly of the size npiazza deals with, but i need to know my machine accuracy. it's knowledge is crucial in order to eventually trust the computed data. :)
perl -e '$eps=1;while(1<1+$eps){$eps/=2;}print "$eps\n"'
please tell me if my assumption are nuts. on a debian x86 and alpha i get: 1.11022302462516e-16
number that is found on various googled site in relation with the "NAG Fortran Library" and its precesion (example).
e~(N)^(1/2)*eps
where eps would be the machine accuracy.
N the number of multiplications.
e would result in the supposed mean fault
thx for your advice maksl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: machine accuracy
by BrowserUk (Patriarch) on Jun 18, 2003 at 08:49 UTC | |
Okay. That's a question I can understand:) Whether I can answer it is a different matter, but I'll have a go. If your numbers are in the range 0.0 to 1.0 (or possibly -1.0 to +1.0, but that being pedantic), then that number is significant. However, if your numbers get larger, in the range 1 .. 10, then the significant value is different. vis.
And when the number gets larger still, then it changes again.
And, of course, it works the other way too Rather than carry on step-by-step, it's instructive to look at the output over a range of ranges.
There are three things to notice here.
For much more (and much more accurate:) information, you might like to read IEEE reals. In summary, perl's floats are accurate to approx 53-binary bits or approx. 16 significant (decimal) digits (not places). Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] [d/l] [select] |
by zengargoyle (Deacon) on Jun 18, 2003 at 09:15 UTC | |
...or to total up the number of atoms in the Earth, and our Solar System (and quite possibly all the stars we can see, but I won't guarentee that bit:). approximate number of stars in the universe: 10^22, approximate number of atoms in the universe: 10^83. these are rough and from memory, it's amazing that it's pretty easy to imagine numbers that are greater than all of the little-itty-bitty things that actually exist. | [reply] |
by BrowserUk (Patriarch) on Jun 18, 2003 at 09:53 UTC | |
Are those number accurate to 15 decimal places or 16:) it's amazing that it's pretty easy to imagine numbers that are greater than all of the little-itty-bitty things that actually exist. You've a better imagination than I:). The other day I was playing with Othello, and worked out that on an 8x8 board there are 3^63 possible positions. My first thought was that if I could represent each board position using 128-bits, I might be able to compile a complete compendium of all possible board positions--till I did the math! 3^63 = 1.144561273^10 = 1_144_561_273_430_837_400_000_000_000_000 But just how much storage would that require? Assuming 16 -bytes per board, if I packed them onto 73MB CD's with no overhead for the file system, then it would take 59_810_339_179_409_363_000_000 cd's. A lot for sure. More than exist, or ever probably will, but it's still just a number. So I tried to take this a litte further, and the best I could come up with was that, assuming there are a nice round 6 billion people on the Earth, then it would require every person on Earth to have 1662 CD's, for every other person on the Earth, to be able to hold all those board permuations. Now, I'm not entirely sure that all the math in there is correct, it could be out by a magnitude or two, but it was sufficiently accurate to convince me to try a different approach:) I got in the habit of trying to visualise such numbers very early on. My last year of Junior school, age 11 (I've no idea how that translates into US style grades), we were learning about Napier's Bones, logarithms and stuff, and the teacher told us the old riddle about 1 grain of rice on the first square of a chess board and 2 on the second etc. He then had us weight 1 ounce of rice each and count the grains, and average the counts. Then we calculated the total number of grains, and from that the weight, and from that the volume, and discovered that it would fill the school hall that had a 20 ft high ceiling and was capable of seating 500 kids. Needless to say, I never forgot the experiment, nor the power of the visualisation, but trying to wrap my brain around just how much larger 10^83 is that 10^30 I cannot even begin to see a way:) Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] [d/l] [select] |
by maksl (Pilgrim) on Jun 18, 2003 at 09:24 UTC | |
| [reply] |
Re: machine accuracy
by tedrek (Pilgrim) on Jun 18, 2003 at 07:59 UTC | |
you could just throw a use bignum; at the top of your script and not have to deal with numeric limits. as for that snippet, it seems right to me but I only have a slight clue about math. I believe perl uses double precision numbers on most platforms which means you have 53 bits of precision. I expect somebody will speak up if I'm wrong :) | [reply] [d/l] |
Re: machine accuracy
by BrowserUk (Patriarch) on Jun 17, 2003 at 23:29 UTC | |
I'm being a bit quick off the mark and should probably wait to see what other people make of your question, but could you point out what your question is please? You say "please tell me if my assumption are nuts", but I can't work out what your assumption are:) Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller | [reply] |
by maksl (Pilgrim) on Jun 18, 2003 at 07:03 UTC | |
is the number that the one-liner above is printing relevant for the accuracy of perl calculations? or i'm i completly wrong in assuming that number as important for numerical calculations in perl? | [reply] |
Re: machine accuracy
by TomDLux (Vicar) on Jun 18, 2003 at 09:27 UTC | |
Take a look in your Numerical Methods text, or google for "floatingpoint number" mantissa, you'll get pages like read this. Basically, a floating point number consists of two portions: -- | [reply] |
Re: machine accuracy
by Maclir (Curate) on Jun 18, 2003 at 12:43 UTC | |
What you are describing is precision - and as someone else mentioned, bignum could be your friend. However, once you start manipulating high precision values, you need to make sure your numerical methods do not reduce your accuracy. In the dim, dark past, I did an honours-level university applied math subject that dealt with how to structure calculations so that numerical rounding errors did not accumulate and destroy your accuracy. Sadly, I have forgotten much of it! | [reply] |
by maksl (Pilgrim) on Jun 18, 2003 at 16:18 UTC | |
i'm interested as the title and the little formula indicates in the accuracy, which as physician i would describe in analogy to a statistical random walk depending on the square root of how many times you walk(multiplicate) multiplicated with the inevitable machine inaccuracy. "how close to the correct value is my answer" permits some level of trust to the data, doesn't it? but please tell more if you can dig up :) | [reply] |