Index: kernel/f5gb.cc
===================================================================
--- kernel/f5gb.cc	(revision 694257b820eac75a8100417ebf8f059879a873fd)
+++ kernel/f5gb.cc	(revision 6b0aa282252fc9ee946503d2609e77b28ea0aa7f)
@@ -147,4 +147,5 @@
         //int timer4  =   initTimer();
         //startTimer();
+        critPairs->print();
         computeSPols(critPairsMinDeg,rTag,rules,sPolyList);
         //timer4  =   getTimer();
@@ -161,5 +162,7 @@
         //int timer3  =   initTimer();
         //startTimer();
+        sPolyList->print();
         reduction(sPolyList, critPairs, gPrev, rules, lTag, rTag, gbPrev);
+        //newReduction(sPolyList, critPairs, gPrev, rules, lTag, rTag, gbPrev);
         //timer3      =  getTimer();
         //reductionTime = reductionTime + timer3;
@@ -354,5 +357,5 @@
             //Print("%d\n",testNode->getIndex());
             if(pLmDivisibleByNoComp(testNode->getPoly(),u1)) {
-                //Print("Criterion 1 NOT passed!\n");
+                Print("Criterion 1 NOT passed!\n");
                 return true;
             }
@@ -479,5 +482,5 @@
         //Print("%d\n",testNode->getRuleIndex());
         if(pLmDivisibleByNoComp(testNode->getRuleTerm(),u1)) {
-            //Print("-----------------Criterion 2 NOT passed!-----------------------------------\n");
+            Print("-----------------Criterion 2 NOT passed!-----------------------------------\n");
             //Print("INDEX: %d\n",l->getIndex());
             pDelete(&u1);
@@ -525,5 +528,5 @@
         //pWrite(testNode->getRuleTerm());
         if(pLmDivisibleByNoComp(testNode->getRuleTerm(),u1)) {
-            //Print("--------------------------Criterion 2 NOT passed!------------------------------\n");
+            Print("--------------------------Criterion 2 NOT passed!------------------------------\n");
             //Print("INDEX: %d\n",l->getIndex());
             pDelete(&u1);
@@ -686,5 +689,170 @@
 }    
 
-
+/*
+========================================================================
+reduction including subalgorithm topReduction() using Faugere's criteria
+========================================================================
+*/
+void newReduction(LList* sPolyList, CList* critPairs, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, 
+                 ideal gbPrev) { 
+    //Print("##########################################In REDUCTION!########################################\n");
+    // check if sPolyList has any elements
+    // NOTE: due to initialization sPolyList always has a default NULL element
+    LNode* temp = sPolyList->getFirst();
+    while(NULL != temp) {
+        // 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
+        // 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());
+        poly tempNF = kNF(gbPrev,currQuotient,temp->getPoly());
+        if(NULL != tempNF) {
+            pNorm(tempNF);
+            temp->setPoly(tempNF);
+            // 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
+            findReducers(temp,sPolyList,gPrev,critPairs,rules,lTag,rTag); 
+        }
+        else {
+            reductionsToZero++;
+            delete temp;
+        }
+        //if(NULL != temp->getPoly()) {
+        //    criticalPair(gPrev,critPairs,lTag,rTag,rules);
+        //}
+        temp =   sPolyList->getFirst();
+    }
+    //sPolyList->print();
+    //delete sPolyList;
+}     
+
+
+/*!
+ * ================================================================================
+ * searches for reducers of temp similar to the symbolic preprocessing of F4  and 
+ * divides them into a "good" and "bad" part:
+ * 
+ * the "good" ones are the reducers which do not corrupt the label of temp, with
+ * these the normal form of temp is computed
+ *
+ * the "bad" ones are the reducers which corrupt the label of temp, they are tested 
+ * later on for possible new rules and S-polynomials to be added to the algorithm
+ * ================================================================================
+*/
+void findReducers(LNode* l, LList* sPolyList, LList* gPrev, CList* critPairs, RList* rules, LTagList* lTag, RTagList* rTag) {
+    LList* good         =   new LList();
+    LList* bad          =   new LList();
+    LList* monomials    =   new LList(l->getLPoly());
+    poly u              =   pOne();
+    number nOne         =   nInit(1);
+    LNode* tempRed      =   lTag->getFirstCurrentIdx();
+    LNode* tempMon      =   monomials->getFirst();
+    Print("IN FIND REDUCERS:  ");
+    pWrite(l->getPoly());
+    while(NULL != tempMon) {
+        // iteration over all monomials in tempMon
+        poly tempPoly   =   tempMon->getPoly();
+        while(NULL != tempPoly) {
+            // iteration of all elements in gPrev of the current index
+            while(NULL != tempRed) {
+                if(pDivisibleBy(tempRed->getPoly(),tempPoly)) {
+                    u   =   pDivide(pHead(tempPoly),pHead(tempRed->getPoly()));
+                    pSetCoeff(u,nOne);
+                    //poly red =   ppMult_qq(u,temp->getPoly());
+                    //pNorm(red);
+                    // check if both have the same label
+                    if(pLmCmp(ppMult_qq(u,tempRed->getTerm()),tempMon->getTerm()) != 0) {
+                        // passing criterion2 ?
+                        if(!criterion2(gPrev->getFirst()->getIndex(), u,tempRed,rules,rTag)) {
+                            // passing criterion1 ?
+                            if(!criterion1(gPrev,u,tempRed,lTag)) {
+                                if(pLmCmp(ppMult_qq(u,tempRed->getTerm()),tempMon->getTerm()) == 1) {
+    //Print("HIER1\n");
+                                    bad->insertSP(tempRed->getLPoly());
+                                }
+                                else {
+                                    monomials->insertSP(tempRed->getLPoly());
+                                    good->insertSP(tempRed->getLPoly());
+    //Print("HIER2\n");
+                                }
+                            }    
+                    
+                        }
+                    }
+                }
+                tempRed =   tempRed->getNext();
+            }
+            pIter(tempPoly);
+        }
+        tempMon =   tempMon->getNext();
+    }
+    // if there are reducers than reduce l
+    if(NULL != good->getFirst()) {
+        LNode* tempGood         =   good->getFirst();
+        ideal reductionId       =   idInit(good->getLength(),1);
+        int i;
+        for(i=0;i<good->getLength();i++) {
+            reductionId->m[i]   =   tempGood->getPoly();
+            tempGood            =   tempGood->getNext();
+        }
+        poly temp   =   kNF(reductionId,currQuotient,l->getPoly());
+        if(NULL != temp) {
+            pNorm(temp);
+            Print("NEW REDUCTION:  ");
+            pWrite(temp);
+            l->setPoly(temp);
+            pWrite(l->getPoly());
+            gPrev->insert(l->getLPoly());
+            rules->print();
+            criticalPair(gPrev,critPairs,lTag,rTag,rules);
+        }
+        else {
+            reductionsToZero++;
+            pDelete(&temp);
+        }
+        //pWrite(temp);
+        for(i=0;i<IDELEMS(reductionId);i++) {
+            reductionId->m[i]    =   NULL;
+        }
+        idDelete(&reductionId);
+    
+    }
+    else {
+        //pWrite(l->getPoly());
+        gPrev->insert(l->getLPoly());
+        Print("GENAU HIER:  ");
+        pWrite(l->getPoly());
+        criticalPair(gPrev,critPairs,lTag,rTag,rules);
+    }
+    // if there are "bad" reducers than try to compute new S-polynomials and rules
+    if(NULL != bad->getFirst()) {
+        LNode* tempBad  =   bad->getFirst();
+        while(NULL != tempBad) {
+            if(pDivisibleBy(tempBad->getPoly(),l->getPoly())) {
+                u   =   pDivide(pHead(l->getPoly()),pHead(tempBad->getPoly()));
+                pSetCoeff(u,nOne);
+                if(pLmCmp(ppMult_qq(u,tempBad->getTerm()),l->getTerm()) != 0) {
+                    // passing criterion2 ?
+                    if(!criterion2(gPrev->getFirst()->getIndex(), u,tempBad,rules,rTag)) {
+                        // passing criterion1 ?
+                        if(!criterion1(gPrev,u,tempBad,lTag)) {
+
+                            rules->insert(tempBad->getIndex(),ppMult_qq(u,tempBad->getTerm()));
+                            poly temp   =   pSub(ppMult_qq(u,tempBad->getPoly()),l->getPoly());
+                            LNode* tempBadNew   =   new LNode(ppMult_qq(u,tempBad->getTerm()),tempBad->getIndex(),temp,rules->getFirst()->getRule());
+                            //tempRed->getLPoly()->setRule(rules->getFirst()->getRule());
+                            tempBadNew->setDel(1);
+                            sPolyList->insertByLabel(tempBadNew);
+                        }
+                    }
+                }
+            }
+            tempBad =   tempBad->getNext();
+        }
+    }
+
+}
 
 /*
@@ -703,4 +871,6 @@
         //int timer5  =   initTimer();
         //startTimer();
+        //Print("TOP REDUCTION:  ");
+        //pWrite(l->getPoly());
         tempRed  =   findReductor(l,sPolyList,gPrevRedCheck,gPrev,rules,lTag,rTag);
         //timer5  =   getTimer();
@@ -710,4 +880,5 @@
             // if label of reductor is greater than the label of l we have to built a new element
             // and add it to sPolyList
+            
             if(pLmCmp(tempRed->getTerm(),l->getTerm()) == 1) {
                 // needed sinc pSub destroys the arguments!
@@ -738,4 +909,5 @@
                 }
             }
+            
             // label of reductor is smaller than the label of l, subtract reductor from l and delete the 
             // gPrevRedCheck pointer added to l during findReductor() as the head term of l changes 
@@ -773,4 +945,8 @@
                 pNorm(l->getPoly());
                 gPrev->insert(l->getLPoly());
+                Print("TEMP RED == 0  ");
+                pWrite(l->getPoly());
+                pWrite(l->getTerm());
+                rules->print();
                 criticalPair(gPrev,critPairs,lTag,rTag,rules);
             }
@@ -813,5 +989,5 @@
             pNorm(red);
             // check if both have the same label
-            if(pLmCmp(ppMult_qq(u,temp->getTerm()),l->getTerm()) == -1) {
+            if(pLmCmp(ppMult_qq(u,temp->getTerm()),l->getTerm()) != 0) {
                 // passing criterion2 ?
                 if(!criterion2(gPrev->getFirst()->getIndex(), u,temp,rules,rTag)) {
Index: kernel/f5gb.h
===================================================================
--- kernel/f5gb.h	(revision 694257b820eac75a8100417ebf8f059879a873fd)
+++ kernel/f5gb.h	(revision 6b0aa282252fc9ee946503d2609e77b28ea0aa7f)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.h,v 1.36 2009-04-07 13:30:01 ederc Exp $ */
+/* $Id: f5gb.h,v 1.37 2009-04-20 13:54:50 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -98,4 +98,26 @@
 
 /*
+========================================================================
+reduction including subalgorithm topReduction() using Faugere's criteria
+========================================================================
+*/
+inline void newReduction(LList* sPolyList, CList* critPairs, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag,
+                 ideal gbPrev);
+
+/*!
+ * ================================================================================
+ * searches for reducers of temp similar to the symbolic preprocessing of F4  and 
+ * divides them into a "good" and "bad" part:
+ * 
+ * the "good" ones are the reducers which do not corrupt the label of temp, with
+ * these the normal form of temp is computed
+ *
+ * the "bad" ones are the reducers which corrupt the label of temp, they are tested 
+ * later on for possible new rules and S-polynomials to be added to the algorithm
+ * ================================================================================
+ */
+void findReducers(LNode* l, LList* sPolyList, LList* gPrev, CList* critPairs, RList* rules, LTagList* lTag, RTagList* rTag); 
+
+/*
 =====================================================================================
 top reduction in F5, i.e. reduction of a given S-polynomial by labeled polynomials of
Index: kernel/f5lists.cc
===================================================================
--- kernel/f5lists.cc	(revision 694257b820eac75a8100417ebf8f059879a873fd)
+++ kernel/f5lists.cc	(revision 6b0aa282252fc9ee946503d2609e77b28ea0aa7f)
@@ -431,5 +431,4 @@
 
  LTagNode::~LTagNode() {
-    delete next;
     delete data;   
 }
@@ -481,4 +480,14 @@
     LTagNode* first =   new LTagNode(l);
     length          =   1;
+}
+
+LTagList::~LTagList() {
+    LTagNode* temp;
+    while(first) {
+        temp    =   first;
+        first   =   first->getNext();
+        delete  temp;
+        //Print("%p\n",first);
+    }
 }
 
@@ -889,4 +898,13 @@
 }
 
+void RNode::print() {
+    RNode* temp  =   this;
+    while(NULL != temp) {
+        pWrite(temp->getRuleTerm());
+        Print("%d\n\n",temp->getRuleIndex());
+        temp    =   temp->getNext();
+    }
+}
+
 /*
 ====================================
@@ -936,4 +954,8 @@
 }
 
+void RList::print() {
+    first->print();
+}
+
 /*
 =======================================
Index: kernel/f5lists.h
===================================================================
--- kernel/f5lists.h	(revision 694257b820eac75a8100417ebf8f059879a873fd)
+++ kernel/f5lists.h	(revision 6b0aa282252fc9ee946503d2609e77b28ea0aa7f)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5lists.h,v 1.16 2009-03-29 17:17:09 ederc Exp $ */
+/* $Id: f5lists.h,v 1.17 2009-04-20 13:54:50 ederc Exp $ */
 /*
 * ABSTRACT: list interface
@@ -266,4 +266,5 @@
         int     getRuleIndex();
         poly    getRuleTerm();
+        void    print();
 };
 
@@ -286,4 +287,5 @@
         RNode*  getFirst();
         Rule*   getRule();
+        void    print();
 };
 
