Ask Your Question

# Converting expression to list of terms and back

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 close merge delete

## 1 answer

Sort by ยป oldest newest most voted

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)]

more

## Comments

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

( 2017-02-08 17:07:29 -0600 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2015-12-25 22:22:09 -0600

Seen: 64 times

Last updated: Dec 28 '15