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 "lpolynomial.h" |
---|
19 | #include "f5lists.h" |
---|
20 | |
---|
21 | /* |
---|
22 | ==================================== |
---|
23 | functions working on the class LNode |
---|
24 | ==================================== |
---|
25 | */ |
---|
26 | |
---|
27 | // generating new list elements (labeled / classical polynomial / LNode view) |
---|
28 | LNode::LNode(LPoly* lp) { |
---|
29 | data = lp; |
---|
30 | next = NULL; |
---|
31 | } |
---|
32 | |
---|
33 | LNode::LNode(poly* t, int* i, poly* p) { |
---|
34 | LPoly* lp = new LPoly(t,i,p); |
---|
35 | data = lp; |
---|
36 | next = NULL; |
---|
37 | } |
---|
38 | |
---|
39 | LNode::LNode(LNode* ln) { |
---|
40 | data = ln->getLPoly(); |
---|
41 | next = ln->getNext(); |
---|
42 | } |
---|
43 | |
---|
44 | LNode::~LNode() { |
---|
45 | delete next; |
---|
46 | delete data; |
---|
47 | } |
---|
48 | |
---|
49 | // insert new elements to the list always in front (labeled / classical polynomial view) |
---|
50 | LNode* LNode::insert(LPoly* lp) { |
---|
51 | LNode* newElement = new LNode(lp); |
---|
52 | newElement->next = this; |
---|
53 | return newElement; |
---|
54 | } |
---|
55 | |
---|
56 | LNode* LNode::insert(poly* t, int* i, poly* p) { |
---|
57 | LNode* newElement = new LNode(t,i,p); |
---|
58 | newElement->next = this; |
---|
59 | return newElement; |
---|
60 | } |
---|
61 | |
---|
62 | // insert new elemets to the list w.r.t. increasing labels |
---|
63 | // only used for the S-polys to be reduced (TopReduction building new S-polys with higher label) |
---|
64 | LNode* LNode::insertByLabel(LPoly* lp) { |
---|
65 | if( lp->getTerm() <= this->data->getTerm() ) { |
---|
66 | LNode* newElement = new LNode(lp); |
---|
67 | newElement->next = this; |
---|
68 | return newElement; |
---|
69 | } |
---|
70 | else { |
---|
71 | LNode* temp = this; |
---|
72 | while( NULL != temp->next ) { |
---|
73 | if( lp->getTerm() <= temp->next->data->getTerm() ) { |
---|
74 | LNode* newElement = new LNode(lp); |
---|
75 | newElement->next = temp->next; |
---|
76 | temp->next = newElement; |
---|
77 | return this; |
---|
78 | } |
---|
79 | else { |
---|
80 | temp = temp->next; |
---|
81 | } |
---|
82 | } |
---|
83 | LNode* newElement = new LNode(lp); |
---|
84 | temp->next = newElement; |
---|
85 | newElement->next = NULL; |
---|
86 | return this; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | // deletes the first elements of the list with the same degree |
---|
91 | // only used for the S-polys, which are already sorted by increasing degree by CList |
---|
92 | LNode* LNode::deleteByDeg() { |
---|
93 | return this; |
---|
94 | } |
---|
95 | |
---|
96 | // get next from current LNode |
---|
97 | LNode* LNode::getNext() { |
---|
98 | return next; |
---|
99 | } |
---|
100 | |
---|
101 | // get the LPoly* out of LNode* |
---|
102 | LPoly* LNode::getLPoly() { |
---|
103 | return data; |
---|
104 | } |
---|
105 | |
---|
106 | // get the data from the LPoly saved in LNode |
---|
107 | poly* LNode::getPoly() { |
---|
108 | return data->getPoly(); |
---|
109 | } |
---|
110 | |
---|
111 | poly* LNode::getTerm() { |
---|
112 | return data->getTerm(); |
---|
113 | } |
---|
114 | |
---|
115 | int* LNode::getIndex() { |
---|
116 | return data->getIndex(); |
---|
117 | } |
---|
118 | |
---|
119 | // test if for any list element the polynomial part of the data is equal to *p |
---|
120 | bool LNode::polyTest(poly* p) { |
---|
121 | LNode* temp = new LNode(this); |
---|
122 | while(NULL != temp) { |
---|
123 | if(pComparePolys(*(temp->getPoly()),*p)) { |
---|
124 | return 1; |
---|
125 | } |
---|
126 | temp = temp->next; |
---|
127 | } |
---|
128 | return 0; |
---|
129 | } |
---|
130 | |
---|
131 | LNode* LNode::getNext(LNode* l) { |
---|
132 | return l->next; |
---|
133 | } |
---|
134 | |
---|
135 | /* |
---|
136 | ==================================== |
---|
137 | functions working on the class LList |
---|
138 | ==================================== |
---|
139 | */ |
---|
140 | |
---|
141 | LList::LList(LPoly* lp) { |
---|
142 | first = new LNode(lp); |
---|
143 | } |
---|
144 | |
---|
145 | LList::LList(poly* t,int* i,poly* p) { |
---|
146 | first = new LNode(t,i,p); |
---|
147 | } |
---|
148 | |
---|
149 | LList::~LList() { |
---|
150 | delete first; |
---|
151 | } |
---|
152 | |
---|
153 | // insertion in front of the list |
---|
154 | void LList::insert(LPoly* lp) { |
---|
155 | first = first->insert(lp); |
---|
156 | } |
---|
157 | |
---|
158 | void LList::insert(poly* t,int* i, poly* p) { |
---|
159 | first = first->insert(t,i,p); |
---|
160 | } |
---|
161 | |
---|
162 | void LList::insertByLabel(LPoly* lp) { |
---|
163 | first = first->insertByLabel(lp); |
---|
164 | } |
---|
165 | |
---|
166 | void LList::deleteByDeg() { |
---|
167 | first = first->deleteByDeg(); |
---|
168 | } |
---|
169 | |
---|
170 | bool LList::polyTest(poly* p) { |
---|
171 | return first->polyTest(p); |
---|
172 | } |
---|
173 | |
---|
174 | LNode* LList::getFirst() { |
---|
175 | return first; |
---|
176 | } |
---|
177 | |
---|
178 | LNode* LList::getNext(LNode* l) { |
---|
179 | return l->getNext(); |
---|
180 | } |
---|
181 | |
---|
182 | /* |
---|
183 | ======================================= |
---|
184 | functions working on the class PrevNode |
---|
185 | ======================================= |
---|
186 | */ |
---|
187 | |
---|
188 | PrevNode::PrevNode(LNode* l) { |
---|
189 | data = l; |
---|
190 | next = NULL; |
---|
191 | } |
---|
192 | |
---|
193 | PrevNode::~PrevNode() { |
---|
194 | delete next; |
---|
195 | delete data; |
---|
196 | } |
---|
197 | |
---|
198 | PrevNode* PrevNode::append(LNode* l) { |
---|
199 | PrevNode* new_element = new PrevNode(l); |
---|
200 | next = new_element; |
---|
201 | return new_element; |
---|
202 | } |
---|
203 | |
---|
204 | LNode* PrevNode::getLNode() { |
---|
205 | return this->data; |
---|
206 | } |
---|
207 | |
---|
208 | LNode* PrevNode::getPrevLast(int i) { |
---|
209 | int j; |
---|
210 | PrevNode* temp = this; |
---|
211 | for(j=1;j<=i-1;j++) { |
---|
212 | temp = temp->next; |
---|
213 | } |
---|
214 | return temp->data; |
---|
215 | } |
---|
216 | |
---|
217 | /* |
---|
218 | ======================================= |
---|
219 | functions working on the class PrevList |
---|
220 | ======================================= |
---|
221 | */ |
---|
222 | |
---|
223 | PrevList::PrevList(LNode* l) { |
---|
224 | PrevNode* first = new PrevNode(l); |
---|
225 | last = first; |
---|
226 | } |
---|
227 | |
---|
228 | void PrevList::append(LNode* l) { |
---|
229 | last = last->append(l); |
---|
230 | } |
---|
231 | |
---|
232 | LNode* PrevList::getPrevLast(int i) { |
---|
233 | switch(i) { |
---|
234 | case 0: return NULL; |
---|
235 | case 1: return first->getLNode(); |
---|
236 | default: first->getPrevLast(i); |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | /* |
---|
241 | ==================================== |
---|
242 | functions working on the class CNode |
---|
243 | ==================================== |
---|
244 | */ |
---|
245 | |
---|
246 | CNode::CNode(CPair* c) { |
---|
247 | data = c; |
---|
248 | next = NULL; |
---|
249 | } |
---|
250 | |
---|
251 | CNode::~CNode() { |
---|
252 | delete next; |
---|
253 | delete data; |
---|
254 | } |
---|
255 | |
---|
256 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
257 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
258 | // working only with linked, but not doubly linked lists due to memory usage we have to check the |
---|
259 | // insertion around the first element separately from the insertion around all other elements in the list |
---|
260 | CNode* CNode::insert(CPair* c) { |
---|
261 | if( c->getDeg() < this->data->getDeg() ) { // lower degree than the first list element |
---|
262 | CNode* newElement = new CNode(c); |
---|
263 | newElement->next = this; |
---|
264 | return newElement; |
---|
265 | } |
---|
266 | if( c->getDeg() == this->data->getDeg() ) { // same degree than the first list element |
---|
267 | if( c->getT1() <= this->data->getT1() ) { |
---|
268 | CNode* newElement = new CNode(c); |
---|
269 | newElement->next = this; |
---|
270 | return newElement; |
---|
271 | } |
---|
272 | else { |
---|
273 | CNode* temp = this; |
---|
274 | while( NULL != temp->next ) { |
---|
275 | if( temp->next->data->getDeg() == c->getDeg() ) { |
---|
276 | if( c->getT1() <= temp->next->data->getT1() ) { |
---|
277 | temp = temp->next; |
---|
278 | } |
---|
279 | else { |
---|
280 | CNode* newElement = new CNode(c); |
---|
281 | newElement->next = temp->next; |
---|
282 | temp->next = newElement; |
---|
283 | return this; |
---|
284 | } |
---|
285 | } |
---|
286 | else { |
---|
287 | CNode* newElement = new CNode(c); |
---|
288 | newElement->next = temp->next; |
---|
289 | temp->next = newElement; |
---|
290 | return this; |
---|
291 | } |
---|
292 | } |
---|
293 | CNode* newElement = new CNode(c); |
---|
294 | newElement->next = NULL; |
---|
295 | temp->next = newElement; |
---|
296 | return this; |
---|
297 | } |
---|
298 | } // outer if-clause |
---|
299 | if( c->getDeg() > this->data->getDeg() ) { // greater degree than the first list element |
---|
300 | CNode* temp = this; |
---|
301 | while( NULL != temp->next ) { |
---|
302 | if( c->getDeg() < temp->next->data->getDeg() ) { |
---|
303 | CNode* newElement = new CNode(c); |
---|
304 | newElement->next = temp->next; |
---|
305 | temp->next = newElement; |
---|
306 | return this; |
---|
307 | } |
---|
308 | if( c->getDeg() == temp->next->data->getDeg() ) { |
---|
309 | if( c->getT1() <= temp->next->data->getT1() ) { |
---|
310 | CNode* newElement = new CNode(c); |
---|
311 | newElement->next = temp->next; |
---|
312 | temp->next = newElement; |
---|
313 | return this; |
---|
314 | } |
---|
315 | else { |
---|
316 | temp = temp->next; |
---|
317 | while( NULL != temp->next ) { |
---|
318 | if( temp->next->data->getDeg() == c->getDeg() ) { |
---|
319 | if( c->getT1() <= temp->next->data->getT1() ) { |
---|
320 | temp = temp->next; |
---|
321 | } |
---|
322 | else { |
---|
323 | CNode* newElement = new CNode(c); |
---|
324 | newElement->next = temp->next; |
---|
325 | temp->next = newElement; |
---|
326 | return this; |
---|
327 | } |
---|
328 | } |
---|
329 | else { |
---|
330 | CNode* newElement = new CNode(c); |
---|
331 | newElement->next = temp->next; |
---|
332 | temp->next = newElement; |
---|
333 | return this; |
---|
334 | } |
---|
335 | } |
---|
336 | CNode* newElement = new CNode(c); |
---|
337 | newElement->next = NULL; |
---|
338 | temp->next = newElement; |
---|
339 | return this; |
---|
340 | } |
---|
341 | } |
---|
342 | if( c->getDeg() > temp->next->data->getDeg() ) { |
---|
343 | temp = temp->next; |
---|
344 | } |
---|
345 | } |
---|
346 | CNode* newElement = new CNode(c); |
---|
347 | newElement->next = NULL; |
---|
348 | temp->next = newElement; |
---|
349 | return this; |
---|
350 | } |
---|
351 | } |
---|
352 | |
---|
353 | // get the first elements from CList which by the above sorting have minimal degree |
---|
354 | CNode* CNode::getMinDeg() { |
---|
355 | CNode* temp = this; |
---|
356 | while( NULL != temp ) { |
---|
357 | if( temp->next->data->getDeg() == this->data->getDeg() ) { |
---|
358 | temp = temp->next; |
---|
359 | } |
---|
360 | CNode* returnCNode = temp->next; |
---|
361 | temp->next = NULL; |
---|
362 | return returnCNode; |
---|
363 | } |
---|
364 | return NULL; |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | /* |
---|
369 | ==================================== |
---|
370 | functions working on the class CList |
---|
371 | ==================================== |
---|
372 | */ |
---|
373 | CList::CList(CPair* c) { |
---|
374 | first = new CNode(c); |
---|
375 | } |
---|
376 | |
---|
377 | CList::~CList() { |
---|
378 | delete first; |
---|
379 | } |
---|
380 | |
---|
381 | // insert sorts the critical pairs firstly by increasing total degree, secondly by increasing label |
---|
382 | // note: as all critical pairs have the same index here, the second sort is done on the terms of the labels |
---|
383 | void CList::insert(CPair* c) { |
---|
384 | first = first->insert(c); |
---|
385 | } |
---|
386 | |
---|
387 | // get the first elements from CList which by the above sorting have minimal degree |
---|
388 | // returns the pointer on the first element of those |
---|
389 | CNode* CList::getMinDeg() { |
---|
390 | CNode* temp = first; |
---|
391 | first = first->getMinDeg(); |
---|
392 | return temp; |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | /* |
---|
397 | ==================================== |
---|
398 | functions working on the class RNode |
---|
399 | ==================================== |
---|
400 | */ |
---|
401 | RNode::RNode(Rule* r) { |
---|
402 | data = r; |
---|
403 | next = NULL; |
---|
404 | } |
---|
405 | |
---|
406 | RNode::~RNode() { |
---|
407 | delete next; |
---|
408 | delete data; |
---|
409 | } |
---|
410 | |
---|
411 | RNode* RNode::insert(Rule* r) { |
---|
412 | RNode* newElement = new RNode(r); |
---|
413 | newElement->next = this; |
---|
414 | return newElement; |
---|
415 | } |
---|
416 | |
---|
417 | /* |
---|
418 | ==================================== |
---|
419 | functions working on the class RList |
---|
420 | ==================================== |
---|
421 | */ |
---|
422 | RList::RList(Rule* r) { |
---|
423 | first = new RNode(r); |
---|
424 | } |
---|
425 | |
---|
426 | void RList::insert(Rule* r) { |
---|
427 | first = first->insert(r); |
---|
428 | } |
---|
429 | #endif |
---|