source: git/kernel/f5lists.cc @ eab144e

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