Ticket #12289: trac_12289-add_algorithm_arg.patch

File trac_12289-add_algorithm_arg.patch, 9.0 KB (added by burcin, 8 years ago)
  • sage/functions/hyperbolic.py

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1326180292 -3600
    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  
    6666        """
    6767        BuiltinFunction.__init__(self, "erf", latex_name=r"\text{erf}")
    6868
    69     def _evalf_(self, x, parent):
     69    def _evalf_(self, x, parent=None, algorithm=None):
    7070        """
    7171        EXAMPLES::
    7272
     
    706706            return sqrt(pi)*(1-erf(sqrt(y)))
    707707        return None
    708708
    709     def _evalf_(self, x, y, parent=None):
     709    def _evalf_(self, x, y, parent=None, algorithm=None):
    710710        """
    711711        EXAMPLES::
    712712
  • sage/functions/transcendental.py

    diff --git a/sage/functions/transcendental.py b/sage/functions/transcendental.py
    a b  
    306306            return self._evalf_(x, parent(x))
    307307        return None
    308308           
    309     def _evalf_(self, x, parent=None):
     309    def _evalf_(self, x, parent=None, algorithm=None):
    310310        """
    311311        EXAMPLES::
    312312
  • 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'))
    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  
    795795        else:
    796796            raise TypeError, "Cannot evaluate symbolic expression to a numeric value."
    797797
    798     cpdef _convert(self, R):
     798    cpdef _convert(self, kwds):
    799799        """
    800800        Convert all the numeric coefficients and constants in this expression
    801801        to the given ring `R`. This results in an expression which contains
     
    805805       
    806806            sage: f = sqrt(2) * cos(3); f
    807807            sqrt(2)*cos(3)
    808             sage: f._convert(RDF)
     808            sage: f._convert({'parent':RDF})
    809809            -1.40006081534
    810             sage: f._convert(float)
     810            sage: f._convert({'parent':float})
    811811            -1.40006081533995
    812812
    813813        There is nothing to convert for variables::
    814814
    815             sage: x._convert(CC)
     815            sage: x._convert({'parent':CC})
    816816            x
    817817
    818818        Note that the output is not meant to be in the in the given ring `R`.
     
    826826           
    827827        ::
    828828
    829             sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert(QQ)
     829            sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert({'parent':QQ})
    830830            0.331368631904900/log(287/50/x^0.900000000000000)^2
    831             sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert(CC)
     831            sage: (0.25 / (log(5.74 /x^0.9, 10))^2 / 4)._convert({'parent':CC})
    832832            0.331368631904900/log(5.74000000000000/x^0.900000000000000)^2
    833833       
    834834        When converting to an exact domain, powers remain unevaluated::
    835835
    836836            sage: f = sqrt(2) * cos(3); f
    837837            sqrt(2)*cos(3)
    838             sage: f._convert(int)
     838            sage: f._convert({'parent':int})
    839839            -0.989992496600445*sqrt(2)
    840840        """
    841         cdef GEx res = self._gobj.evalf(0, {'parent':R})
     841        cdef GEx res = self._gobj.evalf(0, kwds)
    842842        return new_Expression_from_GEx(self._parent, res)
    843843
    844844    def _mpfr_(self, R):
     
    39703970            res._expr = self
    39713971            return res
    39723972
    3973     def _numerical_approx(self, prec=None, digits=None):
     3973    def _numerical_approx(self, prec=None, digits=None, algorithm=None):
    39743974        """
    39753975        Return a numerical approximation this symbolic expression as
    39763976        either a real or complex number with at least the requested
     
    40344034                prec = int((digits+1) * 3.32192) + 1
    40354035        from sage.rings.real_mpfr import RealField
    40364036        R = RealField(prec)
     4037        kwds = {'parent': R, 'algorithm': algorithm}
    40374038        cdef Expression x
    40384039        try:
    4039             x = self._convert(R)
     4040            x = self._convert(kwds)
    40404041        except TypeError: # numerical approximation for real number failed
    40414042            pass          # try again with complex
    4042             R = R.complex_field()
    4043             x = self._convert(R)
     4043            kwds['parent'] = R.complex_field()
     4044            x = self._convert(kwds)
    40444045
    40454046        # we have to consider constants as well, since infinity is a constant
    40464047        # in pynac
  • sage/symbolic/function.pyx

    diff --git a/sage/symbolic/function.pyx b/sage/symbolic/function.pyx
    a b  
    846846            sage: class my_function(SymbolicFunction):
    847847            ...  def __init__(self):
    848848            ...     SymbolicFunction.__init__(self, 'foo', nargs=2)
    849             ...  def _evalf_(self, x, y, parent=None):
     849            ...  def _evalf_(self, x, y, parent=None, algorithm=None):
    850850            ...     return x*y*2r
    851851            ...  def _conjugate_(self, x, y):
    852852            ...     return x
     
    970970            sage: u(y,x)
    971971            2*y
    972972
    973             sage: def evalf_f(self, x, parent=None): return int(6)
     973            sage: def evalf_f(self, x, **kwds): return int(6)
    974974            sage: foo = function("foo", nargs=1, evalf_func=evalf_f)
    975975            sage: foo.__getstate__()
    976976            (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