Ask Your Question

How to use a string in a symbolic expression with SageMath?

asked 2019-12-05 14:57:48 +0200

JarenK gravatar image

I would like to use a string as part of a symbolic expression. For instance:

function('P') var('x1 x2 x3 y1 y2 y3')
st = eval('y1,0,1')

How could I use st which is a string in the symbolic expression sum?

I want the same result as if I had typed directly:


edit retag flag offensive close merge delete


Why do you want to eval a string here?

Iguananaut gravatar imageIguananaut ( 2019-12-06 15:07:11 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-05 20:45:39 +0200

rburing gravatar image

I would re-evaluate whether using strings is really what you want to do; probably whatever problem you have can be solved in a better way. Nevertheless, it is possible:

var('x1 x2 x3 y1 y2 y3')
st = eval('y1,0,1')
edit flag offensive delete link more



Let's go ahead and give them the "proper" way of doing this which would be simply:

st = (y1,0,1)

The eval there is completely superfluous :)

Iguananaut gravatar imageIguananaut ( 2019-12-06 15:06:49 +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

1 follower


Asked: 2019-12-05 14:57:48 +0200

Seen: 157 times

Last updated: Dec 05 '19