factor() doesn't do such "partial factorizations". In general, the notion is not very well defined. See http://stackoverflow.com/a/21067479/161801 for some more discussion on this.
In general, what would you expect SymPy to do? Factor the part of the expression that doesn't include z? If it's that, you can use expr.as_independent(z) to give the parts that have and don't have z. Aaron Meurer On Wed, Aug 6, 2014 at 4:24 PM, Clément Bœsch <[email protected]> wrote: > Hi, > > >>> import sympy as sp > >>> w, x, y, z = sp.symbols("w x y z") > >>> sp.factor(w*x + w*y + z) > w*x + w*y + z > > I would obviously want w*(x+y) + z > > Without the "+ z" part it works as expected: > > >>> sp.factor(w*x + w*y) > w*(x + y) > > I tried several thing, like using deep=True argument, or even hinting by > providing the answer: > > >>> sp.factor(w*x + w*y + z, deep=True) > w*x + w*y + z > >>> sp.factor(w*(x + y) + z) > w*x + w*y + z > > Strangely, if I mix both it suddenly works: > > >>> sp.factor(w*(x + y) + z, deep=True) > w*(x + y) + z > > But this obviously doesn't help me. > > I considered parsing my expression myself at this point, but I'd really > love to > avoid doing this... > > Regards, > > -- > 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 http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/d59be48c-a760-4e95-9188-1890d0e6dda6%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/d59be48c-a760-4e95-9188-1890d0e6dda6%40googlegroups.com?utm_medium=email&utm_source=footer> > . > 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 http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BcFdMng8pN%2BYFsNZqDdLLHKdQYBzogso3dLbT%3Dkk-WOw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
