Ticket #12289: trac_12289-add_algorithm-rebase.patch

File trac_12289-add_algorithm-rebase.patch, 8.3 KB (added by kcrisman, 6 years ago)
  • sage/functions/hyperbolic.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1326180292 -3600
    # Node ID 58ea043327ae35ed900e2b22ae690bf678c839ed
    # Parent  eb5c76b7892dd65758dfd11cdd746a2135bbe022
    trac 12289: add algorithm argument to numerical_approx() and  _evalf_ methods
    
    Add an algorithm keyword argument to the numerical_approx() method of symbolic
    expressions. This argument is passed on to the _evalf_() method of all
    symbolic functions, so the signatures of these functions need to be modified
    as well.
    
    diff --git a/sage/functions/hyperbolic.py b/sage/functions/hyperbolic.py
    a b  
    4343        BuiltinFunction.__init__(self, name, latex_name=latex_name,
    4444                conversions=conversions)
    4545
    46     def _evalf_(self, x, parent):
     46    def _evalf_(self, x, parent=None, algorithm=None):
    4747        """
    4848        EXAMPLES::
    4949
  • sage/functions/other.py

    diff --git a/sage/functions/other.py b/sage/functions/other.py
    a b  
    193193            return x
    194194        return None
    195195
    196     def _evalf_(self, x, parent):
     196    def _evalf_(self, x, parent=None, algorithm=None):
    197197        """
    198198        EXAMPLES::
    199199
     
    954954            return sqrt(pi)*(1-erf(sqrt(y)))
    955955        return None
    956956
    957     def _evalf_(self, x, y, parent=None):
     957    def _evalf_(self, x, y, parent=None, algorithm=None):
    958958        """
    959959        EXAMPLES::
    960960
  • sage/functions/trig.py

    diff --git a/sage/functions/trig.py b/sage/functions/trig.py
    a b  
    154154        """
    155155        BuiltinFunction.__init__(self, "sec", latex_name=r"\sec")
    156156
    157     def _evalf_(self, x, parent=None):
     157    def _evalf_(self, x, parent=None, algorithm=None):
    158158        """
    159159        EXAMPLES::
    160160
     
    245245        """
    246246        BuiltinFunction.__init__(self, "csc", latex_name=r"\csc")
    247247
    248     def _evalf_(self, x, parent=None):
     248    def _evalf_(self, x, parent=None, algorithm=None):
    249249        """
    250250        EXAMPLES::
    251251
     
    365365        """
    366366        return 1 / tan(x)
    367367
    368     def _evalf_(self, x, parent=None):
     368    def _evalf_(self, x, parent=None, algorithm=None):
    369369        """
    370370        EXAMPLES::
    371371
     
    590590        BuiltinFunction.__init__(self, "arccot", latex_name=r'{\rm arccot}',
    591591                conversions=dict(maxima='acot', sympy='acot'))
    592592
    593     def _evalf_(self, x, parent=None):
     593    def _evalf_(self, x, parent=None, algorithm=None):
    594594        """
    595595        EXAMPLES::
    596596
     
    658658        BuiltinFunction.__init__(self, "arccsc", latex_name=r'{\rm arccsc}',
    659659                                   conversions=dict(maxima='acsc'))
    660660
    661     def _evalf_(self, x, parent=None):
     661    def _evalf_(self, x, parent=None, algorithm=None):
    662662        """
    663663        EXAMPLES::
    664664
     
    722722        BuiltinFunction.__init__(self, "arcsec", latex_name=r'{\rm arcsec}',
    723723                                   conversions=dict(maxima='asec'))
    724724
    725     def _evalf_(self, x, parent=None):
     725    def _evalf_(self, x, parent=None, algorithm=None):
    726726        """
    727727        EXAMPLES::
    728728
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    920920        else:
    921921            raise TypeError, "Cannot evaluate symbolic expression to a numeric value."
    922922
    923     cpdef _convert(self, R):
     923    cpdef _convert(self, kwds):
    924924        """
    925925        Convert all the numeric coefficients and constants in this expression
    926926        to the given ring `R`. This results in an expression which contains
     
    930930       
    931931            sage: f = sqrt(2) * cos(3); f
    932932            sqrt(2)*cos(3)
    933             sage: f._convert(RDF)
     933            sage: f._convert({'parent':RDF})
    934934            -1.40006081534
    935             sage: f._convert(float)
     935            sage: f._convert({'parent':float})
    936936            -1.40006081533995
    937937
    938938        There is nothing to convert for variables::
    939939
    940             sage: x._convert(CC)
     940            sage: x._convert({'parent':CC})
    941941            x
    942942
    943943        Note that the output is not meant to be in the in the given ring `R`.
     
    951951           
    952952        ::
    953953
    954             sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert(QQ)
     954            sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert({'parent':QQ})
    955955            0.331368631904900/log(287/50/x^0.900000000000000)^2
    956             sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert(CC)
     956            sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert({'parent':CC})
    957957            0.331368631904900/log(5.74000000000000/x^0.900000000000000)^2
    958958       
    959959        When converting to an exact domain, powers remain unevaluated::
    960960
    961961            sage: f = sqrt(2) * cos(3); f
    962962            sqrt(2)*cos(3)
    963             sage: f._convert(int)
     963            sage: f._convert({'parent':int})
    964964            -0.989992496600445*sqrt(2)
    965965        """
    966         cdef GEx res = self._gobj.evalf(0, {'parent':R})
     966        cdef GEx res = self._gobj.evalf(0, kwds)
    967967        return new_Expression_from_GEx(self._parent, res)
    968968
    969969    def _mpfr_(self, R):
     
    44874487            res._expr = self
    44884488            return res
    44894489
    4490     def _numerical_approx(self, prec=None, digits=None):
     4490    def _numerical_approx(self, prec=None, digits=None, algorithm=None):
    44914491        """
    44924492        Return a numerical approximation this symbolic expression as
    44934493        either a real or complex number with at least the requested
     
    45594559                prec = int((digits+1) * LOG_TEN_TWO_PLUS_EPSILON) + 1
    45604560        from sage.rings.real_mpfr import RealField
    45614561        R = RealField(prec)
     4562        kwds = {'parent': R, 'algorithm': algorithm}
    45624563        cdef Expression x
    45634564        try:
    4564             x = self._convert(R)
     4565            x = self._convert(kwds)
    45654566        except TypeError: # numerical approximation for real number failed
    45664567            pass          # try again with complex
    4567             R = R.complex_field()
    4568             x = self._convert(R)
     4568            kwds['parent'] = R.complex_field()
     4569            x = self._convert(kwds)
    45694570
    45704571        # we have to consider constants as well, since infinity is a constant
    45714572        # in pynac
  • sage/symbolic/function.pyx

    diff --git a/sage/symbolic/function.pyx b/sage/symbolic/function.pyx
    a b  
    10391039            sage: u(y,x)
    10401040            2*y
    10411041
    1042             sage: def evalf_f(self, x, parent=None): return int(6)
     1042            sage: def evalf_f(self, x, **kwds): return int(6)
    10431043            sage: foo = function("foo", nargs=1, evalf_func=evalf_f)
    10441044            sage: foo.__getstate__()
    10451045            (2, 'foo', 1, None, {}, True, [None, "...", None, None, None, None, None, None, None, None, None])
  • sage/symbolic/function_factory.py

    diff --git a/sage/symbolic/function_factory.py b/sage/symbolic/function_factory.py
    a b  
    3434        sage: f._mathematica_init_()
    3535        'Foo'
    3636
    37         sage: def evalf_f(self, x, parent=None): return x*.5r
     37        sage: def evalf_f(self, x, parent=None, algorithm=None): return x*.5r
    3838        sage: g = function_factory('g',1,evalf_func=evalf_f)
    3939        sage: g(2)
    4040        g(2)
     
    111111        'Foo'
    112112
    113113        sage: from sage.symbolic.function import pickle_wrapper
    114         sage: def evalf_f(self, x, parent=None): return 2r*x + 5r
     114        sage: def evalf_f(self, x, parent=None, algorithm=None): return 2r*x + 5r
    115115        sage: def conjugate_f(self, x): return x/2r
    116116        sage: nf = unpickle_function('g', 1, None, None, True, [None, pickle_wrapper(evalf_f), pickle_wrapper(conjugate_f)] + [None]*8)
    117117        sage: nf
     
    237237        sage: bar(x)
    238238        bar(x)
    239239
    240         sage: def evalf_f(self, x, parent=None): return 6
     240        sage: def evalf_f(self, x, parent=None, algorithm=None): return 6
    241241        sage: foo = function("foo", nargs=1, evalf_func=evalf_f)
    242242        sage: foo(x)
    243243        foo(x)
  • sage/symbolic/integration/integral.py

    diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
    a b  
    175175                pass
    176176        return None
    177177
    178     def _evalf_(self, f, x, a, b, parent=None):
     178    def _evalf_(self, f, x, a, b, parent=None, algorithm=None):
    179179        """
    180180        Returns numerical approximation of the integral
    181181