Ask Your Question
1

type error when using symbolic calculus

asked 2019-05-02 09:05:14 +0200

gus gravatar image

updated 2019-05-03 18:16:14 +0200

I have been using Sage for a few months. Up to now, plotting, polynomials, and arithmetic functions have been running fine.

Now I'm trying to use the symbolic calculation skills of Sage, but ... I am getting the error : "unable to simplify to float approximation" when running, for instance :

var('t')
sin(t)

on a locally hosted jupyter notebook running the SageMath 8.3 kernel. My OS is Ubuntu 18.04.

Same error in pure Sage :

sage: var('t')
t
sage: sin(t)
Traceback (most recent call last)
<ipython-input-3-17829414d33a> in <module>()
----> 1 sin(t)
/xxxxxxxxxxxxxxxxxxxxxx/lib/python2.7/site-packages/sage/symbolic/expression.pyx in
sage.symbolic.expression.Expression.__float__
(build/cythonized/sage/symbolic/expression.cpp:11836)()
    1426                    raise
    1427            except TypeError:
 -> 1428                raise TypeError("unable to simplify to float approximation")
    1429        return ret
    1430

TypeError: unable to simplify to float approximation
sage:
edit retag flag offensive close merge delete

Comments

Everything running fine for a while and then breaking sounds like some other package got upgraded and that broke Sage. Can you reinstall Sage?

John Palmieri gravatar imageJohn Palmieri ( 2019-05-03 06:37:33 +0200 )edit

How was Sage installed? Built from source? Using a binary installer from the SageMath download page? Using apt-get install? Using Conda? Using Docker? Using Nix? Other?

slelievre gravatar imageslelievre ( 2019-05-04 01:05:07 +0200 )edit

hi sorry for the delay, I installed SageMath using apt-get install on Ubuntu 18.04. Actually I did that recently and know my kernel does not even start. I cleaned all pythonpath and pythonrc from my bashrc. I'm posting the error next :

gus gravatar imagegus ( 2019-05-31 20:46:12 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-05-03 19:15:54 +0200

slelievre gravatar image

Was sin redefined, maybe by importing sin from some package, for example by running the following:

sage: from math import sin

Here is a demo using Sage 8.8.beta3 built for Python 3.

$ sage -q
sage: version()
'SageMath version 8.8.beta3, Release Date: 2019-04-18'
sage: sys.version_info[:3]
(3, 7, 3)

The suggested code works fine out of the box:

sage: var('t')
t
sage: sin(t)
sin(t)

Importing the function sin from the Python package math, it now fails as in the question:

sage: from math import sin
sage: var('t')
t
sage: sin(t)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/xxx/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx
in sage.symbolic.expression.Expression.__float__
(build/cythonized/sage/symbolic/expression.cpp:10846)()
   1418         try:
-> 1419             ret = float(self._eval_self(float))
   1420         except TypeError:

/xxx/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx
in sage.symbolic.expression.Expression._eval_self
(build/cythonized/sage/symbolic/expression.cpp:9977)()
   1226         else:
-> 1227             raise TypeError("Cannot evaluate symbolic expression to a numeric value.")
   1228

TypeError: Cannot evaluate symbolic expression to a numeric value.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/xxx/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx
in sage.symbolic.expression.Expression.__float__
(build/cythonized/sage/symbolic/expression.cpp:10908)()
   1421             try:
-> 1422                 c = (self._eval_self(complex))
   1423                 if imag(c) == 0:

/opt/s/sage/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx
in sage.symbolic.expression.Expression._eval_self
(build/cythonized/sage/symbolic/expression.cpp:9977)()
   1226         else:
-> 1227             raise TypeError("Cannot evaluate symbolic expression to a numeric value.")
   1228

TypeError: Cannot evaluate symbolic expression to a numeric value.

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-111-17829414d33a> in <module>()
----> 1 sin(t)

/xxx/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx
in sage.symbolic.expression.Expression.__float__
(build/cythonized/sage/symbolic/expression.cpp:11039)()
   1426                     raise
   1427             except TypeError:
-> 1428                 raise TypeError("unable to simplify to float approximation")
   1429         return ret
   1430

TypeError: unable to simplify to float approximation

If sin was imported from some package like math, Sage's sin can still be used:

sage: from math import sin
sage: var('t')
t
sage: sage.functions.trig.sin(t)
sin(t)
edit flag offensive delete link more

Comments

I did not import anything, however it does seem that the python sin function shadows the sage sin function. I'll try installing sage 8.7 and see if something changes

gus gravatar imagegus ( 2019-05-03 20:25:53 +0200 )edit

One way to work around this situation would be to run from sage.all import * when starting a new session (or you could put that in your ~/.sage/init.sage file -- by the way do you have anything in that file now?).

In any case it's always a good idea to get the latest version of Sage.

slelievre gravatar imageslelievre ( 2019-05-04 01:07:13 +0200 )edit

Have you added anything to your .sage/init.sage file that would cause an issue with sin?

John Palmieri gravatar imageJohn Palmieri ( 2019-05-04 20:42:07 +0200 )edit

Hello, I built Sage from source, now the sine function works and I get a plot. I guess downloading a binary from apt-get is not adapted, I guess it makes sense to compile, seeing so many powerful low level libraries at the base of Sage

gus gravatar imagegus ( 2019-06-01 10:10:56 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2019-05-02 09:05:14 +0200

Seen: 1,015 times

Last updated: May 03 '19