source: git/kernel/f5gb.cc @ e90881

spielwiese
Last change on this file since e90881 was e90881, checked in by Christian Eder, 15 years ago
implemented deletion of known useless polynomials before the interreduction of gprev takes place git-svn-id: file:///usr/local/Singular/svn/trunk@11596 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 44.6 KB
RevLine 
[936551]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: f5gb interface
6*/
[bc103b]7
[936551]8#include "mod2.h"
[ee3507]9#ifdef HAVE_F5
[bc103b]10#include <unistd.h>
[936551]11#include "structs.h"
[bc103b]12#include "kutil.h"
[936551]13#include "omalloc.h"
14#include "polys.h"
15#include "p_polys.h"
16#include "ideals.h"
17#include "febase.h"
18#include "kstd1.h"
19#include "khstd.h"
20#include "kbuckets.h"
21#include "weight.h"
22#include "intvec.h"
23#include "pInline1.h"
24#include "f5gb.h"
[5d0556]25#include "f5data.h"
[a3771a]26#include "f5lists.h"
[85a342]27#include "timer.h"
[e90881]28int reductionsToZero    =   0;
29int reductionTime       =   0;
30int spolsTime           =   0;
31int highestDegree       =   0;
[199ae7]32/*
33====================================================================
34sorting ideals by decreasing total degree "left" and "right" are the
35pointer of the first and last polynomial in the considered ideal
36====================================================================
[ed30c5]37*/
[199ae7]38void qsortDegree(poly* left, poly* right) {
39    poly* ptr1 = left;
40    poly* ptr2 = right;
41    poly p1,p2;
42    p2 = *(left + (right - left >> 1));
43    do {
44            while(pTotaldegree(*ptr1, currRing) < pTotaldegree(p2, currRing)) {
45                    ptr1++;
46            } 
47            while(pTotaldegree(*ptr2, currRing) > pTotaldegree(p2,currRing)) {
48                    ptr2--;
49            }
50            if(ptr1 > ptr2) {
51                    break;
52            }
53            p1    = *ptr1;
54            *ptr1 = *ptr2;
55            *ptr2 = p1;
56    } while(++ptr1 <= --ptr2);
57
58    if(left < ptr2) {
59            qsortDegree(left,ptr2);
60    }
61    if(ptr1 < right) {
62            qsortDegree(ptr1,right);
63    }
[4cfd6d]64}
65
66
[9bb97e]67
[199ae7]68/*
69==================================================
70computes incrementally gbs of subsets of the input
71gb{f_m} -> gb{f_m,f_(m-1)} -> gb{f_m,...,f_1}
72==================================================
[9a6e9f]73*/
[87beab7]74LList* F5inc(int i, poly f_i, LList* gPrev, ideal gbPrev, poly ONE, LTagList* lTag, RList* rules, RTagList* rTag) {
[66a5f8]75    Print("in f5inc\n");           
[9cb4078]76    //pWrite(rules->getFirst()->getRuleTerm());
[9bb97e]77    int j;
[eab144e]78    //Print("%p\n",gPrev->getFirst());
79    //pWrite(gPrev->getFirst()->getPoly());
[61944d0]80    poly tempNF =   kNF(gbPrev,currQuotient,f_i);
81    f_i         =   tempNF;
[55a828]82    //gPrev->insert(ONE,i,f_i);
83    gPrev->insert(ONE,gPrev->getLength()+1,f_i);
[d51339]84    // tag the first element in gPrev of the current index for findReductor()
[70c15e]85    lTag->setFirstCurrentIdx(gPrev->getLast());
[eab144e]86    //Print("1st gPrev: ");
87    //pWrite(gPrev->getFirst()->getPoly());
88    //Print("2nd gPrev: ");
89    //pWrite(gPrev->getFirst()->getNext()->getPoly());
[87beab7]90    //pWrite(gPrev->getFirst()->getNext()->getPoly());   
[9bb97e]91    CList* critPairs        =   new CList();
92    CNode* critPairsMinDeg  =   new CNode();   
[d51339]93    // computation of critical pairs with checking of criterion 1 and criterion 2 and saving them
94    // in the list critPairs
95    criticalPair(gPrev, critPairs, lTag, rTag, rules);
[87beab7]96    static LList* sPolyList        =   new LList();
[c4158f]97    //sPolyList->print();
[9bb97e]98    // labeled polynomials which have passed reduction() and have to be added to list gPrev
[87beab7]99    static LList* completed        =   new LList();
[9bb97e]100    // the reduced labeled polynomials which are returned from subalgorithm reduction()
[87beab7]101    static LList* reducedLPolys     =   new LList();
[9bb97e]102    // while there are critical pairs to be further checked and deleted/computed
[7c81165]103    while(NULL != critPairs->getFirst()) { 
[9bb97e]104        // critPairs->getMinDeg() deletes the first elements of minimal degree from
105        // critPairs, thus the while loop is not infinite.
106        critPairsMinDeg =   critPairs->getMinDeg();
107        // adds all to be reduced S-polynomials in the list sPolyList and adds
108        // the corresponding rules to the list rules
109        // NOTE: inside there is a second check of criterion 2 if new rules are
110        // added
[e90881]111        int timer4  =   initTimer();
112        startTimer();
[fcb8022]113        computeSPols(critPairsMinDeg,rTag,rules,sPolyList);
[e90881]114        timer4  =   getTimer();
115        Print("SPOLS TIMER: %d\n",timer4);
116        spolsTime  =   spolsTime  +   timer4;
[87beab7]117        // DEBUG STUFF FOR SPOLYLIST
118        LNode* temp     =   sPolyList->getFirst();
[8066e80]119        //while(NULL != temp && NULL != temp->getLPoly()) {
[598870]120            //Print("Spolylist element: ");
121            //pWrite(temp->getPoly());
[8066e80]122            //temp    =   temp->getNext();
123        //}
[d51339]124        // reduction process of new S-polynomials and also adds new critical pairs to critPairs
[e90881]125        int timer3  =   initTimer();
126        startTimer();
[d51339]127        reduction(sPolyList, critPairs, gPrev, rules, lTag, rTag, gbPrev);
[e90881]128        timer3      =  getTimer();
129        reductionTime = reductionTime + timer3;
130        Print("REDUCTION TIMER: %d\n",timer3); 
[70c15e]131        // DEBUG STUFF FOR GPREV
[598870]132        //temp    =   gPrev->getFirst();
133        //int number  =   1;
134        //Print("\n\n");
135        //while(NULL != temp) {
136        //    Print("%d.  ",number);
137        //    pWrite(temp->getPoly());
138        //    temp    =   temp->getNext();
139        //    number++;
140        //    Print("\n");
141        //}
142        //sleep(5);
[70c15e]143   
[87beab7]144    }
[598870]145    //Print("REDUCTION DONE\n");
146    //Print("%p\n",rules->getFirst());
147    //Print("%p\n",rTag->getFirst());
[c3da59]148    //if(rules->getFirst() != rTag->getFirst()) {
[598870]149        //Print("+++++++++++++++++++++++++++++++++++++NEW RULES+++++++++++++++++++++++++++++++++++++\n");
[c3da59]150        //rTag->insert(rules->getFirst());
151    //}
152    //else {
[598870]153        //Print("+++++++++++++++++++++++++++++++++++NO NEW RULES++++++++++++++++++++++++++++++++++++\n");
[c3da59]154    //}
[d51339]155    lTag->insert(lTag->getFirstCurrentIdx());
[598870]156    //Print("INDEX: %d\n",tempTag->getIndex());
157    //pWrite(tempTag->getPoly());
158    //Print("COMPLETED FIRST IN F5INC: \n");
[eab144e]159    //Print("1st gPrev: ");
160    //pWrite(gPrev->getFirst()->getPoly());
161    //Print("2nd gPrev: ");
162    //pWrite(gPrev->getFirst()->getNext()->getPoly());
163    //Print("3rd gPrev: ");
164    //pWrite(gPrev->getFirst()->getNext()->getNext()->getPoly());
[338842d]165    //delete sPolyList;
[55a828]166    //critPairs->print();
[9cb4078]167    delete critPairs;
[55a828]168    //Print("IN F5INC\n");
[f6c7c9b]169    /*
170    Print("\n\n\nRULES: \n");
[1534d9]171        RNode* tempR    =   rules->getFirst();
172        Print("%p\n",tempR);
173        int t   = 1;
174        while(NULL != tempR) {
175            Print("ADDRESS OF %d RNODE: %p\n",t,tempR);
176            Print("ADDRESS OF RULE: %p\n",tempR->getRule());
177            pWrite(tempR->getRuleTerm());
178            Print("ADDRESS OF TERM: %p\n",tempR->getRuleTerm());
179            Print("%d\n\n",tempR->getRuleIndex());
180            tempR   =   tempR->getNext();
181            t++;
182        }
[f6c7c9b]183    */
[338842d]184    //gPrev->print();
[e90881]185    Print("COMPLETE REDUCTION TIME UNTIL NOW: %d\n",reductionTime);
186    Print("COMPLETE SPOLS TIME UNTIL NOW:     %d\n",spolsTime);
[cce6ed3]187    return gPrev;
188}
189
190
[9bb97e]191
[cce6ed3]192/*
193================================================================
194computes a list of critical pairs for the next reduction process
195first element in gPrev is always the newest element which must
196build critical pairs with all other elements in gPrev
197================================================================
198*/
[9cb4078]199inline void criticalPair(LList* gPrev, CList* critPairs, LTagList* lTag, RTagList* rTag, RList* rules) {
[55a828]200    //Print("IN CRITPAIRS\n");
[c9193a]201    // initialization for usage in pLcm()
202    number nOne         =   nInit(1);
203    LNode* newElement   =   gPrev->getLast();
204    LNode* temp         =   gPrev->getFirst();
205    poly u1             =   pOne();
206    poly u2             =   pOne();
207    poly lcm            =   pOne();
208    poly t              =   pHead(newElement->getPoly());
[c4158f]209    Rule* testedRule    =   NULL;
210    if(NULL != rules->getFirst()) {
211        testedRule  =   rules->getFirst()->getRule();
212    }
[c9193a]213    // computation of critical pairs
[7c81165]214    //critPairs->print();
[c9193a]215    while( gPrev->getLast() != temp) {
216        //pWrite( *(gPrev->getFirst()->getPoly()) );
217       // pWrite( *(l->getPoly()) );
[1534d9]218       //pWrite(newElement->getPoly());
219        //pWrite(temp->getPoly());
[c9193a]220        pLcm(newElement->getPoly(), temp->getPoly(), lcm);
221        pSetCoeff(lcm,nOne);
222        // computing factors u2 for new labels
[1534d9]223        //pExpVectorDiff(u1,lcm,t);
224        //Print("U1: ");
[24ac666]225        //pWrite(u1);
[1534d9]226        u1 = pDivide(lcm,t);
[24ac666]227        //pWrite(u1);
[1534d9]228        pSetCoeff(u1,nOne);
229        //Print("%p\n",u1);
230        //critPairs->print();
231        //pExpVectorDiff(u2,lcm,temp->getPoly());
232        //Print("U2: ");
[24ac666]233        //pWrite(u2);
[1534d9]234        u2 = pDivide(lcm, pHead(temp->getPoly()));
[24ac666]235        //pWrite(u2);
[1534d9]236        //Print("%p\n",u2);
237        pSetCoeff(u2,nOne);
[c9193a]238        //if(gPrev->getLast()->getIndex()==5) {
239            //Print("IN CRITPAIRS\n");
240        //    pWrite(u1);
241        //    Print("1st ELEMENT: ");
242        //    pWrite(newElement->getPoly());
243        //    Print("2nd ELEMENT: ");
244        //    pWrite(temp->getPoly());
245        //}
246        // testing both new labels by the F5 Criterion
[1534d9]247        //critPairs->print();
[85a342]248        if(!criterion2(gPrev->getFirst()->getIndex(), u2, temp, rules, rTag)
249           && !criterion2(gPrev->getFirst()->getIndex(), u1, newElement, rules, rTag) 
250           && !criterion1(gPrev,u1,newElement,lTag) && !criterion1(gPrev,u2,temp,lTag)) {
[c9193a]251            // if they pass the test, add them to CList critPairs, having the LPoly with greater
252            // label as first element in the CPair
253            if(newElement->getIndex() == temp->getIndex() && 
254            -1 == pLmCmp(ppMult_qq(u1, newElement->getTerm()),ppMult_qq(u2, temp->getTerm()))) {
255                //Print("zweites groesser\n");
[7c81165]256               
[c9193a]257                CPair* cp   =   new CPair(pDeg(ppMult_qq(u2,pHead(temp->getPoly()))), u2, 
258                                temp->getLPoly(), u1, newElement->getLPoly(), testedRule);                   
[1534d9]259               
[c9193a]260                critPairs->insert(cp);
[7c81165]261                //Print("LALA %p\n",critPairs->getFirst());
262                //sleep(5);
[c9193a]263            }
264            else {
265                CPair* cp   =   new CPair(pDeg(ppMult_qq(u2,pHead(temp->getPoly()))), u1, 
266                                newElement->getLPoly(), u2, temp->getLPoly(), testedRule);                   
[7c81165]267                //Print("erstes groesser\n");
[c9193a]268                critPairs->insert(cp);
[7c81165]269                //Print("LALA %p\n",critPairs->getFirst());
270                //sleep(5);
[c9193a]271            }
272        }
273        else {
274        }
275       
276        //Print("\n\n");
277        temp    =   temp->getNext();
278    }
279    // for debugging
280    //if(NULL != critPairs) {
281        //critPairs->print();
282        //sleep(5);
283    //}
[7c81165]284    //Print("END CRITPAIRS\n");
[c9193a]285}
286
287
288
289
[d51339]290
291
[9bb97e]292
[cce6ed3]293/*
294========================================
295Criterion 1, i.e. Faugere's F5 Criterion
296========================================
297*/
[9cb4078]298inline bool criterion1(LList* gPrev, poly t, LNode* l, LTagList* lTag) {
[a41f3aa]299    // starts at the first element in gPrev with index = (index of l)-1, these tags are saved in lTag
[d51339]300        int idx =   l->getIndex();
[24ac666]301    int i;
[d51339]302    if(idx == 1) {
[1534d9]303        //Print("HIER\n");
[d51339]304        return false;
305    }
306    else {
307        LNode* testNode =   gPrev->getFirst();
308        // save the monom t1*label_term(l) as it is tested various times in the following
309        poly u1 = ppMult_qq(t,l->getTerm());
[598870]310        //Print("------------------------------IN CRITERION 1-----------------------------------------\n");
311        //Print("TESTED ELEMENT: ");
312        //pWrite(l->getPoly());
[8066e80]313        //pWrite(l->getTerm());
[598870]314        //pWrite(ppMult_qq(t,l->getTerm()));
315        //Print("%d\n\n",l->getIndex());
[c4158f]316        while(testNode->getIndex() < idx) { // && NULL != testNode->getLPoly()) {
[598870]317            //pWrite(testNode->getPoly());
318            //Print("%d\n",testNode->getIndex());
[d51339]319            if(pLmDivisibleByNoComp(testNode->getPoly(),u1)) {
[598870]320                //Print("Criterion 1 NOT passed!\n");
[d51339]321                return true;
322            }
[598870]323            //pWrite(testNode->getNext()->getPoly());
[d51339]324            testNode    =   testNode->getNext();
[cce6ed3]325        }
[85a342]326        /*
[24ac666]327        ideal testId    =   idInit(idx-1,1);
328        for(i=0;i<idx-1;i++) {
329            testId->m[i]  =   pHead(testNode->getPoly());
330            testNode        =   testNode->getNext();
331        }
332        poly temp   =   kNF(testId,currQuotient,u1);
333        //pWrite(temp);
334        for(i=0;i<IDELEMS(testId);i++) {
335            testId->m[i]    =   NULL;
336        }
337        idDelete(&testId);
338        if(NULL == temp) {
[f6c7c9b]339            //if(l->getIndex() != gPrev->getFirst()->getIndex()) {
340            //    Print("----------------------------Criterion1 not passed----------------------------------\n");
341            //}
[24ac666]342            return true;
343        }
[85a342]344        */
[d51339]345        return false;
[66e7b5]346    }
347}
[cce6ed3]348
[9bb97e]349
350
[66e7b5]351/*
352=====================================
353Criterion 2, i.e. Rewritten Criterion
354=====================================
355*/
[f6c7c9b]356inline bool criterion2(int idx, poly t, LNode* l, RList* rules, RTagList* rTag) {
[55a828]357    //Print("------------------------------IN CRITERION 2/1-----------------------------------------\n");
[1534d9]358    /* 
[7c81165]359    Print("RULES: \n");
360        RNode* tempR    =   rules->getFirst();
[1534d9]361        Print("%p\n",tempR);
[7c81165]362        int i   = 1;
[c4158f]363        while(NULL != tempR) {
[7c81165]364            Print("ADDRESS OF %d RNODE: %p\n",i,tempR);
365            Print("ADDRESS OF RULE: %p\n",tempR->getRule());
366            pWrite(tempR->getRuleTerm());
367            Print("ADDRESS OF TERM: %p\n",tempR->getRuleTerm());
368            Print("%d\n\n",tempR->getRuleIndex());
369            tempR   =   tempR->getNext();
370            i++;
371        }
[55a828]372        //Print("TESTED ELEMENT: ");
373        //pWrite(l->getPoly());
374        //pWrite(l->getTerm());
375        //pWrite(ppMult_qq(t,l->getTerm()));
376        //Print("%d\n\n",l->getIndex());
[1534d9]377      */
[d51339]378// start at the previously added element to gPrev, as all other elements will have the same index for sure
[f6c7c9b]379    if(idx > l->getIndex()) {
380        return false;
381    }
382   
[c4158f]383    RNode* testNode; // =   new RNode();
[f6c7c9b]384   
385
[1534d9]386    if(NULL == rTag->getFirst()) {
[24ac666]387        if(NULL != rules->getFirst()) {
388            testNode    =   rules->getFirst();
389        }
390        else {
391            return false;
392        }
[87beab7]393    }
394    else {
[24ac666]395
[87beab7]396        if(l->getIndex() > rTag->getFirst()->getRuleIndex()) {
397            testNode    =   rules->getFirst();
398        }
399        else {
[e6d283f]400       //Print("HIER\n");
401            //Print("DEBUG\n");
[598870]402        //Print("L INDEX: %d\n",l->getIndex());
[fe88079]403            /*-------------------------------------
404             * TODO: WHEN INTERREDUCING THE GB THE
405             *       INDEX OF THE PREVIOUS ELEMENTS
406             *       GETS HIGHER!
[e6d283f]407             *-----------------------------------*/
408            //testNode    =   rules->getFirst();
409            testNode    =   rTag->get(l->getIndex());
410            if(NULL == testNode) {
411                testNode    =   rules->getFirst();
412            }
[598870]413            //Print("TESTNODE ADDRESS: %p\n",testNode);
[87beab7]414        }
415    }
[e6d283f]416    //testNode    =   rules->getFirst();
[35d0d1a]417        // save the monom t1*label_term(l) as it is tested various times in the following
[d51339]418    poly u1 = ppMult_qq(t,l->getTerm());
[a41f3aa]419    // first element added to rTag was NULL, check for this
[87beab7]420    //Print("%p\n",testNode->getRule());
421    // NOTE: testNode is possibly NULL as rTag->get() returns NULL for elements of index <=1!
[fe88079]422    //Print("TESTNODE: %p\n",testNode);
423    //pWrite(testNode->getRuleTerm());
[c4158f]424    if(NULL != testNode ) {   
[598870]425        //pWrite(testNode->getRuleTerm());
[70c15e]426    }
427    if(NULL != testNode) {
428        if(testNode->getRule() == l->getRule()) {
[598870]429            //Print("%p\n%p\n",testNode->getRule(),l->getRule());
430            //Print("EQUAL\n");
[70c15e]431        }
432        else {
[598870]433            //Print("NOT EQUAL\n");
[70c15e]434        }
435    }
[c4158f]436    while(NULL != testNode && testNode->getRule() != l->getRule() 
[87beab7]437          && l->getIndex() == testNode->getRuleIndex()) {
[55a828]438        //Print("%p\n",testNode);
[598870]439        //pWrite(testNode->getRuleTerm());
[55a828]440        //pWrite(t);
441        //pWrite(l->getTerm());
442        //pWrite(u1);
[61944d0]443        //Print("%d\n",testNode->getRuleIndex());
[24ac666]444        if(pLmDivisibleByNoComp(testNode->getRuleTerm(),u1)) {
[f6c7c9b]445            //Print("-----------------Criterion 2 NOT passed!-----------------------------------\n");
446            //Print("INDEX: %d\n",l->getIndex());
[70c15e]447            pDelete(&u1);
[e6d283f]448    //Print("------------------------------IN CRITERION 2/1-----------------------------------------\n\n");
[66e7b5]449            return true;
450        }
[35d0d1a]451                testNode    =   testNode->getNext();
[66e7b5]452    }
[fe88079]453    //delete testNode;
[70c15e]454    pDelete(&u1);
[e6d283f]455    //Print("------------------------------IN CRITERION 2/1-----------------------------------------\n\n");
[66e7b5]456    return false;
[199ae7]457}
458
[9bb97e]459
460
[8978fd]461/*
[9bb97e]462=================================================================================================================
463Criterion 2, i.e. Rewritten Criterion, for its second call in computeSPols(), with added lastRuleTested parameter
464=================================================================================================================
[8978fd]465*/
[9cb4078]466inline bool criterion2(poly t, LPoly* l, RList* rules, Rule* testedRule) {
[55a828]467    //Print("------------------------------IN CRITERION 2/2-----------------------------------------\n");
[598870]468    //Print("LAST RULE TESTED: %p",testedRule);
[c4158f]469    /*
470    Print("RULES: \n");
471        RNode* tempR    =   rules->getFirst();
472        while(NULL != tempR) {
473            pWrite(tempR->getRuleTerm());
474            Print("%d\n\n",tempR->getRuleIndex());
475            tempR   =   tempR->getNext();
476        }
[598870]477        //Print("TESTED ELEMENT: ");
478        //pWrite(l->getPoly());
[8066e80]479        //pWrite(l->getTerm());
[598870]480        //pWrite(ppMult_qq(t,l->getTerm()));
481        //Print("%d\n\n",l->getIndex());
[c4158f]482    */
[d51339]483// start at the previously added element to gPrev, as all other elements will have the same index for sure
[87beab7]484        RNode* testNode =   rules->getFirst();
[8978fd]485    // save the monom t1*label_term(l) as it is tested various times in the following
[d51339]486    poly u1 = ppMult_qq(t,l->getTerm());
[35d0d1a]487        // first element added to rTag was NULL, check for this
[c4158f]488        while(NULL != testNode && testNode->getRule() != testedRule) {
[598870]489        //pWrite(testNode->getRuleTerm());
[24ac666]490        if(pLmDivisibleByNoComp(testNode->getRuleTerm(),u1)) {
[f6c7c9b]491            //Print("--------------------------Criterion 2 NOT passed!------------------------------\n");
492            //Print("INDEX: %d\n",l->getIndex());
[70c15e]493            pDelete(&u1);
[e6d283f]494    //Print("------------------------------IN CRITERION 2/2-----------------------------------------\n\n");
[8978fd]495            return true;
496        }
[35d0d1a]497                testNode    =   testNode->getNext();
[8978fd]498    }
[70c15e]499    pDelete(&u1);
[e6d283f]500    //Print("------------------------------IN CRITERION 2/2-----------------------------------------\n\n");
[8978fd]501    return false;
502}
[66e7b5]503
[9bb97e]504
505
506/*
507==================================
508Computation of S-Polynomials in F5
509==================================
510*/
[fcb8022]511void computeSPols(CNode* first, RTagList* rTag, RList* rules, LList* sPolyList) { 
[87beab7]512    CNode* temp         =   first;
[61d32c]513    poly sp      =   pInit();
[eab144e]514    //Print("###############################IN SPOLS##############################\n");
[7c81165]515    //first->print();
516
517    while(NULL != temp) {
518        //Print("JA\n");
[9bb97e]519        // only if a new rule was added since the last test in subalgorithm criticalPair()
[87beab7]520        //if(rules->getFirst() != rTag->getFirst()) {
[7c81165]521        if(!criterion2(temp->getT1(),temp->getAdLp1(),rules,temp->getTestedRule())) {
[9bb97e]522                // the second component is tested only when it has the actual index, otherwise there is
523                // no new rule to test since the last test in subalgorithm criticalPair()
[e90881]524                if(highestDegree < pDeg(ppMult_qq(temp->getT1(),temp->getLp1Poly()))) { 
525                    highestDegree   = pDeg(ppMult_qq(temp->getT1(),temp->getLp1Poly()));
526                    //pWrite(pHead(ppMult_qq(temp->getT1(),temp->getLp1Poly())));
527                }   
[9bb97e]528                if(temp->getLp2Index() == temp->getLp1Index()) {
[eab144e]529                    if(!criterion2(temp->getT2(),temp->getAdLp2(),rules,temp->getTestedRule())) {
[9bb97e]530                        // computation of S-polynomial
531                        sp      =   pSub(ppMult_qq(temp->getT1(),temp->getLp1Poly()),
532                                         ppMult_qq(temp->getT2(),temp->getLp2Poly()));
[598870]533                        //Print("BEGIN SPOLY1\n====================\n");
[eab144e]534                        pNorm(sp);
[598870]535                        //pWrite(sp);
536                        //Print("END SPOLY1\n====================\n");
[87beab7]537                        if(NULL == sp) {
[9bb97e]538                            // as rules consist only of pointers we need to save the labeled
539                            // S-polynomial also of a zero S-polynomial
540                            //zeroList->insert(temp->getAdT1(),temp->getLp1Index(),&sp);
541                            // origin of rule can be set NULL as the labeled polynomial
542                            // will never be used again as it is zero => no problems with
543                            // further criterion2() tests and termination conditions
[598870]544                            //Print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ZERO REDUCTION~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
[35d0d1a]545                                                        reductionsToZero++;
[55a828]546                        //Print("IN SPOLS 1\n");
[eab144e]547                            rules->insert(temp->getLp1Index(),ppMult_qq(temp->getT1(),temp->getLp1Term()));
[598870]548                            //Print("RULE ADDED: \n");
549                            //pWrite(rules->getFirst()->getRuleTerm());
[87beab7]550                            // as sp = NULL, delete it
[eab144e]551                            pDelete(&sp);
[598870]552                            //Print("HIER\n");
[9bb97e]553                        }
554                        else {
[55a828]555                        //Print("IN SPOLS 2\n");
[eab144e]556                            rules->insert(temp->getLp1Index(),ppMult_qq(temp->getT1(),temp->getLp1Term()));
[598870]557                            //Print("RULE ADDED: \n");
558                            //pWrite(rules->getFirst()->getRuleTerm()); 
[8066e80]559                            sPolyList->insertByLabel(ppMult_qq(temp->getT1(),temp->getLp1Term()),temp->getLp1Index(),sp,rules->getFirst()->getRule());
[9bb97e]560                        }
561                        // data is saved in sPolyList or zero => delete sp
562                    }
563                }
564                else { // temp->getLp2Index() < temp->getLp1Index()
565                    // computation of S-polynomial
566                    sp      =   pSub(ppMult_qq(temp->getT1(),temp->getLp1Poly()),
567                                     ppMult_qq(temp->getT2(),temp->getLp2Poly()));
[598870]568                    //Print("BEGIN SPOLY2\n====================\n");
[d51339]569                    pNorm(sp);
[598870]570                    //pWrite(sp);
571                    //Print("END SPOLY2\n====================\n");
[87beab7]572                    if(NULL == sp) {
[9bb97e]573                        // zeroList->insert(temp->getAdT1(),temp->getLp1Index(),&sp);
574                        // origin of rule can be set NULL as the labeled polynomial
575                        // will never be used again as it is zero => no problems with
576                        // further criterion2() tests and termination conditions
[598870]577                            //Print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ZERO REDUCTION~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
[fcb8022]578                        reductionsToZero++;
[55a828]579                        //Print("IN SPOLS 3\n");
[eab144e]580                        rules->insert(temp->getLp1Index(),ppMult_qq(temp->getT1(),temp->getLp1Term()));
[598870]581                        //Print("RULE ADDED: \n");
582                        //pWrite(rules->getFirst()->getRuleTerm());
[87beab7]583                        // as sp = NULL, delete it
[eab144e]584                        pDelete(&sp);
[9bb97e]585                    }
586                    else {
[55a828]587                        //Print("IN SPOLS 4\n");
[eab144e]588                        rules->insert(temp->getLp1Index(),ppMult_qq(temp->getT1(),temp->getLp1Term()));
[598870]589                        //Print("RULE ADDED: \n");
590                        //pWrite(rules->getFirst()->getRuleTerm());
591                        //Print("%d\n",rules->getFirst()->getRuleIndex());
592                        //Print("%p\n",sPolyList->getFirst());
[61944d0]593                        sPolyList->insertByLabel(ppMult_qq(temp->getT1(),temp->getLp1Term()),temp->getLp1Index(),sp,rules->getFirst()->getRule());
[9bb97e]594                    }
595                }
596            }
[87beab7]597        //}
[7c81165]598        //Print("%p\n",temp);
[9bb97e]599        temp    =   temp->getNext();
[7c81165]600        //Print("%p\n",temp);
601        //Print("%p\n",temp->getData());
602        //pWrite(temp->getLp1Poly());
[9bb97e]603    }
604    // these critical pairs can be deleted now as they are either useless for further computations or
605    // already saved as an S-polynomial to be reduced in the following
606    delete first;   
607}
608
609
610
611/*
612========================================================================
613reduction including subalgorithm topReduction() using Faugere's criteria
614========================================================================
615*/
[d51339]616void reduction(LList* sPolyList, CList* critPairs, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, 
[fcb8022]617                 ideal gbPrev) { 
[598870]618    //Print("##########################################In REDUCTION!########################################\n");
[416ea2]619    // check if sPolyList has any elements
620    // NOTE: due to initialization sPolyList always has a default NULL element
[d51339]621    while(sPolyList->getLength() > 0) {
[598870]622        //Print("SPOLYLIST LENGTH: %d\n",sPolyList->getLength());
[70c15e]623        if(sPolyList->getLength() > 1) {
[598870]624        //Print("%p\n",sPolyList->getFirst());
625        //Print("%p\n",sPolyList->getFirst()->getLPoly());
626        //Print("%p\n",sPolyList->getFirst()->getNext());
627        //Print("%p\n",sPolyList->getFirst()->getNext()->getLPoly());
628        //Print("%p\n",sPolyList->getFirst());
[70c15e]629        }
[61944d0]630        //if(gPrev->getLast()->getIndex() == 5) {
631            //sPolyList->print();
632            //sleep(5);
633        //}
634       
[416ea2]635        // temp is the first element in the sPolyList which should be reduced
636        // due to earlier sorting this is the element of minimal degree AND
637        // minimal label
[9bb97e]638        LNode* temp =   sPolyList->getFirst();
[598870]639        //pWrite(temp->getPoly());
[416ea2]640        // delete the above first element from sPolyList, temp will be either reduced to
641        // zero or added to gPrev, but never come back to sPolyList
[c4158f]642        if(NULL != temp) { 
[598870]643            sPolyList->setFirst(temp->getNext());
644        //Print("HIER\n");
645        }
646        else {
647            break;
648        }
649        //Print("HALLO %p\n",temp->getPoly());
650        //Print("%p\n",temp->getPoly());
651        //pWrite(temp->getPoly());
652        //idShow(gbPrev);
[416ea2]653        poly tempNF = kNF(gbPrev,currQuotient,temp->getPoly());
[598870]654        //Print("LENGTH: %d\n",sPolyList->getLength());
655        //pWrite(tempNF);
656        //pWrite(temp->getPoly());
[416ea2]657        if(NULL != tempNF) {
[c9193a]658            pNorm(tempNF);
[416ea2]659            // write the reduced polynomial in temp
[fcb8022]660            temp->setPoly(tempNF);
[416ea2]661            // try further reductions of temp with polynomials in gPrev
662            // with label index = current label index: this is done such that there
663            // is no label corruption during the reduction process
[61944d0]664            topReduction(temp,sPolyList,gPrev,rules,lTag,rTag,gbPrev);
[70c15e]665       
[d51339]666        }
667        if(NULL != temp->getPoly()) {
668            //CList* newCritPairs = new CList;
[598870]669            //Print("##################IN CRITPAIRS IN REDUCTION#####################\n");
[9cb4078]670            criticalPair(gPrev,critPairs,lTag,rTag,rules);
[8066e80]671            //Print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++H I E R++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
[d51339]672        }
673        else {
[70c15e]674            //delete temp;
675            LNode* tempLoop = gPrev->getFirst();
[598870]676            //Print("AUSGABE IN REDUCTION:\n");       
[8066e80]677            //while(NULL != tempLoop) {
[598870]678                //pWrite(tempLoop->getPoly());
[8066e80]679                //tempLoop = tempLoop->getNext();
680            //}
[70c15e]681            //sleep(10);
[9bb97e]682        }
[9cb4078]683       
[9bb97e]684    }
685}   
686
687
688
689/*
690=====================================================================================
691top reduction in F5, i.e. reduction of a given S-polynomial by labeled polynomials of
692the same index whereas the labels are taken into account
693=====================================================================================
694*/
[61944d0]695void topReduction(LNode* l, LList* sPolyList, LList* gPrev, RList* rules, LTagList* lTag, RTagList* rTag, ideal gbPrev) {
[598870]696    //Print("##########################################In topREDUCTION!########################################\n");
[d51339]697    // try l as long as there are reductors found by findReductor()
698    do {
[338842d]699        LNode* gPrevRedCheck    =   new LNode(lTag->getFirstCurrentIdx());
[9cb4078]700        //Print("gPrevCheckPOLY: ");
701        //pWrite(gPrevRedCheck->getPoly());
[338842d]702        LNode* tempRed          =   new LNode();
[55a828]703        //Print("TESTED POLYNOMIAL IN THE FOLLOWING: ");
704        //pWrite(l->getPoly());
[c9193a]705        //Print("HIER\n");
[338842d]706        tempRed  =   findReductor(l,gPrevRedCheck,gPrev,rules,lTag,rTag);
[fe88079]707        //Print("TEMPRED NEXT: %p\n",tempRed->getNext());
[598870]708        //Print("--------------------------------HIER DEBUG 2----------------------------------\n");
[d51339]709        // if a reductor for l is found and saved in tempRed
710        if(NULL != tempRed) {
711            // if label of reductor is greater than the label of l we have to built a new element
712            // and add it to sPolyList
[55a828]713            //Print("REDUCTOR POLYNOMIAL: ");
714            //pWrite(tempRed->getPoly());
715            //Print("TEMPRED: %p\n",tempRed);
716            //Print("TERM: ");
717            //pWrite(tempRed->getTerm());
[d51339]718            if(pLmCmp(tempRed->getTerm(),l->getTerm()) == 1) {
[61944d0]719                // needed sinc pSub destroys the arguments!
[8066e80]720                //Print("H----------I------------E--------------R\n");
[61944d0]721                poly temp_poly_l    =   pInit();
722                temp_poly_l         =   pCopy(l->getPoly());
723                //Print("POLYNOMIAL L: ");
724                //pWrite(l->getPoly());
725                //pWrite(temp_poly_l);
726                poly temp           =   pSub(tempRed->getPoly(),temp_poly_l);
727                //Print("POLYNOMIAL L: ");
728                //pWrite(l->getPoly());
729                //pWrite(temp_poly_l);
730                //Print("AFTER REDUCTION STEP: ");
731                //pWrite(temp);
732                //sleep(20);
[598870]733                //pWrite(temp);
[d51339]734                if(NULL != temp) {
[70c15e]735                    pNorm(temp);
[d51339]736                    tempRed->setPoly(temp);
[e90881]737                    tempRed->setDel(1);
[d51339]738                    // for debugging
[598870]739                    //pWrite(tempRed->getPoly());
[55a828]740                    //Print("RULE ADDED\n");
[d51339]741                    rules->insert(tempRed->getIndex(),tempRed->getTerm());
742                    tempRed->getLPoly()->setRule(rules->getFirst()->getRule());
[55a828]743                    //Print("%p\n",sPolyList->getFirst());
744                    //Print("%p\n",sPolyList->getFirst()->getLPoly());
745                    //Print("SPOLYLIST LENGTH: %d\n",sPolyList->getLength());
[8066e80]746                    //sPolyList->print();
747                   
[d51339]748                    sPolyList->insertByLabel(tempRed);
[55a828]749                    //sPolyList->print();
[8066e80]750                    //Print("SPOLYLIST LENGTH: %d\n",sPolyList->getLength());
751                    //Print("OH JE\n");
[d51339]752                }
753                else {
754                    pDelete(&temp);
755                    reductionsToZero++;
[598870]756                    //Print("RULE ADDED\n");
[55a828]757                    //rules->insert(tempRed->getIndex(),tempRed->getTerm());
758                    //pWrite(rules->getFirst()->getRuleTerm());
759                    //Print("DELETE TEMPRED\n");
[d51339]760                    delete tempRed;
761                }
762            }
763            // label of reductor is smaller than the label of l, subtract reductor from l and delete the
764            // gPrevRedCheck pointer added to l during findReductor() as the head term of l changes
765            // after subtraction
766            else {
[61944d0]767                poly temp_poly_l    =   pInit();
768                temp_poly_l         =   pCopy(l->getPoly());
769                poly temp   =   pSub(temp_poly_l,tempRed->getPoly());
770                //Print("AFTER REDUCTION STEP: ");
[598870]771                //pWrite(temp);
[d51339]772                if(NULL != temp) {
[70c15e]773                    pNorm(temp);
[61944d0]774                    poly tempNF =   kNF(gbPrev,currQuotient,temp); 
775                    pNorm(tempNF);
[c9193a]776                    //pWrite(tempNF);
777                    if(NULL == tempNF) {
778                        reductionsToZero++;
779                        pDelete(&tempNF);
780                        l->setPoly(NULL);
781                        break;
782                    }
[61944d0]783                    l->setPoly(tempNF);
[c9193a]784                   
785                    //pWrite(l->getPoly());
[338842d]786                    gPrevRedCheck   =   lTag->getFirstCurrentIdx();
[d51339]787                }
788                else {
[598870]789                    //Print("ZERO REDUCTION!\n");
[70c15e]790                    reductionsToZero++;
[d51339]791                    pDelete(&temp);
792                    l->setPoly(NULL);
[598870]793                    //pWrite(gPrev->getLast()->getPoly());
[70c15e]794                    break;
[d51339]795                }
796            }   
797        }
798        else {
799            if(NULL != l->getPoly()) {
[61944d0]800                pNorm(l->getPoly());
[55a828]801                //Print("----------------------------------ADDED TO GPREV IN TOPREDUCTION:-------------------------------------- ");
802                //pWrite(l->getPoly());
803                //pWrite(l->getTerm());
804                //Print("INDEX: %d\n\n\n", l->getIndex());
[8066e80]805                //sleep(20);
[d51339]806                gPrev->insert(l->getLPoly());
[598870]807                //Print("GPREV: \n");
[d51339]808                LNode* tempLoop = gPrev->getFirst();
[8066e80]809                //while(NULL != tempLoop) {
[598870]810                    //Print("HERE\n");
811                    //pWrite(tempLoop->getPoly());
[8066e80]812                    //tempLoop = tempLoop->getNext();
813                //}
[d51339]814            }
815            break;
816        }
817    } while(1);
[416ea2]818}
[9bb97e]819
820
821/*
822=====================================================================
823subalgorithm to find a possible reductor for the labeled polynomial l
824=====================================================================
825*/
[338842d]826LNode* findReductor(LNode* l, LNode* gPrevRedCheck, LList* gPrev, RList* rules, LTagList* lTag,RTagList* rTag) {
[d51339]827    // allociation of memory for the possible reductor
[598870]828    //Print("IN FIND REDUCTOR\n");
[d51339]829    poly u      =   pOne();
830    poly red    =   pOne();
831    number nOne =   nInit(1);
832    LNode* temp =   new LNode();
833    // head term of actual element such that we do not have to call pHead at each new reductor test
834    poly t      =   pHead(l->getPoly());
835    // if l was already checked use the information in gPrevRedCheck such
836    // that we can start searching for new reducers from this point and
837    // not from the first element of gPrev with the current index
[338842d]838    temp    =   gPrevRedCheck;
[fe88079]839    //temp    =   lTag->getFirstCurrentIdx(); 
840    //Print("GPREVREDCHECK: %p\n",gPrevRedCheck);
841    //pWrite(gPrevRedCheck->getPoly());
[d51339]842    // search for reductors until we are at the end of gPrev resp. at the
843    // end of the elements of the current index
844    while(NULL != temp && temp->getIndex() == l->getIndex()) {
[338842d]845        //pWrite(temp->getPoly());
846        //Print("INDEX: %d\n",temp->getIndex());
[d51339]847        // does the head of the element of gPrev divides the head of
848        // the to be reduced element?
[c9193a]849        //Print("-------------FOUND REDUCTORS----------------------\n");
850        //Print("\n");
851        //pWrite(temp->getPoly());
852        //pWrite(temp->getTerm());
853        //pWrite(t);
854        //Print("HALLO\n");
[24ac666]855        if(pLmDivisibleByNoComp(pHead(temp->getPoly()),t)) {
[c9193a]856        //Print("HALLO\n");
[d51339]857            // get all the information needed for the following tests
858            // of the criteria
859            u   =   pDivide(t,pHead(temp->getPoly()));
860            pSetCoeff(u,nOne);
[c9193a]861            //Print("HIER FINDRED\n");
862            //pWrite(u);
863            //Print("\n");
[d51339]864            red =   ppMult_qq(u,temp->getPoly());
865            pNorm(red);
[61944d0]866            //u   =   ppMult_qq(u,temp->getTerm());
867            //pSetCoeff(u,nOne);
[d51339]868            // check if both have the same label
[c9193a]869        //Print("HALLO\n");
[d51339]870            if(pLmCmp(u,l->getTerm()) != 0) {
[c9193a]871        //Print("HALLO\n");
[d51339]872                // passing criterion2 ?
[f6c7c9b]873                if(!criterion2(gPrev->getFirst()->getIndex(), u,temp,rules,rTag)) {
[d51339]874                    // passing criterion1 ?
875                    if(!criterion1(gPrev,u,temp,lTag)) {
[598870]876                            //Print("HIER DEBUG\n");
[9cb4078]877                            gPrevRedCheck   =   temp->getNext();
[8066e80]878                            LNode* redNode  =   new LNode(ppMult_qq(u,temp->getTerm()),temp->getIndex(),red,NULL,NULL);
[d51339]879                            return redNode;
880                    }
881                }
882            }
883        }
[c9193a]884        //Print("%p\n",temp->getNext());
885        //pWrite(temp->getPoly());
886        //Print("HALLO\n");
[d51339]887        temp = temp->getNext();
888    }
889   
890//    delete temp;
[598870]891   //Print("1st gPrev: ");
892    //pWrite(gPrev->getFirst()->getPoly());
893    //Print("2nd gPrev: ");
894    //pWrite(gPrev->getFirst()->getNext()->getPoly());
[d51339]895 return NULL;
[9bb97e]896}
897
898
899
[199ae7]900/*
901==========================================================================
[66e7b5]902MAIN:computes a gb of the ideal i in the ring r with our F5 implementation
[199ae7]903==========================================================================
904*/
905ideal F5main(ideal id, ring r) {
[85a342]906    int timer   =   initTimer();
907    startTimer();
[9cb4078]908    int i,j,k,l;
[87beab7]909    int gbLength;
[a0350e9]910    // 1 polynomial for defining initial labels & further tests
[66e7b5]911    poly ONE = pOne();
[9cb4078]912    poly pOne   =   pOne();
913    number nOne =   nInit(1);
[87beab7]914    // tag the first element of index i-1 for criterion 1
915    LTagList* lTag  =   new LTagList();
[55a828]916    //Print("LTAG BEGINNING: %p\n",lTag);
[ed30c5]917   
[e90881]918    // DEBUGGING STUFF START
[66a5f8]919    //Print("NUMBER: %d\n",r->N);
[e90881]920   
921    //int* ev = new int[r->N];
922    //int  ev2;
923    //for(i=0;i<IDELEMS(id);i++) {
924        //pGetExpV(id->m[i],ev);
925        //ev2  =   pGetExp(id->m[i],1);
926        //pWrite(id->m[i]);
927        //Print("%d\n",ev2);
928        //Print("EXP1: %d\n",ev[1]);
929        //Print("EXP2: %d\n",ev[2]);
930        //Print("EXP3: %d\n\n",ev[3]);
931    //}
[66a5f8]932    //delete ev;
[e90881]933   
934    /*DEBUGGING STUFF END */
[66a5f8]935   
[87beab7]936    // first element in rTag is first element of rules which is NULL RNode,
937    // this must be done due to possible later improvements
938    RList* rules    =   new RList();
[f6c7c9b]939    //Print("RULES FIRST: %p\n",rules->getFirst());
[55a828]940    //Print("RULES FIRST DATA: %p\n",rules->getFirst()->getRule());
[87beab7]941    RTagList* rTag  =   new RTagList(rules->getFirst());
942    i = 1;
[66a5f8]943    /*for(j=0; j<IDELEMS(id); j++) {
[199ae7]944        if(NULL != id->m[j]) {
945            if(pComparePolys(id->m[j],ONE)) {
[ed30c5]946                Print("One Polynomial in Input => Computations stopped\n");
[cce6ed3]947                ideal idNew = idInit(1,1);
948                idNew->m[0] = ONE;
949                return(idNew);
[ed30c5]950            }   
[cfb8edb]951        }
[66a5f8]952    }*/ 
[c9193a]953    ideal idNew     =   kInterRed(id); 
954    id              =   idNew;
[24ac666]955    //qsortDegree(&id->m[0],&id->m[IDELEMS(id)-1]);
[9cb4078]956    idShow(id);
[9bb97e]957    LList* gPrev    =   new LList(ONE, i, id->m[0]);
[61944d0]958    //idShow(id);
[598870]959    //Print("%p\n",id->m[0]);
960    //pWrite(id->m[0]);
961    //Print("%p\n",gPrev->getFirst()->getPoly());
962    //pWrite(gPrev->getFirst()->getPoly());
[61d32c]963
[87beab7]964    lTag->insert(gPrev->getFirst());
[d51339]965    lTag->setFirstCurrentIdx(gPrev->getFirst());
[9bb97e]966    // computing the groebner basis of the elements of index < actual index
[87beab7]967    gbLength    =   gPrev->getLength();
[598870]968    //Print("Laenge der bisherigen Groebner Basis: %d\n",gPrev->getLength());
[fcb8022]969    ideal gbPrev    =   idInit(gbLength,1);
[9bb97e]970    // initializing the groebner basis of elements of index < actual index
971    gbPrev->m[0]    =   gPrev->getFirst()->getPoly();
[598870]972    //idShow(gbPrev);
973    //idShow(currQuotient);
[cce6ed3]974    for(i=2; i<=IDELEMS(id); i++) {
[d51339]975        LNode* gPrevTag =   gPrev->getLast();
[598870]976        //Print("Last POlynomial in GPREV: ");
977        //Print("%p\n",gPrevTag);   
978        //pWrite(gPrevTag->getPoly());
[87beab7]979        gPrev   =   F5inc(i, id->m[i-1], gPrev, gbPrev, ONE, lTag, rules, rTag);
[e90881]980        Print("%d\n",gPrev->count(gPrevTag->getNext()));
981        Print("%d\n",gPrev->getLength());
[7c81165]982        //Print("____________________________________ITERATION STEP DONE________________________________________\n");
[9cb4078]983       
[70c15e]984        // DEBUGGING STUFF
985        LNode* temp    =   gPrev->getFirst();
[598870]986    // computing new groebner basis gbPrev
[d51339]987        if(gPrev->getLength() > gbLength) {
[e90881]988            if(i < IDELEMS(id)) {
989                ideal gbAdd =   idInit(gPrev->getLength()-gbLength,1);
990                LNode*  temp =   gPrevTag;
991                int counter =   0;
992                for(j=0;j<=gPrev->getLength()-gbLength-1;j++) {
993                    temp        =   temp->getNext();
994                    if(0 == temp->getDel()) {
995                        counter++;
996                        gbAdd->m[j] =   temp->getPoly();
997                    }
998                        //if(1 == temp->getDel()) {
999                        //    pWrite(temp->getPoly());
1000                        //}
[9cb4078]1001                }
[e90881]1002                if(counter != gPrev->count(gPrevTag->getNext())) {
1003                    Print("----------------------------------WRONG COUNTING---------------------------\n");
1004                }
1005                    gbPrev          =   idAdd(gbPrev,gbAdd);
1006                    //idShow(gbPrev);
1007            }
1008            else {
1009                ideal gbAdd =   idInit(gPrev->getLength()-gbLength,1);
1010                LNode*  temp =   gPrevTag;
1011                for(j=0;j<=gPrev->getLength()-gbLength-1;j++) {
1012                    temp        =   temp->getNext();
1013                    gbAdd->m[j] =   temp->getPoly();
1014                }
1015                gbPrev          =   idAdd(gbPrev,gbAdd);
[9cb4078]1016            }
1017            // interreduction stuff
1018            if(i<IDELEMS(id)) {
[e90881]1019                int timer2  =   initTimer();
1020                startTimer();
[9cb4078]1021                ideal tempId    =   kInterRed(gbPrev);
[e90881]1022               
[24ac666]1023                //idShow(tempId);
[9cb4078]1024                gbPrev          =   tempId;
[e90881]1025                timer2  =   getTimer();
1026                Print("Timer INTERREDUCTION: %d\n",timer2);
1027                //idShow(gbPrev);
[24ac666]1028                //qsortDegree(&gbPrev->m[0],&gbPrev->m[IDELEMS(gbPrev)-1]);
[9cb4078]1029                delete gPrev;
[1534d9]1030                //sleep(5);
[fe88079]1031                //Print("RULES FIRST NOW1: %p\n",rules->getFirst());
[55a828]1032                //Print("HIER\n");
[9cb4078]1033                delete rules;
[c3da59]1034                //delete rTag;
[55a828]1035                //Print("HIER AUCH\n");
[fe88079]1036                //Print("%p\n",rules->getFirst());
1037                gPrev    =   new LList(pOne,1,gbPrev->m[0]);
[9cb4078]1038                gPrev->insert(pOne,1,gbPrev->m[1]);
[85a342]1039                //poly tempPoly = pInit();
1040                //pLcm(pHead(gbPrev->m[0]),pHead(gbPrev->m[1]),tempPoly);
1041                //tempPoly    =   pDivide(tempPoly,pOne());
1042                //pSetCoeff(tempPoly,nOne);
[9cb4078]1043                rules    =   new RList();
[e6d283f]1044                rTag     =   new RTagList(rules->getFirst());
[c3da59]1045               
[fe88079]1046                //Print("%p\n",rules->getFirst());
[f6c7c9b]1047                //pWrite(tempPoly);
[85a342]1048                //rules->insert(2,tempPoly);
1049                //rTag->insert(rules->getFirst());
[e6d283f]1050                //Print("%p\n",rules->getFirst());
1051                //Print("%p\n",rTag->getFirst());
[fe88079]1052                //Print("%p\n",rules->getFirst());
1053                //Print("%p\n",rules->getFirst()->getNext()->getNext());
1054                //Print("HIERLALA\n");
1055            //pWrite(rules->getFirst()->getRuleTerm());
[55a828]1056           // Print("RULES FIRST NOW2: %p\n",rules->getFirst());
[9cb4078]1057                for(k=2; k<IDELEMS(gbPrev); k++) {
1058                    gPrev->insert(pOne,k+1,gbPrev->m[k]);
1059                    for(l=0; l<k; l++) {
[55a828]1060                        //pWrite(gbPrev->m[k]);
1061                        //pWrite(gbPrev->m[l]);
[85a342]1062                        //poly tempPoly2  =   pOne();
1063                        //pLcm(pHead(gbPrev->m[k]),pHead(gbPrev->m[l]),tempPoly2);
1064                        //tempPoly2   =   pDivide(tempPoly2,pOne());
1065                        //pSetCoeff(tempPoly2,nOne);
[f6c7c9b]1066                        //pWrite(tempPoly2);
[85a342]1067                        //rules->insert(k+1,tempPoly2);
[9cb4078]1068                    }
[85a342]1069                    //rTag->insert(rules->getFirst());
[9cb4078]1070                }
1071            }
1072            gbLength    =   gPrev->getLength(); 
[e6d283f]1073            //Print("HIER\n");
[d51339]1074        }
[55a828]1075        //gPrev->print();
[9cb4078]1076        //int anzahl  =   1;
[598870]1077        //while(NULL != temp) {
1078        //    Print("%d. Element: ",anzahl);
1079        //    pWrite(temp->getPoly());
1080        //    Print("\n");
1081        //    temp    =   temp->getNext();
1082        //    anzahl++;
1083        //}
1084        //sleep(5);
1085        //Print("GROEBNER BASIS:\n====================================================\n");
1086        //idShow(gbPrev);
1087        //Print("===================================================\n");
1088        //Print("JA\n");
[e90881]1089        Print("LENGTH OF GPREV: %d\n",gPrev->getLength());
[cce6ed3]1090    } 
[c4158f]1091        //idShow(gbPrev);
[fcb8022]1092    Print("\n\nNumber of zero-reductions:  %d\n",reductionsToZero);
[85a342]1093    timer   =   getTimer();
[e90881]1094    Print("Highest Degree during computations: %d\n",highestDegree);
[85a342]1095    Print("Time for computations: %d/1000 seconds\n",timer);
[598870]1096    //LNode* temp    =   gPrev->getFirst();
1097    //while(NULL != temp) {
1098    //    pWrite(temp->getPoly());
1099    //    temp    =   temp->getNext();
1100    // }
[338842d]1101    //gPrev->print();
1102    //delete lTag;
1103    //delete rTag;
[9cb4078]1104    //delete gPrev;
[e90881]1105    reductionTime   =   0;
1106    spolsTime       =   0;
[fcb8022]1107    return(gbPrev);
[9a6e9f]1108
1109
[936551]1110}
[9a6e9f]1111
[936551]1112#endif
Note: See TracBrowser for help on using the repository browser.