I have an expression in sympy like: m*a+m*b+n*a+n*b
Which could be simplified to (a+b)*(m+n), but if I run simplify() on it I just get the same expression back. Is there any tricks to make it simplify more?
I have tried using collect(expression, expression.free_symbols) but that at best gets me only to a⋅(m + n) + b⋅(m + n). I have thought about trying to run collect on combinations, but that would get out of hand very quickly since i have a lot more variables in my actual equation and also would have to look for subtractions and more. Is there any better way to do it?
Open to suggestions for other libraries also , not fixed on sympy.
Use
factorinstead ofsimplify; the former is very specific in output while the latter is more general in trying to make the expression "nicer".