Use gcfac instead of factor
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
(%i2) load("scifac")$
(%i3) gcfac(expand(tmp));
- b t - a t
(%o3) c d (%e - %e )
You can also use collectterms
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
(%i2) e:expand(tmp);
- b t - a t
(%o2) c d %e - c d %e
(%i3) collectterms(e,c,d);
- b t - a t
(%o3) c d (%e - %e )
You can use the box statement. We use it in a way similar to the answer that uses the substitution t by -t: box(-t) isn't recognized as negative exponent anymore. It can be written in one compound statement. The intermediate result after applying ratsubst may look like a little bit scary:
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
(%i2) rembox(factor(expand(ratsubst(box(-t),-t,tmp))));
- b t - a t
(%o2) c d (%e - %e )
Here are two other ways how you can use the box statements. Both avoid ratsubst but are more complicate in specifying the expressions you want to box.
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
reveal shows us that tmpis a product of 4 factors.
(%i2) reveal(tmp,2);
(%o2) c d Sum(2) Expt
In this situation one can use the substpart command to put a box around the 3rd and 4th factor of the product. The variable piece is a global variable that contains the part of the expression specified by the access path ([3,4])in the substpart command.
(%i3) substpart(box(piece),tmp,[3,4]);
"""""""""""""""""""""""""""""""""
" a t b t (- b t) - a t"
(%o3) c d "(%e - %e ) %e "
"""""""""""""""""""""""""""""""""
Then one expands the the expression. c and d will not be multiplied into the box.
(%i4) expand(%);
"""""""""""""""""""
" - b t - a t"
(%o4) c d "%e - %e "
"""""""""""""""""""
% references the last ouput. After expansion the box will be removed by rembox.
(%i5) rembox(%);
- b t - a t
(%o5) c d (%e - %e )
One can do this with one statement:
(%i6) rembox(expand(substpart(box(piece),tmp,[3,4])));
- b t - a t
(%o6) c d (%e - %e )
Here is another method based on the box statement that will work
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
(%i2) subst([(-a*t)=box((-a*t)),(-b*t)=box((-b*t))],expand(tmp));
""""""" """""""
"- b t" "- a t"
""""""" """""""
(%o2) c d %e - c d %e
(%i3) kill(all);
(%o0) done
(%i1) tmp : c * d * (exp(a*t) - exp(b*t)) * exp(-a*t-b*t);
a t b t (- b t) - a t
(%o1) c d (%e - %e ) %e
(%i2) expand(%);
- b t - a t
(%o2) c d %e - c d %e
(%i3) subst([(-a*t)=box((-a*t)),(-b*t)=box((-b*t))],%);
""""""" """""""
"- b t" "- a t"
""""""" """""""
(%o3) c d %e - c d %e
(%i4) factor(%);
""""""" """""""
"- b t" "- a t"
""""""" """""""
(%o4) c d (%e - %e )
(%i5) rembox(%);
- b t - a t
(%o5) c d (%e - %e )
We can do it in one statement.
(%i6) rembox(factor(subst([(-a*t)=box((-a*t)),(-b*t)=box((-b*t))],expand(tmp))));
- b t - a t
(%o6) c d (%e - %e )