Get Symbolics.simplify to work a little bit harder

I’m working with some fairly long expressions, where the structure of each term is reasonably simple, but every term has the same three variables, and then a smattering of one or two other variables, and maybe an Int or Rational. It seems like simplify should pull those three variables out; by any metric I can think of, this would lead to a simpler expression. But that’s not what happens. Here’s a MWE:

julia> using Symbolics

julia> @variables a b c x y z;

julia> simplify(a*b*c*x + a*b*c*y*z)
a*b*c*x + a*b*c*y*z

I would have expected a*b*c*(x + y*z). Note that the same thing happens if I change — say — y to a literal 2, but the expression simplifies nicely if I just remove y. (Though that’s not the expression I actually have.)

This failure to pull out a*b*c gets even more problematic the more terms you have — and I have dozens. Is there anything I can do to get more compact results?

1 Like