Index: kernel/tgb.cc
===================================================================
--- kernel/tgb.cc	(revision cf2307dc9864719fabb9577ce88d785d229b1eea)
+++ kernel/tgb.cc	(revision d491e3539a2da0402b635d237784feb83bcdc3e8)
@@ -5,5 +5,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: tgb.cc,v 1.34 2005-06-02 12:38:51 bricken Exp $ */
+/* $Id: tgb.cc,v 1.35 2005-07-20 11:12:43 bricken Exp $ */
 /*
 * ABSTRACT: slimgb and F4 implementation
@@ -14,4 +14,6 @@
 #include "tgbgauss.h"
 #include "F4.h"
+#include "gring.h"
+//#include "gr_kstd2.h"
 #include "longrat.h"
 static const int bundle_size=100;
@@ -220,12 +222,33 @@
 //   return pLength(p);
 // }
+
+
+
+
+
+
+
+
 static inline int pQuality(poly p, slimgb_alg* c, int l=-1){
   
   if(l<0)
     l=pLength(p);
-  if(c->is_char0) return pSLength(p,l);
+  if(c->is_char0) {
+    if((pLexOrder) &&(!c->is_homog)){
+      int cs;
+      number coef=pGetCoeff(p);
+      if (rField_is_Q(currRing)){
+	cs=QlogSize(coef);
+      }
+      else
+	cs=nSize(coef);
+      return cs*pELength(p,c,l);
+    }
+    return pSLength(p,l);
+  }
   if((pLexOrder) &&(!c->is_homog)) return pELength(p,c,l);
   return l;
 }
+
 static inline int pTotaldegree_full(poly p){
   int r=0;
@@ -242,7 +265,32 @@
     //case, you have to look on coefs
     int s=0;
-    if (c->is_char0)
+    if (c->is_char0){
       //s=kSBucketLength(bucket,this->p);
+      if((pLexOrder) &&(!c->is_homog)){
+	  int cs;
+	  number coef;
+	  
+	  coef=pGetCoeff(kBucketGetLm(bucket));
+	  //c=nSize(pGetCoeff(kBucketGetLm(b)));
+	 
+	  //c=nSize(pGetCoeff(lm));
+	  if (rField_is_Q(currRing)){
+	    cs=QlogSize(coef);
+	  }
+	  else
+	    cs=nSize(coef);
+	  if (bucket->coef[0]!=NULL){
+	    if (rField_is_Q(currRing)){
+	      int modifier=QlogSize(pGetCoeff(bucket->coef[0]));
+	      cs+=modifier;
+	    }
+	    else{
+	      int modifier=nSize(pGetCoeff(bucket->coef[0]));
+	      cs*=modifier;}
+	  }
+	  return cs*kEBucketLength(this->bucket,this->p,c);
+      }
       s=kSBucketLength(bucket,NULL);
+    }
     else 
     {
@@ -255,4 +303,5 @@
     return s;
 }
+
 // static int guess_quality(const red_object & p, slimgb_alg* c){
 //   //looks only on bucket
@@ -583,4 +632,6 @@
 static void length_one_crit(slimgb_alg* c, int pos, int len)
 {
+  if (c->nc)
+    return;
   if (len==1)
   {
@@ -595,5 +646,6 @@
         c->states[i][pos]=HASTREP;
     }
-    shorten_tails(c,c->S->m[pos]);
+    if (!c->nc)
+      shorten_tails(c,c->S->m[pos]);
   }
 }
@@ -1036,7 +1088,7 @@
       continue;
     } else
-    if ((c->lengths[i]==1) && (c->lengths[j]==1))
+    if ((!c->nc) && (c->lengths[i]==1) && (c->lengths[j]==1))
       c->states[i][j]=HASTREP;
-    else if (pHasNotCF(c->S->m[i],c->S->m[j]))
+    else if ((!(c->nc)) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
     {
       c->easy_product_crit++;
@@ -1165,7 +1217,8 @@
   add_to_reductors(c, h, c->lengths[c->n-1]);
   //i=posInS(c->strat,c->strat->sl,h,0 ecart);
-
-  if (c->lengths[c->n-1]==1)
-    shorten_tails(c,c->S->m[c->n-1]);
+  if (!(c->nc)){
+    if (c->lengths[c->n-1]==1)
+      shorten_tails(c,c->S->m[c->n-1]);
+  }
   //you should really update c->lengths, c->strat->lenS, and the oder of polys in strat if you sort after lengths
 
@@ -1196,9 +1249,4 @@
 
 
-
-
-
-
-
 static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n)
 {
@@ -1219,4 +1267,7 @@
   // BOOLEAN corr=lenS_correct(strat);
   kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/);
+  intset lenSw=strat->lenS;
+  if (strat->lenSw!=NULL)
+    lenSw=strat->lenSw;
   //int max_pos=simple_posInS(strat,P.p);
   loop
@@ -1224,5 +1275,5 @@
 
       j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P);
-      if ((j>=0) && ((!n)||(strat->lenS[j]<=n)))
+      if ((j>=0) && ((!n)||(lenSw[j]<=n)))
       {
 
@@ -1277,4 +1328,5 @@
 
 
+
 static poly redTailShort(poly h, kStrategy strat){
 
@@ -1312,5 +1364,6 @@
 static void c_S_element_changed_hook(int pos, slimgb_alg* c){
   length_one_crit(c,pos, c->lengths[pos]);
-  line_of_extended_prod(pos,c);
+  if (!c->nc)
+    line_of_extended_prod(pos,c);
 }
 class poly_tree_node {
@@ -1527,4 +1580,5 @@
     quick_pop_pair(c);
     if(s->i>=0){
+      //be careful replace_pair use createShortSpoly which is not noncommutative
       //replace_pair(s->i,s->j,c);
     if(s->i==s->j) {
@@ -1534,6 +1588,10 @@
     }
     poly h;
-    if(s->i>=0)
-      h=ksOldCreateSpoly(c->S->m[s->i], c->S->m[s->j], NULL, c->r);
+    if(s->i>=0){
+      if (!c->nc)
+	h=ksOldCreateSpoly(c->S->m[s->i], c->S->m[s->j], NULL, c->r);
+      else
+	h= nc_CreateSpoly(c->S->m[s->i], c->S->m[s->j], NULL, c->r);
+    } 
     else
       h=s->lcm_of_lm;
@@ -1542,8 +1600,9 @@
     number coef;
     int mlen=pLength(h);
-    h=redNF2(h,c,mlen,coef,2);
-    redTailShort(h,c->strat);
-    nDelete(&coef);
-
+    if (!c->nc){
+      h=redNF2(h,c,mlen,coef,2);
+      redTailShort(h,c->strat);
+      nDelete(&coef);
+    }
     free_sorted_pair_node(s,c->r);
     if(!h) continue;
@@ -1648,5 +1707,6 @@
     // delete buf[j];
     //remember to free res here
-    p=redTailShort(p, c->strat);
+    if (!c->nc)
+      p=redTailShort(p, c->strat);
     sbuf[j]=add_to_basis_ideal_quotient(p,-1,-1,c,ibuf+j);
     //sbuf[j]=add_to_basis(p,-1,-1,c,ibuf+j);
@@ -1683,62 +1743,5 @@
 }
 
-static poly redNF (poly h,kStrategy strat, int &len)
-{
-  len=0;
-  if (h==NULL) return NULL;
-  int j;
-
-  len=pLength(h);
-  if (0 > strat->sl)
-  {
-    return h;
-  }
-  LObject P(h);
-  P.SetShortExpVector();
-  P.bucket = kBucketCreate(currRing);
-  kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/);
-  //int max_pos=simple_posInS(strat,P.p);
-  loop
-    {
-      j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P);
-      if (j>=0)
-      {
-        nNormalize(pGetCoeff(P.p));
-#ifdef KDEBUG
-        if (TEST_OPT_DEBUG)
-        {
-          PrintS("red:");
-          wrp(h);
-          PrintS(" with ");
-          wrp(strat->S[j]);
-        }
-#endif
-        number coef=kBucketPolyRed(P.bucket,strat->S[j],
-                                   strat->lenS[j]/*pLength(strat->S[j])*/,
-                                   strat->kNoether);
-        nDelete(&coef);
-        h = kBucketGetLm(P.bucket);
-        if (h==NULL) return NULL;
-        P.p=h;
-        P.t_p=NULL;
-        P.SetShortExpVector();
-#ifdef KDEBUG
-        if (TEST_OPT_DEBUG)
-        {
-          PrintS("\nto:");
-          wrp(h);
-          PrintLn();
-        }
-#endif
-      }
-      else
-      {
-        kBucketClear(P.bucket,&(P.p),&len);
-        kBucketDestroy(&P.bucket);
-        pNormalize(P.p);
-        return P.p;
-      }
-    }
-}
+
 
 #ifdef REDTAIL_S
@@ -1901,4 +1904,6 @@
   
   r=currRing;
+  nc=rIsPluralRing(r);
+  Print("nc %i",nc);
   is_homog=TRUE;
   {
@@ -1934,4 +1939,5 @@
   //(rChar()==0);
   F4_mode=F4;
+  
   if ((!F4_mode)&&(!is_homog) &&(pLexOrder)){
     this->doubleSugar=TRUE;
@@ -2516,4 +2522,6 @@
 //for impl reasons may return false if the the normal product criterion matches
 static inline BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c){
+  if (c->nc)
+    return FALSE;
   if(gcd1==NULL) return FALSE;
         if(gcd2==NULL) return FALSE;
@@ -3071,7 +3079,12 @@
 void reduction_step::reduce(red_object* r, int l, int u){}
 void simple_reducer::target_is_no_sum_reduce(red_object & ro){
-  kBucketPolyRed(ro.bucket,p,
-		 p_len,
-		 c->strat->kNoether);
+  number coef;
+  if (!c->nc)
+    coef=kBucketPolyRed(ro.bucket,p,
+		   p_len,
+		   c->strat->kNoether);
+  else
+    nc_kBucketPolyRed_Z(ro.bucket, p, &coef);
+  nDelete(&coef);
 }
 
@@ -3146,6 +3159,9 @@
       pSetExp(m,i,(pGetExp(r[erg.to_reduce_l].p, i)-pGetExp(red,i)));
     pSetm(m);
-    poly red_cp=ppMult_mm(red,m);
-    
+    poly red_cp;
+    if (!c->nc)
+      red_cp=ppMult_mm(red,m);
+    else
+      red_cp=nc_mm_Mult_p(m, pCopy(red), c->r);
     if(!erg.fromS){
       kBucketInit(r[rn].bucket,red,red_len);
@@ -3153,5 +3169,6 @@
     //now reduce the copy
     //static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n)
-    redTailShort(red_cp,c->strat);
+    if (!c->nc)
+      redTailShort(red_cp,c->strat);
     //number mul;
     // red_len--;
Index: kernel/tgb_internal.h
===================================================================
--- kernel/tgb_internal.h	(revision cf2307dc9864719fabb9577ce88d785d229b1eea)
+++ kernel/tgb_internal.h	(revision d491e3539a2da0402b635d237784feb83bcdc3e8)
@@ -5,5 +5,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: tgb_internal.h,v 1.15 2005-06-01 09:06:04 bricken Exp $ */
+/* $Id: tgb_internal.h,v 1.16 2005-07-20 11:12:43 bricken Exp $ */
 /*
  * ABSTRACT: tgb internal .h file
@@ -130,4 +130,5 @@
   BOOLEAN doubleSugar;
   BOOLEAN F4_mode;
+  BOOLEAN nc;
 };
 class red_object{
Index: kernel/tgb_obsolete.cc
===================================================================
--- kernel/tgb_obsolete.cc	(revision cf2307dc9864719fabb9577ce88d785d229b1eea)
+++ kernel/tgb_obsolete.cc	(revision d491e3539a2da0402b635d237784feb83bcdc3e8)
@@ -1,3 +1,61 @@
 #include "tgb_internal.h"
+static poly redNF (poly h,kStrategy strat, int &len)
+{
+  len=0;
+  if (h==NULL) return NULL;
+  int j;
+
+  len=pLength(h);
+  if (0 > strat->sl)
+  {
+    return h;
+  }
+  LObject P(h);
+  P.SetShortExpVector();
+  P.bucket = kBucketCreate(currRing);
+  kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/);
+  //int max_pos=simple_posInS(strat,P.p);
+  loop
+    {
+      j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P);
+      if (j>=0)
+      {
+        nNormalize(pGetCoeff(P.p));
+#ifdef KDEBUG
+        if (TEST_OPT_DEBUG)
+        {
+          PrintS("red:");
+          wrp(h);
+          PrintS(" with ");
+          wrp(strat->S[j]);
+        }
+#endif
+        number coef=kBucketPolyRed(P.bucket,strat->S[j],
+                                   strat->lenS[j]/*pLength(strat->S[j])*/,
+                                   strat->kNoether);
+        nDelete(&coef);
+        h = kBucketGetLm(P.bucket);
+        if (h==NULL) return NULL;
+        P.p=h;
+        P.t_p=NULL;
+        P.SetShortExpVector();
+#ifdef KDEBUG
+        if (TEST_OPT_DEBUG)
+        {
+          PrintS("\nto:");
+          wrp(h);
+          PrintLn();
+        }
+#endif
+      }
+      else
+      {
+        kBucketClear(P.bucket,&(P.p),&len);
+        kBucketDestroy(&P.bucket);
+        pNormalize(P.p);
+        return P.p;
+      }
+    }
+}
 int find_best(red_object* r,int l, int u, int &w, calc_dat* c){
 
