I think Poly.cancel(expr) is what you want.

Aaron Meurer

Sent from my iPod touch.

On Mar 11, 2010, at 9:56 AM, dschult <dsch...@colgate.edu> wrote:

I'm enjoying exploring this package.  Thank you!

I have a question about the "best" way or "standard practice" for
helping sympy simplify expressions.
My output from solving a linear system looks like a quotient with many
terms in the top that multiply
the denominator and thus could be simplified.  I'd like to be able to
simplify those terms.

Here's a simple example:

from symp.abc import *
div=1/(a+b)
expr=(a+a*r+b*r)*div
print expr
(a+a*r+b*r)/(a+b)

I'd like to present this as:  a/(a+b) + r  or similar
Here's my solution:

bplusa=sympy.Symbol('bplusa')
tmp=sympy.expand(expr.subs(b,bplusa-a))
print tmp
r + a/bplusa
print tmp.subs(bplusa,b+a)
r + a/(a+b)

Is this a reasonable approach?  Do others have a better way to do
this--especially one that doesn't rely on knowledge of what the
denominator is so it can be automated?

Thanks,
Dan

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