First time here? Check out the FAQ!

Ask Your Question
0

how to append to a symbolic expression in a loop?

asked 5 years ago

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.

Preview: (hide)

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

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

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

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: 411 times

Last updated: Apr 27 '19