Ticket #12289: trac_12289-evalf_dictionary.patch

File trac_12289-evalf_dictionary.patch, 3.5 KB (added by burcin, 8 years ago)
  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1326177946 -3600
    trac 12289: convert parent keyword argument of _evalf_() to an arbitrary dict
    
    Custom evaluation methods defined in symbolic functions only accept parent as
    a keyword argument. This framework does not allow the user to select different
    systems for the numeric evaluation of a function.
    
    Pynac passes around a Python object around during numeric evaluation. This
    patch, along with the corresponding changes in Pynac, makes this object an
    arbitrary dict. This dictionary can later be used to pass around different
    options relevant for numeric evaluation.
    
    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    789789            ...
    790790            TypeError: Cannot evaluate symbolic expression to a numeric value.
    791791       """
    792         cdef GEx res = self._gobj.evalf(0, R)
     792        cdef GEx res = self._gobj.evalf(0, {'parent':R})
    793793        if is_a_numeric(res):
    794794            return R(py_object_from_numeric(res))
    795795        else:
     
    838838            sage: f._convert(int)
    839839            -0.989992496600445*sqrt(2)
    840840        """
    841         cdef GEx res = self._gobj.evalf(0, R)
     841        cdef GEx res = self._gobj.evalf(0, {'parent':R})
    842842        return new_Expression_from_GEx(self._parent, res)
    843843
    844844    def _mpfr_(self, R):
  • sage/symbolic/pynac.pyx

    diff --git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
    a b  
    10541054    """
    10551055    return py_is_cinteger(x)
    10561056
    1057 cdef public object py_float(object n, object parent) except +:
     1057cdef public object py_float(object n, object kwds) except +:
    10581058    """
    10591059    Evaluate pynac numeric objects numerically.
    10601060
    10611061    TESTS::
    10621062
    10631063        sage: from sage.symbolic.pynac import py_float_for_doctests as py_float
    1064         sage: py_float(I, ComplexField(10))
     1064        sage: py_float(I, {'parent':ComplexField(10)})
    10651065        1.0*I
    1066         sage: py_float(pi, RealField(100))
     1066        sage: py_float(pi, {'parent':RealField(100)})
    10671067        3.1415926535897932384626433833
    10681068        sage: py_float(10, CDF)
    10691069        10.0
    1070         sage: type(py_float(10, CDF))
     1070        sage: type(py_float(10, {'parent':CDF}))
    10711071        <type 'sage.rings.complex_double.ComplexDoubleElement'>
    10721072        sage: py_float(1/2, CC)
    10731073        0.500000000000000
    1074         sage: type(py_float(1/2, CC))
     1074        sage: type(py_float(1/2, {'parent':CC}))
    10751075        <type 'sage.rings.complex_number.ComplexNumber'>
    10761076    """
    1077     return parent(n)
     1077    return kwds['parent'](n)
    10781078
    1079 def py_float_for_doctests(n, prec):
     1079def py_float_for_doctests(n, kwds):
    10801080    """
    10811081    This function is for testing py_float.
    10821082
    10831083    EXAMPLES::
    10841084       
    10851085        sage: from sage.symbolic.pynac import py_float_for_doctests
    1086         sage: py_float_for_doctests(pi, RealField(80))
     1086        sage: py_float_for_doctests(pi, {'parent':RealField(80)})
    10871087        3.1415926535897932384626
    10881088    """
    1089     return py_float(n, prec)
     1089    return py_float(n, kwds)
    10901090
    10911091# TODO: Optimize this
    10921092from sage.rings.real_double import RDF
     
    18611861        pc = c._pynac
    18621862        return pc.object
    18631863
    1864 cdef public object py_eval_constant(unsigned serial, object parent) except +:
     1864cdef public object py_eval_constant(unsigned serial, object kwds) except +:
    18651865    from sage.symbolic.constants import constants_table
    18661866    constant = constants_table[serial]
    1867     return parent(constant)
     1867    return kwds['parent'](constant)
    18681868
    18691869cdef public object py_eval_unsigned_infinity() except +:
    18701870    """