Index: kernel/f5gb.cc
===================================================================
--- kernel/f5gb.cc	(revision 61d32c91fe3976149b9b30938476f2c3c1257eee)
+++ kernel/f5gb.cc	(revision 416ea2bc9e1b72d15cc10ae59eb6997e0a9e9355)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.cc,v 1.28 2009-02-15 20:33:56 ederc Exp $ */
+/* $Id: f5gb.cc,v 1.29 2009-02-16 14:23:42 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -81,5 +81,4 @@
     CList* critPairs        =   new CList();
     CNode* critPairsMinDeg  =   new CNode();   
-    LNode* sPolys           =   new LNode();
     // computation of critical pairs with checking of criterion 1 and criterion 2
     critPairs               =   criticalPair(gPrev, critPairs, lTag, rTag, rules);
@@ -94,4 +93,5 @@
         // critPairs->getMinDeg() deletes the first elements of minimal degree from
         // critPairs, thus the while loop is not infinite.
+        critPairs->print();
         critPairsMinDeg =   critPairs->getMinDeg();
         // adds all to be reduced S-polynomials in the list sPolyList and adds 
@@ -108,5 +108,7 @@
             temp    =   temp->getNext();
         } 
-        reducedLPolys   =   reduction(sPolyList, completed, gPrev, rules, lTag, rTag, gbPrev);
+        //while(NULL != sPolyList->getFirst()->getLPoly()) {
+            reduction(sPolyList, completed, gPrev, rules, lTag, rTag, gbPrev);
+        //}
     }
     Print("HIER123\n");
@@ -122,5 +124,4 @@
     lTag->insert(gPrev->getFirst());
     Print("COMPLETED FIRST IN F5INC: \n");
-    pWrite(completed->getFirst()->getPoly());
     return gPrev;
 }
@@ -374,72 +375,36 @@
 ========================================================================
 */
-LList* reduction(LList* sPolyList, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, 
+void reduction(LList* sPolyList, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, 
                  ideal gbPrev) { 
     Print("##########################################In REDUCTION!########################################\n");
-    // temporary normal form and zero polynomial for testing
-    static poly tempNF =   pInit();
-    TopRed* ret =   new TopRed();
-    // compute only if there are any S-polynomials to be reduced
-    Print("LENGTH OF SPOLYLIST: %d\n",sPolyList->getLength());
-    if(NULL != sPolyList->getFirst()->getLPoly()) {
+     // LNode* saving the last element in gPrev before the completed elements from the reduction process are added
+    // this is needed to get the new critical pairs computed
+    LNode* gPrevTag = gPrev->getLast();
+    //for debugging
+    pWrite(gPrevTag->getPoly());
+    // check if sPolyList has any elements
+    // NOTE: due to initialization sPolyList always has a default NULL element
+    while(sPolyList->getLength() > 1) {
+        // temp is the first element in the sPolyList which should be reduced
+        // due to earlier sorting this is the element of minimal degree AND 
+        // minimal label
         LNode* temp =   sPolyList->getFirst();
-		Print("SPOLYLIST FIRST START: %p\n",temp);			
-        while(NULL != temp && NULL != temp->getLPoly()) {
-            if(NULL != completed->getFirst()->getLPoly()) {
-				Print("BIS HIERHIN UND NICHT WEITER\n");	
-				Print("%p\n",completed->getFirst());
-				pWrite(completed->getFirst()->getPoly());
-                Print("ADDRESS OF TERM: %p\n",completed->getFirst()->getTerm());
-                pWrite(completed->getFirst()->getTerm());
-			}
-			tempNF = kNF(gbPrev,currQuotient,temp->getPoly());  
+        // delete the above first element from sPolyList, temp will be either reduced to
+        // zero or added to gPrev, but never come back to sPolyList
+        sPolyList->setFirst(temp->getNext());
+        pWrite(temp->getPoly());
+        poly tempNF = kNF(gbPrev,currQuotient,temp->getPoly());
+        Print("LENGTH: %d\n",sPolyList->getLength());
+        pWrite(tempNF);
+        pWrite(temp->getPoly());
+        if(NULL != tempNF) {
+            // write the reduced polynomial in temp
             temp->setPoly(tempNF);
-            // test if normal form is zero
-            if(NULL == tempNF) {
-                reductionsToZero++;
-                // TODO: sPolyList -> delete first element of list as it is zero and done
-                // TODO: problem is that when deleting the first element, the origin of the 
-                // corresponding rule is deleted!
-                Print("LENGTH OF SPOLYLIST: %d\n",sPolyList->getLength());
-                //temp    =   temp->getNext();
-                //sPolyList->setFirst(temp);
-                Print("///////////////////////////////////////////////////////////////////////\n");
-                Print("SPOLYLIST FIRST ELEMENT: %p\n",temp);
-                //Print("%p\n",temp->getLPoly());
-                Print("///////////////////////////////////////////////////////////////////////\n");
-            }
-            else {
-                ret =   topReduction(temp, completed, gPrev, rules, lTag, rTag);
-                // in topReduction() the investigated first element of sPolyList will be deleted after its
-                // reduction has finished => the next to be investigated element is the newly first element
-                // in sPolyList => the while loop is finite
-                // first possible after implementation of topReduction(): temp = sPolyList->getFirst();
-                
-				completed   =   ret->getCompleted();
-                Print("ZURUECK IN REDUCTION COMPLETED TERM ADDRESS: %p\n",completed->getFirst()->getTerm());
-                pWrite(completed->getFirst()->getTerm());
-                if(NULL != ret->getToDo()) {
-                    sPolyList->insertByLabel(ret->getToDo()->getFirst());
-                }
-            }
-            if(NULL != temp) {
-                sPolyList->setFirst(temp->getNext());
-                temp	=	sPolyList->getFirst();
-            }
-            else {
-                return completed;
-            }
-    Print("ADDRESS OF TERM: %p\n",completed->getFirst()->getTerm());
-
-			//pWrite(completed->getFirst()->getPoly());
-			Print("SPOLYLIST FIRST NOW: %p\n",temp);			
-            //pWrite(temp->getPoly());
-        }
-    }
-    Print("RETURN VALUE OF REDUCTION(): %p\n",completed->getFirst());
-    Print("ADDRESS OF TERM: %p\n",completed->getFirst()->getTerm());
-    Print("ADDRESS OF POLY: %p\n",completed->getFirst()->getPoly());
-    pWrite(completed->getFirst()->getPoly());
-    return completed;
+            // try further reductions of temp with polynomials in gPrev
+            // with label index = current label index: this is done such that there 
+            // is no label corruption during the reduction process
+            topReduction(temp,completed,gPrev,rules,lTag,rTag);
+        }
+    }
 }    
 
@@ -452,32 +417,8 @@
 =====================================================================================
 */
-TopRed* topReduction(LNode* l, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag) {
+void topReduction(LNode* l, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag) {
     Print("##########################################In topREDUCTION!########################################\n");
-			Print("L BEGIN TOP RED: %p\n",l->getLPoly());
-            pWrite(l->getPoly());
-            pWrite(l->getTerm());
-            Print("ADDRESS OF TERM: %p\n",l->getTerm());
-            //pWrite(completed->getFirst()->getPoly());
-            LNode* red   =   new LNode();
-    
-    do {
-        red  =   findReductor(l, completed, gPrev, rules, lTag, rTag, 
-                              red->getGPrevRedCheck(), red->getCompletedRedCheck());
-        // no reductor found
-        if(NULL == red) {
-            completed->insert(l->getLPoly());
-            Print("AT INSERTION IN COMPLETED ADDRESS OF TERM: %p\n",l->getTerm());
-            Print("AT INSERTION IN COMPLETED ADDRESS OF TERM II: %p\n",completed->getFirst()->getTerm());
-            pWrite(completed->getFirst()->getTerm());
-            TopRed* ret =   new TopRed(completed,NULL);
-            return ret;
-        }
-        // reductor found
-        else {
-            red->setPoly(ppMult_nn(red->getPoly(),pGetCoeff(l->getPoly())));
-        }            
-    } while(NULL != red);
-}
-
+
+}
 
 
@@ -488,90 +429,6 @@
 */
 LNode* findReductor(LNode* l,LList* completed,LList* gPrev, RList* rules, LTagList* lTag,RTagList* rTag,
-                    LNode* gPrevRedCheck, LNode* completedRedCheck) {
-    Print("HIER FIND REDUCTOR\n");
-        number nOne     =   nInit(1);
-    poly u          =   pOne();
-    poly redPoly    =   pOne();
-    poly t          =   pHead(l->getPoly());
-    LNode* temp     =   new LNode();
-    // setting starting point for search of reductors in gPrev
-    if(NULL != gPrevRedCheck) { 
-        temp =   gPrevRedCheck;
-    }
-    else {
-        temp =   gPrev->getFirst();
-    }
-    // search only for reductors with the same index, as reductions with elements of lower
-    // index were already done in reduction() beforehand
-    while(NULL != temp && NULL != temp->getLPoly() && temp->getIndex() == l->getIndex()) {
-        // divides head term t?
-        if(pLmDivisibleByNoComp(temp->getPoly(),t)) {
-            u       =   pDivide(t,pHead(temp->getPoly()));
-            pSetCoeff(u,nOne);
-            // multiply reductor with factor and normalize it, i.e. LC = 1
-            redPoly =   ppMult_qq(u,temp->getPoly());
-            pNorm(redPoly);
-            u       =   ppMult_qq(u,temp->getTerm());
-            pSetCoeff(u,nOne);
-            Print("IN FIND REDUCTOR:  ");
-            pWrite(u);
-            pWrite(redPoly);
-            // same label? NOTE: also used to 
-            if(pLmCmp(u,l->getTerm()) != 0) {
-                // passing criterion 2?
-                if(!criterion2(&u,temp, rules, rTag)) {
-                    // passing criterion 1?
-                    if(!criterion1(&u,temp,lTag)) {
-                        // set tag findRedCheck such that you can start at this point when the 
-                        // next time a reductor is searched for in findReductor()
-                        LNode* red      =   new LNode(u,temp->getIndex(),redPoly,NULL,temp->getNext(),completedRedCheck);
-                        return red;
-                    }
-                }
-            }
-        }
-        temp    =   temp->getNext();
-    }
-    if(0 != completed->getLength()) {
-    // do the same as above now for the elements in completed
-    if(NULL != completedRedCheck) {
-        temp    =   completedRedCheck;
-    }
-    else {
-        Print("HIER DRIN\n");
-        temp    =   completed->getFirst();
-        pWrite(temp->getTerm());
-    }
-    // search only for reductors with the same index, as reductions with elements of lower
-    // index where already done in reduction() beforehand
-    while(NULL != temp && NULL != temp->getLPoly() && NULL != temp->getPoly()) {
-        // divides head term t?
-        if(pLmDivisibleByNoComp(temp->getPoly(),t)) {
-            u       =   pDivide(t,pHead(temp->getPoly()));
-            pSetCoeff(u,nOne);
-            pWrite(u);
-            redPoly =   ppMult_qq(u,temp->getPoly());
-            pWrite(temp->getPoly());
-            pWrite(temp->getTerm());
-            u       =   ppMult_qq(u,temp->getTerm());
-            // same label? NOTE: also used to 
-        if(pLmCmp(u,l->getTerm()) != 0) {
-                // passing criterion 2?
-                if(!criterion2(&u,temp, rules, rTag)) {
-                    // passing criterion 1?
-                    if(!criterion1(&u,temp,lTag)) {
-                        // set tag findRedCheck such that you can start at this point when the 
-                        // next time a reductor is searched for in findReductor()
-                        LNode* red      =   new LNode(u,temp->getIndex(),redPoly,NULL,gPrevRedCheck,temp->getNext());
-                        return red;
-                    }
-                }
-            }
-        }
-        temp    =   temp->getNext();
-    }
-    }
-    // no reductor found
-    Print("HIER DU NULL!\n");
+                    LNode* gPrevRedCheck) {
+   Print("HIER DU NULL!\n");
     return NULL;
 }
Index: kernel/f5gb.h
===================================================================
--- kernel/f5gb.h	(revision 61d32c91fe3976149b9b30938476f2c3c1257eee)
+++ kernel/f5gb.h	(revision 416ea2bc9e1b72d15cc10ae59eb6997e0a9e9355)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.h,v 1.25 2009-02-12 12:43:31 ederc Exp $ */
+/* $Id: f5gb.h,v 1.26 2009-02-16 14:23:42 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -79,5 +79,5 @@
 ========================================================================
 */
-LList* reduction(LList* sPolyList, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag,
+void reduction(LList* sPolyList, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag,
                  ideal gbPrev);
 
@@ -88,5 +88,5 @@
 =====================================================================================
 */
-TopRed* topReduction(LNode* l, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag); 
+void topReduction(LNode* l, LList* completed, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag); 
 
 /*
@@ -96,5 +96,5 @@
 */
 LNode* findReductor(LNode* l,LList* completed,LList* gPrev, RList* rules, LTagList* lTag,RTagList* rTag,
-                    LNode* gPrevRedCheck, LNode* completedRedCheck);
+                    LNode* gPrevRedCheck);
 
 /*
Index: kernel/f5lists.cc
===================================================================
--- kernel/f5lists.cc	(revision 61d32c91fe3976149b9b30938476f2c3c1257eee)
+++ kernel/f5lists.cc	(revision 416ea2bc9e1b72d15cc10ae59eb6997e0a9e9355)
@@ -30,5 +30,4 @@
     next                =   NULL;
     gPrevRedCheck       =   NULL;
-    completedRedCheck   =   NULL;
 }
  LNode::LNode(LPoly* lp) {
@@ -36,5 +35,4 @@
     next                =   NULL;
     gPrevRedCheck       =   NULL;
-    completedRedCheck   =   NULL;
 }
        
@@ -44,21 +42,18 @@
     next                =   l;
     gPrevRedCheck       =   NULL;
-    completedRedCheck   =   NULL;
-}
-
-LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* CompCheck) {
+}
+
+LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck) {
 LPoly* lp           =   new LPoly(t,i,p,r);
 data                =   lp;
 next                =   NULL;
 gPrevRedCheck       =   gPCheck;
-completedRedCheck   =   CompCheck;
 }
        
-LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* CompCheck, LNode* l) {
+LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* l) {
     LPoly* lp           =   new LPoly(t,i,p,r);
     data                =   lp;
     next                =   l;
     gPrevRedCheck       =   gPCheck;
-    completedRedCheck   =   CompCheck;
 }
 
@@ -67,11 +62,9 @@
     next                =   ln->getNext();
     gPrevRedCheck       =   NULL;
-    completedRedCheck   =   NULL;
 }
         
 LNode::~LNode() {
-    delete next;
+    //delete next;
     delete gPrevRedCheck;
-    delete completedRedCheck;
     delete data;   
 }
@@ -85,8 +78,13 @@
         
 LNode* LNode::insert(poly t, int i, poly p, Rule* r) {
-    LNode* newElement = new LNode(t, i, p, r, NULL, NULL, this);
+    LNode* newElement = new LNode(t, i, p, r, NULL, this);
     return newElement;
 }
-        
+
+LNode* LNode::append(poly t, int i, poly p, Rule* r) {
+    LNode* newElement   =   new LNode(t,i,p,r,NULL);
+    this->next          =   newElement;
+}
+
 // insert new elemets to the list w.r.t. increasing labels
 // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label)
@@ -151,8 +149,4 @@
 }
 
-LNode* LNode::getCompletedRedCheck() {
-    return completedRedCheck;
-}
-
 // set the data from the LPoly saved in LNode
 void LNode::setPoly(poly p) {
@@ -170,8 +164,4 @@
 void LNode::setGPrevRedCheck(LNode* l) {
     gPrevRedCheck   =   l;
-}
-
-void LNode::setCompletedRedCheck(LNode* l) {
-    completedRedCheck   =   l;
 }
 
@@ -200,4 +190,5 @@
 LList::LList() {
     first   =   new LNode();
+    last    =   first;
     length  =   0;
 }
@@ -205,4 +196,5 @@
 LList::LList(LPoly* lp) {
     first   =   new LNode(lp);
+    last    =   first;
     length  =   1;
 }
@@ -210,4 +202,5 @@
 LList::LList(poly t,int i,poly p,Rule* r) {
     first   =   new LNode(t,i,p,r);
+    last    =   first;
     length  =   1;
 } 
@@ -228,4 +221,9 @@
 }
 
+void LList::append(poly t, int i, poly p, Rule* r) {
+    last    =   last->append(t,i,p,r);
+    length++;
+}
+
 void LList::insertByLabel(poly t, int i, poly p, Rule* r) {
     first = first->insertByLabel(t,i,p,r);
@@ -248,4 +246,8 @@
 LNode* LList::getFirst() {
     return first;
+}
+
+LNode* LList::getLast() {
+    return last;
 }
 
@@ -262,4 +264,5 @@
     first       =   l;
     delete(temp);
+    length--;
 }
 
Index: kernel/f5lists.h
===================================================================
--- kernel/f5lists.h	(revision 61d32c91fe3976149b9b30938476f2c3c1257eee)
+++ kernel/f5lists.h	(revision 416ea2bc9e1b72d15cc10ae59eb6997e0a9e9355)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5lists.h,v 1.8 2009-02-11 21:24:08 ederc Exp $ */
+/* $Id: f5lists.h,v 1.9 2009-02-16 14:23:42 ederc Exp $ */
 /*
 * ABSTRACT: list interface
@@ -40,5 +40,4 @@
         LNode*  next;
         LNode*  gPrevRedCheck;
-        LNode*  completedRedCheck;
     public:
         // generating new list elements from the labeled / classical polynomial view
@@ -46,6 +45,6 @@
                 LNode(LPoly* lp);
                 LNode(LPoly* lp, LNode* l);
-                LNode(poly t, int i, poly p, Rule* r=NULL, LNode* gPCheck=NULL, LNode* CompCheck=NULL);
-                LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* CompCheck, LNode* l);
+                LNode(poly t, int i, poly p, Rule* r=NULL, LNode* gPCheck=NULL);
+                LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* l);
                 LNode(LNode* ln);
                 ~LNode();
@@ -53,4 +52,6 @@
         LNode*  insert(LPoly* lp);
         LNode*  insert(poly t, int i, poly p, Rule* r);
+        //appends elements to the end of the list, done in reduction() in f5gb.cc
+        LNode*  append(poly t, int i, poly p, Rule* r);
         // insert new elements to the list with resp. to increasing labels
         // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label)
@@ -69,5 +70,4 @@
         Rule*   getRule();
         LNode*  getGPrevRedCheck();
-        LNode*  getCompletedRedCheck();
         // set the data from the LPoly saved in LNode
         void    setPoly(poly p);
@@ -75,5 +75,4 @@
         void    setIndex(int i);
         void    setGPrevRedCheck(LNode* l);
-        void    setCompletedRedCheck(LNode* l);
         // test if for any list element the polynomial part of the data is equal to *p
         bool    polyTest(poly* p);
@@ -90,4 +89,5 @@
     private:
         LNode*  first;
+        LNode*  last;
         int     length;
     public:
@@ -101,7 +101,9 @@
         void    insertByLabel(poly t, int i, poly p, Rule* r = NULL);
         void    insertByLabel(LNode* l);
+        void    append(poly t, int i, poly p, Rule* r=NULL);
         void    deleteByDeg();
         bool    polyTest(poly* p);
-        LNode*  getFirst(); 
+        LNode*  getFirst();
+        LNode*  getLast();
         LNode*  getNext(LNode* l);
         int     getLength();
