Is there a straightforward way to identify when terms are identical within a form and collect them? For example, automatically convert
(u + w + u + u + w)*dx
to
(3*u + 2*w)*dx
The motivation is that automatic differentiation tends to produce huge sums that are a gigantic mess. Often one ends out with lots of duplicate terms. It would be nice to be able to automatically simplify them, similar to how one can simplify() expressions in computer algebra systems like Maple, Mathematica, etc.
If this is not possible with standard methods, what do I need to learn about FEniCS in order to implement this or other computer algebra operations on forms?