Index: kernel/f5gb.cc
===================================================================
--- kernel/f5gb.cc	(revision 7a8ca6fdf98e2078621ae6ac00ff9481cab3def8)
+++ kernel/f5gb.cc	(revision 61944d0a0689203f1f85c43b1610be266ec31371)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.cc,v 1.33 2009-02-23 14:28:38 ederc Exp $ */
+/* $Id: f5gb.cc,v 1.34 2009-02-26 09:01:52 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -73,4 +73,6 @@
     //Print("%p\n",gPrev->getFirst());
     //pWrite(gPrev->getFirst()->getPoly());
+    poly tempNF =   kNF(gbPrev,currQuotient,f_i);
+    f_i         =   tempNF;
     gPrev->insert(ONE,i,f_i);
     // tag the first element in gPrev of the current index for findReductor()
@@ -183,10 +185,12 @@
         u2 = pDivide(lcm, pHead(temp->getPoly()));
         pSetCoeff(u2,nOne);
-        //Print("IN CRITPAIRS\n");
-        //pWrite(u1);
-        //Print("1st ELEMENT: ");
-        //pWrite(newElement->getPoly());
-        //Print("2nd ELEMENT: ");
-        //pWrite(temp->getPoly());
+        //if(gPrev->getLast()->getIndex()==5) {
+        //    Print("IN CRITPAIRS\n");
+        //    pWrite(u1);
+        //    Print("1st ELEMENT: ");
+        //    pWrite(newElement->getPoly());
+        //    Print("2nd ELEMENT: ");
+        //    pWrite(temp->getPoly());
+        //}
         // testing both new labels by the F5 Criterion
         if(!criterion1(gPrev,u1,newElement,lTag) && !criterion1(gPrev,u2,temp,lTag) && 
@@ -215,6 +219,7 @@
     }
     // for debugging
-    if(NULL != critPairs) {
-        //critPairs->print(); 
+    if(NULL != critPairs && gPrev->getLast()->getIndex() == 4) {
+        //critPairs->print();
+        //sleep(5);
     }
 }
@@ -315,5 +320,10 @@
           && l->getIndex() == testNode->getRuleIndex()) {
         //pWrite(testNode->getRuleTerm());
-		if(pLmDivisibleBy(testNode->getRuleTerm(),u1)) {
+		//pWrite(testNode->getRuleTerm());
+        //pWrite(t);
+        //pWrite(l->getTerm());
+        //pWrite(u1);
+        //Print("%d\n",testNode->getRuleIndex());
+        if(pLmDivisibleBy(testNode->getRuleTerm(),u1)) {
             //Print("Criterion 2 NOT passed!\n");
             pDelete(&u1);
@@ -443,5 +453,5 @@
                         //Print("%d\n",rules->getFirst()->getRuleIndex());
                         //Print("%p\n",sPolyList->getFirst());
-                        sPolyList->insertSP(ppMult_qq(temp->getT1(),temp->getLp1Term()),temp->getLp1Index(),sp,rules->getFirst()->getRule());
+                        sPolyList->insertByLabel(ppMult_qq(temp->getT1(),temp->getLp1Term()),temp->getLp1Index(),sp,rules->getFirst()->getRule());
                     }
                     // data is saved in sPolyList or zero => delete sp
@@ -477,5 +487,9 @@
         //Print("%p\n",sPolyList->getFirst());
         }
-        //sPolyList->print();
+        //if(gPrev->getLast()->getIndex() == 5) {
+            //sPolyList->print();
+            //sleep(5);
+        //}
+        
         // temp is the first element in the sPolyList which should be reduced
         // due to earlier sorting this is the element of minimal degree AND 
@@ -507,5 +521,5 @@
             // with label index = current label index: this is done such that there 
             // is no label corruption during the reduction process
-            topReduction(temp,sPolyList,gPrev,rules,lTag,rTag);
+            topReduction(temp,sPolyList,gPrev,rules,lTag,rTag,gbPrev);
         
         }
@@ -536,9 +550,11 @@
 =====================================================================================
 */
-void topReduction(LNode* l, LList* sPolyList, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag) {
+void topReduction(LNode* l, LList* sPolyList, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, ideal gbPrev) {
     //Print("##########################################In topREDUCTION!########################################\n");
     // try l as long as there are reductors found by findReductor()
     do {
         LNode* tempRed  =   new LNode();
+        Print("TESTED POLYNOMIAL IN THE FOLLOWING: ");
+        pWrite(l->getPoly());
         tempRed  =   findReductor(l,gPrev,rules,lTag,rTag);
         //Print("--------------------------------HIER DEBUG 2----------------------------------\n");
@@ -547,10 +563,27 @@
             // if label of reductor is greater than the label of l we have to built a new element
             // and add it to sPolyList
+            Print("REDUCTOR POLYNOMIAL: ");
+            pWrite(tempRed->getPoly());
+            Print("TERM: ");
+            pWrite(tempRed->getTerm());
             if(pLmCmp(tempRed->getTerm(),l->getTerm()) == 1) {
-                poly temp   =   pSub(tempRed->getPoly(),l->getPoly());
+                // needed sinc pSub destroys the arguments!
+                poly temp_poly_l    =   pInit();
+                temp_poly_l         =   pCopy(l->getPoly());
+                //Print("POLYNOMIAL L: ");
+                //pWrite(l->getPoly());
+                //pWrite(temp_poly_l);
+                poly temp           =   pSub(tempRed->getPoly(),temp_poly_l);
+                //Print("POLYNOMIAL L: ");
+                //pWrite(l->getPoly());
+                //pWrite(temp_poly_l);
+                //Print("AFTER REDUCTION STEP: ");
+                //pWrite(temp);
+                //sleep(20);
                 //pWrite(temp);
                 if(NULL != temp) {
                     pNorm(temp);
                     tempRed->setPoly(temp);
+                    //pWrite(tempRed->getPoly());
                     // for debugging
                     //pWrite(tempRed->getPoly());
@@ -577,9 +610,14 @@
             // after subtraction 
             else {
-                poly temp   =   pSub(l->getPoly(),tempRed->getPoly());
+                poly temp_poly_l    =   pInit();
+                temp_poly_l         =   pCopy(l->getPoly());
+                poly temp   =   pSub(temp_poly_l,tempRed->getPoly());
+                //Print("AFTER REDUCTION STEP: ");
                 //pWrite(temp);
                 if(NULL != temp) {
                     pNorm(temp);
-                    l->setPoly(temp);
+                    poly tempNF =   kNF(gbPrev,currQuotient,temp);  
+                    pNorm(tempNF);
+                    l->setPoly(tempNF);
                     l->setGPrevRedCheck(NULL);
                 }
@@ -596,9 +634,10 @@
         else {
             if(NULL != l->getPoly()) {
-                //Print("ADDED TO GPREV IN TOPREDUCTION: ");
-                //pWrite(l->getPoly());
-                //pWrite(l->getTerm());
-                //Print("INDEX: %d\n", l->getIndex());
-                //sleep(10);
+                pNorm(l->getPoly());
+                Print("----------------------------------ADDED TO GPREV IN TOPREDUCTION:-------------------------------------- ");
+                pWrite(l->getPoly());
+                pWrite(l->getTerm());
+                Print("INDEX: %d\n\n\n", l->getIndex());
+                
                 gPrev->insert(l->getLPoly());
                 //Print("GPREV: \n");
@@ -646,4 +685,8 @@
         // does the head of the element of gPrev divides the head of
         // the to be reduced element?
+        //Print("-------------FOUND REDUCTORS----------------------\n");
+        //Print("\n");
+        //pWrite(temp->getPoly());
+        //pWrite(temp->getTerm());
         if(pLmDivisibleByNoComp(temp->getPoly(),t)) {
             // get all the information needed for the following tests
@@ -651,8 +694,10 @@
             u   =   pDivide(t,pHead(temp->getPoly()));
             pSetCoeff(u,nOne);
+            //pWrite(u);
+            //Print("\n");
             red =   ppMult_qq(u,temp->getPoly());
             pNorm(red);
-            u   =   ppMult_qq(u,temp->getTerm());
-            pSetCoeff(u,nOne);
+            //u   =   ppMult_qq(u,temp->getTerm());
+            //pSetCoeff(u,nOne);
             // check if both have the same label
             if(pLmCmp(u,l->getTerm()) != 0) {
@@ -711,5 +756,8 @@
         }
     } 
+    id              =   kInterRed(id); 
+    qsortDegree(&id->m[0],&id->m[IDELEMS(id)-1]);
     LList* gPrev    =   new LList(ONE, i, id->m[0]);
+    //idShow(id); 
     //Print("%p\n",id->m[0]);
     //pWrite(id->m[0]);
@@ -774,4 +822,5 @@
     //    temp    =   temp->getNext();
     // }
+    delete(gPrev);
     return(gbPrev);
 
Index: kernel/f5gb.h
===================================================================
--- kernel/f5gb.h	(revision 7a8ca6fdf98e2078621ae6ac00ff9481cab3def8)
+++ kernel/f5gb.h	(revision 61944d0a0689203f1f85c43b1610be266ec31371)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.h,v 1.28 2009-02-19 14:52:34 ederc Exp $ */
+/* $Id: f5gb.h,v 1.29 2009-02-26 09:01:52 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -19,5 +19,5 @@
 ======================================================
 */
-void qsort_degree(poly* left, poly* right);
+void qsortDegree(poly* left, poly* right);
 
 /*
@@ -88,5 +88,5 @@
 =====================================================================================
 */
-void topReduction(LNode* l, LList* sPolyList, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag); 
+void topReduction(LNode* l, LList* sPolyList, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, ideal gbPrev); 
 
 /*
Index: kernel/f5lists.cc
===================================================================
--- kernel/f5lists.cc	(revision 7a8ca6fdf98e2078621ae6ac00ff9481cab3def8)
+++ kernel/f5lists.cc	(revision 61944d0a0689203f1f85c43b1610be266ec31371)
@@ -106,5 +106,5 @@
     }
     else {
-        if(0 == pLmCmp(t,this->getTerm()) || -1 == pLmCmp(t,this->getTerm())) {
+        if(-1 == pLmCmp(t,this->getTerm())) {
             LNode* newElement   =   new LNode(t, i, p, r, this);
             return newElement;
@@ -113,5 +113,5 @@
             LNode* temp = this;
             while(NULL != temp->next && NULL != temp->next->data) {
-                if( 0 == pLmCmp(t,temp->next->getTerm()) || -1 == pLmCmp(t,temp->next->getTerm())) {
+                if(-1 == pLmCmp(t,temp->next->getTerm())) {
                     LNode* newElement   =   new LNode(t, i, p, r, temp->next);
                     temp->next          =   newElement;
@@ -188,4 +188,8 @@
 }
 
+void LNode::setNext(LNode* l) {
+    next    =   l;
+}
+
 // test if for any list element the polynomial part of the data is equal to *p
 bool LNode::polyTest(poly* p) {
@@ -213,7 +217,7 @@
         Print("Index: %d\n",temp->getIndex());
         Print("Term: ");
-        //pWrite(temp->getTerm());
+        pWrite(temp->getTerm());
         Print("Poly: ");
-        //pWrite(temp->getPoly());
+        pWrite(temp->getPoly());
         Print("\n");
         temp = temp->next;
@@ -312,4 +316,6 @@
 
 void LList::setFirst(LNode* l) {
+    LNode* temp =   first;
+    temp->setNext(NULL);
     first       =   l;
     length--;
Index: kernel/f5lists.h
===================================================================
--- kernel/f5lists.h	(revision 7a8ca6fdf98e2078621ae6ac00ff9481cab3def8)
+++ kernel/f5lists.h	(revision 61944d0a0689203f1f85c43b1610be266ec31371)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5lists.h,v 1.11 2009-02-19 14:52:34 ederc Exp $ */
+/* $Id: f5lists.h,v 1.12 2009-02-26 09:01:52 ederc Exp $ */
 /*
 * ABSTRACT: list interface
@@ -79,4 +79,5 @@
         void    setIndex(int i);
         void    setGPrevRedCheck(LNode* l);
+        void    setNext(LNode* l);
         // test if for any list element the polynomial part of the data is equal to *p
         bool    polyTest(poly* p);
