On Sat, Mar 22, 2014 at 7:06 PM, Aaron Meurer <[email protected]> wrote: > Ah, so it's more or less what you would expect. It's just like if you > were to subtract the two numbers on paper. In other words, you have to > think about lining up the decimal point. If you have 100 - 1.002e-13, > you would have > > 100.0000000000000000 > - 000.0000000000001002 > > except at the end, you can only have say 15 digits after the first > nonzero digit, but here the first nonzero digit would still be on the > order of 100 (actually in the tens place), so by the time you get to > 15 you lose the precision of the 2. > > Of course, this all actually happens in base 2, but other than that > it's the same idea. > > Am I correct?
Yep, that's it. Good numerical algorithms avoid this, but as I've shown above, taking a long symbolic formula from SymPy, like Legendre, and plugging in double precision number simply fails miserably. Ondrej > > Aaron Meurer > > > On Fri, Mar 21, 2014 at 10:52 PM, Ondřej Čertík <[email protected]> > wrote: >> On Fri, Mar 21, 2014 at 7:18 PM, Aaron Meurer <[email protected]> wrote: >>> Is this an issue with any subtraction of similar magnitude, or only if >>> it changes the exponent of the number (i.e., it gets closer to 0)? In >>> other words, when you say "magnitude", do you mean "value", or "order >>> of magnitude (log2(x))"? >> >> Roughly speaking, if you have two numbers x*10^a and y*10^b, where 1 >> <= x, y <= 10, then when you subtract them, >> you roughly get only |a-b| correct significant digits. So if a=b, you >> get around 1 significant digit. If a = 1, b = -16, then you retain all >> 16 significant digits. I hope I wrote it up correctly. >> >> http://en.wikipedia.org/wiki/Loss_of_significance >> >> Ondrej >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/sympy. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/CADDwiVD2xp-JEPCBZGG-OL1hbzmu_nGJ%2BS9t4tvQpqdySffP7Q%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CAKgW%3D6Ly4gwj6-MiA9sipbTrwZqAx0FbRe6f_yR%2B%3D6TOHb6peg%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVD%2BpmezgbtaLhR_HgEyiUQx-0yMokOfM3%3Di3TziZu7dkQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
