There is no standard function, and as far as I know, no share function,
which does exactly what you want. In particular, the scanmap function (which
is what I think you're thinking of) does one pass over the tree, without
searching among partitions of nodes -- that is, scanmap(q,a+b+c)) =
q(q(a)+q(b)+q(c)); q never sees the partition a+b.
However, it is easy enough to write it yourself, especially if you don't
care about efficiency :-) . However, I don't think it's guaranteed that if
you have a1+...+an and ai+aj => simpx(ai+aj) is a size-reducing
transformation, that an arbitrary sequence of simpx's will get you to the
smallest global result. You might have to do a combinatorial search....
The base transformation you want is, I think, performed by trigrat, which I
suppose you've experimented with?
-s