Re: [sage-devel] Dealing with libc math differences
On Fri, Aug 12, 2016 at 9:42 AM, Jeroen Demeyerwrote: > On 2016-08-11 12:24, Erik Bray wrote: >> >> In this case the difference is just one ulp. > > > To be more precise: the difference is actually about 0.59 ulp on Cygwin: > > sage: R = RealField(256) > sage: log3_exact = R(3).log() > sage: log3_cygwin = RDF(1.0986122886681096) > sage: (R(log3_cygwin) - log3_exact)/log3_cygwin.ulp() > -0.5914650915268009 Oh nice, I did't know you could do that. In the above I meant the difference between the result I had on Linux and on Cygwin which of course have the same floating point precision, not the difference from the (closer to) exact value. Using the same calculation as above the difference of the Linux result from exact is ~0.41 ulp. All the more reason to just add a small tolerance on this particular test. Thanks again! -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Dealing with libc math differences
On 2016-08-11 12:24, Erik Bray wrote: In this case the difference is just one ulp. To be more precise: the difference is actually about 0.59 ulp on Cygwin: sage: R = RealField(256) sage: log3_exact = R(3).log() sage: log3_cygwin = RDF(1.0986122886681096) sage: (R(log3_cygwin) - log3_exact)/log3_cygwin.ulp() -0.5914650915268009 -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Dealing with libc math differences
On Wed, Aug 10, 2016 at 2:45 PM, Thierry Dumontwrote: > Le 10/08/2016 à 13:38, Erik Bray a écrit : >> Hi all, >> >> Sorry if this has been discussed ad-infinitum before--I looked around >> a bit but didn't find a definitive answer. >> >> I have one (well at least one) test that's failing on Cygwin due to >> tiny difference in the last digit of the result of log(3). >> >> This leads to to several questions: >> >> 1) Is it worth investigating the reason for the difference? >> 2) Is it worth trying to provide a workaround for the difference? >> 3) Or should the test just be updated to ignore the last couple digits >> of the result, and if so how (ellipses?) >> >> Thanks, >> Erik >> > Hello, > > What do you mean by log(3) ? > > Is it log(3.) or log(RDF(3)) ? Really what I meant was `float(log(3))` which I guess in Sage ends up being same as `log(RDF(3))` > With log(RDF(3)), this is classical; changing the library version, or > the compiler version often changes the way some expressions and > functions are computed. As floating point arithmetic is not associative, > this is classical. With log(3.) (RealField()), I don't know. > When we wrote the book "Calcul Mathématique avec Sage", we had this > problem: after some release (some months) some doctests of the chapter > on numerical algebra and floating point numbers failed. The only work > around we found was to truncate the last digit in the output, to try to > test what should remain constant. I have: sage: R = RealField(100) sage: log(R(3)) 1.0986122886681096913952452369 Okay. With Cygwin's libm: sage: float(log(3)) 1.0986122886681096 While on Linux I get: sage: float(log(3)) 1.0986122886681098 It looks like the latter result is properly rounded up (with an error of 1ulp) while my result on Cygwin is just truncated. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Dealing with libc math differences
On Wed, Aug 10, 2016 at 3:08 PM, Jeroen Demeyerwrote: > On 2016-08-10 13:38, Erik Bray wrote: >> >> 1) Is it worth investigating the reason for the difference? > > > No, but it is worth determining how bad the error is. In all cases, I would > say that an error of less than 1 ulp is totally acceptable. If the error is > 1 ulp or more for a basic function (like log) on a reasonable > non-pathological input (like 3.0), I would consider that an upstream bug. > Still, it would not necessarily be a problem for Sage if the error is a few > ulp. In this case the difference is just one ulp. >> 3) Or should the test just be updated to ignore the last couple digits >> of the result, and if so how (ellipses?) > > > The best way is to use # (rel|abs) tol in the doctest. Great, I found that shortly after posting. I think in this case it should probably be fine? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Dealing with libc math differences
On 2016-08-10 13:38, Erik Bray wrote: 1) Is it worth investigating the reason for the difference? No, but it is worth determining how bad the error is. In all cases, I would say that an error of less than 1 ulp is totally acceptable. If the error is 1 ulp or more for a basic function (like log) on a reasonable non-pathological input (like 3.0), I would consider that an upstream bug. Still, it would not necessarily be a problem for Sage if the error is a few ulp. 3) Or should the test just be updated to ignore the last couple digits of the result, and if so how (ellipses?) The best way is to use # (rel|abs) tol in the doctest. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
Re: [sage-devel] Dealing with libc math differences
Le 10/08/2016 à 13:38, Erik Bray a écrit : > Hi all, > > Sorry if this has been discussed ad-infinitum before--I looked around > a bit but didn't find a definitive answer. > > I have one (well at least one) test that's failing on Cygwin due to > tiny difference in the last digit of the result of log(3). > > This leads to to several questions: > > 1) Is it worth investigating the reason for the difference? > 2) Is it worth trying to provide a workaround for the difference? > 3) Or should the test just be updated to ignore the last couple digits > of the result, and if so how (ellipses?) > > Thanks, > Erik > Hello, What do you mean by log(3) ? Is it log(3.) or log(RDF(3)) ? With log(RDF(3)), this is classical; changing the library version, or the compiler version often changes the way some expressions and functions are computed. As floating point arithmetic is not associative, this is classical. With log(3.) (RealField()), I don't know. When we wrote the book "Calcul Mathématique avec Sage", we had this problem: after some release (some months) some doctests of the chapter on numerical algebra and floating point numbers failed. The only work around we found was to truncate the last digit in the output, to try to test what should remain constant. Note that: sage: log(RDF(3)) 1.0986122886681098 sage: log(3.) 1.09861228866811 But: sage: log(RDF(3)).n(prec=53) 1.09861228866811 sage: log(3.).n(prec=53) 1.09861228866811 sage: log(RDF(3))==log(3.) True as we also know that: sage: RDF.prec()==RealField().prec() True So in this case it is only a problem of rounding output. Good luck. Yours t. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout. <>
[sage-devel] Dealing with libc math differences
Hi all, Sorry if this has been discussed ad-infinitum before--I looked around a bit but didn't find a definitive answer. I have one (well at least one) test that's failing on Cygwin due to tiny difference in the last digit of the result of log(3). This leads to to several questions: 1) Is it worth investigating the reason for the difference? 2) Is it worth trying to provide a workaround for the difference? 3) Or should the test just be updated to ignore the last couple digits of the result, and if so how (ellipses?) Thanks, Erik -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.