# 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


789  789  ... 
790  790  TypeError: Cannot evaluate symbolic expression to a numeric value. 
791  791  """ 
792   cdef GEx res = self._gobj.evalf(0, R) 
 792  cdef GEx res = self._gobj.evalf(0, {'parent':R}) 
793  793  if is_a_numeric(res): 
794  794  return R(py_object_from_numeric(res)) 
795  795  else: 
… 
… 

838  838  sage: f._convert(int) 
839  839  0.989992496600445*sqrt(2) 
840  840  """ 
841   cdef GEx res = self._gobj.evalf(0, R) 
 841  cdef GEx res = self._gobj.evalf(0, {'parent':R}) 
842  842  return new_Expression_from_GEx(self._parent, res) 
843  843  
844  844  def _mpfr_(self, R): 
diff git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
a

b


1054  1054  """ 
1055  1055  return py_is_cinteger(x) 
1056  1056  
1057   cdef public object py_float(object n, object parent) except +: 
 1057  cdef public object py_float(object n, object kwds) except +: 
1058  1058  """ 
1059  1059  Evaluate pynac numeric objects numerically. 
1060  1060  
1061  1061  TESTS:: 
1062  1062  
1063  1063  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)}) 
1065  1065  1.0*I 
1066   sage: py_float(pi, RealField(100)) 
 1066  sage: py_float(pi, {'parent':RealField(100)}) 
1067  1067  3.1415926535897932384626433833 
1068  1068  sage: py_float(10, CDF) 
1069  1069  10.0 
1070   sage: type(py_float(10, CDF)) 
 1070  sage: type(py_float(10, {'parent':CDF})) 
1071  1071  <type 'sage.rings.complex_double.ComplexDoubleElement'> 
1072  1072  sage: py_float(1/2, CC) 
1073  1073  0.500000000000000 
1074   sage: type(py_float(1/2, CC)) 
 1074  sage: type(py_float(1/2, {'parent':CC})) 
1075  1075  <type 'sage.rings.complex_number.ComplexNumber'> 
1076  1076  """ 
1077   return parent(n) 
 1077  return kwds['parent'](n) 
1078  1078  
1079   def py_float_for_doctests(n, prec): 
 1079  def py_float_for_doctests(n, kwds): 
1080  1080  """ 
1081  1081  This function is for testing py_float. 
1082  1082  
1083  1083  EXAMPLES:: 
1084  1084  
1085  1085  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)}) 
1087  1087  3.1415926535897932384626 
1088  1088  """ 
1089   return py_float(n, prec) 
 1089  return py_float(n, kwds) 
1090  1090  
1091  1091  # TODO: Optimize this 
1092  1092  from sage.rings.real_double import RDF 
… 
… 

1861  1861  pc = c._pynac 
1862  1862  return pc.object 
1863  1863  
1864   cdef public object py_eval_constant(unsigned serial, object parent) except +: 
 1864  cdef public object py_eval_constant(unsigned serial, object kwds) except +: 
1865  1865  from sage.symbolic.constants import constants_table 
1866  1866  constant = constants_table[serial] 
1867   return parent(constant) 
 1867  return kwds['parent'](constant) 
1868  1868  
1869  1869  cdef public object py_eval_unsigned_infinity() except +: 
1870  1870  """ 