Index: libfac/charset/alg_factor.cc
===================================================================
--- libfac/charset/alg_factor.cc	(revision e44bd88b22a2439b301aba30f2adc6bb930bbefc)
+++ libfac/charset/alg_factor.cc	(revision 9b25e7ebdfecad841a8035000dec808877e8c27a)
@@ -3,5 +3,5 @@
 // emacs edit mode for this file is -*- C++ -*-
 ////////////////////////////////////////////////////////////
-static char * rcsid = "$Id: alg_factor.cc,v 1.10 2002-08-19 11:11:29 Singular Exp $";
+static char * rcsid = "$Id: alg_factor.cc,v 1.11 2002-10-24 17:22:21 Singular Exp $";
 ////////////////////////////////////////////////////////////
 // FACTORY - Includes
@@ -20,5 +20,5 @@
 #include "alg_factor.h"
 
-//void out_cf(char *s1,const CanonicalForm &f,char *s2);
+void out_cf(char *s1,const CanonicalForm &f,char *s2);
 
 #ifdef ALGFACTORDEBUG
@@ -198,11 +198,11 @@
       Variable X;
       if (getAlgVar(R,X))
-      { 
+      {
         if (R.isUnivariate())
-	  testlist=factorize( R, X );
-	else  
+          testlist=factorize( R, X );
+        else
           testlist= Factorize(R, X, 0);
       }
-      else 
+      else
         testlist= Factorize(R);
       DEBOUTLN(cout, "testlist= ", testlist);
@@ -369,5 +369,5 @@
     return alg_lc(f.LC());
   }
-}  
+}
 
 // the heart of the algorithm: the one from Trager
@@ -400,5 +400,8 @@
 //cout << "alg: "<< X << " mipo=" << getMipo(X,Variable('X')) <<endl;
     if (R.isUnivariate())
+    {
+      DEBOUTLN(cout, "alg_factor: factorize( ", R);
       Factorlist =  factorize( R, X );
+    }
     else
     {
@@ -407,7 +410,9 @@
       CanonicalForm mipo=getMipo(X,XX);
       CFList as(mipo);
+      DEBOUTLN(cout, "alg_factor: newfactoras( ", R);
       Factorlist = newfactoras(R, as , 1);
       #else
       // factor R over k
+      DEBOUTLN(cout, "alg_factor: Factorize( ", R);
       Factorlist = Factorize(R);
       #endif
@@ -417,4 +422,5 @@
   {
     // factor R over k
+    DEBOUTLN(cout, "alg_factor: Factorize( ", R);
     Factorlist = Factorize(R);
   }
@@ -444,13 +450,13 @@
         // undo linear transformation!!!! and then gcd!
         //cout << "algcd(" << g << "," << fnew << ",as" << as << ")" << endl;
-	//out_cf("algcd g=",g,"\n");
-	//out_cf("algcd fnew=",fnew,"\n");
+        //out_cf("algcd g=",g,"\n");
+        //out_cf("algcd fnew=",fnew,"\n");
         //h= algcd(g,fnew, as, oldord);
-	//if (as.length() >1)
+        //if (as.length() >1)
         //  h= algcd(g,fnew, as, oldord);
-	//else
-	  h=alg_gcd(g,fnew,as);
-	//out_cf(" -> algcd=",algcd(g,fnew, as, oldord),"\n");
-	//out_cf(" -> alg_gcd=",alg_gcd(g,fnew,as),"\n");
+        //else
+          h=alg_gcd(g,fnew,as);
+        //out_cf(" -> algcd=",algcd(g,fnew, as, oldord),"\n");
+        //out_cf(" -> alg_gcd=",alg_gcd(g,fnew,as),"\n");
         //cout << "algcd result:" << h << endl;
         DEBOUTLN(cout, "  alg_factor: h= ", h);
@@ -647,10 +653,10 @@
   //CanonicalForm Fgcd= algcd(f,f.deriv(),Astar,gcdord);
   CanonicalForm Fgcd;
-	//if (Astar.length() >1)
+        //if (Astar.length() >1)
         //  Fgcd= algcd(f,f.deriv(),Astar,gcdord);
-	//else
-	  Fgcd= alg_gcd(f,f.deriv(),Astar);
-	//out_cf("algcd:",algcd(f,f.deriv(),Astar,gcdord),"\n");
-	//out_cf("alg_gcd:",alg_gcd(f,f.deriv(),Astar),"\n");
+        //else
+          Fgcd= alg_gcd(f,f.deriv(),Astar);
+        //out_cf("algcd:",algcd(f,f.deriv(),Astar,gcdord),"\n");
+        //out_cf("alg_gcd:",alg_gcd(f,f.deriv(),Astar),"\n");
  // cout << "algcd result:"  << Fgcd << endl;
   if ( Fgcd == 0 ) DEBOUTMSG(cerr, "WARNING: p'th root ?");
@@ -738,4 +744,7 @@
 /*
 $Log: not supported by cvs2svn $
+Revision 1.10  2002/08/19 11:11:29  Singular
+* hannes/pfister: alg_gcd etc.
+
 Revision 1.9  2002/07/30 15:16:19  Singular
 *hannes: fix for alg. extension
Index: libfac/charset/csutil.cc
===================================================================
--- libfac/charset/csutil.cc	(revision e44bd88b22a2439b301aba30f2adc6bb930bbefc)
+++ libfac/charset/csutil.cc	(revision 9b25e7ebdfecad841a8035000dec808877e8c27a)
@@ -2,5 +2,5 @@
 ////////////////////////////////////////////////////////////
 // emacs edit mode for this file is -*- C++ -*-
-static char * rcsid = "$Id: csutil.cc,v 1.7 2002-08-19 11:11:31 Singular Exp $";
+static char * rcsid = "$Id: csutil.cc,v 1.8 2002-10-24 17:22:22 Singular Exp $";
 /////////////////////////////////////////////////////////////
 // FACTORY - Includes
@@ -14,5 +14,5 @@
 // Charset - Includes
 #include "csutil.h"
-//extern void out_cf(char *s1,const CanonicalForm &f,char *s2);
+extern void out_cf(char *s1,const CanonicalForm &f,char *s2);
 extern CanonicalForm alg_lc(const CanonicalForm &f);
 extern int hasAlgVar(const CanonicalForm &f);
@@ -660,5 +660,5 @@
   {
     if (f.mvar()==i.getItem().mvar()) return f;
-  }  
+  }
   if (f.level()>0)
   {
@@ -672,8 +672,20 @@
                       const CFList &as)
 {
+  CanonicalForm f=fff;
+  CanonicalForm g=ggg;
+  f=Prem(f,as);
+  g=Prem(g,as);
+  if ( f.isZero() )
+  {
+    if ( g.lc().sign() < 0 ) return -g;
+    else                     return g;
+  }
+  else  if ( g.isZero() )
+  {
+    if ( f.lc().sign() < 0 ) return -f;
+    else                     return f;
+  }
   //out_cf("alg_gcd(",fff," , ");
   //out_cf("",ggg,")\n");
-  CanonicalForm f=fff;
-  CanonicalForm g=ggg;
   CanonicalForm res;
   // does as appear in f and g ?
@@ -682,7 +694,8 @@
   {
     Variable v=j.getItem().mvar();
-    if (hasVar(f,v)) {has_alg_var=true; break;}
-    if (hasVar(g,v)) {has_alg_var=true; break;}
-  }  
+    if (hasVar(f,v)) {has_alg_var=true; /*break;*/}
+    if (hasVar(g,v)) {has_alg_var=true; /*break;*/}
+    //out_cf("as:",j.getItem(),"\n");
+  }
   if (!has_alg_var)
   {
@@ -698,20 +711,25 @@
       res=gcd(f,g);
     //out_cf("gcd=",res,"\n");
+    //out_cf("of f=",fff," , ");
+    //out_cf("and g=",ggg,"\n");
+
     return res;
-  }  
+  }
 
   int mvf=f.level();
   int mvg=g.level();
   if (mvg > mvf)
-  { 
+  {
     CanonicalForm tmp=f; f=g; g=tmp;
     int tmp2=mvf; mvf=mvg; mvg=tmp2;
-  }  
+  }
   if (g.inBaseDomain() || f.inBaseDomain())
   {
     //printf("const\n");
+    //out_cf("of f=",fff," , ");
+    //out_cf("and g=",ggg,"\n");
     return CanonicalForm(1);
-  }  
-  
+  }
+
   // gcd of all coefficients:
   CFIterator i=f;
@@ -728,6 +746,9 @@
     res=alg_gcd(g,c_gcd,as);
     //out_cf("alg_gcd1=",res,"\n");
+    //out_cf("of f=",fff," , ");
+    //out_cf("and g=",ggg,"\n");
     return res;
   }
+  // now: mvf==mvg, f.level()==g.level()
   if (!c_gcd.inBaseDomain())
   {
@@ -739,24 +760,45 @@
       i++;
     }
-  }  
+  }
 
   f/=c_gcd;
   g/=c_gcd;
 
+  CFList gg;
   CanonicalForm r=1;
-  CFList gg;
-  while (!(r.isZero()))
+  while (1)
   {
     //printf("f.mvar=%d, g.mvar=%d\n",f.level(),g.level());
     gg=as;
-    gg.append(g);
+    if (!g.inCoeffDomain()) gg.append(g);
     //out_cf("Prem(",f," , ");
     //out_cf("",g,")\n");
-    if (g.inCoeffDomain()) r=0;
+    if (g.inCoeffDomain()|| g.isZero())
+    {
+      //printf("in coeff domain:");
+      if (g.isZero()) { //printf("0\n");
+        i=f;
+        CanonicalForm f_gcd=i.coeff(); i++;
+        while( i.hasTerms())
+        {
+          f_gcd=alg_gcd(i.coeff(),f_gcd,as);
+          if (f_gcd.inBaseDomain()) break;
+          i++;
+        }  
+        f/=f_gcd;  
+        return f*c_gcd;
+      }
+      else { //printf("c\n"); 
+	return c_gcd;}
+    }  
     else if (g.level()==f.level()) r=Prem(f,gg);
     else
     {
+      //printf("diff. level: %d, %d\n", f.level(), g.level());
       // g and f have different levels
-      return c_gcd;	
+      //out_cf("c_gcd=",c_gcd,"\n");
+    //out_cf("of f=",fff," , ");
+    //out_cf("and g=",ggg,"\n");
+      return c_gcd;
     }
     //out_cf("->",r,"\n");
@@ -764,10 +806,12 @@
     g=r;
   }
-  if (degree(f,Variable(mvg))==0) 
+  if (degree(f,Variable(mvg))==0)
   {
   // remark: mvf == mvg == f.level() ==g.level()
     //out_cf("c_gcd=",c_gcd,"\n");
+    //out_cf("of f=",fff," , ");
+    //out_cf("and g=",ggg,"\n");
     return c_gcd;
-  }  
+  }
   //out_cf("f=",f,"\n");
   i=f;
@@ -781,5 +825,7 @@
     i++;
   }
+  //out_cf("end-k=",k,"\n");
   f/=k;
+  //out_cf("f/k=",f,"\n");
   res=c_gcd*f;
   CanonicalForm r_lc=alg_lc(res);
@@ -788,9 +834,18 @@
   //res/=r_lc;
   //out_cf("alg_gcd2=",res,"\n");
-  return res;
+  //  out_cf("of f=",fff," , ");
+  //  out_cf("and g=",ggg,"\n");
+  //return res;
+  //if (res.level()<fff.level() && res.level() < ggg.level())
+  //  return alg_gcd(alg_gcd(fff,res,as),ggg,as);
+  //else
+    return res;
 }
 
 /*
 $Log: not supported by cvs2svn $
+Revision 1.7  2002/08/19 11:11:31  Singular
+* hannes/pfister: alg_gcd etc.
+
 Revision 1.6  2002/01/21 09:11:07  Singular
 * hannes: handle empty set in removecontent
