Simplify an expression

23 views
Skip to first unread message

Luv Agarwal

unread,
Apr 5, 2016, 1:46:57 PM4/5/16
to sympy
Hey, I was trying to represent the following expression in more compact form:

expr = a*l**2 + 2*a*l + a + b*conjugate(l)**2 - 2*b*conjugate(l) + b

The above expr can be represented as:

expr = a*(l+1)**2 + b*(conjugate(l)-1)**2

Is there any SymPy function to perform such type of conversions? I am aware of combsimp but it is not able to do this conversion.

Thanks

Aaron Meurer

unread,
Apr 5, 2016, 2:03:56 PM4/5/16
to sy...@googlegroups.com
collect(expr, [a, b], func=factor) will do what you want.

Also see this discussion
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/sympy/-0ASBB5JBG0/1XGNURZZCAAJ.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/b4b26fc2-1c61-4281-aae1-3e70e6c75acb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages