My favorites | Sign in
Project Logo
                
New issue | Search
for
| Advanced search | Search tips
Issue 154: mpmathify should work for complex sympy numbers
1 person starred this issue and may be notified of changes. Back to list
Status:  Accepted
Owner:  Vinzent.Steinberg
Priority-Medium


Sign in to add a comment
 
Reported by Vinzent.Steinberg, Jul 30, 2009
>>> from sympy import *
>>> mpmath.mpmathify(S(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/mpmath/mptypes.py", line 363, in convert
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from 1

Let's also make sure that sympy matrices are supported.
Comment 1 by fredrik.johansson, Jul 31, 2009
Are you working on this?
Comment 2 by Vinzent.Steinberg, Aug 05, 2009
I was not, but I probably will do it soon, as this is imho important and easy to fix.
Comment 3 by Vinzent.Steinberg, Aug 06, 2009
Should this be fixed in sympy (adding an _mpmath_ attribute, for which mpmathify is
already checking) or in mpmath?
Comment 4 by fredrik.johansson, Aug 06, 2009
Adding _mpmath_ to sympy is certainly preferrable, as otherwise mpmath will need to
worry about sympy internals.
Comment 5 by Vinzent.Steinberg, Aug 06, 2009
There is already Number._as_mpf_val(prec), which should do the job. Which precision
should be used when converting to mpf? Should mpmathify convert sympy integers to
Python integers?
Comment 6 by fredrik.johansson, Aug 06, 2009
> which should do the job. Which precision should be used when converting to mpf?

What do you mean? mpmathify calls x._mpmath_ with the appropriate precision.

> Should mpmathify convert sympy integers to Python integers?

The easiest solution might be to add an _mpf_ property to sympy integers (not sure if
that will break anything).
Comment 7 by Vinzent.Steinberg, Aug 06, 2009
So why not rename _as_mpf_val to _mpmath_? (Should work for Rational.)

I'd add just add an _mpmath_ property to Integer.
Comment 8 by Vinzent.Steinberg, Aug 13, 2009
I sent a patch to the sympy list. What about complex numbers? This has to be
implemented in mpmath, unless Add grows an _mpmath_ method.
Comment 10 by Vinzent.Steinberg, Aug 14, 2009
It fixed it in sympy HEAD, and added support in mpmathify for matrices.
I'm not sure how to support complex numbers.
Summary: mpmathify should work for complex sympy numbers
Labels: -Priority-High Priority-Medium
Comment 11 by fredrik.johansson, Aug 22, 2009
Easiest way to enable conversion for any SymPy object is to add _mpmath_ to Basic and
have it call evalf.
Sign in to add a comment

Hosted by Google Code