Revision history [back]

How to separate a symbolic expression into sub expressions

I want to separate a symbolic expression into two sub-expressions, one sub-expression with a certain variable and the other without the variable. For example, with the following function, f,

var('x,y')
f=cos(x)*(3*y+2)^2

I want to obtain two sub-expressions as

f1=cos(x)
f2=(3*y+2)^2

How to separate a symbolic expression into sub expressions

I want to separate a symbolic expression into two sub-expressions, one sub-expression with a certain variable and the other without the variable. For example, with the following function, f,

var('x,y')
f=cos(x)*(3*y+2)^2
var('x,y,z')
f=cos(x)*e^(cos(x))*(3*y+z)^2

I want to obtain two sub-expressions as

f1=cos(x)
f2=(3*y+2)^2
f1=cos(x)*e^(cos(x))
f2=(3*y+z)^2

How to separate a symbolic expression into sub expressions

I want to separate a symbolic expression into two sub-expressions, one sub-expression with a certain variable and the other without the variable.

The following example was revised to better demonstrate what I want to achieve

For example, with the following function, f,f,

var('x,y,z')
f=cos(x)*e^(cos(x))*(3*y+z)^2

I want to obtain two sub-expressions as

f1=cos(x)*e^(cos(x))
f2=(3*y+z)^2