source: git/kernel/f5lists.cc @ 9bb97e

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