source: git/kernel/f5lists.cc @ 70c15e

jengelh-datetimespielwiese
Last change on this file since 70c15e was 70c15e, checked in by Christian Eder, 14 years ago
problem in cyclic_n(4) solved git-svn-id: file:///usr/local/Singular/svn/trunk@11441 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.0 KB
Line 
1#include "mod2.h"
2
3#ifdef HAVE_F5
4#include "kutil.h"
5#include "structs.h"
6#include "omalloc.h"
7#include "polys.h"
8#include "p_polys.h"
9#include "ideals.h"
10#include "febase.h"
11#include "kstd1.h"
12#include "khstd.h"
13#include "kbuckets.h"
14#include "weight.h"
15#include "intvec.h"
16#include "pInline1.h"
17#include "f5gb.h"
18#include "f5data.h"
19#include "f5lists.h"
20
21/*
22====================================
23functions working on the class LNode
24====================================
25*/
26
27// generating new list elements (labeled / classical polynomial / LNode view)
28LNode::LNode() {
29    data                =   NULL;
30    next                =   NULL;
31    gPrevRedCheck       =   NULL;
32}
33 LNode::LNode(LPoly* lp) {
34    data                =   lp;
35    next                =   NULL;
36    gPrevRedCheck       =   NULL;
37}
38       
39LNode::LNode(LPoly* lp, LNode* l) {
40Print("HIER LNODE\n");
41    data                =   lp;
42    next                =   l;
43    gPrevRedCheck       =   NULL;
44}
45
46LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck) {
47LPoly* lp           =   new LPoly(t,i,p,r);
48data                =   lp;
49next                =   NULL;
50gPrevRedCheck       =   gPCheck;
51}
52       
53LNode::LNode(poly t, int i, poly p, Rule* r, LNode* gPCheck, LNode* l) {
54    LPoly* lp           =   new LPoly(t,i,p,r);
55    data                =   lp;
56    next                =   l;
57    gPrevRedCheck       =   gPCheck;
58}
59
60 LNode::LNode(LNode* ln) {
61    data                =   ln->getLPoly();
62    next                =   ln->getNext();
63    gPrevRedCheck       =   NULL;
64}
65       
66LNode::~LNode() {
67    //delete next;
68    delete gPrevRedCheck;
69    delete data;   
70}
71       
72// insert new elements to the list always at the end (labeled / classical polynomial view)
73// needed for list gPrev
74LNode* LNode::insert(LPoly* lp) {
75    Print("INSERTION: \n");
76    Print("LAST GPREV: ");
77    pWrite(this->getPoly());
78LNode* newElement   =   new LNode(lp, NULL);
79    this->next          =   newElement;
80    return newElement;
81}
82       
83LNode* LNode::insert(poly t, int i, poly p, Rule* r) {
84    LNode* newElement   =   new LNode(t, i, p, r, NULL, NULL);
85    this->next          =   newElement;
86    return newElement;
87}
88
89// insert new elements to the list always in front (labeled / classical polynomial view)
90// needed for sPolyList
91LNode* LNode::insertSP(LPoly* lp) {
92    LNode* newElement   =   new LNode(lp, this);
93    return newElement;
94}
95       
96LNode* LNode::insertSP(poly t, int i, poly p, Rule* r) {
97    LNode* newElement   =   new LNode(t, i, p, r, NULL, this);
98    return newElement;
99}
100// insert new elemets to the list w.r.t. increasing labels
101// only used for the S-polys to be reduced (TopReduction building new S-polys with higher label)
102LNode* LNode::insertByLabel(poly t, int i, poly p, Rule* r) {
103    if(NULL == data) {
104        LNode* newElement   =   new LNode(t, i, p, r, this);
105        return newElement;
106    }
107    else {
108        if(0 == pLmCmp(t,this->getTerm()) || -1 == pLmCmp(t,this->getTerm())) {
109            LNode* newElement   =   new LNode(t, i, p, r, this);
110            return newElement;
111        }
112        else {
113            LNode* temp = this;
114            while(NULL != temp->next && NULL != temp->next->data) {
115                if( 0 == pLmCmp(t,temp->next->getTerm()) || -1 == pLmCmp(t,temp->next->getTerm())) {
116                    LNode* newElement   =   new LNode(t, i, p, r, temp->next);
117                    temp->next          =   newElement;
118                    return this;
119                }
120                else {
121                    temp = temp->next;
122                    Print("%p\n",temp);
123                    Print("%p\n",temp->data);
124                   
125                    Print("%p\n",temp->next);
126                }
127            }
128        Print("HIER\n");
129            LNode* newElement   =   new LNode(t, i, p, r, temp->next);
130            temp->next          =   newElement;
131            return this;
132        }
133    }
134}
135
136// deletes the first elements of the list with the same degree
137// only used for the S-polys, which are already sorted by increasing degree by CList
138LNode*  LNode::deleteByDeg() {
139    return this;
140}
141
142// get next from current LNode
143LNode* LNode::getNext() {
144    return next;
145}
146
147// get the LPoly* out of LNode*
148LPoly* LNode::getLPoly() {
149    return data;
150}
151
152// get the data from the LPoly saved in LNode
153poly LNode::getPoly() {
154    return data->getPoly();
155}
156
157poly LNode::getTerm() {
158    return data->getTerm();
159}
160
161int LNode::getIndex() {
162    return data->getIndex();
163}
164
165Rule* LNode::getRule() {
166    return data->getRule();
167}
168
169LNode* LNode::getGPrevRedCheck() {
170    return gPrevRedCheck;
171}
172
173// set the data from the LPoly saved in LNode
174void LNode::setPoly(poly p) {
175    data->setPoly(p);
176}
177
178void LNode::setTerm(poly t) {
179    data->setTerm(t);
180}
181
182void LNode::setIndex(int i) {
183    data->setIndex(i);
184}
185
186void LNode::setGPrevRedCheck(LNode* l) {
187    gPrevRedCheck   =   l;
188}
189
190// test if for any list element the polynomial part of the data is equal to *p
191bool LNode::polyTest(poly* p) {
192    LNode* temp = new LNode(this);
193    while(NULL != temp) {
194        if(pComparePolys(temp->getPoly(),*p)) {
195            return 1;
196        }
197        temp = temp->next;
198    }
199    return 0;
200}
201
202LNode* LNode::getNext(LNode* l) {
203    return l->next;
204}
205
206// for debugging
207void LNode::print() {
208    LNode* temp = this;
209    Print("___________________List of S-polynomials______________________:\n");
210    while(NULL != temp && NULL != temp->data) {
211        Print("HIER\n");
212        Print("Index: %d\n",temp->getIndex());
213        Print("Term: ");
214        pWrite(temp->getTerm());
215        Print("Poly: ");
216        pWrite(temp->getPoly());
217        Print("\n");
218        temp = temp->next;
219    }
220}
221
222
223/*
224====================================
225functions working on the class LList
226====================================
227*/
228
229LList::LList() {
230    first   =   new LNode();
231    last    =   first;
232    length  =   0;
233}
234
235LList::LList(LPoly* lp) {
236    first   =   new LNode(lp);
237    last    =   first;
238    length  =   1;
239}
240
241LList::LList(poly t,int i,poly p,Rule* r) {
242    first   =   new LNode(t,i,p,r);
243    last    =   first;
244    length  =   1;
245} 
246
247LList::~LList() {
248    delete first;
249}
250
251// insertion at the end of the list, needed for gPrev
252void LList::insert(LPoly* lp) {
253    last = last->insert(lp);
254    Print("NEW LAST GPREV: ");
255    pWrite(last->getPoly());
256    length++;
257    Print("LENGTH %d\n",length);
258}
259
260void LList::insert(poly t,int i, poly p, Rule* r) {
261    last = last->insert(t,i,p,r);
262    length++;
263    Print("LENGTH %d\n",length);
264}
265
266// insertion in front of the list, needed for sPolyList
267void LList::insertSP(LPoly* lp) {
268    first = first->insertSP(lp);
269    length++;
270    Print("LENGTH %d\n",length);
271}
272
273void LList::insertSP(poly t,int i, poly p, Rule* r) {
274    first = first->insertSP(t,i,p,r);
275    length++;
276    Print("LENGTH %d\n",length);
277}
278
279
280void LList::insertByLabel(poly t, int i, poly p, Rule* r) {
281    first = first->insertByLabel(t,i,p,r);
282    length++;
283    Print("LENGTH %d\n",length);
284}
285
286void LList::insertByLabel(LNode* l) {
287    first = first->insertByLabel(l->getTerm(),l->getIndex(),l->getPoly(),l->getRule());
288    length++;
289    Print("LENGTH %d\n",length);
290}
291
292void LList::deleteByDeg() {
293    first = first->deleteByDeg();
294}
295
296bool LList::polyTest(poly* p) {
297    return first->polyTest(p);
298}
299
300LNode* LList::getFirst() {
301    return first;
302}
303
304LNode* LList::getLast() {
305    return last;
306}
307
308int LList::getLength() {
309    return length;
310}
311
312void LList::setFirst(LNode* l) {
313    first       =   l;
314    length--;
315}
316
317void LList::print() {
318    first->print();
319}
320
321/*
322=======================================
323functions working on the class LTagNode
324=======================================
325*/
326LTagNode::LTagNode() {
327    data    =   NULL;
328    next    =   NULL;
329}
330
331LTagNode::LTagNode(LNode* l) {
332    data = l;
333    next = NULL;
334}
335       
336LTagNode::LTagNode(LNode* l, LTagNode* n) {
337    data = l;
338    next = n;
339}
340
341 LTagNode::~LTagNode() {
342    delete next;
343    delete data;   
344}
345       
346// declaration with first as parameter due to sorting of LTagList
347LTagNode* LTagNode::insert(LNode* l) {
348    LTagNode* newElement  = new LTagNode(l, this);
349    return newElement;
350}
351
352LNode* LTagNode::getLNode() {
353    return this->data;
354}
355
356LTagNode* LTagNode::getNext() {
357    return next;
358}
359
360// NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index.
361//       Thus given actual index i and idx being the index of the LPoly under investigation
362//       the element on position length-idx is the right one
363LNode* LTagNode::get(int idx, int length) {
364    if(idx == 1) {
365        return NULL;
366    }
367    else {
368        int j;
369        LTagNode* temp = this; // last
370        for(j=1;j<=length-idx+1;j++) {
371            temp = temp->next;
372        }
373        return temp->data;
374    }
375}
376
377
378/*
379=======================================
380functions working on the class LTagList
381=======================================
382*/
383LTagList::LTagList() {
384    LTagNode* first =   new LTagNode();
385   
386    length          =   0;
387}
388
389LTagList::LTagList(LNode* l) {
390    LTagNode* first =   new LTagNode(l);
391    length          =   1;
392}
393
394// declaration with first as parameter in LTagNode due to sorting of LTagList
395void LTagList::insert(LNode* l) {
396    first   =   first->insert(l);
397    length++;
398}
399
400void LTagList::setFirstCurrentIdx(LNode* l) {
401    firstCurrentIdx =   l;
402}
403
404LNode* LTagList::get(int idx) {
405    return first->get(idx, length);
406}
407
408LNode* LTagList::getFirst() {
409    return first->getLNode();
410}
411
412LNode* LTagList::getFirstCurrentIdx() {
413    return firstCurrentIdx;
414}
415
416/*
417=====================================
418functions working on the class TopRed
419=====================================
420*/
421
422TopRed::TopRed() {
423    _completed  =   NULL;
424    _toDo       =   NULL;
425}
426
427TopRed::TopRed(LList* c, LList* t) {
428    _completed  =   c;
429    _toDo       =   t;
430}
431
432LList* TopRed::getCompleted() {
433    return _completed;
434}
435
436LList* TopRed::getToDo() {
437    return _toDo;
438}
439
440/*
441====================================
442functions working on the class CNode
443====================================
444*/
445
446CNode::CNode() {
447    data    =   NULL;   
448    next    =   NULL;   
449}
450
451CNode::CNode(CPair* c) {
452    data    =   c;   
453    next    =   NULL;   
454}
455
456CNode::CNode(CPair* c, CNode* n) {
457    data    =   c;   
458    next    =   n;   
459}
460
461CNode::~CNode() {
462    delete next;
463    delete data;
464}
465
466// insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label
467// note: as all critical pairs have the same index here, the second sort is done on the terms of the labels
468// working only with linked, but not doubly linked lists due to memory usage we have to check the
469// insertion around the first element separately from the insertion around all other elements in the list
470CNode* CNode::insert(CPair* c, CNode* last) {
471    if(NULL == this->data) {
472        CNode* newElement   =   new CNode(c, this);
473        return newElement;
474    }
475    else {
476        poly u1 = ppMult_qq(c->getT1(),c->getLp1Term());
477        if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element
478            CNode* newElement   =   new CNode(c, this);
479            return newElement;
480        }
481        if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element
482            if(1 != pLmCmp(u1,ppMult_qq(this->data->getT1(), this->data->getLp1Term()))) {
483                pWrite(u1);
484                Print("Multi-Term in CritPairs Sortierung altes Element: ");
485                pWrite(ppMult_qq(this->data->getT1(),this->data->getLp1Term()));
486                CNode* newElement   =   new CNode(c, this);
487                return newElement;
488            }
489            else {
490                Print("Insert Deg\n");
491                CNode* temp = this;
492                while(  NULL != temp->next->data ) {
493                    if(temp->next->data->getDeg() == c->getDeg() ) { 
494                        if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) {
495                            temp = temp->next;
496                        }
497                        else {
498                            CNode* newElement   =   new CNode(c, temp->next);
499                            temp->next          =   newElement;
500                            return this;
501                        } 
502                    }
503                    else {
504                        CNode* newElement   =   new CNode(c, temp->next);
505                        temp->next          =   newElement;
506                        return this;
507                    }
508                }
509                CNode* newElement   =   new CNode(c, last);
510                temp->next          =   newElement;
511                return this;
512            }
513        } // outer if-clause
514        if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element
515            CNode* temp =   this;
516            while( NULL != temp->next->data ) {   
517                if( c->getDeg() < temp->next->data->getDeg() ) {
518                    CNode* newElement   =   new CNode(c, temp->next);
519                    temp->next          =   newElement;
520                    return this;
521                }
522                if( c->getDeg() == temp->next->data->getDeg() ) {
523                    if(1 != pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),temp->next->data->getLp1Term()))) { 
524                        CNode* newElement   =   new CNode(c, temp->next);
525                        temp->next          =   newElement;
526                        return this;
527                    }
528                    else {
529                        temp = temp->next;
530                        while(  NULL != temp->next->data ) {
531                            if( temp->next->data->getDeg() == c->getDeg() ) { 
532                                if(1 == pLmCmp(u1,ppMult_qq(temp->next->data->getT1(),
533                                               temp->next->data->getLp1Term()))) {
534                                    temp = temp->next;
535                                }
536                                else {
537                                    CNode* newElement   =   new CNode(c, temp->next);
538                                    temp->next          =   newElement;
539                                    return this;
540                                } 
541                            }
542                            else {
543                                CNode* newElement   =   new CNode(c, temp->next);
544                                temp->next          =   newElement;
545                                return this;
546                            }
547                        }
548                        CNode* newElement   =   new CNode(c, last);
549                        temp->next          =   newElement;
550                        return this;
551                    }
552                }
553                if( c->getDeg() > temp->next->data->getDeg() ) {
554                    temp    =   temp->next;
555                }
556            }
557            CNode* newElement   =   new CNode(c, last);
558            temp->next          =   newElement;
559            return this;
560        }
561    }
562}
563
564// get the first elements from CList which by the above sorting have minimal degree
565CNode* CNode::getMinDeg() {
566    CNode* temp = this;
567    while( NULL != temp->data ) {
568        while(NULL != temp->next->data && temp->next->data->getDeg() == this->data->getDeg()) {
569            temp = temp->next;
570        }
571        CNode* returnCNode  =   temp->next;   
572        // every CList should end with a (NULL,NULL) element for a similar behaviour
573        // using termination conditions throughout the algorithm
574        temp->next          =   new CNode();
575        return returnCNode;
576    }
577    return NULL;
578}
579
580CPair* CNode::getData() {
581    return data;
582}
583
584CNode* CNode::getNext() {
585    return next;
586}
587
588LPoly* CNode::getAdLp1() {
589    return this->data->getAdLp1();
590}
591
592LPoly* CNode::getAdLp2() {
593    return this->data->getAdLp2();
594}
595
596poly CNode::getLp1Poly() {
597    return this->data->getLp1Poly();
598}
599
600poly CNode::getLp2Poly() {
601    return this->data->getLp2Poly();
602}
603
604poly CNode::getLp1Term() {
605    return this->data->getLp1Term();
606}
607
608poly CNode::getLp2Term() {
609    return this->data->getLp2Term();
610}
611
612int CNode::getLp1Index() {
613    return this->data->getLp1Index();
614}
615
616int CNode::getLp2Index() {
617    return this->data->getLp2Index();
618}
619
620poly CNode::getT1() {
621    return this->data->getT1();
622}
623
624poly* CNode::getAdT1() {
625    return this->data->getAdT1();
626}
627
628poly CNode::getT2() {
629    return this->data->getT2();
630}
631
632poly* CNode::getAdT2() {
633    return this->data->getAdT2();
634}
635
636Rule* CNode::getTestedRule() {
637    return this->data->getTestedRule();
638}
639
640// for debugging
641void CNode::print() {
642    CNode* temp = this;
643    Print("___________________List of critical pairs______________________:\n");
644    while(NULL != temp->data) {
645        Print("LP1 Index: %d\n",temp->getLp1Index());
646        Print("T1: ");
647        pWrite(temp->getT1());
648        Print("LP1 Term: ");
649        pWrite(temp->getLp1Term());
650        Print("LP1 Poly: ");
651        pWrite(temp->getLp1Poly());
652        Print("LP2 Index: %d\n",temp->getLp2Index());
653        Print("T2: ");
654        pWrite(temp->getT2());
655        Print("LP2 Term: ");
656        pWrite(temp->getLp2Term());
657        Print("LP2 Poly: ");
658        pWrite(temp->getLp2Poly());
659        Print("\n");
660        temp = temp->next;
661    }
662}
663
664/*
665====================================
666functions working on the class CList
667====================================
668*/
669// for initialization of CLists, last element alwas has data=NULL and next=NULL
670CList::CList() {
671    first   =   new CNode();
672    last    =   first;
673}
674
675CList::CList(CPair* c) {
676    first   =   new CNode(c);
677    last    =   first;
678}
679
680CList::~CList() {
681    delete first;
682}
683
684// insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label
685// note: as all critical pairs have the same index here, the second sort is done on the terms of the labels
686void CList::insert(CPair* c) {
687    first = first->insert(c, last);
688}
689
690CNode* CList::getFirst() {
691    return first;
692}
693
694// get the first elements from CList which by the above sorting have minimal degree
695// returns the pointer on the first element of those
696CNode* CList::getMinDeg() {
697    CNode* temp     =   first;
698    first           =   first->getMinDeg();
699    return temp;
700}
701
702void CList::print() {
703    first->print();
704}
705
706/*
707====================================
708functions working on the class RNode
709====================================
710*/
711RNode::RNode() {
712    data    =   NULL;
713    next    =   NULL;
714}
715
716RNode::RNode(Rule* r) {
717    data    =   r;
718    next    =   NULL;
719}
720
721RNode::~RNode() {
722    delete  next;
723    delete  data;
724}
725
726RNode* RNode::insert(Rule* r) {
727    RNode* newElement   =   new RNode(r);
728    newElement->next    =   this;
729    return newElement;
730}
731
732RNode* RNode::insert(int i, poly t) {
733    Rule*   r           =   new Rule(i,t);
734    RNode* newElement   =   new RNode(r);
735    newElement->next    =   this;
736    return newElement;
737}
738
739RNode* RNode::getNext() {
740    return next;
741}   
742
743Rule* RNode::getRule() {
744    return data;
745}
746
747int RNode::getRuleIndex() {
748    return data->getIndex();
749}
750
751poly RNode::getRuleTerm() {
752    return data->getTerm();
753}
754
755/*
756====================================
757functions working on the class RList
758====================================
759*/
760RList::RList() {
761    first = new RNode();
762}
763
764RList::RList(Rule* r) {
765    first = new RNode(r);
766}
767
768void RList::insert(int i, poly t) {
769    first = first->insert(i,t);
770}
771
772void RList::insert(Rule* r) {
773    first = first->insert(r);
774}
775
776RNode* RList::getFirst() {
777    return first;
778}
779
780Rule* RList::getRule() {
781    return this->getRule();
782}
783
784/*
785=======================================
786functions working on the class RTagNode
787=======================================
788*/
789
790RTagNode::RTagNode() {
791    data = NULL;
792    next = NULL;
793}
794 
795RTagNode::RTagNode(RNode* r) {
796    data = r;
797    next = NULL;
798}
799       
800RTagNode::RTagNode(RNode* r, RTagNode* n) {
801    data = r;
802    next = n;
803}
804
805 RTagNode::~RTagNode() {
806    delete next;
807    delete data;   
808}
809       
810// declaration with first as parameter due to sorting of RTagList
811RTagNode* RTagNode::insert(RNode* r) {
812    Print("Hier1\n");
813    RTagNode* newElement  = new RTagNode(r, this);
814    Print("Hier2\n");
815    return newElement;
816}
817
818RNode* RTagNode::getRNode() {
819    return this->data;
820}
821
822// NOTE: We insert at the beginning of the list and length = i-1, where i is the actual index.
823//       Thus given actual index i and idx being the index of the LPoly under investigation
824//       the element on position length-idx+1 is the right one
825RNode* RTagNode::get(int idx, int length) {
826    if(idx==1 || idx==0) {
827        // NOTE: We set this NULL as putting it the last element in the list, i.e. the element having
828        //       RNode* = NULL would cost lots of iterations at each step of F5inc, with increasing
829        //       length of the list this should be prevented
830        return NULL;
831    }
832    else {
833        int j;
834        RTagNode* temp = this; 
835    Print("\n\nHIER IN GET IDX\n");
836    Print("FOR LOOP: %d\n",length-idx+1);   
837    for(j=1; j<=length-idx+1; j++) {
838            temp = temp->next;
839        }
840        return temp->data;
841    }
842}
843
844void RTagNode::set(RNode* r) {
845    this->data  =   r;
846}
847
848void RTagNode::print() {
849    RTagNode* temp  =   this;
850    Print("1. element: %d",getRNode()->getRule()->getIndex());
851    pWrite(getRNode()->getRule()->getTerm());
852    temp    =   temp->next;
853    int i   =   2;
854    while(NULL != temp->getRNode()) {
855        Print("%d. element: %d",i,getRNode()->getRule()->getIndex());
856        pWrite(getRNode()->getRule()->getTerm());
857        temp    =   temp->next;
858        i++;
859    }
860}
861/*
862=======================================
863functions working on the class LTagList
864=======================================
865*/
866
867RTagList::RTagList() {
868    RTagNode* first =   new RTagNode();
869    length          =   0;
870}
871
872RTagList::RTagList(RNode* r) {
873    RTagNode* first =   new RTagNode(r);
874    length          =   1;
875}
876
877// declaration with first as parameter in LTagNode due to sorting of LTagList
878void RTagList::insert(RNode* r) {
879    first = first->insert(r);
880    Print("LENGTH:%d\n",length);
881    length = length +1;
882    Print("LENGTH:%d\n",length);
883}
884
885RNode* RTagList::getFirst() {
886    return first->getRNode();
887}
888
889RNode* RTagList::get(int idx) {
890    return first->get(idx, length);
891}
892
893void RTagList::setFirst(RNode* r) {
894    first->set(r);
895}
896
897void RTagList::print() {
898    first->print();
899}
900
901int RTagList::getLength() {
902    return length;
903}
904#endif
Note: See TracBrowser for help on using the repository browser.