#12557: RDF(1e-17).log() gives NaN
--------------------------------+-------------------------------------------
   Reporter:  mariah            |          Owner:  AlexGhitza
       Type:  defect            |         Status:  new       
   Priority:  minor             |      Milestone:  sage-5.0  
  Component:  basic arithmetic  |       Keywords:            
Work_issues:                    |       Upstream:  N/A       
   Reviewer:                    |         Author:            
     Merged:                    |   Dependencies:            
--------------------------------+-------------------------------------------

Comment(by dsm):

 The problem is this branch:

 {{{
     if self._value < 2:
         if self._value == 0:
             return RDF(-1)/RDF(0)
         if self._value < 0:
             return RDF(0)/RDF(0)
         sig_on()
         a = self._new_c(gsl_sf_log_1plusx(self._value - 1) / log_of_base)
         sig_off()
         return a
 }}}

 When self._value is small enough, self._value-1 becomes -1 and we get the
 log of 0. Frankly, even before this happens we lose precision
 unnecessarily:

 {{{
 sage: [(log(x.n(1000))-RDF(x).log().n()).n(53) for x in [1/10**i for i in
 [0..17]]]
 [0.000000000000000, 0.000000000000000, -8.88178419700125e-16,
 -8.88178419700125e-16,
 1.10134124042816e-13, 4.55102622254344e-12, -2.87556645162113e-11,
 5.26355847796367e-10,
 -5.02475927532942e-9, 2.82819314634253e-8, -8.27403674463767e-8,
 -8.27403674463767e-8,
 0.0000221219648111060, -0.000310896853829234, 0.000799597430194865,
 0.000799597430194865,
 -0.104560918227634, NaN]
 }}}


 Probably the simplest fix is to use the 1+x trick only when the argument
 is actually close to 1. Simply changing the condition to

     if 0.5 <= self._value < 2:

 will change the above results to the less exciting but more useful

 {{{
 [0.000000000000000, 0.000000000000000, 0.000000000000000,
 0.000000000000000, 0.000000000000000,
  0.000000000000000, 0.000000000000000, 0.000000000000000,
 0.000000000000000, 0.000000000000000,
 0.000000000000000, 0.000000000000000, 0.000000000000000,
 0.000000000000000, 0.000000000000000,
 .000000000000000, 0.000000000000000, 0.000000000000000]
 }}}

 Any objections?  Performance seems similar for values which previously
 would have used gsl_sf_log_1plusx but now simply use gsl_sf_log.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12557#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to