First time here? Check out the FAQ!

Ask Your Question
0

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

asked 5 years ago

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)

Preview: (hide)

Comments

Why do you want to eval a string here?

Iguananaut gravatar imageIguananaut ( 5 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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)
Preview: (hide)
link

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 ( 5 years ago )

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: 5 years ago

Seen: 200 times

Last updated: Dec 05 '19