Why `unable to convert (sin(h(x)), cos(h(x))) to a symbolic expression`?

asked 2020-07-01 15:42:06 -0500

martincmartin gravatar image
f(x) = (sin(x), cos(x))
h = function('h', nargs=1)

works fine and produces (sin(h(x)), cos(h(x))). However, if I try to assign that to a function:

g(x) = f(h(x))
TypeError: unable to convert (sin(h(x)), cos(h(x))) to a symbolic expression

How can I compose functions like this?

edit retag flag offensive close merge delete


symbolic_expression(f(h(x))) fails, but symbolic_expression( (sin(h(x)), cos(h(x))) ) succeeds.

martincmartin gravatar imagemartincmartin ( 2020-07-01 16:12:54 -0500 )edit

SageMath version 9.1, Release Date: 2020-05-20

Using Python 3.7.3.

martincmartin gravatar imagemartincmartin ( 2020-07-01 16:13:39 -0500 )edit

Hello! By carefully checking the code for symbolic_expression(), I can see that the problem actually happens when that command sends its output to SR. Here is a simpler example:

f(x) = (x^2, sqrt(x))
h(x) = 2*x^3

If $f$ is a $\mathbb{R}\rightarrow\mathbb{R}$, instead of $\mathbb{R}\rightarrow\mathbb{R}^2$, there is no error message.

I hope this helps to pinpoint the location of the problem!

dsejas gravatar imagedsejas ( 2020-07-01 18:07:24 -0500 )edit

A similar example, but using vector:

f(t) = vector([t, t*t])
TypeError: unable to convert (t, t^2) to a symbolic expression
martincmartin gravatar imagemartincmartin ( 2020-07-08 10:26:51 -0500 )edit