Ask Your Question
0

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')
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 15:07:11 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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:

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 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

Stats

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

Seen: 146 times

Last updated: Dec 05 '19