On Sat, Oct 3, 2009 at 1:17 AM, rjf <fate...@gmail.com> wrote: > > Oh, if you are not really evaluating polynomials but just adding up a > long list of numbers, then you can try some kind of compensating sum > e.g. > http://en.wikipedia.org/wiki/Kahan_summation_algorithm > > Though such things are perhaps unnecessary if you are happy with just > increasing the precision of the operations (substantially. Not just a > few bits.) > RJF
Yes, this is just a case of evaluating a sum and there was a bug in the addition code (which I'm entirely to blame for). SymPy's evalf does detect cancellation and compensates by increasing the precision, so it can evaluate expressions in ill-conditioned form (e.g. expanded polynomials) accurately: >>> r = 0.99999 >>> ((x-1)**10).subs(x,r) 9.99999999954490e-51 >>> ((x-1)**10).expand().subs(x,r) # catastrophic cancellation -2.84217094304040e-14 >>> ((x-1)**10).evalf(subs={x:r}) 9.99999999954490e-51 >>> ((x-1)**10).expand().evalf(subs={x:r}) 9.99999999954490e-51 Fredrik --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---