Ask Your Question

Converting expression to list of terms and back

asked 2015-12-25 22:26:15 -0600

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 02:28:35 -0600

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

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-25 22:22:09 -0600

Seen: 31 times

Last updated: Dec 28 '15