Hi.

The easiest way to do this is to use .args:

In [1]: a = (x + 2)*(x + 1)**2

In [2]: a
Out[2]: 
       2        
(1 + x) ⋅(2 + x)

In [3]: a.args
Out[3]: 
⎛       2       ⎞
⎝(1 + x) , 2 + x⎠

In [4]: a.args[0]
Out[4]: 
       2
(1 + x) 

In [5]: a.args[0].expand()*a.args[1]
Out[5]: 
        ⎛           2⎞
(2 + x)⋅⎝1 + 2⋅x + x ⎠

Aaron Meurer
On Jun 15, 2010, at 12:31 PM, nelson wrote:

> hi all!
>  i am evaluating sympy for a project i'm doing. Basically i want to
> be able to extract a part of an expression, for examplre (x+1)^2 out
> of (x+2)*(x+1)^2 and performing an operation on it. For example,,
> expanding the (x+1)^2 term wold return the expression
>   (x+2)*(x^2+2*x+1)
> 
> is it possibile using sympy? how can i accomplish this task?
> 
> thanks in advance,
>  Andrea
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to