Ask Your Question

Revision history [back]

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)