#8321: numerical integration with arbitrary precision
-------------------------+--------------------------------------------------
   Reporter:  burcin     |          Owner:                      
       Type:  defect     |         Status:  needs_work          
   Priority:  major      |      Milestone:  sage-4.7.2          
  Component:  symbolics  |       Keywords:  numerics,integration
Work_issues:             |       Upstream:  N/A                 
   Reviewer:             |         Author:  Stefan Reiterer     
     Merged:             |   Dependencies:                      
-------------------------+--------------------------------------------------

Comment(by benjaminfjones):

 I tried making !TanhSinhRel the default and including the singleton
 `__new__` code you gave. Here is the resulting class definition:

 {{{
 #!python
 class TanhSinhRel(TanhSinh):
     instance = None
     def __new__(cls, *args, **kwds):
         if not cls.instance:
             cls.instance = super(TanhSinhRel, cls).__new__(cls, *args,
 **kwds)
         return cls.instance

     def estimate_error(self, results, prec, epsilon):
         mag = abs(results[-1])
         if len(results) == 2:
             return abs(results[0]-results[1]) / mag
         try:
             if results[-1] == results[-2] == results[-3]:
                 return self.ctx.zero
             D1 = self.ctx.log(abs(results[-1]-results[-2])/mag, 10)
             D2 = self.ctx.log(abs(results[-1]-results[-3])/mag, 10)
             if D2 == 0:
                 D2 = self.ctx.inf
             else:
                 D2 = self.ctx.one / D2
         except ValueError:
             return epsilon
         D3 = -prec
         D4 = min(0, max(D1**2 * D2, 2*D1, D3))
         return self.ctx.mpf(10) ** int(D4)
 }}}

 I couldn't see a timing difference by adding that code to !TanhSinhRel
 (but maybe this isn't the right place to add it?). Also, I get a
 deprecation warning about arguments passed to `__new__`

 Here are two tests in a row, one shows the deprecation warning, the second
 doesn't:
 {{{
 sage: num_int_test_v2(e**(-x**2)*log(x), 17, 42)
 GSL:                      2.5657285007e-127                    time:
 0.0059130191803
 mpmath:                   2.59225286296247e-127                time:
 0.0680160522461
 /Users/jonesbe/sage/latest/local/bin/sage-ipython:66: DeprecationWarning:
 object.__new__() takes no parameters
 mpmath_rel_tanh (prec=64): 2.56572850056105156e-127             time:
 0.310777187347
 mpmath_rel_tanh (prec=100): 2.5657285005610514829173563973e-127  time:
 0.541303157806
 }}}

 and again in the same session to check if timings have improved:
 {{{
 sage: num_int_test_v2(e**(-x**2)*log(x), 17, 42)
 GSL:                      2.5657285007e-127                    time:
 0.00131511688232
 mpmath:                   2.59225286296247e-127                time:
 0.0299959182739
 mpmath_rel_tanh (prec=64): 2.56572850056105156e-127             time:
 0.211745023727
 mpmath_rel_tanh (prec=100): 2.5657285005610514829173563973e-127  time:
 0.513824939728
 }}}

 The timings do improve after the first call which includes
 `method=TanhSinhRel`, but not dramatically. Am I missing something?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8321#comment:41>
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