Ask Your Question

Converting expression to list of terms and back

asked 2015-12-26 05:26:15 +0100

pircks gravatar image

Given an expression how would I convert it to a list, and how would I convert a list to an expression?

For example:

x * b * cos(x^3) * sin(b)+b * cos(x)+h * sin(x)

Would convert to:

[x * b * cos(x^3) * sin(b),b * cos(x),h * sin(x)]

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-12-28 09:28:35 +0100

slelievre gravatar image

The methods operator and operands for symbolic expressions are what you are looking for.

sage: b, h, x = var('b h x')
sage: expr = x * b * cos(x^3) * sin(b)+b * cos(x)+h * sin(x)
sage: expr.operator()
<function add_vararg at 0x10abe0aa0>
sage: expr.operands()
[b*x*cos(x^3)*sin(b), b*cos(x), h*sin(x)]
edit flag offensive delete link more


How does this work for converting [bxcos(x^3)sin(b), bcos(x), h*sin(x)] back into an expression, say using addition?

NahsiN gravatar imageNahsiN ( 2017-02-09 00:07:29 +0100 )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


Asked: 2015-12-26 05:22:09 +0100

Seen: 314 times

Last updated: Dec 28 '15