Zoho
unread,May 16, 2008, 11:00:01 AM5/16/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
Hello:
I would like convert a sympy real to an mpf. Is this possible? I am on
Debian sid with the latest packages.
In [1]: import sympy as syp
In [2]: import mpmath as mp
In [3]: x = syp.symbols('x')
In [4]: a = syp.diff(syp.exp(1.0/4*x**2), x, 2).subs('x', 0)
In [5]: type(a)
Out[5]: <class 'sympy.core.numbers.Real'>
In [6]: a = syp.diff(syp.exp(1.0/4*x**2), x, 2).subs('x', 0).evalf()
In [7]: type(a)
Out[7]: <class 'sympy.core.numbers.Real'>
In [8]: a = float(syp.diff(syp.exp(1.0/4*x**2), x, 2).subs('x', 0))
In [9]: type(a)
Out[9]: <type 'float'>
In [10]: a = mp.mpf(syp.diff(syp.exp(1.0/4*x**2), x, 2).subs('x', 0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/home/brent/<ipython console> in <module>()
/var/lib/python-support/python2.5/mpmath/mptypes.py in __new__(cls,
val)
242 raise ValueError
243 else:
--> 244 return make_mpf(fpos(mpf_convert_arg(val), gp,
gr))
245
246 man_exp = property(lambda self: self._mpf_[1:3])
/var/lib/python-support/python2.5/mpmath/mptypes.py in
mpf_convert_arg(x)
201 if isinstance(x, basestring): return from_str(x, gp, gr)
202 if hasattr(x, '_mpf_'): return x._mpf_
--> 203 raise TypeError("cannot create mpf from " + repr(x))
204
205 def mpf_convert_rhs(x):
TypeError: cannot create mpf from 0.5