/*-*-MACSYMA-*-*/
if properties(gcfac) = [] then load(scifac)$
/* Since GCFAC has some capability in common with FACTOR and FACTORSUM, we
   begin by illustrating some of this capability with EXP1 :              */
exp1:a*u+a*t*r+a*v*s*x;
gcfac(exp1);
factor(exp1);
factorsum(exp1);
/* Another case where there is some overlap can be seen in EXP2, an
   expression with complex exponents.                               */
exp2:y+a^(r*t*sin(th)/y+u*v+5)+a^(r*t*sin(th)/y+u*v);
gcfac(exp2);
factor(exp2);
factorsum(exp2);
/* GCFAC will sometimes produce results identical with HORNER. */
declare(a,mainvar)$
exp3:a+a^2*u+a^3*b*t+a^4*h^2+a^5+a^6*y+t*z;
horner(exp3);
gcfac(exp3);
remove(a,mainvar)$
/* If there is no knowledge of a MAINVAR, GCFAC can produce results
   superior to HORNER.
   FACTORSUM yields no improvement in this case. */
exp3:ev(exp3);
horner(exp3);
gcfac(exp3);
factorsum(exp3);
/* Next, we embed a subexpression which will factor in an expression which
   will not at top level.  This is illustrated in exp4 :                   */
exp4:a+s*w*x+b*v*z+w*y*r;
gcfac(exp4);
factorsum(exp4);
/* GCFAC can uncover factoring which is not immediately obvious from
   the toplevel expression.  Notice the innermost level of factoring
   in the following example.                                          */
exp5:h*w+p*q*s*t+b*g*q+g*h*p+a*f*g*h;
gcfac(exp5);
factorsum(exp5);
/* A similar effect is illustrated in the following case: */
exp6:h*u^5+r*u^6+s*r*u^8+r*z;
gcfac(exp6);
factorsum(exp6);
/* Repeated pair-factoring on an expression is illustrated in the 
   following two examples.                                        */
exp7:m+n*q+p*u+p*r*q*w+p*r*t*u+p*r*t*v;
gcfac(exp7);
factorsum(exp7);
exp8:-v*w+h*w+r*s*h-r*s*l+r*t*u+r*t*v;
gcfac(exp8);
factorsum(exp8);
/* Unfortunately, if the best ordering for factoring the pairs of terms
   in a sum is not the one generated by the simplifier, GCFAC cannot
   currently deal with it.  The following example demonstrates this
   shortcoming.                                                        */
exp9:b*v+a*u+c*t+a;
gcfac(exp9);
/* While GCFAC can deal with expressions which have not been rationally
   simplified, it is probably best to put expressions in rational form
   before calling GCFAC.  Two forms of EXP10 are used to point out the
   tradeoffs.                                                           */
exp10:r*s/g+t*u/g^2+v*w/g^3-b*g^2;
gcfac(exp10);
exp11:ratsimp(exp10);
gcfac(exp11);
