source: git/kernel/f5lists.cc @ 73e5a2

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