Ticket #8321: trac_8321_rebase.patch

File trac_8321_rebase.patch, 1.9 KB (added by benjaminfjones, 11 years ago)

rebase of previous patch to 4.7.1

  • sage/symbolic/integration/integral.py

    # HG changeset patch
    # User maldun <domors@gmx.net>
    # Date 1282750756 -7200
    # Node ID 4044231004ff89fb17629b07b04b44ea3a1c8fde
    # Parent  eca423c1b89858a247ed84ea526811121831d62f
    Trac 8321: Numerical evaluation of symbolic integrals with arbitrary precision is now possible, with help of mpmath
    
    diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
    a b  
    176176                pass
    177177        return None
    178178
    179     def _evalf_(self, f, x, a, b, parent=None):
     179    def _evalf_(self, f, x, a, b, parent = None):
    180180        """
    181181        Returns numerical approximation of the integral
    182182       
     
    186186            sage: h = definite_integral(sin(x)*log(x)/x^2, x, 1, 2); h
    187187            integrate(log(x)*sin(x)/x^2, x, 1, 2)
    188188            sage: h.n() # indirect doctest
    189             0.14839875208053...
     189            0.472399177268953
    190190
    191191        TESTS:
    192192
     
    194194
    195195            sage: integrate(x^2.7 * e^(-2.4*x), x, 0, 3).n()
    196196            0.154572952320790
     197
     198        #Check if #8321 is fixed:
     199
     200            sage: d = definite_integral(sin(x)/x^2, x, 1, 2)
     201            sage: d.n(77)
     202            0.4723991772689525199904
    197203        """
    198         from sage.gsl.integration import numerical_integral
    199         # The gsl routine returns a tuple, which also contains the error.
    200         # We only return the result.
    201         return numerical_integral(f, a, b)[0]
     204
     205        import sage.libs.mpmath.all as mpmath
     206
     207        try:
     208            precision = parent.prec()
     209            mpmath.mp.prec = precision
     210        except AttributeError:
     211            precision = mpmath.mp.prec
     212
     213        mp_f = lambda z: \
     214               f(x = mpmath.mpmath_to_sage(z,precision))
     215
     216        return mpmath.call(mpmath.quad,mp_f,[a,b])
    202217
    203218    def _tderivative_(self, f, x, a, b, diff_param=None):
    204219        """