source: git/Singular/kInline.cc @ 24d587

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