source: git/Singular/kInline.cc @ 50cbdc

fieker-DuValspielwiese
Last change on this file since 50cbdc was 50cbdc, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: merge-2-0-2 git-svn-id: file:///usr/local/Singular/svn/trunk@5619 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 20.3 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.25 2001-08-27 14:47:04 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(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
83KINLINE TObject** initR()
84{
85  return (TObject**) omAlloc0(setmax*sizeof(TObject*));
86}
87
88KINLINE unsigned long* initsevT()
89{
90  return (unsigned long*) omAlloc0(setmax*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    p = k_LmInit_tailRing_2_currRing(t_p, tailRing,
610                                     (lmBin!=NULL?lmBin:currRing->PolyBin));
611  else if (lmBin != NULL && lmBin != currRing->PolyBin)
612    p = p_LmShallowCopyDelete(p, currRing, lmBin);
613
614  if (bucket != NULL)
615  {
616    kBucketClear(bucket, &pNext(p), &pLength);
617    kBucketDestroy(&bucket);
618    pLength++;
619    if (t_p != NULL) pNext(t_p) = pNext(p);
620  }
621  kTest_L(this);
622  return p;
623}
624
625KINLINE void
626sLObject::ShallowCopyDelete(ring new_tailRing,
627                            pShallowCopyDeleteProc p_shallow_copy_delete)
628{
629  if (bucket != NULL)
630    kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
631                             p_shallow_copy_delete);
632  sTObject::ShallowCopyDelete(new_tailRing,
633                              new_tailRing->PolyBin,p_shallow_copy_delete,
634                              FALSE);
635  last = NULL;
636}
637
638KINLINE void sLObject::SetShortExpVector()
639{
640  if (t_p != NULL)
641  {
642    sev = p_GetShortExpVector(t_p, tailRing);
643  }
644  else
645  {
646    sev = p_GetShortExpVector(p, currRing);
647  }
648}
649
650KINLINE void sLObject::Copy()
651{
652  if (bucket != NULL)
653  {
654    int i = kBucketCanonicalize(bucket);
655    kBucket_pt new_bucket = kBucketCreate(tailRing);
656    kBucketInit(new_bucket,
657                p_Copy(bucket->buckets[i], tailRing),
658                bucket->buckets_length[i]);
659    bucket = new_bucket;
660    if (t_p != NULL) pNext(t_p) = NULL;
661    if (p != NULL) pNext(p) = NULL;
662  }
663  TObject::Copy();
664  last = NULL;
665}
666
667KINLINE poly sLObject::CopyGetP()
668{
669  last = NULL;
670  if (bucket != NULL)
671  {
672    int i = kBucketCanonicalize(bucket);
673    poly bp = p_Copy(bucket->buckets[i], tailRing);
674    pLength = bucket->buckets_length[i] + 1;
675    if (bp != NULL)
676    {
677      assume(t_p != NULL || p != NULL);
678      if (t_p != NULL) pNext(t_p) = bp;
679      else pNext(p) = bp;
680    }
681    bucket = NULL;
682  }
683  return sLObject::GetP();
684}
685
686
687KINLINE long sLObject::pLDeg()
688{
689  poly tp = GetLmTailRing();
690  assume(tp != NULL);
691  if (bucket != NULL)
692  {
693    int i = kBucketCanonicalize(bucket);
694    pNext(tp) = bucket->buckets[i];
695    long ldeg = tailRing->pLDeg(tp, &length, tailRing);
696    pNext(tp) = NULL;
697    return ldeg;
698  }
699  else
700    return tailRing->pLDeg(tp, &length, tailRing);
701}
702KINLINE long sLObject::pLDeg(BOOLEAN deg_last)
703{
704  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
705
706  if (last == NULL || pLength == 0)
707    last = pLast(GetLmTailRing(), pLength);
708#ifdef HAVE_ASSUME
709  long fdeg;
710  fdeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
711  assume (pLength == length && fdeg == tailRing->pFDeg(last, tailRing));
712  return fdeg;
713#else
714  length = pLength;
715  return tailRing->pFDeg(last, tailRing);
716#endif
717}
718
719KINLINE long sLObject::SetDegStuffReturnLDeg()
720{
721  FDeg = this->pFDeg();
722  long d = this->pLDeg();
723  ecart = d - FDeg;
724  return d;
725}
726KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last)
727{
728  FDeg = this->pFDeg();
729  long d = this->pLDeg(use_last);
730  ecart = d - FDeg;
731  return d;
732}
733KINLINE int sLObject::GetpLength()
734{
735  if (bucket == NULL)
736    return sTObject::GetpLength();
737  int i = kBucketCanonicalize(bucket);
738  return bucket->buckets_length[i] + 1;
739}
740KINLINE int sLObject::SetLength(BOOLEAN length_pLength)
741{
742  if (length_pLength)
743  {
744    length = this->GetpLength();
745  }
746  else
747    this->pLDeg();
748  return length;
749}
750KINLINE long sLObject::MinComp()
751{
752  poly tp = GetLmTailRing();
753  assume(tp != NULL);
754  if (bucket != NULL)
755  {
756    int i = kBucketCanonicalize(bucket);
757    pNext(tp) = bucket->buckets[i];
758    long m = p_MinComp(tp, tailRing);
759    pNext(tp) = NULL;
760    return m;
761  }
762  else
763    return p_MinComp(tp, tailRing);
764}
765KINLINE long sLObject::Comp()
766{
767  poly p;
768  ring r;
769  GetLm(p, r);
770  assume(p != NULL);
771  return p_GetComp(p, r);
772}
773
774KINLINE sLObject& sLObject::operator=(const sTObject& t)
775{
776  memset(this, 0, sizeof(*this));
777  memcpy(this, &t, sizeof(sTObject));
778  return *this;
779}
780
781KINLINE TObject* sLObject::T_1(const skStrategy* s)
782{
783  if (p1 == NULL) return NULL;
784  if (i_r1 == -1) i_r1 = kFindInT(p1, s->T, s->tl);
785  assume(i_r1 >= 0 && i_r1 <= s->tl);
786  TObject* T = s->R[i_r1];
787  assume(T->p == p1);
788  return T;
789}
790
791KINLINE TObject* sLObject::T_2(const skStrategy* strat)
792{
793  if (p1 == NULL) return NULL;
794  assume(p2 != NULL);
795  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
796  assume(i_r2 >= 0 && i_r2 <= strat->tl);
797  TObject* T = strat->R[i_r2];
798  assume(T->p == p2);
799  return T;
800}
801
802KINLINE void    sLObject::T_1_2(const skStrategy* strat,
803                                TObject* &T_1, TObject* &T_2)
804{
805  if (p1 == NULL)
806  {
807    T_1 = NULL;
808    T_2 = NULL;
809    return;
810  }
811  assume(p1 != NULL && p2 != NULL);
812  if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl);
813  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
814  assume(i_r1 >= 0 && i_r1 <= strat->tl);
815  assume(i_r2 >= 0 && i_r2 <= strat->tl);
816  T_1 = strat->R[i_r1];
817  T_2 = strat->R[i_r2];
818  assume(T_1->p == p1);
819  assume(T_2->p == p2);
820  return;
821}
822
823/***************************************************************
824 *
825 * Conversion of polys
826 *
827 ***************************************************************/
828
829KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
830{
831
832  poly np = p_LmInit(p, currRing, tailRing, tailBin);
833  pNext(np) = pNext(p);
834  pSetCoeff0(np, pGetCoeff(p));
835  return np;
836}
837
838KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
839{
840  poly np = p_LmInit(p, tailRing, currRing, lmBin);
841  pNext(np) = pNext(p);
842  pSetCoeff0(np, pGetCoeff(p));
843  return np;
844}
845
846// this should be made more efficient
847KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
848{
849  poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin);
850  p_LmFree(p, currRing);
851  return np;
852}
853
854KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
855{
856  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
857  p_LmFree(p, tailRing);
858  return np;
859}
860
861KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
862{
863  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
864}
865
866KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
867{
868  return  k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
869}
870
871KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing)
872{
873  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
874}
875
876KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing)
877{
878  return  k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
879}
880
881/***************************************************************
882 *
883 * Lcm business
884 *
885 ***************************************************************/
886// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
887//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
888KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
889                               poly &m1, poly &m2, const ring m_r)
890{
891  p_LmCheckPolyRing(p1, p_r);
892  p_LmCheckPolyRing(p2, p_r);
893
894  int i;
895  Exponent_t x;
896  m1 = p_Init(m_r);
897  m2 = p_Init(m_r);
898
899  for (i = p_r->N; i; i--)
900  {
901    x = p_GetExpDiff(p1, p2, i, p_r);
902    if (x > 0)
903    {
904      if (x > (long) m_r->bitmask) goto false_return;
905      p_SetExp(m2,i,x, m_r);
906      p_SetExp(m1,i,0, m_r);
907    }
908    else
909    {
910      if (-x > (long) m_r->bitmask) goto false_return;
911      p_SetExp(m1,i,-x, m_r);
912      p_SetExp(m2,i,0, m_r);
913    }
914  }
915
916  p_Setm(m1, m_r);
917  p_Setm(m2, m_r);
918  return TRUE;
919
920  false_return:
921  p_LmFree(m1, m_r);
922  p_LmFree(m2, m_r);
923  m1 = m2 = NULL;
924  return FALSE;
925}
926
927/***************************************************************
928 *
929 * Misc things
930 *
931 ***************************************************************/
932KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red)
933{
934  BOOLEAN ret;
935  number coef;
936
937  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
938  ret = ksReducePoly(Red, PW, NULL, &coef);
939
940  if (!ret)
941  {
942    if (! n_IsOne(coef, currRing))
943      PR->Mult_nn(coef);
944    n_Delete(&coef, currRing);
945  }
946  return ret;
947}
948
949/***************************************************************
950 *
951 * Routines for backwards-Compatibility
952 *
953 *
954 ***************************************************************/
955KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
956{
957  LObject L(p2);
958  TObject T(p1);
959
960  ksReducePoly(&L, &T, spNoether);
961
962  return L.GetLmCurrRing();
963}
964
965KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
966{
967  LObject L(p_Copy(p2, currRing));
968  TObject T(p1);
969
970  ksReducePoly(&L, &T, spNoether);
971
972  return L.GetLmCurrRing();
973}
974
975KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
976{
977  LObject L(r);
978  L.p1 = p1;
979  L.p2 = p2;
980
981  ksCreateSpoly(&L, spNoether);
982  return L.GetLmCurrRing();
983}
984
985void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
986{
987  LObject L(q,  currRing, r);
988  TObject T(p1, currRing, r);
989
990  ksReducePolyTail(&L, &T, q2, spNoether);
991}
992
993KINLINE poly redtailBba (poly p,int pos,kStrategy strat)
994{
995  LObject L(p, currRing, strat->tailRing);
996  return redtailBba(&L, pos, strat);
997}
998
999KINLINE poly redtailBba(TObject *T, int pos,kStrategy strat, BOOLEAN withT)
1000{
1001  LObject L;
1002  L = *T;
1003  poly p = redtailBba(&L, pos, strat, FALSE);
1004  *T = L;
1005  kTest_T(T);
1006  assume( p == T->p);
1007  return p;
1008}
1009
1010#endif // defined(KINLINE) || defined(KUTIL_CC)
1011#endif // KINLINE_CC
Note: See TracBrowser for help on using the repository browser.