--- yang.rr	2005-08-25 15:34:53.948562920 +0900
+++ yang.rr.new	2005-08-25 15:33:57.124201536 +0900
@@ -498,11 +498,7 @@
 
 /* Ê¬»¶É½¸½Â¿¹à¼°¤Î·¸¿ô¤¿¤Á¤Î gcd */
 def dp_coef_gcd(P) {
-    C = dp_hc(P);
-    for(P = dp_rest(P); P != 0; P = dp_rest(P)) {
-        C = gcd(C, dp_hc(P));
-    }
-    return C;
+    return (P==0)? 0: sdiv(dp_hc(P),dp_hc(dp_prim(P)));
 }
 
 /* Í­Íý·¸¿ôÊ¬»¶É½¸½Â¿¹à¼°¤òÌóÊ¬¤¹¤ë */
@@ -511,32 +507,19 @@
         D = LP[1];
         LP= LP[0];
     }else {
-        return [red2(LP),1];
+        return [LP,1];
     }
 
     if(LP==0) {
         return [0,1];
     }
-    for(C = D, P = LP; P != 0; P = dp_rest(P)) {
-        C = gcd(C, dp_hc(P));
-    }
-    /* C == gcd(D, coefs(P)) */
-    for(Q = 0, P = LP; P != 0; P = dp_rest(P)) {
-        Q += sdiv(dp_hc(P),C)*dp_ht(P);
-    }
-    return [Q, sdiv(D,C)];
+    PRIM = dp_prim((LP));
+    C = red(sdiv(dp_hc(LP), dp_hc(PRIM))/D);
+    return [nm(C)*PRIM, dn(C)];
 }
 
-/* Ê¬»¶É½¸½Â¿¹à¼°¤Î·¸¿ô¤«¤é¶¦ÄÌ°ø»Ò¤ò¤¯¤¯¤ê¤À¤¹ */
 def red2(DP) {
-    if(DP==0) {
-        return 0;
-    }
-    C = dp_coef_gcd(DP);
-    for(Q = 0; DP != 0; DP = dp_rest(DP)) {
-        Q += sdiv(dp_hc(DP),C)*dp_ht(DP);
-    }
-    return Q;
+    return dp_prim(DP);
 }
 
 /* LP ¤¬ LQ ¤Ç´ÊÌó²ÄÇ½¤Ê¤é¤Ð 1 ¤òÊÖ¤¹ */
@@ -558,8 +541,12 @@
         DQ = dp_subd(P,Q);
         PP = red(dp_hc(P)/(dp_hc(Q)));
         F  = nm(PP); G = dn(PP);
+        message(":");
         R  = [G*P - F*multi(DQ,Q),D*G];
+        /* very slow! (Aug. 24, 2005) */
+        message(";");
         R  = red1(R);
+        message("^");
     }
     return R;
 }
@@ -571,8 +558,11 @@
         DQ = dp_subd(P,Q);
         PP = red(dp_hc(P)/act_difference(DQ,dp_hc(Q)));
         F  = nm(PP); G = dn(PP);
+        message(":");
         R  = [G*P - F*multi(DQ,Q),D*G];
+        message(";");
         R  = red1(R);
+        message("^");
     }
     return R;
 }
@@ -589,15 +579,11 @@
 
     Rem = [0,1];
     while (F[0] != 0) {
-/*      message("."); */
         for (U = 0, L = G; L != []; L = cdr(L)) {
             Red = car(L);
             if (reducible(F,Red)) {
-/*              message("("+rtostr(dp_mag(F[0]))+")");
-                if(dp_mag(F[0])>300000) {
-                    F = red1(F);
-                }
-*/
+                message(sprintf("(%a)",dp_mag(F[0])));
+                message("d");
                 F = division(F,Red);
                 if (F[0] == 0) {
                     return Rem;
@@ -611,6 +597,7 @@
             F   = [dp_rest(F[0]), F[1]];
             Rem = add(Rem,H);
         }
+        message("+");
     }
     return Rem;
 }
@@ -644,7 +631,7 @@
 
     SP = sdiv(CQ,GCD)*multi(DP,P)
         -sdiv(CP,GCD)*multi(DQ,Q);
-    return red2(SP);
+    return dp_prim(SP);
 }
 
 /* Í­Íý´Ø¿ô·¸¿ô¤ÎÈùÊ¬/º¹Ê¬ºîÍÑÁÇ¤Î S Â¿¹à¼°¤òµá¤á¤ë¡£
@@ -668,7 +655,7 @@
 
     SP = sdiv(CQ,GCD)*multi_DE(DP,P)
         -sdiv(CP,GCD)*multi_DE(DQ,Q);
-    return red2(SP);
+    return dp_prim(SP);
 }
 
 /* Gebauer-Moeller's Criterion F */
@@ -767,20 +754,23 @@
         Pairs = cdr(Pairs);
         if(MaxSugar < K[2]) {
             MaxSugar=K[2];
-            message(" "+rtostr(MaxSugar)+" ");
+            message(sprintf(" %a ", MaxSugar));
         }
         if (UseSM1) {
             IN = map(dp_dtop,in(G),Vars);
             Sm1_hilbert = sm1.hilbert([IN,Vars]);
-            message("<"+rtostr(Sm1_hilbert)+">");
+            message(sprintf("\n<%a>\n", Sm1_hilbert));
             if (Sm1_hilbert == Hilbert) {
                 break;
             }
         }
         SP = spolynomial(K[0],K[1]);
+        message("s");
         Rem = reduction(SP,G);
         if (Rem[0] != 0) {
             message(".");
+            MAG = dp_mag(Rem[0]);
+            message(sprintf("\n{%a}\n", MAG));
             G = append(G, [Rem]);
             L = [];
             for(I=0; I<N; I++) {
@@ -788,6 +778,7 @@
                     L = cons([G[I],G[N],spair_sugar(G[I],G[N])],L);
                 }
             }
+            message("c");
             Pairs = qsort(append(Pairs, L), spair_compare); /* sort by sugar */
             N++;
         }else {
