1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: kInline.cc |
---|
6 | * Purpose: implementation of std related inline routines |
---|
7 | * Author: obachman (Olaf Bachmann) |
---|
8 | * Created: 8/00 |
---|
9 | * Version: $Id: kInline.cc,v 1.19 2000-12-14 16:38:49 obachman Exp $ |
---|
10 | *******************************************************************/ |
---|
11 | #ifndef KINLINE_CC |
---|
12 | #define KINLINE_CC |
---|
13 | |
---|
14 | #if !defined(NO_KINLINE) || defined(KUTIL_CC) |
---|
15 | |
---|
16 | #include "p_polys.h" |
---|
17 | #include "p_Procs.h" |
---|
18 | #include "kbuckets.h" |
---|
19 | #include "omalloc.h" |
---|
20 | |
---|
21 | #define HAVE_TAIL_BIN |
---|
22 | // Hmm ... this I don't understand: |
---|
23 | // with HAVE_LM_BIN, cyclic_7 is appr. 10% slower (on Intel) |
---|
24 | // #define HAVE_LM_BIN |
---|
25 | |
---|
26 | KINLINE skStrategy::skStrategy() |
---|
27 | { |
---|
28 | memset(this, 0, sizeof(skStrategy)); |
---|
29 | tailRing = currRing; |
---|
30 | P.tailRing = currRing; |
---|
31 | tl = -1; |
---|
32 | sl = -1; |
---|
33 | #ifdef HAVE_LM_BIN |
---|
34 | lmBin = omGetStickyBinOfBin(currRing->PolyBin); |
---|
35 | #endif |
---|
36 | #ifdef HAVE_TAIL_BIN |
---|
37 | tailBin = omGetStickyBinOfBin(currRing->PolyBin); |
---|
38 | #endif |
---|
39 | pOrigFDeg = pFDeg; |
---|
40 | pOrigLDeg = pLDeg; |
---|
41 | } |
---|
42 | |
---|
43 | KINLINE skStrategy::~skStrategy() |
---|
44 | { |
---|
45 | if (lmBin != NULL) |
---|
46 | omMergeStickyBinIntoBin(lmBin, currRing->PolyBin); |
---|
47 | if (tailBin != NULL) |
---|
48 | omMergeStickyBinIntoBin(tailBin, |
---|
49 | (tailRing != NULL ? tailRing->PolyBin: |
---|
50 | currRing->PolyBin)); |
---|
51 | if (currRing != tailRing) |
---|
52 | rKillModifiedRing(tailRing); |
---|
53 | pLDeg = pOrigLDeg; |
---|
54 | pFDeg = pOrigFDeg; |
---|
55 | } |
---|
56 | |
---|
57 | KINLINE TObject* skStrategy::S_2_T(int i) |
---|
58 | { |
---|
59 | assume(i>= 0 && i<=sl); |
---|
60 | assume(S_2_R[i] >= 0 && S_2_R[i] <= tl); |
---|
61 | TObject* T = R[S_2_R[i]]; |
---|
62 | assume(T != NULL && T->p == S[i]); |
---|
63 | return T; |
---|
64 | } |
---|
65 | |
---|
66 | /*************************************************************** |
---|
67 | * |
---|
68 | * Operation on TObjects |
---|
69 | * |
---|
70 | ***************************************************************/ |
---|
71 | |
---|
72 | KINLINE TSet initT () |
---|
73 | { |
---|
74 | TSet T = (TSet)omAlloc0(setmax*sizeof(TObject)); |
---|
75 | for (int i=0; i<setmax; i++) |
---|
76 | { |
---|
77 | T[i].tailRing = currRing; |
---|
78 | T[i].i_r = -1; |
---|
79 | } |
---|
80 | return T; |
---|
81 | } |
---|
82 | |
---|
83 | KINLINE TObject** initR() |
---|
84 | { |
---|
85 | return (TObject**) omAlloc0(setmax*sizeof(TObject*)); |
---|
86 | } |
---|
87 | |
---|
88 | KINLINE unsigned long* initsevT() |
---|
89 | { |
---|
90 | return (unsigned long*) omAlloc0(setmax*sizeof(unsigned long)); |
---|
91 | } |
---|
92 | |
---|
93 | // initialization |
---|
94 | KINLINE void sTObject::Set(ring r) |
---|
95 | { |
---|
96 | tailRing = r; |
---|
97 | } |
---|
98 | KINLINE void sTObject::Init(ring r) |
---|
99 | { |
---|
100 | memset(this, 0, sizeof(sTObject)); |
---|
101 | i_r = -1; |
---|
102 | Set(r); |
---|
103 | } |
---|
104 | KINLINE sTObject::sTObject(ring r) |
---|
105 | { |
---|
106 | Init(r); |
---|
107 | } |
---|
108 | KINLINE void sTObject::Set(poly p_in, ring r) |
---|
109 | { |
---|
110 | if (r != currRing) |
---|
111 | { |
---|
112 | assume(r == tailRing); |
---|
113 | p_Test(p_in, r); |
---|
114 | t_p = p_in; |
---|
115 | } |
---|
116 | else |
---|
117 | { |
---|
118 | pp_Test(p_in, currRing, tailRing); |
---|
119 | p = p_in; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | KINLINE sTObject::sTObject(poly p_in, ring r) |
---|
124 | { |
---|
125 | Init(r); |
---|
126 | Set(p_in, r); |
---|
127 | } |
---|
128 | |
---|
129 | KINLINE void sTObject::Set(poly p_in, ring c_r, ring t_r) |
---|
130 | { |
---|
131 | if (c_r != t_r) |
---|
132 | { |
---|
133 | assume(c_r == currRing && t_r == tailRing); |
---|
134 | pp_Test(p_in, currRing, t_r); |
---|
135 | p = p_in; |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | Set(p_in, c_r); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | KINLINE sTObject::sTObject(poly p_in, ring c_r, ring t_r) |
---|
144 | { |
---|
145 | Init(t_r); |
---|
146 | Set(p_in, c_r, t_r); |
---|
147 | } |
---|
148 | |
---|
149 | KINLINE sTObject::sTObject(sTObject* T, int copy) |
---|
150 | { |
---|
151 | *this = *T; |
---|
152 | if (copy) |
---|
153 | { |
---|
154 | if (t_p != NULL) |
---|
155 | { |
---|
156 | t_p = p_Copy(t_p, tailRing); |
---|
157 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | p = p_Copy(p, currRing, tailRing); |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | KINLINE void sTObject::Delete() |
---|
167 | { |
---|
168 | if (t_p != NULL) |
---|
169 | { |
---|
170 | p_Delete(&t_p, tailRing); |
---|
171 | if (p != NULL) |
---|
172 | p_LmFree(p, currRing); |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | p_Delete(&p, currRing, tailRing); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | KINLINE void sTObject::Clear() |
---|
181 | { |
---|
182 | p = NULL; |
---|
183 | t_p = NULL; |
---|
184 | ecart = 0; |
---|
185 | length = 0; |
---|
186 | pLength = 0; |
---|
187 | FDeg = 0; |
---|
188 | is_normalized = FALSE; |
---|
189 | } |
---|
190 | |
---|
191 | KINLINE void sTObject::Copy() |
---|
192 | { |
---|
193 | if (t_p != NULL) |
---|
194 | { |
---|
195 | t_p = p_Copy(t_p, tailRing); |
---|
196 | if (p != NULL) |
---|
197 | { |
---|
198 | p = p_Head(p, currRing); |
---|
199 | if (pNext(t_p) != NULL) pNext(p) = pNext(t_p); |
---|
200 | } |
---|
201 | } |
---|
202 | else |
---|
203 | { |
---|
204 | p = p_Copy(p, currRing, tailRing); |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | KINLINE poly sTObject::GetLmCurrRing() |
---|
209 | { |
---|
210 | if (p == NULL && t_p != NULL) |
---|
211 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
212 | |
---|
213 | return p; |
---|
214 | } |
---|
215 | KINLINE poly sTObject::GetLmTailRing() |
---|
216 | { |
---|
217 | if (t_p == NULL) |
---|
218 | { |
---|
219 | if (p != NULL && tailRing != currRing) |
---|
220 | { |
---|
221 | t_p = k_LmInit_currRing_2_tailRing(p, tailRing); |
---|
222 | return t_p; |
---|
223 | } |
---|
224 | return p; |
---|
225 | } |
---|
226 | return t_p; |
---|
227 | } |
---|
228 | KINLINE poly sTObject::GetLm(ring r) |
---|
229 | { |
---|
230 | assume(r == tailRing || r == currRing); |
---|
231 | if (r == currRing) |
---|
232 | return GetLmCurrRing(); |
---|
233 | |
---|
234 | if (t_p == NULL && p != NULL) |
---|
235 | t_p = k_LmInit_currRing_2_tailRing(p, tailRing); |
---|
236 | |
---|
237 | return t_p; |
---|
238 | } |
---|
239 | |
---|
240 | KINLINE void sTObject::GetLm(poly &p_r, ring &r_r) const |
---|
241 | { |
---|
242 | if (t_p != NULL) |
---|
243 | { |
---|
244 | p_r = t_p; |
---|
245 | r_r = tailRing; |
---|
246 | } |
---|
247 | else |
---|
248 | { |
---|
249 | p_r = p; |
---|
250 | r_r = currRing; |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | KINLINE BOOLEAN sTObject::IsNull() const |
---|
255 | { |
---|
256 | return (p == NULL && t_p == NULL); |
---|
257 | } |
---|
258 | |
---|
259 | KINLINE int sTObject::GetpLength() |
---|
260 | { |
---|
261 | if (pLength <= 0) pLength = ::pLength(p != NULL ? p : t_p); |
---|
262 | return pLength; |
---|
263 | } |
---|
264 | |
---|
265 | KINLINE void sTObject::SetLmCurrRing() |
---|
266 | { |
---|
267 | if (p == NULL && t_p != NULL) |
---|
268 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
269 | } |
---|
270 | |
---|
271 | |
---|
272 | // Iterations |
---|
273 | KINLINE void sTObject::LmDeleteAndIter() |
---|
274 | { |
---|
275 | assume(p != NULL || t_p != NULL); |
---|
276 | if (t_p != NULL) |
---|
277 | { |
---|
278 | t_p = p_LmDeleteAndNext(t_p, tailRing); |
---|
279 | if (p != NULL) |
---|
280 | { |
---|
281 | p_LmFree(p, currRing); |
---|
282 | p = NULL; |
---|
283 | } |
---|
284 | } |
---|
285 | else |
---|
286 | { |
---|
287 | p = p_LmDeleteAndNext(p, currRing); |
---|
288 | } |
---|
289 | is_normalized = FALSE; |
---|
290 | } |
---|
291 | |
---|
292 | |
---|
293 | // arithmetic |
---|
294 | KINLINE void sTObject::Mult_nn(number n) |
---|
295 | { |
---|
296 | if (t_p != NULL) |
---|
297 | { t_p = tailRing->p_Procs->p_Mult_nn(t_p, n, tailRing); |
---|
298 | if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p)); |
---|
299 | } |
---|
300 | else |
---|
301 | { |
---|
302 | p = p_Mult_nn(p, n, currRing, tailRing); |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | KINLINE void |
---|
307 | sTObject::ShallowCopyDelete(ring new_tailRing, omBin new_tailBin, |
---|
308 | pShallowCopyDeleteProc p_shallow_copy_delete, |
---|
309 | BOOLEAN set_max) |
---|
310 | { |
---|
311 | if (new_tailBin == NULL) new_tailBin = new_tailRing->PolyBin; |
---|
312 | if (t_p != NULL) |
---|
313 | { |
---|
314 | t_p = p_shallow_copy_delete(t_p, tailRing, new_tailRing, new_tailBin); |
---|
315 | if (p != NULL) |
---|
316 | pNext(p) = pNext(t_p); |
---|
317 | if (new_tailRing == currRing) |
---|
318 | { |
---|
319 | if (p == NULL) p = t_p; |
---|
320 | else p_LmFree(t_p, tailRing); |
---|
321 | t_p = NULL; |
---|
322 | } |
---|
323 | } |
---|
324 | else if (p != NULL) |
---|
325 | { |
---|
326 | if (pNext(p) != NULL) |
---|
327 | { |
---|
328 | pNext(p) = p_shallow_copy_delete(pNext(p), |
---|
329 | tailRing, new_tailRing, new_tailBin); |
---|
330 | } |
---|
331 | if (new_tailRing != currRing) |
---|
332 | { |
---|
333 | t_p = k_LmInit_currRing_2_tailRing(p, new_tailRing); |
---|
334 | pNext(t_p) = pNext(p); |
---|
335 | } |
---|
336 | } |
---|
337 | if (max != NULL) |
---|
338 | { |
---|
339 | if (new_tailRing == currRing) |
---|
340 | { |
---|
341 | p_LmFree(max, tailRing); |
---|
342 | max = NULL; |
---|
343 | } |
---|
344 | else |
---|
345 | max = p_shallow_copy_delete(max,tailRing,new_tailRing,new_tailBin); |
---|
346 | } |
---|
347 | else if (set_max && new_tailRing != currRing && pNext(t_p) != NULL) |
---|
348 | { |
---|
349 | max = p_GetMaxExpP(pNext(t_p), new_tailRing); |
---|
350 | } |
---|
351 | tailRing = new_tailRing; |
---|
352 | } |
---|
353 | |
---|
354 | KINLINE long sTObject::pFDeg() const |
---|
355 | { |
---|
356 | if (p != NULL) return ::pFDeg(p, currRing); |
---|
357 | return tailRing->pFDeg(t_p, tailRing); |
---|
358 | } |
---|
359 | KINLINE long sTObject::SetpFDeg() |
---|
360 | { |
---|
361 | FDeg = this->pFDeg(); |
---|
362 | return FDeg; |
---|
363 | } |
---|
364 | KINLINE long sTObject::GetpFDeg() const |
---|
365 | { |
---|
366 | assume(FDeg == this->pFDeg()); |
---|
367 | return FDeg; |
---|
368 | } |
---|
369 | KINLINE long sTObject::pLDeg() |
---|
370 | { |
---|
371 | return ::pLDeg(GetLmTailRing(), &length, tailRing); |
---|
372 | } |
---|
373 | KINLINE long sTObject::SetDegStuffReturnLDeg() |
---|
374 | { |
---|
375 | FDeg = this->pFDeg(); |
---|
376 | long d = this->pLDeg(); |
---|
377 | ecart = d - FDeg; |
---|
378 | return d; |
---|
379 | } |
---|
380 | |
---|
381 | extern void pCleardenom(poly p); |
---|
382 | extern void pNorm(poly p); |
---|
383 | // manipulations |
---|
384 | KINLINE void sTObject::pCleardenom() |
---|
385 | { |
---|
386 | assume(p != NULL); |
---|
387 | ::pCleardenom(p); |
---|
388 | if (t_p != NULL) |
---|
389 | pSetCoeff0(t_p, pGetCoeff(p)); |
---|
390 | } |
---|
391 | |
---|
392 | KINLINE void sTObject::pNorm() |
---|
393 | { |
---|
394 | assume(p != NULL); |
---|
395 | if (! is_normalized) |
---|
396 | { |
---|
397 | ::pNorm(p); |
---|
398 | if (t_p != NULL) |
---|
399 | pSetCoeff0(t_p, pGetCoeff(p)); |
---|
400 | is_normalized = TRUE; |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | /*************************************************************** |
---|
407 | * |
---|
408 | * Operation on LObjects |
---|
409 | * |
---|
410 | ***************************************************************/ |
---|
411 | // Initialization |
---|
412 | KINLINE void sLObject::Clear() |
---|
413 | { |
---|
414 | sTObject::Clear(); |
---|
415 | sev = 0; |
---|
416 | } |
---|
417 | |
---|
418 | KINLINE void sLObject::Init(ring r) |
---|
419 | { |
---|
420 | memset(this, 0, sizeof(sLObject)); |
---|
421 | i_r1 = -1; |
---|
422 | i_r2 = -1; |
---|
423 | i_r = -1; |
---|
424 | Set(r); |
---|
425 | } |
---|
426 | KINLINE sLObject::sLObject(ring r) |
---|
427 | { |
---|
428 | Init(r); |
---|
429 | } |
---|
430 | KINLINE sLObject::sLObject(poly p_in, ring r) |
---|
431 | { |
---|
432 | Init(r); |
---|
433 | Set(p_in, r); |
---|
434 | } |
---|
435 | |
---|
436 | KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r) |
---|
437 | { |
---|
438 | Init(t_r); |
---|
439 | Set(p_in, c_r, t_r); |
---|
440 | } |
---|
441 | |
---|
442 | KINLINE void sLObject::PrepareRed(BOOLEAN use_bucket) |
---|
443 | { |
---|
444 | if (bucket == NULL) |
---|
445 | { |
---|
446 | int l = GetpLength(); |
---|
447 | if (use_bucket && l > 1) |
---|
448 | { |
---|
449 | poly tp = GetLmTailRing(); |
---|
450 | assume(l == ::pLength(tp)); |
---|
451 | bucket = kBucketCreate(tailRing); |
---|
452 | kBucketInit(bucket, pNext(tp), l-1); |
---|
453 | pNext(tp) = NULL; |
---|
454 | if (p != NULL) pNext(p) = NULL; |
---|
455 | pLength = 0; |
---|
456 | last = NULL; |
---|
457 | } |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring tailRing, poly _last) |
---|
462 | { |
---|
463 | |
---|
464 | Set(lm, tailRing); |
---|
465 | if (use_bucket) |
---|
466 | { |
---|
467 | bucket = kBucketCreate(tailRing); |
---|
468 | kBucketInit(bucket, p_tail, p_Length); |
---|
469 | pNext(lm) = NULL; |
---|
470 | pLength = 0; |
---|
471 | last = NULL; |
---|
472 | } |
---|
473 | else |
---|
474 | { |
---|
475 | pNext(lm) = p_tail; |
---|
476 | pLength = p_Length + 1; |
---|
477 | last = _last; |
---|
478 | } |
---|
479 | |
---|
480 | } |
---|
481 | |
---|
482 | KINLINE void sLObject::Tail_Mult_nn(number n) |
---|
483 | { |
---|
484 | if (bucket != NULL) |
---|
485 | { |
---|
486 | kBucket_Mult_n(bucket, n); |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | poly _p = (t_p != NULL ? t_p : p); |
---|
491 | assume(_p != NULL); |
---|
492 | pNext(_p) = tailRing->p_Procs->p_Mult_nn(pNext(_p), n, tailRing); |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | KINLINE void sLObject::Tail_Minus_mm_Mult_qq(poly m, poly q, int lq, |
---|
497 | poly spNoether) |
---|
498 | { |
---|
499 | if (bucket != NULL) |
---|
500 | { |
---|
501 | kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether); |
---|
502 | } |
---|
503 | else |
---|
504 | { |
---|
505 | poly _p = (t_p != NULL ? t_p : p); |
---|
506 | assume(_p != NULL); |
---|
507 | int shorter; |
---|
508 | pNext(_p) = tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, |
---|
509 | shorter,spNoether, |
---|
510 | tailRing, last); |
---|
511 | pLength += lq - shorter; |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | KINLINE void sLObject::LmDeleteAndIter() |
---|
516 | { |
---|
517 | sTObject::LmDeleteAndIter(); |
---|
518 | if (bucket != NULL) |
---|
519 | { |
---|
520 | poly _p = kBucketExtractLm(bucket); |
---|
521 | if (_p == NULL) |
---|
522 | { |
---|
523 | kBucketDestroy(&bucket); |
---|
524 | p = t_p = NULL; |
---|
525 | return; |
---|
526 | } |
---|
527 | Set(_p, tailRing); |
---|
528 | } |
---|
529 | else |
---|
530 | { |
---|
531 | pLength--; |
---|
532 | } |
---|
533 | } |
---|
534 | |
---|
535 | KINLINE poly sLObject::LmExtractAndIter() |
---|
536 | { |
---|
537 | poly ret = GetLmTailRing(); |
---|
538 | poly pn; |
---|
539 | |
---|
540 | assume(p != NULL || t_p != NULL); |
---|
541 | |
---|
542 | if (bucket != NULL) |
---|
543 | { |
---|
544 | pn = kBucketExtractLm(bucket); |
---|
545 | if (pn == NULL) |
---|
546 | kBucketDestroy(&bucket); |
---|
547 | } |
---|
548 | else |
---|
549 | { |
---|
550 | pn = pNext(ret); |
---|
551 | } |
---|
552 | pLength--; |
---|
553 | pNext(ret) = NULL; |
---|
554 | if (p != NULL && t_p != NULL) |
---|
555 | p_LmFree(p, currRing); |
---|
556 | |
---|
557 | Set(pn, tailRing); |
---|
558 | return ret; |
---|
559 | } |
---|
560 | |
---|
561 | KINLINE poly sLObject::CanonicalizeP() |
---|
562 | { |
---|
563 | kTest_L(this); |
---|
564 | int i = -1; |
---|
565 | |
---|
566 | if (bucket != NULL) |
---|
567 | i = kBucketCanonicalize(bucket); |
---|
568 | |
---|
569 | if (p == NULL) |
---|
570 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
571 | |
---|
572 | if (i >= 0) pNext(p) = bucket->buckets[i]; |
---|
573 | return p; |
---|
574 | } |
---|
575 | |
---|
576 | KINLINE poly sLObject::GetTP() |
---|
577 | { |
---|
578 | kTest_L(this); |
---|
579 | poly tp = GetLmTailRing(); |
---|
580 | assume(tp != NULL); |
---|
581 | |
---|
582 | if (bucket != NULL) |
---|
583 | { |
---|
584 | kBucketClear(bucket, &pNext(tp), &pLength); |
---|
585 | kBucketDestroy(&bucket); |
---|
586 | pLength++; |
---|
587 | } |
---|
588 | return tp; |
---|
589 | } |
---|
590 | |
---|
591 | |
---|
592 | KINLINE poly sLObject::GetP(omBin lmBin = NULL) |
---|
593 | { |
---|
594 | kTest_L(this); |
---|
595 | if (p == NULL) |
---|
596 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing, |
---|
597 | (lmBin!=NULL?lmBin:currRing->PolyBin)); |
---|
598 | else if (lmBin != NULL && lmBin != currRing->PolyBin) |
---|
599 | p = p_LmShallowCopyDelete(p, currRing, lmBin); |
---|
600 | |
---|
601 | if (bucket != NULL) |
---|
602 | { |
---|
603 | kBucketClear(bucket, &pNext(p), &pLength); |
---|
604 | kBucketDestroy(&bucket); |
---|
605 | pLength++; |
---|
606 | if (t_p != NULL) pNext(t_p) = pNext(p); |
---|
607 | } |
---|
608 | kTest_L(this); |
---|
609 | return p; |
---|
610 | } |
---|
611 | |
---|
612 | KINLINE void |
---|
613 | sLObject::ShallowCopyDelete(ring new_tailRing, |
---|
614 | pShallowCopyDeleteProc p_shallow_copy_delete) |
---|
615 | { |
---|
616 | if (bucket != NULL) |
---|
617 | kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin, |
---|
618 | p_shallow_copy_delete); |
---|
619 | sTObject::ShallowCopyDelete(new_tailRing, |
---|
620 | new_tailRing->PolyBin,p_shallow_copy_delete, |
---|
621 | FALSE); |
---|
622 | } |
---|
623 | |
---|
624 | KINLINE void sLObject::SetShortExpVector() |
---|
625 | { |
---|
626 | if (t_p != NULL) |
---|
627 | { |
---|
628 | sev = p_GetShortExpVector(t_p, tailRing); |
---|
629 | } |
---|
630 | else |
---|
631 | { |
---|
632 | sev = p_GetShortExpVector(p, currRing); |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | KINLINE void sLObject::Copy() |
---|
637 | { |
---|
638 | if (bucket != NULL) |
---|
639 | { |
---|
640 | int i = kBucketCanonicalize(bucket); |
---|
641 | kBucket_pt new_bucket = kBucketCreate(tailRing); |
---|
642 | kBucketInit(new_bucket, |
---|
643 | p_Copy(bucket->buckets[i], tailRing), |
---|
644 | bucket->buckets_length[i]); |
---|
645 | bucket = new_bucket; |
---|
646 | if (t_p != NULL) pNext(t_p) = NULL; |
---|
647 | if (p != NULL) pNext(p) = NULL; |
---|
648 | } |
---|
649 | TObject::Copy(); |
---|
650 | last = NULL; |
---|
651 | } |
---|
652 | |
---|
653 | KINLINE poly sLObject::CopyGetP() |
---|
654 | { |
---|
655 | last = NULL; |
---|
656 | if (bucket != NULL) |
---|
657 | { |
---|
658 | int i = kBucketCanonicalize(bucket); |
---|
659 | poly bp = p_Copy(bucket->buckets[i], tailRing); |
---|
660 | pLength = bucket->buckets_length[i] + 1; |
---|
661 | if (bp != NULL) |
---|
662 | { |
---|
663 | assume(t_p != NULL || p != NULL); |
---|
664 | if (t_p != NULL) pNext(t_p) = bp; |
---|
665 | else pNext(p) = bp; |
---|
666 | } |
---|
667 | bucket = NULL; |
---|
668 | } |
---|
669 | return sLObject::GetP(); |
---|
670 | } |
---|
671 | |
---|
672 | |
---|
673 | KINLINE long sLObject::pLDeg() |
---|
674 | { |
---|
675 | poly tp = GetLmTailRing(); |
---|
676 | assume(tp != NULL); |
---|
677 | if (bucket != NULL) |
---|
678 | { |
---|
679 | int i = kBucketCanonicalize(bucket); |
---|
680 | pNext(tp) = bucket->buckets[i]; |
---|
681 | long ldeg = ::pLDeg(tp, &length, tailRing); |
---|
682 | pNext(tp) = NULL; |
---|
683 | return ldeg; |
---|
684 | } |
---|
685 | else |
---|
686 | return ::pLDeg(tp, &length, tailRing); |
---|
687 | } |
---|
688 | KINLINE long sLObject::pLDeg(BOOLEAN deg_last) |
---|
689 | { |
---|
690 | if (! deg_last || bucket != NULL) return sLObject::pLDeg(); |
---|
691 | |
---|
692 | if (last == NULL || pLength == 0) |
---|
693 | last = pLast((t_p != NULL ? t_p : p), pLength); |
---|
694 | #ifdef HAVE_ASSUME |
---|
695 | long fdeg; |
---|
696 | fdeg = ::pLDeg(GetLmTailRing(), &length, tailRing); |
---|
697 | assume (pLength == length && fdeg == ::pFDeg(last, tailRing)); |
---|
698 | return fdeg; |
---|
699 | #else |
---|
700 | length = pLength; |
---|
701 | return ::pFDeg(last, tailRing); |
---|
702 | #endif |
---|
703 | } |
---|
704 | |
---|
705 | KINLINE long sLObject::SetDegStuffReturnLDeg() |
---|
706 | { |
---|
707 | FDeg = this->pFDeg(); |
---|
708 | long d = this->pLDeg(); |
---|
709 | ecart = d - FDeg; |
---|
710 | return d; |
---|
711 | } |
---|
712 | KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last) |
---|
713 | { |
---|
714 | FDeg = this->pFDeg(); |
---|
715 | long d = this->pLDeg(use_last); |
---|
716 | ecart = d - FDeg; |
---|
717 | return d; |
---|
718 | } |
---|
719 | KINLINE int sLObject::GetpLength() |
---|
720 | { |
---|
721 | if (bucket == NULL) |
---|
722 | return sTObject::GetpLength(); |
---|
723 | int i = kBucketCanonicalize(bucket); |
---|
724 | return bucket->buckets_length[i] + 1; |
---|
725 | } |
---|
726 | KINLINE int sLObject::SetLength(BOOLEAN length_pLength) |
---|
727 | { |
---|
728 | if (length_pLength) |
---|
729 | { |
---|
730 | length = this->GetpLength(); |
---|
731 | } |
---|
732 | else |
---|
733 | this->pLDeg(); |
---|
734 | return length; |
---|
735 | } |
---|
736 | KINLINE long sLObject::MinComp() |
---|
737 | { |
---|
738 | poly tp = GetLmTailRing(); |
---|
739 | assume(tp != NULL); |
---|
740 | if (bucket != NULL) |
---|
741 | { |
---|
742 | int i = kBucketCanonicalize(bucket); |
---|
743 | pNext(tp) = bucket->buckets[i]; |
---|
744 | long m = p_MinComp(tp, tailRing); |
---|
745 | pNext(tp) = NULL; |
---|
746 | return m; |
---|
747 | } |
---|
748 | else |
---|
749 | return p_MinComp(tp, tailRing); |
---|
750 | } |
---|
751 | KINLINE long sLObject::Comp() |
---|
752 | { |
---|
753 | poly p; |
---|
754 | ring r; |
---|
755 | GetLm(p, r); |
---|
756 | assume(p != NULL); |
---|
757 | return p_GetComp(p, r); |
---|
758 | } |
---|
759 | |
---|
760 | KINLINE sLObject& sLObject::operator=(const sTObject& t) |
---|
761 | { |
---|
762 | memset(this, 0, sizeof(*this)); |
---|
763 | memcpy(this, &t, sizeof(sTObject)); |
---|
764 | return *this; |
---|
765 | } |
---|
766 | |
---|
767 | KINLINE TObject* sLObject::T_1(const skStrategy* strat) |
---|
768 | { |
---|
769 | if (p1 == NULL) return NULL; |
---|
770 | if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl); |
---|
771 | assume(i_r1 >= 0 && i_r1 <= strat->tl); |
---|
772 | TObject* T = strat->R[i_r1]; |
---|
773 | assume(T->p == p1); |
---|
774 | return T; |
---|
775 | } |
---|
776 | |
---|
777 | KINLINE TObject* sLObject::T_2(const skStrategy* strat) |
---|
778 | { |
---|
779 | if (p1 == NULL) return NULL; |
---|
780 | assume(p2 != NULL); |
---|
781 | if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl); |
---|
782 | assume(i_r2 >= 0 && i_r2 <= strat->tl); |
---|
783 | TObject* T = strat->R[i_r2]; |
---|
784 | assume(T->p == p2); |
---|
785 | return T; |
---|
786 | } |
---|
787 | |
---|
788 | KINLINE void sLObject::T_1_2(const skStrategy* strat, |
---|
789 | TObject* &T_1, TObject* &T_2) |
---|
790 | { |
---|
791 | if (p1 == NULL) |
---|
792 | { |
---|
793 | T_1 = NULL; |
---|
794 | T_2 = NULL; |
---|
795 | return; |
---|
796 | } |
---|
797 | assume(p1 != NULL && p2 != NULL); |
---|
798 | if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl); |
---|
799 | if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl); |
---|
800 | assume(i_r1 >= 0 && i_r1 <= strat->tl); |
---|
801 | assume(i_r2 >= 0 && i_r2 <= strat->tl); |
---|
802 | T_1 = strat->R[i_r1]; |
---|
803 | T_2 = strat->R[i_r2]; |
---|
804 | assume(T_1->p == p1); |
---|
805 | assume(T_2->p == p2); |
---|
806 | return; |
---|
807 | } |
---|
808 | |
---|
809 | /*************************************************************** |
---|
810 | * |
---|
811 | * Conversion of polys |
---|
812 | * |
---|
813 | ***************************************************************/ |
---|
814 | |
---|
815 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin) |
---|
816 | { |
---|
817 | |
---|
818 | poly np = p_LmInit(p, currRing, tailRing, tailBin); |
---|
819 | pNext(np) = pNext(p); |
---|
820 | pSetCoeff0(np, pGetCoeff(p)); |
---|
821 | return np; |
---|
822 | } |
---|
823 | |
---|
824 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin) |
---|
825 | { |
---|
826 | poly np = p_LmInit(p, tailRing, currRing, lmBin); |
---|
827 | pNext(np) = pNext(p); |
---|
828 | pSetCoeff0(np, pGetCoeff(p)); |
---|
829 | return np; |
---|
830 | } |
---|
831 | |
---|
832 | // this should be made more efficient |
---|
833 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin) |
---|
834 | { |
---|
835 | poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin); |
---|
836 | p_LmFree(p, currRing); |
---|
837 | return np; |
---|
838 | } |
---|
839 | |
---|
840 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin) |
---|
841 | { |
---|
842 | poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin); |
---|
843 | p_LmFree(p, tailRing); |
---|
844 | return np; |
---|
845 | } |
---|
846 | |
---|
847 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing) |
---|
848 | { |
---|
849 | return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin); |
---|
850 | } |
---|
851 | |
---|
852 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing) |
---|
853 | { |
---|
854 | return k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin); |
---|
855 | } |
---|
856 | |
---|
857 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing) |
---|
858 | { |
---|
859 | return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin); |
---|
860 | } |
---|
861 | |
---|
862 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing) |
---|
863 | { |
---|
864 | return k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin); |
---|
865 | } |
---|
866 | |
---|
867 | /*************************************************************** |
---|
868 | * |
---|
869 | * Lcm business |
---|
870 | * |
---|
871 | ***************************************************************/ |
---|
872 | // get m1 = LCM(LM(p1), LM(p2))/LM(p1) |
---|
873 | // m2 = LCM(LM(p1), LM(p2))/LM(p2) |
---|
874 | KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, |
---|
875 | poly &m1, poly &m2, const ring m_r) |
---|
876 | { |
---|
877 | p_LmCheckPolyRing(p1, p_r); |
---|
878 | p_LmCheckPolyRing(p2, p_r); |
---|
879 | |
---|
880 | int i; |
---|
881 | Exponent_t x; |
---|
882 | m1 = p_Init(m_r); |
---|
883 | m2 = p_Init(m_r); |
---|
884 | |
---|
885 | for (i = p_r->N; i; i--) |
---|
886 | { |
---|
887 | x = p_GetExpDiff(p1, p2, i, p_r); |
---|
888 | if (x > 0) |
---|
889 | { |
---|
890 | if (x > (long) m_r->bitmask) goto false_return; |
---|
891 | p_SetExp(m2,i,x, m_r); |
---|
892 | p_SetExp(m1,i,0, m_r); |
---|
893 | } |
---|
894 | else |
---|
895 | { |
---|
896 | if (-x > (long) m_r->bitmask) goto false_return; |
---|
897 | p_SetExp(m1,i,-x, m_r); |
---|
898 | p_SetExp(m2,i,0, m_r); |
---|
899 | } |
---|
900 | } |
---|
901 | |
---|
902 | p_Setm(m1, m_r); |
---|
903 | p_Setm(m2, m_r); |
---|
904 | return TRUE; |
---|
905 | |
---|
906 | false_return: |
---|
907 | p_LmFree(m1, m_r); |
---|
908 | p_LmFree(m2, m_r); |
---|
909 | m1 = m2 = NULL; |
---|
910 | return FALSE; |
---|
911 | } |
---|
912 | |
---|
913 | /*************************************************************** |
---|
914 | * |
---|
915 | * Misc things |
---|
916 | * |
---|
917 | ***************************************************************/ |
---|
918 | KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red) |
---|
919 | { |
---|
920 | BOOLEAN ret; |
---|
921 | number coef; |
---|
922 | |
---|
923 | assume(PR->GetLmCurrRing() != PW->GetLmCurrRing()); |
---|
924 | ret = ksReducePoly(Red, PW, NULL, &coef); |
---|
925 | |
---|
926 | if (!ret) |
---|
927 | { |
---|
928 | if (! n_IsOne(coef, currRing)) |
---|
929 | PR->Mult_nn(coef); |
---|
930 | |
---|
931 | n_Delete(&coef, currRing); |
---|
932 | } |
---|
933 | return ret; |
---|
934 | } |
---|
935 | |
---|
936 | /*************************************************************** |
---|
937 | * |
---|
938 | * Routines for backwards-Compatibility |
---|
939 | * |
---|
940 | * |
---|
941 | ***************************************************************/ |
---|
942 | KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether) |
---|
943 | { |
---|
944 | LObject L(p2); |
---|
945 | TObject T(p1); |
---|
946 | |
---|
947 | ksReducePoly(&L, &T, spNoether); |
---|
948 | |
---|
949 | return L.GetLmCurrRing(); |
---|
950 | } |
---|
951 | |
---|
952 | KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether) |
---|
953 | { |
---|
954 | LObject L(p_Copy(p2, currRing)); |
---|
955 | TObject T(p1); |
---|
956 | |
---|
957 | ksReducePoly(&L, &T, spNoether); |
---|
958 | |
---|
959 | return L.GetLmCurrRing(); |
---|
960 | } |
---|
961 | |
---|
962 | KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r) |
---|
963 | { |
---|
964 | LObject L(r); |
---|
965 | L.p1 = p1; |
---|
966 | L.p2 = p2; |
---|
967 | |
---|
968 | ksCreateSpoly(&L, spNoether); |
---|
969 | return L.GetLmCurrRing(); |
---|
970 | } |
---|
971 | |
---|
972 | void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r) |
---|
973 | { |
---|
974 | LObject L(q, currRing, r); |
---|
975 | TObject T(p1, currRing, r); |
---|
976 | |
---|
977 | ksReducePolyTail(&L, &T, q2, spNoether); |
---|
978 | } |
---|
979 | |
---|
980 | KINLINE poly redtailBba (poly p,int pos,kStrategy strat) |
---|
981 | { |
---|
982 | LObject L(p, currRing, strat->tailRing); |
---|
983 | return redtailBba(&L, pos, strat); |
---|
984 | } |
---|
985 | |
---|
986 | |
---|
987 | #endif // defined(KINLINE) || defined(KUTIL_CC) |
---|
988 | #endif // KINLINE_CC |
---|
989 | |
---|