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

On Tue, Apr 5, 2016 at 1:45 PM, Luv Agarwal <[email protected]> wrote:
> 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
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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.

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAKgW%3D6LYpJ5NuQbjrQH1nRt5N6TNm_t%3DrvP%2BmHueS1NYgkkR5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to