Ask Your Question
0

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

asked 2019-12-05 07:57:48 -0600

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')
sum(P(x1,y1,y2,y3),st)

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:

sum(P(x1,y1,y2,y3),y1,0,1)

edit retag flag offensive close merge delete

Comments

Why do you want to eval a string here?

Iguananaut gravatar imageIguananaut ( 2019-12-06 08:07:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-12-05 13:45:39 -0600

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:

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

Comments

1

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

st = (y1,0,1)
sum(P(x1,y1,y2,y3),*st)

The eval there is completely superfluous :)

Iguananaut gravatar imageIguananaut ( 2019-12-06 08:06:49 -0600 )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

Stats

Asked: 2019-12-05 07:57:48 -0600

Seen: 47 times

Last updated: Dec 05 '19