rearranging and collecting terms



> This may not help you answering your question, but I hope it helps 
> understanding why the question is non trivial, without confusing you too 
> much.
> 
> Eric Reyssat
>

Thank you Eric for helping me in focusing the issue, you were very clear indeed.
Trying to express my needs more precisely i would say that, given an expression,
- i don't want to factor or expand or reduce it;
- i want to simplify it by collecting terms, if possible;

So i would "just" need a somewhat increased functionality of "collectterms" function. In my humble opinion "collectterms", when called without variables, should:
- parse the given expression for sums, starting from the most internal layer and going up;
- for each sum found, check if there are one or more common terms, as in the following examples (taken from yours);

(%i4) collectterms((3*a*b1-3*a*b2)*x,a);
(%o4) (3*a*b1-3*a*b2)*x
(%i4) collecttermsNEW((3*a*b1-3*a*b2)*x,a);
(%o4) 3*a*(b1-b2)*x

(%i10) collectterms(3*u^3-3*v^3);
(%o10) 3*u^3-3*v^3
(%i10) collecttermsNEW(3*u^3-3*v^3);
(%o10) 3*(u^3-v^3)

(%i11) collectterms((x+2)*(x^2+x+1));
(%o11) (x+2)*(x^2+x+1) 
(%i11) collecttermsNEW((x+2)*(x^2+x+1));
same output, in this case the x in the second factor is not collected because collecttermsNEW should look for "collectables" among ALL terms of the sum

(%i15) collectterms(3*(u-v)*u+3*(u-v)*v);
(%o15) 3*(u-v)*v+3*u*(u-v)
(%i15) collecttermsNEW(3*(u-v)*u+3*(u-v)*v);
(%o15) 3*(u-v)*(v+u)                                         (terms  3  and  u-v  collected)

(%i17) collectterms((2+1)*(u^2-v^2));
(%o17) 3*(u^2-v^2)
(%i17) collecttermsNEW((2+1)*(u^2-v^2));
(%o17) (2+1)*(u^2-v^2)                                       (collecttermsNEW should do only what it says, collect)

(%i18) collectterms((1-x)+x*(1-x));
(%o18) (1-x)*x-x+1
(%i18) collecttermsNEW((1-x)+x*(1-x));
(%o18) (1-x)*(1+x)                                             (term  1-x  collected)

(%i20) collectterms((3*cos(d1)^3-3*cos(d2)^3)*x);
(%o20) (3*cos(d1)^3-3*cos(d2)^3)*x
(%i20) collecttermsNEW((3*cos(d1)^3-3*cos(d2)^3)*x);
(%o20) 3*(cos(d1)^3-cos(d2)^3)*x

Thanks again for your attention.

Mario

P.S. where can i find information about function "collecttermsl", which, as you already noticed, is not documented ?