source: git/kernel/kInline.cc @ 35aab3

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