On Jan 13, 4:32 pm, Ondrej Certik <[email protected]> wrote:
> On Wed, Jan 13, 2010 at 4:30 AM, mindcorrosive <[email protected]> wrote:
> > I've got a problem when evaluating exponents using sympy (class
> > sympy.exp). Small code sample:
>
> >   import sympy as sy
> >   a=sy.exp(10)+sy.exp(20)
> >   print a
> >   >>> exp(10) + exp(20)
>
> > All is well and good, but I'd like to evaluate the expression (which
> > is obviously a constant). I try simply to convert it into a float:
>
> >   b=float(a)
>
> > and get an exception
> >   (trace omitted)
> >   TypeError: unsupported operand type(s) for >>: 'long' and 'float'
>
> > If "a" would have been
>
> >   a=sy.exp(10)
>
> > then the conversion works as expected.
>
> > Perhaps I'm not doing it the right way? I couldn't find an obvious way
> > to handle this.
>
> > If that's relevant, I'm running Py2.4, sympy 0.6.6 on win32.
>
> This works on linux (latest sympy, both python2.4 and 2.6):
>
> In [2]: a = exp(10) + exp(20)
>
> In [3]: a
> Out[3]:
>  10    20
> ℯ   + ℯ
>
> In [4]: float(a)
> Out[4]: 485187221.876
>
> so you found a bug. Could you please post the whole traceback? Let's fix it.
>
> Ondrej

Here's the trace:
---

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy as sy
>>> a=sy.exp(10)+sy.exp(20)
>>> a
exp(10) + exp(20)
>>> float(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python24\Lib\site-packages\sympy\core\basic.py", line 2099,
in __float__
    result = self.evalf()
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 1031,
in Basic_evalf
    result = evalf(x, prec+4, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 326,
in evalf_add
    terms = [evalf(arg, prec+10, options) for arg in args]
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 943,
in <lambda>
    evaluate=False), prec, options),
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 433,
in evalf_pow
    re, im, re_acc, im_acc = evalf(base, prec+5, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 938,
in <lambda>
    C.Exp1 : lambda x, prec, options: (mpf_e(prec), None, prec, None),
  File "C:\Python24\Lib\site-packages\sympy\mpmath\libelefun.py", line
74, in f
    v = fixed(wp)
  File "C:\Python24\Lib\site-packages\sympy\mpmath\libelefun.py", line
59, in g
    return f.memo_val >> (newprec-prec)
TypeError: unsupported operand type(s) for >>: 'long' and 'float'

---
I've tested this on Fedora 12 with Py2.6 and sympy 0.6.3 and it works
as expected. So it seems to be either a Py2.4 bug, or a Windows bug.
(I don't have any other Py versions installed to test for py 2.6)

@Aaron

a.evalf() doesn't work either - the trace is a almost-duplicate of the
one above:
---
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 1031,
in Basic_evalf
    result = evalf(x, prec+4, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 326,
in evalf_add
    terms = [evalf(arg, prec+10, options) for arg in args]
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 943,
in <lambda>
    evaluate=False), prec, options),
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 433,
in evalf_pow
    re, im, re_acc, im_acc = evalf(base, prec+5, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 971,
in evalf
    r = rf(x, prec, options)
  File "C:\Python24\Lib\site-packages\sympy\core\evalf.py", line 938,
in <lambda>
    C.Exp1 : lambda x, prec, options: (mpf_e(prec), None, prec, None),
  File "C:\Python24\Lib\site-packages\sympy\mpmath\libelefun.py", line
74, in f
    v = fixed(wp)
  File "C:\Python24\Lib\site-packages\sympy\mpmath\libelefun.py", line
59, in g
    return f.memo_val >> (newprec-prec)
TypeError: unsupported operand type(s) for >>: 'long' and 'float

---
I'd guess that it's a problem with evalf(), not with sy.exp() itself.
Hope this helps. If you need some extra debugging info, please let me
know.
-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.


Reply via email to