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.14 2000-11-08 15:34:56 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 | } |
---|
40 | |
---|
41 | KINLINE skStrategy::~skStrategy() |
---|
42 | { |
---|
43 | if (lmBin != NULL) |
---|
44 | omMergeStickyBinIntoBin(lmBin, currRing->PolyBin); |
---|
45 | if (tailBin != NULL) |
---|
46 | omMergeStickyBinIntoBin(tailBin, |
---|
47 | (tailRing != NULL ? tailRing->PolyBin: |
---|
48 | currRing->PolyBin)); |
---|
49 | if (currRing != tailRing) |
---|
50 | rKillModifiedRing(tailRing); |
---|
51 | } |
---|
52 | |
---|
53 | KINLINE TObject* skStrategy::S_2_T(int i) |
---|
54 | { |
---|
55 | assume(i>= 0 && i<=sl); |
---|
56 | assume(S_2_R[i] >= 0 && S_2_R[i] <= tl); |
---|
57 | TObject* T = R[S_2_R[i]]; |
---|
58 | assume(T != NULL && T->p == S[i]); |
---|
59 | return T; |
---|
60 | } |
---|
61 | |
---|
62 | /*************************************************************** |
---|
63 | * |
---|
64 | * Operation on TObjects |
---|
65 | * |
---|
66 | ***************************************************************/ |
---|
67 | |
---|
68 | KINLINE TSet initT () |
---|
69 | { |
---|
70 | TSet T = (TSet)omAlloc0(setmax*sizeof(TObject)); |
---|
71 | for (int i=0; i<setmax; i++) |
---|
72 | { |
---|
73 | T[i].tailRing = currRing; |
---|
74 | T[i].i_r = -1; |
---|
75 | } |
---|
76 | return T; |
---|
77 | } |
---|
78 | |
---|
79 | KINLINE TObject** initR() |
---|
80 | { |
---|
81 | return (TObject**) omAlloc0(setmax*sizeof(TObject*)); |
---|
82 | } |
---|
83 | |
---|
84 | KINLINE unsigned long* initsevT() |
---|
85 | { |
---|
86 | return (unsigned long*) omAlloc0(setmax*sizeof(unsigned long)); |
---|
87 | } |
---|
88 | |
---|
89 | // initialization |
---|
90 | KINLINE void sTObject::Set(ring r) |
---|
91 | { |
---|
92 | tailRing = r; |
---|
93 | } |
---|
94 | KINLINE void sTObject::Init(ring r) |
---|
95 | { |
---|
96 | memset(this, 0, sizeof(sTObject)); |
---|
97 | i_r = -1; |
---|
98 | Set(r); |
---|
99 | } |
---|
100 | KINLINE sTObject::sTObject(ring r) |
---|
101 | { |
---|
102 | Init(r); |
---|
103 | } |
---|
104 | KINLINE void sTObject::Set(poly p_in, ring r) |
---|
105 | { |
---|
106 | if (r != currRing) |
---|
107 | { |
---|
108 | assume(r == tailRing); |
---|
109 | p_Test(p_in, r); |
---|
110 | t_p = p_in; |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | pp_Test(p_in, currRing, tailRing); |
---|
115 | p = p_in; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | KINLINE sTObject::sTObject(poly p_in, ring r) |
---|
120 | { |
---|
121 | Init(r); |
---|
122 | Set(p_in, r); |
---|
123 | } |
---|
124 | |
---|
125 | KINLINE void sTObject::Set(poly p_in, ring c_r, ring t_r) |
---|
126 | { |
---|
127 | if (c_r != t_r) |
---|
128 | { |
---|
129 | assume(c_r == currRing && t_r == tailRing); |
---|
130 | pp_Test(p_in, currRing, t_r); |
---|
131 | p = p_in; |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | Set(p_in, c_r); |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | KINLINE sTObject::sTObject(poly p_in, ring c_r, ring t_r) |
---|
140 | { |
---|
141 | Init(t_r); |
---|
142 | Set(p_in, c_r, t_r); |
---|
143 | } |
---|
144 | |
---|
145 | KINLINE sTObject::sTObject(sTObject* T, int copy) |
---|
146 | { |
---|
147 | *this = *T; |
---|
148 | if (copy) |
---|
149 | { |
---|
150 | if (t_p != NULL) |
---|
151 | { |
---|
152 | t_p = p_Copy(t_p, tailRing); |
---|
153 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | p = p_Copy(p, currRing, tailRing); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | KINLINE void sTObject::Delete() |
---|
163 | { |
---|
164 | if (t_p != NULL) |
---|
165 | { |
---|
166 | p_Delete(&t_p, tailRing); |
---|
167 | if (p != NULL) |
---|
168 | p_LmFree(p, currRing); |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | p_Delete(&p, currRing, tailRing); |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | KINLINE void sTObject::Clear() |
---|
177 | { |
---|
178 | p = NULL; |
---|
179 | t_p = NULL; |
---|
180 | } |
---|
181 | |
---|
182 | KINLINE poly sTObject::GetLmCurrRing() |
---|
183 | { |
---|
184 | if (p == NULL && t_p != NULL) |
---|
185 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
186 | |
---|
187 | return p; |
---|
188 | } |
---|
189 | KINLINE poly sTObject::GetLmTailRing() |
---|
190 | { |
---|
191 | if (t_p == NULL) |
---|
192 | { |
---|
193 | if (p != NULL && tailRing != currRing) |
---|
194 | { |
---|
195 | t_p = k_LmInit_currRing_2_tailRing(p, tailRing); |
---|
196 | return t_p; |
---|
197 | } |
---|
198 | return p; |
---|
199 | } |
---|
200 | return t_p; |
---|
201 | } |
---|
202 | KINLINE poly sTObject::GetLm(ring r) |
---|
203 | { |
---|
204 | assume(r == tailRing || r == currRing); |
---|
205 | if (r == currRing) |
---|
206 | return GetLmCurrRing(); |
---|
207 | |
---|
208 | if (t_p == NULL && p != NULL) |
---|
209 | t_p = k_LmInit_currRing_2_tailRing(p, tailRing); |
---|
210 | |
---|
211 | return t_p; |
---|
212 | } |
---|
213 | |
---|
214 | KINLINE void sTObject::GetLm(poly &p_r, ring &r_r) const |
---|
215 | { |
---|
216 | if (t_p != NULL) |
---|
217 | { |
---|
218 | p_r = t_p; |
---|
219 | r_r = tailRing; |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | p_r = p; |
---|
224 | r_r = currRing; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | KINLINE int sTObject::GetpLength() |
---|
229 | { |
---|
230 | assume(pLength <= 0 || pLength == ::pLength(p != NULL ? p : t_p)); |
---|
231 | if (pLength <= 0) pLength = ::pLength(p != NULL ? p : t_p); |
---|
232 | return pLength; |
---|
233 | } |
---|
234 | |
---|
235 | KINLINE void sTObject::SetLmCurrRing() |
---|
236 | { |
---|
237 | if (p == NULL && t_p != NULL) |
---|
238 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | // Iterations |
---|
243 | KINLINE void sTObject::LmDeleteAndIter() |
---|
244 | { |
---|
245 | assume(p != NULL || t_p != NULL); |
---|
246 | if (t_p != NULL) |
---|
247 | { |
---|
248 | t_p = p_LmDeleteAndNext(t_p, tailRing); |
---|
249 | if (p != NULL) |
---|
250 | { |
---|
251 | p_LmFree(p, currRing); |
---|
252 | p = NULL; |
---|
253 | } |
---|
254 | } |
---|
255 | else |
---|
256 | { |
---|
257 | p = p_LmDeleteAndNext(p, currRing); |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | // arithmetic |
---|
263 | KINLINE void sTObject::Mult_nn(number n) |
---|
264 | { |
---|
265 | if (t_p != NULL) |
---|
266 | { t_p = tailRing->p_Procs->p_Mult_nn(t_p, n, tailRing); |
---|
267 | if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p)); |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | p = p_Mult_nn(p, n, currRing, tailRing); |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | KINLINE void |
---|
276 | sTObject::ShallowCopyDelete(ring new_tailRing, omBin new_tailBin, |
---|
277 | pShallowCopyDeleteProc p_shallow_copy_delete, |
---|
278 | BOOLEAN set_max) |
---|
279 | { |
---|
280 | if (new_tailBin == NULL) new_tailBin = new_tailRing->PolyBin; |
---|
281 | if (t_p != NULL) |
---|
282 | { |
---|
283 | t_p = p_shallow_copy_delete(t_p, tailRing, new_tailRing, new_tailBin); |
---|
284 | if (p != NULL) |
---|
285 | pNext(p) = pNext(t_p); |
---|
286 | if (new_tailRing == currRing) |
---|
287 | { |
---|
288 | if (p == NULL) p = t_p; |
---|
289 | else p_LmFree(t_p, tailRing); |
---|
290 | t_p = NULL; |
---|
291 | } |
---|
292 | } |
---|
293 | else if (p != NULL) |
---|
294 | { |
---|
295 | if (pNext(p) != NULL) |
---|
296 | { |
---|
297 | pNext(p) = p_shallow_copy_delete(pNext(p), |
---|
298 | tailRing, new_tailRing, new_tailBin); |
---|
299 | } |
---|
300 | if (new_tailRing != currRing) |
---|
301 | { |
---|
302 | t_p = k_LmInit_currRing_2_tailRing(p, new_tailRing); |
---|
303 | pNext(t_p) = pNext(p); |
---|
304 | } |
---|
305 | } |
---|
306 | if (max != NULL) |
---|
307 | { |
---|
308 | if (new_tailRing == currRing) |
---|
309 | { |
---|
310 | p_LmFree(max, tailRing); |
---|
311 | max = NULL; |
---|
312 | } |
---|
313 | else |
---|
314 | max = p_shallow_copy_delete(max,tailRing,new_tailRing,new_tailBin); |
---|
315 | } |
---|
316 | else if (set_max && new_tailRing != currRing && pNext(t_p) != NULL) |
---|
317 | { |
---|
318 | max = p_GetMaxExpP(pNext(t_p), new_tailRing); |
---|
319 | } |
---|
320 | tailRing = new_tailRing; |
---|
321 | } |
---|
322 | |
---|
323 | KINLINE int sTObject::pFDeg() |
---|
324 | { |
---|
325 | if (p != NULL) return ::pFDeg(p, currRing); |
---|
326 | return tailRing->pFDeg(t_p, tailRing); |
---|
327 | } |
---|
328 | |
---|
329 | extern void pCleardenom(poly p); |
---|
330 | extern void pNorm(poly p); |
---|
331 | // manipulations |
---|
332 | KINLINE void sTObject::pCleardenom() |
---|
333 | { |
---|
334 | assume(p != NULL); |
---|
335 | ::pCleardenom(p); |
---|
336 | if (t_p != NULL) |
---|
337 | pSetCoeff0(t_p, pGetCoeff(p)); |
---|
338 | } |
---|
339 | |
---|
340 | KINLINE void sTObject::pNorm() |
---|
341 | { |
---|
342 | assume(p != NULL); |
---|
343 | ::pNorm(p); |
---|
344 | if (t_p != NULL) |
---|
345 | pSetCoeff0(t_p, pGetCoeff(p)); |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | /*************************************************************** |
---|
351 | * |
---|
352 | * Operation on LObjects |
---|
353 | * |
---|
354 | ***************************************************************/ |
---|
355 | // Initialization |
---|
356 | KINLINE void sLObject::Init(ring r) |
---|
357 | { |
---|
358 | memset(this, 0, sizeof(sLObject)); |
---|
359 | i_r1 = -1; |
---|
360 | i_r2 = -1; |
---|
361 | i_r = -1; |
---|
362 | Set(r); |
---|
363 | } |
---|
364 | KINLINE sLObject::sLObject(ring r) |
---|
365 | { |
---|
366 | Init(r); |
---|
367 | } |
---|
368 | KINLINE sLObject::sLObject(poly p_in, ring r) |
---|
369 | { |
---|
370 | Init(r); |
---|
371 | Set(p_in, r); |
---|
372 | } |
---|
373 | |
---|
374 | KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r) |
---|
375 | { |
---|
376 | Init(t_r); |
---|
377 | Set(p_in, c_r, t_r); |
---|
378 | } |
---|
379 | |
---|
380 | KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring tailRing) |
---|
381 | { |
---|
382 | Set(lm, tailRing); |
---|
383 | if (use_bucket) |
---|
384 | { |
---|
385 | bucket = kBucketCreate(tailRing); |
---|
386 | kBucketInit(bucket, p_tail, p_Length); |
---|
387 | pNext(lm) = NULL; |
---|
388 | pLength = 0; |
---|
389 | } |
---|
390 | else |
---|
391 | { |
---|
392 | pNext(lm) = p_tail; |
---|
393 | pLength = p_Length; |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | KINLINE void sLObject::Tail_Mult_nn(number n) |
---|
398 | { |
---|
399 | if (bucket != NULL) |
---|
400 | { |
---|
401 | kBucket_Mult_n(bucket, n); |
---|
402 | } |
---|
403 | else |
---|
404 | { |
---|
405 | poly _p = (t_p != NULL ? t_p : p); |
---|
406 | assume(_p != NULL); |
---|
407 | pNext(_p) = tailRing->p_Procs->p_Mult_nn(pNext(_p), n, tailRing); |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | KINLINE void sLObject::Tail_Minus_mm_Mult_qq(poly m, poly q, int lq, |
---|
412 | poly spNoether) |
---|
413 | { |
---|
414 | if (bucket != NULL) |
---|
415 | { |
---|
416 | kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether); |
---|
417 | } |
---|
418 | else |
---|
419 | { |
---|
420 | poly _p = (t_p != NULL ? t_p : p); |
---|
421 | assume(_p != NULL); |
---|
422 | int dummy; |
---|
423 | pNext(_p) = tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, |
---|
424 | dummy,spNoether,tailRing); |
---|
425 | } |
---|
426 | } |
---|
427 | |
---|
428 | KINLINE void sLObject::LmDeleteAndIter() |
---|
429 | { |
---|
430 | sTObject::LmDeleteAndIter(); |
---|
431 | if (bucket != NULL) |
---|
432 | { |
---|
433 | poly _p = kBucketExtractLm(bucket); |
---|
434 | if (_p == NULL) |
---|
435 | { |
---|
436 | kBucketDestroy(&bucket); |
---|
437 | return; |
---|
438 | } |
---|
439 | Set(_p, tailRing); |
---|
440 | } |
---|
441 | } |
---|
442 | |
---|
443 | KINLINE void sLObject::CanonicalizeP() |
---|
444 | { |
---|
445 | kTest_L(this); |
---|
446 | |
---|
447 | if (bucket != NULL) |
---|
448 | kBucketCanonicalize(bucket); |
---|
449 | |
---|
450 | if (p == NULL) |
---|
451 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing); |
---|
452 | } |
---|
453 | |
---|
454 | KINLINE poly sLObject::GetP(omBin lmBin = NULL) |
---|
455 | { |
---|
456 | kTest_L(this); |
---|
457 | if (p == NULL) |
---|
458 | p = k_LmInit_tailRing_2_currRing(t_p, tailRing, |
---|
459 | (lmBin!=NULL?lmBin:currRing->PolyBin)); |
---|
460 | else if (lmBin != NULL && lmBin != currRing->PolyBin) |
---|
461 | p = p_LmShallowCopyDelete(p, currRing, lmBin); |
---|
462 | |
---|
463 | if (bucket != NULL) |
---|
464 | { |
---|
465 | kBucketClear(bucket, &pNext(p), &pLength); |
---|
466 | kBucketDestroy(&bucket); |
---|
467 | pLength++; |
---|
468 | if (t_p != NULL) pNext(t_p) = pNext(p); |
---|
469 | } |
---|
470 | kTest_L(this); |
---|
471 | return p; |
---|
472 | } |
---|
473 | |
---|
474 | KINLINE void |
---|
475 | sLObject::ShallowCopyDelete(ring new_tailRing, |
---|
476 | pShallowCopyDeleteProc p_shallow_copy_delete) |
---|
477 | { |
---|
478 | if (bucket != NULL) |
---|
479 | kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin, |
---|
480 | p_shallow_copy_delete); |
---|
481 | sTObject::ShallowCopyDelete(new_tailRing, |
---|
482 | new_tailRing->PolyBin,p_shallow_copy_delete, |
---|
483 | FALSE); |
---|
484 | } |
---|
485 | |
---|
486 | KINLINE void sLObject::SetShortExpVector() |
---|
487 | { |
---|
488 | if (t_p != NULL) |
---|
489 | { |
---|
490 | sev = p_GetShortExpVector(t_p, tailRing); |
---|
491 | } |
---|
492 | else |
---|
493 | { |
---|
494 | sev = p_GetShortExpVector(p, currRing); |
---|
495 | } |
---|
496 | } |
---|
497 | |
---|
498 | KINLINE sLObject& sLObject::operator=(const sTObject& t) |
---|
499 | { |
---|
500 | memset(this, 0, sizeof(*this)); |
---|
501 | memcpy(this, &t, sizeof(sTObject)); |
---|
502 | return *this; |
---|
503 | } |
---|
504 | |
---|
505 | KINLINE TObject* sLObject::T_1(const skStrategy* strat) |
---|
506 | { |
---|
507 | if (p1 == NULL) return NULL; |
---|
508 | if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl); |
---|
509 | assume(i_r1 >= 0 && i_r1 <= strat->tl); |
---|
510 | TObject* T = strat->R[i_r1]; |
---|
511 | assume(T->p == p1); |
---|
512 | return T; |
---|
513 | } |
---|
514 | |
---|
515 | KINLINE TObject* sLObject::T_2(const skStrategy* strat) |
---|
516 | { |
---|
517 | if (p1 == NULL) return NULL; |
---|
518 | assume(p2 != NULL); |
---|
519 | if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl); |
---|
520 | assume(i_r2 >= 0 && i_r2 <= strat->tl); |
---|
521 | TObject* T = strat->R[i_r2]; |
---|
522 | assume(T->p == p2); |
---|
523 | return T; |
---|
524 | } |
---|
525 | |
---|
526 | KINLINE void sLObject::T_1_2(const skStrategy* strat, |
---|
527 | TObject* &T_1, TObject* &T_2) |
---|
528 | { |
---|
529 | if (p1 == NULL) |
---|
530 | { |
---|
531 | T_1 = NULL; |
---|
532 | T_2 = NULL; |
---|
533 | return; |
---|
534 | } |
---|
535 | assume(p1 != NULL && p2 != NULL); |
---|
536 | if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl); |
---|
537 | if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl); |
---|
538 | assume(i_r1 >= 0 && i_r1 <= strat->tl); |
---|
539 | assume(i_r2 >= 0 && i_r2 <= strat->tl); |
---|
540 | T_1 = strat->R[i_r1]; |
---|
541 | T_2 = strat->R[i_r2]; |
---|
542 | assume(T_1->p == p1); |
---|
543 | assume(T_2->p == p2); |
---|
544 | return; |
---|
545 | } |
---|
546 | |
---|
547 | /*************************************************************** |
---|
548 | * |
---|
549 | * Conversion of polys |
---|
550 | * |
---|
551 | ***************************************************************/ |
---|
552 | |
---|
553 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin) |
---|
554 | { |
---|
555 | |
---|
556 | poly np = p_LmInit(p, currRing, tailRing, tailBin); |
---|
557 | pNext(np) = pNext(p); |
---|
558 | pSetCoeff0(np, pGetCoeff(p)); |
---|
559 | return np; |
---|
560 | } |
---|
561 | |
---|
562 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin) |
---|
563 | { |
---|
564 | poly np = p_LmInit(p, tailRing, currRing, lmBin); |
---|
565 | pNext(np) = pNext(p); |
---|
566 | pSetCoeff0(np, pGetCoeff(p)); |
---|
567 | return np; |
---|
568 | } |
---|
569 | |
---|
570 | // this should be made more efficient |
---|
571 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin) |
---|
572 | { |
---|
573 | poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin); |
---|
574 | p_LmFree(p, currRing); |
---|
575 | return np; |
---|
576 | } |
---|
577 | |
---|
578 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin) |
---|
579 | { |
---|
580 | poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin); |
---|
581 | p_LmFree(p, tailRing); |
---|
582 | return np; |
---|
583 | } |
---|
584 | |
---|
585 | KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing) |
---|
586 | { |
---|
587 | return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin); |
---|
588 | } |
---|
589 | |
---|
590 | KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing) |
---|
591 | { |
---|
592 | return k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin); |
---|
593 | } |
---|
594 | |
---|
595 | KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing) |
---|
596 | { |
---|
597 | return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin); |
---|
598 | } |
---|
599 | |
---|
600 | KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing) |
---|
601 | { |
---|
602 | return k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin); |
---|
603 | } |
---|
604 | |
---|
605 | /*************************************************************** |
---|
606 | * |
---|
607 | * Lcm business |
---|
608 | * |
---|
609 | ***************************************************************/ |
---|
610 | // get m1 = LCM(LM(p1), LM(p2))/LM(p1) |
---|
611 | // m2 = LCM(LM(p1), LM(p2))/LM(p2) |
---|
612 | KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, |
---|
613 | poly &m1, poly &m2, const ring m_r) |
---|
614 | { |
---|
615 | p_LmCheckPolyRing(p1, p_r); |
---|
616 | p_LmCheckPolyRing(p2, p_r); |
---|
617 | |
---|
618 | int i; |
---|
619 | Exponent_t x; |
---|
620 | m1 = p_Init(m_r); |
---|
621 | m2 = p_Init(m_r); |
---|
622 | |
---|
623 | for (i = p_r->N; i; i--) |
---|
624 | { |
---|
625 | x = p_GetExpDiff(p1, p2, i, p_r); |
---|
626 | if (x > 0) |
---|
627 | { |
---|
628 | if (x > (long) m_r->bitmask) goto false_return; |
---|
629 | p_SetExp(m2,i,x, m_r); |
---|
630 | p_SetExp(m1,i,0, m_r); |
---|
631 | } |
---|
632 | else |
---|
633 | { |
---|
634 | if (-x > (long) m_r->bitmask) goto false_return; |
---|
635 | p_SetExp(m1,i,-x, m_r); |
---|
636 | p_SetExp(m2,i,0, m_r); |
---|
637 | } |
---|
638 | } |
---|
639 | |
---|
640 | p_Setm(m1, m_r); |
---|
641 | p_Setm(m2, m_r); |
---|
642 | return TRUE; |
---|
643 | |
---|
644 | false_return: |
---|
645 | p_LmFree(m1, m_r); |
---|
646 | p_LmFree(m2, m_r); |
---|
647 | m1 = m2 = NULL; |
---|
648 | return FALSE; |
---|
649 | } |
---|
650 | |
---|
651 | /*************************************************************** |
---|
652 | * |
---|
653 | * Routines for backwards-Compatibility |
---|
654 | * |
---|
655 | * |
---|
656 | ***************************************************************/ |
---|
657 | KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether) |
---|
658 | { |
---|
659 | LObject L(p2); |
---|
660 | TObject T(p1); |
---|
661 | |
---|
662 | ksReducePoly(&L, &T, spNoether); |
---|
663 | |
---|
664 | return L.GetLmCurrRing(); |
---|
665 | } |
---|
666 | |
---|
667 | KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether) |
---|
668 | { |
---|
669 | LObject L(p_Copy(p2, currRing)); |
---|
670 | TObject T(p1); |
---|
671 | |
---|
672 | ksReducePoly(&L, &T, spNoether); |
---|
673 | |
---|
674 | return L.GetLmCurrRing(); |
---|
675 | } |
---|
676 | |
---|
677 | KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r) |
---|
678 | { |
---|
679 | LObject L(r); |
---|
680 | L.p1 = p1; |
---|
681 | L.p2 = p2; |
---|
682 | |
---|
683 | ksCreateSpoly(&L, spNoether); |
---|
684 | return L.GetLmCurrRing(); |
---|
685 | } |
---|
686 | |
---|
687 | void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r) |
---|
688 | { |
---|
689 | LObject L(q, currRing, r); |
---|
690 | TObject T(p1, currRing, r); |
---|
691 | |
---|
692 | ksReducePolyTail(&L, &T, q2, spNoether); |
---|
693 | } |
---|
694 | |
---|
695 | KINLINE poly redtailBba (poly p,int pos,kStrategy strat) |
---|
696 | { |
---|
697 | LObject L(p, currRing, strat->tailRing); |
---|
698 | return redtailBba(&L, pos, strat); |
---|
699 | } |
---|
700 | |
---|
701 | #endif // defined(KINLINE) || defined(KUTIL_CC) |
---|
702 | #endif // KINLINE_CC |
---|
703 | |
---|