Ask Your Question

how to append to a symbolic expression in a loop?

asked 2019-04-27 15:18:13 -0600

stockh0lm gravatar image

This must be super basic, but i don't get how to do the classic

for i in list:
    expression = expression + i

symbolically. I want to add new terms to the expression, and the "==" notation does not mash well with that.

An .append() method would make sense, but i was not able to find one.

edit retag flag offensive close merge delete


the = is the solution. I had defined expression as a symbolic variable and then it didn't work.

can you please move this to a proper answer so i can upvote it?

stockh0lm gravatar imagestockh0lm ( 2019-04-27 16:11:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-27 15:31:18 -0600

vdelecroix gravatar image

Could you clarify your question? The following code works

sage: expression =
sage: for i in [SR.var('x'), SR.var('y'), SR.var('z')]:
....:     expression = expression + i
sage: expression
x + y + z
edit flag offensive delete link more

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-04-27 15:18:13 -0600

Seen: 65 times

Last updated: Apr 27 '19