Index: kernel/kutil.cc
===================================================================
--- kernel/kutil.cc	(revision 822aa3ad9062852dd98789a4bd54970e85327ef2)
+++ kernel/kutil.cc	(revision 9f17c9f13b717a920473663201c9bb8a3daa9f77)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: kutil.cc,v 1.134 2009-04-10 19:01:11 motsak Exp $ */
+/* $Id: kutil.cc,v 1.135 2009-04-23 17:28:07 Singular Exp $ */
 /*
 * ABSTRACT: kernel: utils for kStd
@@ -169,5 +169,5 @@
                            q,currRing,
                            currRing->real_var_start, currRing->real_var_end))
-        return 0; 
+        return 0;
       return pLmCmp(q,p); // ONLY FOR GLOBAL ORDER!
     }
@@ -1557,8 +1557,8 @@
         else
         {
-          Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing); 
+          Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
                 nc_CreateShortSpoly(strat->S[i], p, currRing);
 
-          assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used    
+          assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
           pNext(Lp.p) = strat->tail; // !!!
         }
@@ -1566,13 +1566,13 @@
       else
       {
-        Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing); 
+        Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
               nc_CreateShortSpoly(strat->S[i], p, currRing);
 
-        assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used    
+        assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
         pNext(Lp.p) = strat->tail; // !!!
 
       }
 
-      
+
 #if MYTEST
       if (TEST_OPT_DEBUG)
@@ -1582,6 +1582,6 @@
         PrintS("SPoly: "); pWrite(Lp.p);
       }
-#endif      
-      
+#endif
+
     }
     else
@@ -1597,5 +1597,5 @@
         PrintS("commutative SPoly: "); pWrite(Lp.p);
       }
-#endif      
+#endif
 
       }
@@ -1627,8 +1627,8 @@
     if (
         (!rIsPluralRing(currRing))
-//      ||  (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))         
+//      ||  (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
        )
     {
-      assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used    
+      assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
       pNext(Lp.p) = strat->tail; // !!!
     }
@@ -2006,5 +2006,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 Print("chain-crit-part: S[%d]=",j); 
+                 Print("chain-crit-part: S[%d]=",j);
                  p_wrp(strat->S[j],currRing);
                  Print(" divide B[%d].lcm=",i);
@@ -2041,5 +2041,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 PrintS("chain-crit-part: pCompareChainPart p="); 
+                 PrintS("chain-crit-part: pCompareChainPart p=");
                  p_wrp(p,currRing);
                  Print(" delete L[%d]",j);
@@ -2072,5 +2072,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 Print("chain-crit-part: sugar B[%d].lcm=",j); 
+                 Print("chain-crit-part: sugar B[%d].lcm=",j);
                  p_wrp(strat->B[j].lcm,currRing);
                  Print(" delete B[%d]",i);
@@ -2085,5 +2085,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 Print("chain-crit-part: sugar B[%d].lcm=",i); 
+                 Print("chain-crit-part: sugar B[%d].lcm=",i);
                  p_wrp(strat->B[i].lcm,currRing);
                  Print(" delete B[%d]",j);
@@ -2115,5 +2115,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 PrintS("chain-crit-part: sugar:pCompareChainPart p="); 
+                 PrintS("chain-crit-part: sugar:pCompareChainPart p=");
                  p_wrp(p,currRing);
                  Print(" delete L[%d]",j);
@@ -2141,5 +2141,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 Print("chain-crit-part: equal lcm B[%d].lcm=",j); 
+                 Print("chain-crit-part: equal lcm B[%d].lcm=",j);
                  p_wrp(strat->B[j].lcm,currRing);
                  Print(" delete B[%d]\n",i);
@@ -2168,5 +2168,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 PrintS("chain-crit-part: pCompareChainPart p="); 
+                 PrintS("chain-crit-part: pCompareChainPart p=");
                  p_wrp(p,currRing);
                  Print(" delete L[%d]",j);
@@ -2232,5 +2232,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 PrintS("chain-crit-part: divisible_by p="); 
+                 PrintS("chain-crit-part: divisible_by p=");
                  p_wrp(p,currRing);
                  Print(" delete L[%d]",l);
@@ -2245,5 +2245,5 @@
               if(TEST_OPT_DEBUG)
               {
-                 PrintS("chain-crit-part: divisible_by(2) p="); 
+                 PrintS("chain-crit-part: divisible_by(2) p=");
                  p_wrp(p,currRing);
                  Print(" delete L[%d]",i);
@@ -2320,5 +2320,5 @@
     }
 
-    if (new_pair) 
+    if (new_pair)
     {
 #ifdef HAVE_RATGRING
@@ -3112,5 +3112,5 @@
 
   if (strat->noClearS) return;
-  
+
 //   #ifdef HAVE_PLURAL
 /*
@@ -3128,12 +3128,12 @@
         k--;
       }
-      
+
       j++;
     }
-  }    
+  }
   else
-*/  
-//   #endif // ??? Why was the following cancelation disabled for non-commutative rings? 
-  { 
+*/
+//   #endif // ??? Why was the following cancelation disabled for non-commutative rings?
+  {
     j=pos;
     loop
@@ -4542,7 +4542,7 @@
       if (cnt==0)
       {
-        cnt=REDTAIL_CANONICALIZE; 
-        poly tmp=Ln.CanonicalizeP(); 
-        if (normalize) 
+        cnt=REDTAIL_CANONICALIZE;
+        poly tmp=Ln.CanonicalizeP();
+        if (normalize)
         {
           Ln.Normalize();
@@ -4887,5 +4887,5 @@
   /*- test, if a unit is in F -*/
 
-  if ((strat->Ll>=0) 
+  if ((strat->Ll>=0)
 #ifdef HAVE_RINGS
        && nIsUnit(pGetCoeff(strat->L[strat->Ll].p))
@@ -5524,9 +5524,9 @@
   assume(!p.is_normalized || nIsOne(pGetCoeff(p.p)));
 
-#ifdef KDEBUG  
+#ifdef KDEBUG
   // do not put an LObject twice into T:
   for(i=strat->tl;i>=0;i--)
   {
-    if (p.p==strat->T[i].p) 
+    if (p.p==strat->T[i].p)
     {
       printf("already in T at pos %d of %d, atT=%d\n",i,strat->tl,atT);
@@ -5534,5 +5534,5 @@
     }
   }
-#endif  
+#endif
   strat->newt = TRUE;
   if (atT < 0)
@@ -5943,5 +5943,5 @@
 {
   int i;
-  int low = (pOrdSgn == 1 ? 1 : 0);
+  int low = (((pOrdSgn==1) && (strat->fromQ==NULL) ? 1 : 0);
   LObject L;
 
@@ -5964,4 +5964,7 @@
   for (i=strat->sl; i>=low; i--)
   {
+    int end_pos=strat->sl;
+    if ((strat->fromQ!=NULL) && (strat->fromQ[i])) continue; // do not reduce Q_i
+    if (strat->ak==0) end_pos=i-1;
     TObject* T_j = strat->s_2_t(i);
     if (T_j != NULL)
@@ -5970,5 +5973,5 @@
       poly p;
       if (pOrdSgn == 1)
-        strat->S[i] = redtailBba(&L, i-1, strat, withT);
+        strat->S[i] = redtailBba(&L, end_pos, strat, withT);
       else
         strat->S[i] = redtail(&L, strat->sl, strat);
@@ -5989,5 +5992,5 @@
       assume(currRing == strat->tailRing);
       if (pOrdSgn == 1)
-        strat->S[i] = redtailBba(strat->S[i], i-1, strat, withT);
+        strat->S[i] = redtailBba(strat->S[i], end_pos, strat, withT);
       else
         strat->S[i] = redtail(strat->S[i], strat->sl, strat);
@@ -6019,7 +6022,7 @@
   else
     scComputeHCw(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
-#else    
+#else
   scComputeHC(strat->Shdl,NULL,strat->ak,strat->kHEdge, strat->tailRing);
-#endif  
+#endif
   if (strat->t_kHEdge != NULL) p_LmFree(strat->t_kHEdge, strat->tailRing);
   if (strat->tailRing != currRing)
@@ -6516,5 +6519,5 @@
 {
   /* assume: p is completely in currRing */
-  /* produces an object with LM in curring 
+  /* produces an object with LM in curring
      and TAIL in tailring */
   if (pNext(p)!=NULL)
@@ -6585,5 +6588,5 @@
     /* creates LObject from the poly in currRing */
   /* actually put p into L.p and make L.t_p=NULL : does not work */
- 
+
 //}
 
@@ -6615,5 +6618,5 @@
 //     {
 //       p = p_ShallowCopyDelete(h.p, (strat->tailRing != NULL ? strat->tailRing : currRing), strat->tailBin);
-//     } 
+//     }
 //     return(p);
 //   }
@@ -6773,9 +6776,9 @@
   /* these vars hold for all shifts of s[i] */
   int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
-  
+
   int qfromQ;
   if (strat->fromQ != NULL)
   {
-    qfromQ = strat->fromQ[i]; 
+    qfromQ = strat->fromQ[i];
   }
   else
@@ -6791,8 +6794,8 @@
   enterOnePairShift(qq, p, ecart, isFromQ, strat, -1, ecartq, qfromQ, j, i, uptodeg, lV);
 
-  for (j=1; j<= toInsert; j++) 
+  for (j=1; j<= toInsert; j++)
   {
     //    q = pLPshift(strat->S[i],j,uptodeg,lV);
-    q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing); 
+    q = p_LPshiftT(qq, j, uptodeg, lV, strat, currRing);
     //    q = p_mLPshift(qq,j,uptodeg,lV,currRing); // lm in currRing, shift this monomial
     //    s = p_LPshift(pNext(qq), j, uptodeg, lV, strat->tailRing); // from tailRing
@@ -6853,5 +6856,5 @@
   /* these vars hold for all shifts of s[i] */
   int ecartq = 0; //Hans says it's ok; we're in the homog case, no ecart
-  int qfromQ = 0; // strat->fromQ[i]; 
+  int qfromQ = 0; // strat->fromQ[i];
 
   for (; j<= toInsert; j++)
@@ -6898,5 +6901,5 @@
 //       wrp(q); //      wrp(pHead(q));
 //       PrintS(", p = ");
-//       wrp(p); //wrp(pHead(p)); 
+//       wrp(p); //wrp(pHead(p));
 //       PrintLn();
     }
@@ -6933,5 +6936,5 @@
       wrp(q); //      wrp(pHead(q));
       PrintS(", p = ");
-      wrp(p); //wrp(pHead(p)); 
+      wrp(p); //wrp(pHead(p));
       PrintLn();
     }
@@ -7108,5 +7111,5 @@
 //     else
 //     {
-    
+
     /* ksCreateShortSpoly needs two Lobject-kind presentations */
     /* p is already in this form, so convert q */
@@ -7139,6 +7142,6 @@
     /*- the pair (S[i],p) enters B -*/
     /* both of them should have their LM in currRing and TAIL in tailring */
-    Lp.p1 = q;  // already in the needed form 
-    Lp.p2 = p; // already in the needed form 
+    Lp.p1 = q;  // already in the needed form
+    Lp.p2 = p; // already in the needed form
 
     if ( !rIsPluralRing(currRing) )
@@ -7149,5 +7152,5 @@
     if ( (atR >= 0) && (shiftcount==0) && (ifromS >=0) )
     {
-      Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS]; 
+      Lp.i_r1 = kFindInT(Lp.p1,strat); //strat->S_2_R[ifromS];
       Lp.i_r2 = atR;
     }
@@ -7300,5 +7303,5 @@
   if (atT < 0)
     atT = strat->posInT(strat->T, strat->tl, p);
-  
+
   /* can call enterT in a sequence, e.g. */
 
@@ -7309,5 +7312,5 @@
   {
     qq      = p; //qq.Copy();
-    qq.p    = NULL; 
+    qq.p    = NULL;
     qq.max  = NULL;
     qq.t_p = p_LPshift(p_Copy(p.t_p,strat->tailRing), i, uptodeg, lV, strat->tailRing); // direct shift
