Ask Your Question
0

how to append to a symbolic expression in a loop?

asked 2019-04-27 22:18:13 +0100

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

Comments

the = SR.zero() 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 23:11:59 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-04-27 22:31:18 +0100

vdelecroix gravatar image

Could you clarify your question? The following code works

sage: expression = SR.zero()
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

Stats

Asked: 2019-04-27 22:18:13 +0100

Seen: 384 times

Last updated: Apr 27 '19