source: git/kernel/f5lists.cc @ c5d8dd

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