Index: kernel/f5gb.cc
===================================================================
--- kernel/f5gb.cc	(revision d8be851dd8f2cf657611debe1b34b05aedcdf65d)
+++ kernel/f5gb.cc	(revision 70c15eb2e3e8bb6677b7ddd9bbec70924a12865b)
@@ -2,5 +2,5 @@
 *  Computer Algebra System SINGULAR     *
 ****************************************/
-/* $Id: f5gb.cc,v 1.31 2009-02-19 14:52:34 ederc Exp $ */
+/* $Id: f5gb.cc,v 1.32 2009-02-22 18:58:36 ederc Exp $ */
 /*
 * ABSTRACT: f5gb interface
@@ -75,5 +75,5 @@
     gPrev->insert(ONE,i,f_i);
     // tag the first element in gPrev of the current index for findReductor()
-    lTag->setFirstCurrentIdx(gPrev->getFirst());
+    lTag->setFirstCurrentIdx(gPrev->getLast());
     //Print("1st gPrev: ");
     //pWrite(gPrev->getFirst()->getPoly());
@@ -111,4 +111,14 @@
         // reduction process of new S-polynomials and also adds new critical pairs to critPairs
         reduction(sPolyList, critPairs, gPrev, rules, lTag, rTag, gbPrev);
+        
+        // DEBUG STUFF FOR GPREV
+        temp    =   gPrev->getFirst();
+        Print("\n\n");
+        while(NULL != temp) {
+            pWrite(temp->getPoly());
+            temp    =   temp->getNext();
+        }
+        //sleep(10);
+    
     }
     Print("REDUCTION DONE\n");
@@ -255,5 +265,7 @@
         RNode* tempR    =   rules->getFirst();
         while(NULL != tempR->getRule()) {
+            Print("ADDRESS OF RULE: %p\n",tempR->getRule());
             pWrite(tempR->getRuleTerm());
+            Print("ADDRESS OF TERM: %p\n",tempR->getRuleTerm());
             Print("%d\n\n",tempR->getRuleIndex());
             tempR   =   tempR->getNext();
@@ -273,5 +285,8 @@
         }
         else {
+        Print("DEBUG\n");
+        Print("L INDEX: %d\n",l->getIndex());
             testNode    =   rTag->get(l->getIndex());
+            Print("TESTNODE ADDRESS: %p\n",testNode);
         }
     }
@@ -281,13 +296,27 @@
     //Print("%p\n",testNode->getRule());
     // NOTE: testNode is possibly NULL as rTag->get() returns NULL for elements of index <=1!
+    if(NULL != testNode && NULL != testNode->getRule()) {   
+        pWrite(testNode->getRuleTerm());
+    }
+    if(NULL != testNode) {
+        if(testNode->getRule() == l->getRule()) {
+            Print("%p\n%p\n",testNode->getRule(),l->getRule());
+            Print("EQUAL\n");
+        }
+        else {
+            Print("NOT EQUAL\n");
+        }
+    }
     while(NULL != testNode && NULL != testNode->getRule() && testNode->getRule() != l->getRule() 
           && l->getIndex() == testNode->getRuleIndex()) {
         pWrite(testNode->getRuleTerm());
-		if(pLmDivisibleBy(ppMult_qq(t,l->getTerm()),testNode->getRuleTerm())) {
+		if(pLmDivisibleBy(testNode->getRuleTerm(),u1)) {
             Print("Criterion 2 NOT passed!\n");
+            pDelete(&u1);
             return true;
         }
 		testNode    =   testNode->getNext();
     }
+    pDelete(&u1);
     return false;
 }
@@ -321,10 +350,12 @@
 	while(NULL != testNode->getRule() && testNode->getRule() != testedRule) {
         pWrite(testNode->getRuleTerm());
-        if(pLmDivisibleBy(testNode->getRuleTerm(),ppMult_qq(t,l->getTerm()))) {
+        if(pLmDivisibleBy(testNode->getRuleTerm(),u1)) {
             Print("Criterion 2 NOT passed!\n");
+            pDelete(&u1);
             return true;
         }
 		testNode    =   testNode->getNext();
     }
+    pDelete(&u1);
     return false;
 }
@@ -406,4 +437,5 @@
                         Print("RULE ADDED: \n");
                         pWrite(rules->getFirst()->getRuleTerm()); 
+                        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());
@@ -434,4 +466,11 @@
     while(sPolyList->getLength() > 0) {
         Print("SPOLYLIST LENGTH: %d\n",sPolyList->getLength());
+        if(sPolyList->getLength() > 1) {
+        Print("%p\n",sPolyList->getFirst());
+        Print("%p\n",sPolyList->getFirst()->getLPoly());
+        Print("%p\n",sPolyList->getFirst()->getNext());
+        Print("%p\n",sPolyList->getFirst()->getNext()->getLPoly());
+        Print("%p\n",sPolyList->getFirst());
+        }
         sPolyList->print();
         // temp is the first element in the sPolyList which should be reduced
@@ -446,5 +485,7 @@
         Print("%p\n",temp->getPoly());
         pWrite(temp->getPoly());
+        idShow(gbPrev);
         poly tempNF = kNF(gbPrev,currQuotient,temp->getPoly());
+        pNorm(tempNF);
         Print("LENGTH: %d\n",sPolyList->getLength());
         pWrite(tempNF);
@@ -457,16 +498,20 @@
             // is no label corruption during the reduction process
             topReduction(temp,sPolyList,gPrev,rules,lTag,rTag);
-        LNode* tempLoop = gPrev->getFirst();
-                while(NULL != tempLoop) {
-                    pWrite(tempLoop->getPoly());
-                    tempLoop = tempLoop->getNext();
-                    }
+        
         }
         if(NULL != temp->getPoly()) {
             //CList* newCritPairs = new CList;
+            Print("##################IN CRITPAIRS IN REDUCTION#####################\n");
             criticalPair(gPrev,critPairs,lTag,rTag,rules);
         }
         else {
-            delete temp;
+            //delete temp;
+            LNode* tempLoop = gPrev->getFirst();
+            Print("AUSGABE IN REDUCTION:\n");        
+            while(NULL != tempLoop) {
+                pWrite(tempLoop->getPoly());
+                tempLoop = tempLoop->getNext();
+            }
+            //sleep(10);
         }
     }
@@ -487,4 +532,5 @@
         LNode* tempRed  =   new LNode();
         tempRed  =   findReductor(l,gPrev,rules,lTag,rTag);
+        Print("--------------------------------HIER DEBUG 2----------------------------------\n");
         // if a reductor for l is found and saved in tempRed
         if(NULL != tempRed) {
@@ -493,6 +539,8 @@
             if(pLmCmp(tempRed->getTerm(),l->getTerm()) == 1) {
                 poly temp   =   pSub(tempRed->getPoly(),l->getPoly());
+                Print("OH JE\n");
                 pWrite(temp);
                 if(NULL != temp) {
+                    pNorm(temp);
                     tempRed->setPoly(temp);
                     // for debugging
@@ -500,6 +548,9 @@
                     Print("RULE ADDED\n");
                     rules->insert(tempRed->getIndex(),tempRed->getTerm());
-                    
+                     
                     tempRed->getLPoly()->setRule(rules->getFirst()->getRule());
+                    Print("%p\n",sPolyList->getFirst());
+                    Print("%p\n",sPolyList->getFirst()->getLPoly());
+                    Print("SPOLYLIST LENGTH: %d\n",sPolyList->getLength());
                     sPolyList->insertByLabel(tempRed);
                 }
@@ -508,4 +559,5 @@
                     reductionsToZero++;
                     Print("RULE ADDED\n");
+        Print("wieder hier2\n");
                     rules->insert(tempRed->getIndex(),tempRed->getTerm());
                     delete tempRed;
@@ -519,10 +571,15 @@
                 pWrite(temp);
                 if(NULL != temp) {
+                    pNorm(temp);
                     l->setPoly(temp);
                     l->setGPrevRedCheck(NULL);
                 }
                 else {
+                    Print("ZERO REDUCTION!\n");
+                    reductionsToZero++;
                     pDelete(&temp);
                     l->setPoly(NULL);
+                    pWrite(gPrev->getLast()->getPoly()); 
+                    break;
                 }
             }    
@@ -533,8 +590,11 @@
                 pWrite(l->getPoly());
                 pWrite(l->getTerm());
+                Print("INDEX: %d\n", l->getIndex());
+                //sleep(10);
                 gPrev->insert(l->getLPoly());
                 Print("GPREV: \n");
                 LNode* tempLoop = gPrev->getFirst();
                 while(NULL != tempLoop) {
+                    Print("HERE\n");
                     pWrite(tempLoop->getPoly());
                     tempLoop = tempLoop->getNext();
@@ -554,4 +614,5 @@
 LNode* findReductor(LNode* l, LList* gPrev, RList* rules, LTagList* lTag,RTagList* rTag) {
     // allociation of memory for the possible reductor
+    Print("IN FIND REDUCTOR\n");
     poly u      =   pOne();
     poly red    =   pOne();
@@ -591,4 +652,5 @@
                     // passing criterion1 ?
                     if(!criterion1(gPrev,u,temp,lTag)) {
+                            Print("HIER DEBUG\n");
                             l->setGPrevRedCheck(temp);
                             LNode* redNode  =   new LNode(u,temp->getIndex(),red,NULL,NULL);
@@ -663,5 +725,10 @@
         pWrite(gPrevTag->getPoly());
         gPrev   =   F5inc(i, id->m[i-1], gPrev, gbPrev, ONE, lTag, rules, rTag);
-        // comuting new groebner basis gbPrev
+        // DEBUGGING STUFF
+        LNode* temp    =   gPrev->getFirst();
+    while(NULL != temp) {
+        pWrite(temp->getPoly());
+        temp    =   temp->getNext();
+    }// comuting new groebner basis gbPrev
         if(gPrev->getLength() > gbLength) {
             ideal gbAdd =   idInit(gPrev->getLength()-gbLength,1);
@@ -674,7 +741,7 @@
         for(j=0;j<=gPrev->getLength()-gbLength-1;j++) {
             Print("YES\n");
+            temp        =   temp->getNext();
             gbAdd->m[j] =   temp->getPoly();
             pWrite(temp->getPoly());
-            temp        =   temp->getNext();
         }
         gbLength    =   gPrev->getLength(); 
@@ -684,8 +751,12 @@
         idShow(gbPrev);
         Print("===================================================\n");
-
         Print("JA\n");
     } 
     Print("\n\nNumber of zero-reductions:  %d\n",reductionsToZero);
+    LNode* temp    =   gPrev->getFirst();
+    while(NULL != temp) {
+        pWrite(temp->getPoly());
+        temp    =   temp->getNext();
+    }
     return(gbPrev);
 
Index: kernel/f5lists.cc
===================================================================
--- kernel/f5lists.cc	(revision d8be851dd8f2cf657611debe1b34b05aedcdf65d)
+++ kernel/f5lists.cc	(revision 70c15eb2e3e8bb6677b7ddd9bbec70924a12865b)
@@ -101,23 +101,34 @@
 // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label)
 LNode* LNode::insertByLabel(poly t, int i, poly p, Rule* r) {
-    if(0 == pLmCmp(t,this->getTerm()) || -1 == pLmCmp(t,this->getTerm())) {
+    if(NULL == data) {
         LNode* newElement   =   new LNode(t, i, p, r, this);
         return newElement;
     }
     else {
-        LNode* temp = this;
-        while( NULL != temp->next->data ) {
-            if( 0 == pLmCmp(t,temp->next->getTerm()) || -1 == pLmCmp(t,temp->next->getTerm())) {
-                LNode* newElement   =   new LNode(t, i, p, r, temp->next);
-                temp->next          =   newElement;
-                return this;
+        if(0 == pLmCmp(t,this->getTerm()) || -1 == pLmCmp(t,this->getTerm())) {
+            LNode* newElement   =   new LNode(t, i, p, r, this);
+            return newElement;
+        }
+        else {
+            LNode* temp = this;
+            while(NULL != temp->next && NULL != temp->next->data) {
+                if( 0 == pLmCmp(t,temp->next->getTerm()) || -1 == pLmCmp(t,temp->next->getTerm())) {
+                    LNode* newElement   =   new LNode(t, i, p, r, temp->next);
+                    temp->next          =   newElement;
+                    return this;
+                }
+                else {
+                    temp = temp->next;
+                    Print("%p\n",temp);
+                    Print("%p\n",temp->data);
+                    
+                    Print("%p\n",temp->next);
+                }
             }
-            else {
-                temp = temp->next;
-            }
+        Print("HIER\n");
+            LNode* newElement   =   new LNode(t, i, p, r, temp->next);
+            temp->next          =   newElement;
+            return this;
         }
-        LNode* newElement   =   new LNode(t, i, p, r, NULL);
-        temp->next          =   newElement;
-        return this;
     }
 }
@@ -197,5 +208,6 @@
     LNode* temp = this;
     Print("___________________List of S-polynomials______________________:\n");
-    while(NULL != temp->data) {
+    while(NULL != temp && NULL != temp->data) {
+        Print("HIER\n");
         Print("Index: %d\n",temp->getIndex());
         Print("Term: ");
