a field-theory motivated approach to computer algebra

factor_out

Isolate common factors in a sum of products
Given a list of symbols, this algorithm tries to factor those symbols out of terms. As an example,
ex:= a b + a c e + a d;
$$\displaystyle{}a b% +a c e% +a d$$
factor_out(_, $a$);
$$\displaystyle{}a \left(b% +c e% +d\right)$$
If you have non-commuting objects and want to factor out to the right, use the right=True option, as in
{A,B,C,D}::NonCommuting; ex:= A B C D + B A C D; factor_out(ex, $D$, right=True);
$$\displaystyle{}\text{Attached property NonCommuting to }\left[A, B, C, D\right].$$
$$\displaystyle{}A B C D+B A C D$$
A B C D + B A C D
$$\displaystyle{}\left(A B C+B A C\right) D$$
(A B C + B A C) D
In case you are familiar with FORM, factor_out is like its bracket statement. If you add more factors to factor out, it works as in the following example.
ex:= a b + a c e + a c + c e + c d + a d;
$$\displaystyle{}a b% +a c e% +a c% +c e% +c d% +a d$$
factor_out(_, $a, c$);
$$\displaystyle{}a \left(b% +d\right)% +a c \left(e% +1\right)% +c \left(e% +d\right)$$
That is, separate terms will be generated for terms which differ by powers of the factors to be factored out. The algorithm of course also works with indexed objects, as in
ex:= A_{m} B_{m} + C_{m} A_{m};
$$\displaystyle{}A_{m} B_{m}% +C_{m} A_{m}$$
factor_out(_, $A_{m}$);
$$\displaystyle{}A_{m} \left(B_{m}% +C_{m}\right)$$