source: git/kernel/GBEngine/kInline.h @ caf8c6

spielwiese
Last change on this file since caf8c6 was caf8c6, checked in by Hans Schoenemann <hannes@…>, 6 years ago
chg: HAVE_ASSUME -> !SING_NDEBUG
  • Property mode set to 100644
File size: 23.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/***************************************************************
5 *  File:    kInline.h
6 *  Purpose: implementation of std related inline routines
7 *  Author:  obachman (Olaf Bachmann)
8 *  Created: 8/00
9 *******************************************************************/
10#ifndef KINLINE_H
11#define KINLINE_H
12
13#if !defined(NO_KINLINE) || defined(KUTIL_CC)
14/* this file is a header file with inline routines,
15 *     if NO_KINLINE is not defined (AND ONLY THEN!)
16 * otherwise it is an part of kutil.cc and a source file!
17 * (remark: NO_KINLINE is defined by KDEBUG, i.e. in the debug version)
18 */
19
20#include "omalloc/omalloc.h"
21#include "misc/options.h"
22
23#include "polys/monomials/p_polys.h"
24#include "polys/kbuckets.h"
25
26#include "kernel/polys.h"
27
28
29#define HAVE_TAIL_BIN
30// This doesn't really work, fixme, if necessary
31// #define HAVE_LM_BIN
32
33
34
35KINLINE TObject* skStrategy::S_2_T(int i)
36{
37  assume(i>= 0 && i<=sl);
38  assume(S_2_R[i] >= 0 && S_2_R[i] <= tl);
39  TObject* TT = R[S_2_R[i]];
40  assume(TT != NULL && TT->p == S[i]);
41  return TT;
42}
43
44KINLINE TObject* skStrategy::s_2_t(int i)
45{
46  if (i >= 0 && i <= sl)
47  {
48    int sri= S_2_R[i];
49    if ((sri >= 0) && (sri <= tl))
50    {
51      TObject* t = R[sri];
52      if ((t != NULL) && (t->p == S[i]))
53        return t;
54    }
55    // last but not least, try kFindInT
56    sri = kFindInT(S[i], T, tl);
57    if (sri >= 0)
58      return &(T[sri]);
59  }
60  return NULL;
61}
62
63KINLINE poly skStrategy::kNoetherTail()
64{
65  if (tailRing == currRing)
66    return kNoether;
67  else
68  {
69    assume((kNoether == NULL && t_kNoether == NULL) ||
70           (kNoether != NULL && t_kNoether != NULL));
71    return t_kNoether;
72  }
73}
74
75/***************************************************************
76 *
77 * Operation on TObjects
78 *
79 ***************************************************************/
80
81KINLINE TSet initT ()
82{
83  TSet T = (TSet)omAlloc0(setmaxT*sizeof(TObject));
84  for (int i=setmaxT-1; i>=0; i--)
85  {
86    T[i].tailRing = currRing;
87    T[i].i_r = -1;
88  }
89  return T;
90}
91
92KINLINE TObject** initR()
93{
94  return (TObject**) omAlloc0(setmaxT*sizeof(TObject*));
95}
96
97KINLINE unsigned long* initsevT()
98{
99  return (unsigned long*) omAlloc0(setmaxT*sizeof(unsigned long));
100}
101
102// initialization
103KINLINE void sTObject::Set(ring r)
104{
105  tailRing = r;
106}
107KINLINE void sTObject::Init(ring r)
108{
109  memset(this, 0, sizeof(sTObject));
110  i_r = -1;
111  Set(r);
112}
113KINLINE sTObject::sTObject(ring r)
114{
115  Init(r);
116}
117KINLINE void sTObject::Set(poly p_in, ring r)
118{
119  if (r != currRing)
120  {
121    assume(r == tailRing);
122    p_Test(p_in, r);
123    t_p = p_in;
124  }
125  else
126  {
127    p_Test(p_in, currRing);
128    p = p_in;
129  }
130  pLength=::pLength(p_in);
131}
132
133KINLINE sTObject::sTObject(poly p_in, ring r)
134{
135  Init(r);
136  Set(p_in, r);
137}
138
139KINLINE void sTObject::Set(poly p_in, ring c_r, ring t_r)
140{
141  if (c_r != t_r)
142  {
143    assume(c_r == currRing && t_r == tailRing);
144    p_Test(p_in, currRing);
145    p = p_in;
146    pLength=::pLength(p_in);
147  }
148  else
149  {
150    Set(p_in, c_r);
151  }
152}
153
154KINLINE sTObject::sTObject(poly p_in, ring c_r, ring t_r)
155{
156  Init(t_r);
157  Set(p_in, c_r, t_r);
158}
159
160KINLINE sTObject::sTObject(sTObject* T, int copy)
161{
162  *this = *T;
163  if (copy)
164  {
165    if (t_p != NULL)
166    {
167      t_p = p_Copy(t_p, tailRing);
168      p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
169    }
170    else
171    {
172      p = p_Copy(p, currRing);
173    }
174  }
175}
176
177KINLINE void sTObject::Delete()
178{
179  if (t_p != NULL)
180  {
181    p_Delete(&t_p, tailRing);
182    if (p != NULL)
183      p_LmFree(p, currRing);
184  }
185  else
186  {
187    p_Delete(&p, currRing);
188  }
189}
190
191KINLINE void sTObject::Clear()
192{
193  p = NULL;
194  t_p = NULL;
195  ecart = 0;
196  length = 0;
197  pLength = 0;
198  FDeg = 0;
199  is_normalized = FALSE;
200}
201
202KINLINE void sTObject::Copy()
203{
204  if (t_p != NULL)
205  {
206    t_p = p_Copy(t_p, tailRing);
207    if (p != NULL) /* and t_p!=NULL*/
208    {
209      p = p_LmInit(p, currRing);
210      pGetCoeff(p)=pGetCoeff(t_p);
211      pNext(p) = pNext(t_p);
212    }
213  }
214  else
215  {
216    p = p_Copy(p, currRing);
217  }
218}
219
220KINLINE poly sTObject::GetLmCurrRing()
221{
222  if (p == NULL && t_p != NULL)
223    p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
224
225  return p;
226}
227KINLINE poly sTObject::GetLmTailRing()
228{
229  if (t_p == NULL)
230  {
231    if (p != NULL && tailRing != currRing)
232    {
233      t_p = k_LmInit_currRing_2_tailRing(p, tailRing);
234      return t_p;
235    }
236    return p;
237  }
238  return t_p;
239}
240KINLINE poly sTObject::GetLm(ring r)
241{
242  assume(r == tailRing || r == currRing);
243  if (r == currRing)
244    return GetLmCurrRing();
245
246  if (t_p == NULL && p != NULL)
247    t_p = k_LmInit_currRing_2_tailRing(p, tailRing);
248
249  return t_p;
250}
251
252KINLINE void sTObject::GetLm(poly &p_r, ring &r_r) const
253{
254  if (t_p != NULL)
255  {
256    p_r = t_p;
257    r_r = tailRing;
258  }
259  else
260  {
261    p_r = p;
262    r_r = currRing;
263  }
264}
265
266KINLINE BOOLEAN sTObject::IsNull() const
267{
268  return (p == NULL && t_p == NULL);
269}
270
271KINLINE int sTObject::GetpLength()
272{
273  if (pLength <= 0) pLength = ::pLength(p != NULL ? p : t_p);
274  return pLength;
275}
276
277KINLINE void sTObject::SetLmCurrRing()
278{
279  if (p == NULL && t_p != NULL)
280    p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
281}
282
283KINLINE poly sTObject::Next()
284{
285  assume(p != NULL || t_p != NULL);
286  if (t_p != NULL) return pNext(t_p);
287  return pNext(p);
288}
289
290// Iterations
291KINLINE void sTObject::LmDeleteAndIter()
292{
293  assume(p != NULL || t_p != NULL);
294  if (t_p != NULL)
295  {
296    t_p = p_LmDeleteAndNext(t_p, tailRing);
297    if (p != NULL)
298    {
299      p_LmFree(p, currRing);
300      p = NULL;
301    }
302  }
303  else
304  {
305    p = p_LmDeleteAndNext(p, currRing);
306  }
307  is_normalized = FALSE;
308}
309
310
311// arithmetic
312KINLINE void sTObject::Mult_nn(number n)
313{
314  if (t_p != NULL)
315  {
316    t_p = p_Mult_nn(t_p, n, tailRing);
317    if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
318  }
319  else
320  {
321    p = p_Mult_nn(p, n, currRing, tailRing);
322  }
323}
324
325KINLINE void sLObject::Normalize()
326{
327  if (t_p != NULL)
328  {
329    pNormalize(t_p);
330    if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
331  }
332  else
333  {
334    pNormalize(p);
335  }
336}
337
338KINLINE void sLObject::HeadNormalize()
339{
340  if (t_p != NULL)
341  {
342    nNormalize(pGetCoeff(t_p));
343    if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
344  }
345  else
346  {
347    nNormalize(pGetCoeff(p));
348  }
349}
350
351KINLINE void
352sTObject::ShallowCopyDelete(ring new_tailRing, omBin new_tailBin,
353                            pShallowCopyDeleteProc p_shallow_copy_delete,
354                            BOOLEAN set_max)
355{
356  if (new_tailBin == NULL) new_tailBin = new_tailRing->PolyBin;
357  if (t_p != NULL)
358  {
359    t_p = p_shallow_copy_delete(t_p, tailRing, new_tailRing, new_tailBin);
360    if (p != NULL)
361      pNext(p) = pNext(t_p);
362    if (new_tailRing == currRing)
363    {
364      if (p == NULL) p = t_p;
365      else p_LmFree(t_p, tailRing);
366      t_p = NULL;
367    }
368  }
369  else if (p != NULL) /* && t_p==NULL */
370  {
371    if (pNext(p) != NULL)
372    {
373      pNext(p) = p_shallow_copy_delete(pNext(p),
374                                       tailRing, new_tailRing, new_tailBin);
375    }
376    if (new_tailRing != currRing)
377    {
378      t_p = k_LmInit_currRing_2_tailRing(p, new_tailRing);
379      pNext(t_p) = pNext(p);
380    }
381  }
382  if (max_exp != NULL)
383  {
384    max_exp = p_shallow_copy_delete(max_exp,tailRing,new_tailRing,new_tailBin);
385  }
386  else if (set_max && pNext(t_p) != NULL)
387  {
388    max_exp = p_GetMaxExpP(pNext(t_p), new_tailRing);
389  }
390  tailRing = new_tailRing;
391}
392
393KINLINE long sTObject::pFDeg() const
394{
395  if (p != NULL) return p_FDeg(p, currRing);
396  return tailRing->pFDeg(t_p, tailRing);
397}
398KINLINE long sTObject::pTotalDeg() const
399{
400  if (p != NULL) return p_Totaldegree(p, currRing);
401  return p_Totaldegree(t_p,tailRing);
402}
403KINLINE long sTObject::SetpFDeg()
404{
405  FDeg = this->pFDeg();
406  return FDeg;
407}
408KINLINE long sTObject::GetpFDeg() const
409{
410  assume(FDeg == this->pFDeg());
411  return FDeg;
412}
413KINLINE long sTObject::pLDeg()
414{
415  return tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
416}
417KINLINE long sTObject::SetDegStuffReturnLDeg()
418{
419  FDeg = this->pFDeg();
420  long d = this->pLDeg();
421  ecart = d - FDeg;
422  return d;
423}
424
425//extern void pCleardenom(poly p);
426// extern void pNorm(poly p);
427
428// manipulations
429KINLINE void  sTObject::pCleardenom()
430{
431  assume(p != NULL);
432  if (TEST_OPT_CONTENTSB)
433  {
434    number n;
435    if (t_p != NULL)
436    {
437      p_Cleardenom_n(t_p, tailRing, n);
438      pSetCoeff0(p, pGetCoeff(t_p));
439    }
440    else
441    {
442      p_Cleardenom_n(p, currRing, n);
443    }
444    if (!nIsOne(n))
445    {
446      denominator_list denom=(denominator_list)omAlloc(sizeof(denominator_list_s));
447      denom->n=nInvers(n);
448      denom->next=DENOMINATOR_LIST;
449      DENOMINATOR_LIST=denom;
450    }
451    nDelete(&n);
452  }
453  else
454  {
455    if (t_p != NULL)
456    {
457      p_ProjectiveUnique(t_p, tailRing);
458      pSetCoeff0(p, pGetCoeff(t_p));
459    }
460    else
461    {
462      p_ProjectiveUnique(p, currRing);
463    }
464  }
465}
466
467KINLINE void sTObject::pNorm() // pNorm seems to be a _bad_ method name...
468{
469  assume(p != NULL);
470  if (! is_normalized)
471  {
472    p_Norm(p, currRing);
473    if (t_p != NULL)
474      pSetCoeff0(t_p, pGetCoeff(p));
475    is_normalized = TRUE;
476  }
477}
478
479
480
481/***************************************************************
482 *
483 * Operation on LObjects
484 *
485 ***************************************************************/
486// Initialization
487KINLINE void sLObject::Clear()
488{
489  sTObject::Clear();
490  sev = 0;
491}
492// Initialization
493KINLINE void sLObject::Delete()
494{
495  sTObject::Delete();
496  if (bucket != NULL)
497    kBucketDeleteAndDestroy(&bucket);
498}
499
500KINLINE void sLObject::Init(ring r)
501{
502  memset(this, 0, sizeof(sLObject));
503  i_r1 = -1;
504  i_r2 = -1;
505  i_r = -1;
506  Set(r);
507}
508KINLINE sLObject::sLObject(ring r)
509{
510  Init(r);
511}
512KINLINE sLObject::sLObject(poly p_in, ring r)
513{
514  Init(r);
515  Set(p_in, r);
516}
517
518KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r)
519{
520  Init(t_r);
521  Set(p_in, c_r, t_r);
522}
523
524KINLINE void sLObject::PrepareRed(BOOLEAN use_bucket)
525{
526  if (bucket == NULL)
527  {
528    unsigned l = GetpLength();
529    if (use_bucket && (l > 1))
530    {
531      poly tp = GetLmTailRing();
532      assume(l == ::pLength(tp));
533      bucket = kBucketCreate(tailRing);
534      kBucketInit(bucket, pNext(tp), l-1);
535      pNext(tp) = NULL;
536      if (p != NULL) pNext(p) = NULL;
537      pLength = 0;
538    }
539  }
540}
541
542KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing)
543{
544
545  Set(lm, _tailRing);
546  if (use_bucket)
547  {
548    bucket = kBucketCreate(_tailRing);
549    kBucketInit(bucket, p_tail, p_Length);
550    pNext(lm) = NULL;
551    pLength = 0;
552  }
553  else
554  {
555    pNext(lm) = p_tail;
556    pLength = p_Length + 1;
557  }
558}
559
560KINLINE void sLObject::Tail_Mult_nn(number n)
561{
562  if (bucket != NULL)
563  {
564    kBucket_Mult_n(bucket, n);
565  }
566  else
567  {
568    poly _p = (t_p != NULL ? t_p : p);
569    assume(_p != NULL);
570    pNext(_p) = __p_Mult_nn(pNext(_p), n, tailRing);
571  }
572}
573
574KINLINE void sLObject::Tail_Minus_mm_Mult_qq(poly m, poly q, int lq,
575                                             poly spNoether)
576{
577  if (bucket != NULL)
578  {
579    kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether);
580  }
581  else
582  {
583    if (lq<=0) lq= ::pLength(q);
584    poly _p = (t_p != NULL ? t_p : p);
585    assume(_p != NULL);
586
587    int lp=pLength-1;
588    pNext(_p) = p_Minus_mm_Mult_qq( pNext(_p), m, q, lp, lq,
589                                    spNoether, tailRing );
590    pLength=lp+1;
591//    tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, shorter,spNoether, tailRing, last);
592//    pLength += lq - shorter;
593  }
594}
595
596KINLINE void sLObject::LmDeleteAndIter()
597{
598  sTObject::LmDeleteAndIter();
599  if (bucket != NULL)
600  {
601    poly _p = kBucketExtractLm(bucket);
602    if (_p == NULL)
603    {
604      kBucketDestroy(&bucket);
605      p = t_p = NULL;
606      return;
607    }
608    Set(_p, tailRing);
609  }
610  else
611  {
612    pLength--;
613  }
614}
615
616KINLINE poly sLObject::LmExtractAndIter()
617{
618  poly ret = GetLmTailRing();
619  poly pn;
620
621  assume(p != NULL || t_p != NULL);
622
623  if (bucket != NULL)
624  {
625    pn = kBucketExtractLm(bucket);
626    if (pn == NULL)
627      kBucketDestroy(&bucket);
628  }
629  else
630  {
631    pn = pNext(ret);
632  }
633  pLength--;
634  pNext(ret) = NULL;
635  if (p != NULL && t_p != NULL)
636    p_LmFree(p, currRing);
637
638  Set(pn, tailRing);
639  return ret;
640}
641
642KINLINE poly sLObject::CanonicalizeP()
643{
644  //kTest_L(this);
645  int i = -1;
646
647  if (bucket != NULL)
648    i = kBucketCanonicalize(bucket);
649
650  if (p == NULL)
651    p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
652
653  if (i >= 0) pNext(p) = bucket->buckets[i];
654  return p;
655}
656
657KINLINE poly sLObject::GetTP()
658{
659  //kTest_L(this);
660  poly tp = GetLmTailRing();
661  assume(tp != NULL);
662
663  if (bucket != NULL)
664  {
665    kBucketClear(bucket, &pNext(tp), &pLength);
666    kBucketDestroy(&bucket);
667    pLength++;
668  }
669  return tp;
670}
671
672
673KINLINE poly sLObject::GetP(omBin lmBin)
674{
675  //kTest_L(this);
676  if (p == NULL)
677  {
678    p = k_LmInit_tailRing_2_currRing(t_p, tailRing,
679                                     (lmBin!=NULL?lmBin:currRing->PolyBin));
680    FDeg = pFDeg();
681  }
682  else if (lmBin != NULL && lmBin != currRing->PolyBin)
683  {
684    p = p_LmShallowCopyDelete(p, currRing);
685    FDeg = pFDeg();
686  }
687
688  if (bucket != NULL)
689  {
690    kBucketClear(bucket, &pNext(p), &pLength);
691    kBucketDestroy(&bucket);
692    pLength++;
693    if (t_p != NULL) pNext(t_p) = pNext(p);
694  }
695  //kTest_L(this);
696  return p;
697}
698
699KINLINE void
700sLObject::ShallowCopyDelete(ring new_tailRing,
701                            pShallowCopyDeleteProc p_shallow_copy_delete)
702{
703  if (bucket != NULL)
704    kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
705                             p_shallow_copy_delete);
706  sTObject::ShallowCopyDelete(new_tailRing,
707                              new_tailRing->PolyBin,p_shallow_copy_delete,
708                              FALSE);
709}
710
711KINLINE void sLObject::SetShortExpVector()
712{
713  if (t_p != NULL)
714  {
715    sev = p_GetShortExpVector(t_p, tailRing);
716  }
717  else
718  {
719    sev = p_GetShortExpVector(p, currRing);
720  }
721}
722
723KINLINE void sLObject::Copy()
724{
725  if (bucket != NULL)
726  {
727    int i = kBucketCanonicalize(bucket);
728    kBucket_pt new_bucket = kBucketCreate(tailRing);
729    kBucketInit(new_bucket,
730                p_Copy(bucket->buckets[i], tailRing),
731                bucket->buckets_length[i]);
732    bucket = new_bucket;
733    if (t_p != NULL) pNext(t_p) = NULL;
734    if (p != NULL) pNext(p) = NULL;
735  }
736  TObject::Copy();
737}
738
739KINLINE long sLObject::pLDeg()
740{
741  poly tp = GetLmTailRing();
742  assume(tp != NULL);
743  if (bucket != NULL)
744  {
745    int i = kBucketCanonicalize(bucket);
746    pNext(tp) = bucket->buckets[i];
747    long ldeg = tailRing->pLDeg(tp, &length, tailRing);
748    pNext(tp) = NULL;
749    return ldeg;
750  }
751  else
752    return tailRing->pLDeg(tp, &length, tailRing);
753}
754KINLINE long sLObject::pLDeg(BOOLEAN deg_last)
755{
756  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
757
758  long ldeg;
759  ldeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
760#ifndef SING_NDEBUG
761  if ( pLength == 0)
762    p_Last(GetLmTailRing(), pLength, tailRing);
763  assume ( pLength == length || rIsSyzIndexRing(currRing));
764#else
765  pLength=length;
766#endif
767  return ldeg;
768}
769
770KINLINE long sLObject::SetDegStuffReturnLDeg()
771{
772  FDeg = this->pFDeg();
773  long d = this->pLDeg();
774  ecart = d - FDeg;
775  return d;
776}
777KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last)
778{
779  FDeg = this->pFDeg();
780  long d = this->pLDeg(use_last);
781  ecart = d - FDeg;
782  return d;
783}
784KINLINE int sLObject::GetpLength()
785{
786  if (bucket == NULL)
787    return sTObject::GetpLength();
788  int i = kBucketCanonicalize(bucket);
789  return bucket->buckets_length[i] + 1;
790}
791KINLINE int sLObject::SetLength(BOOLEAN length_pLength)
792{
793  if (length_pLength)
794  {
795    length = this->GetpLength();
796  }
797  else
798    this->pLDeg();
799  return length;
800}
801KINLINE long sLObject::MinComp()
802{
803  poly tp = GetLmTailRing();
804  assume(tp != NULL);
805  if (bucket != NULL)
806  {
807    int i = kBucketCanonicalize(bucket);
808    pNext(tp) = bucket->buckets[i];
809    long m = p_MinComp(tp, tailRing);
810    pNext(tp) = NULL;
811    return m;
812  }
813  else
814    return p_MinComp(tp, tailRing);
815}
816KINLINE long sLObject::Comp()
817{
818  poly pp;
819  ring r;
820  GetLm(pp, r);
821  assume(pp != NULL);
822  return p_GetComp(pp, r);
823}
824
825KINLINE sLObject& sLObject::operator=(const sTObject& t)
826{
827  memset(this, 0, sizeof(*this));
828  memcpy(this, &t, sizeof(sTObject));
829  return *this;
830}
831
832KINLINE TObject* sLObject::T_1(const skStrategy* s)
833{
834  if (p1 == NULL) return NULL;
835  if (i_r1 == -1) i_r1 = kFindInT(p1, s->T, s->tl);
836  assume(i_r1 >= 0 && i_r1 <= s->tl);
837  TObject* T = s->R[i_r1];
838  assume(T->p == p1);
839  return T;
840}
841
842KINLINE TObject* sLObject::T_2(const skStrategy* strat)
843{
844  if (p1 == NULL) return NULL;
845  assume(p2 != NULL);
846  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
847  assume(i_r2 >= 0 && i_r2 <= strat->tl);
848  TObject* T = strat->R[i_r2];
849  assume(T->p == p2);
850  return T;
851}
852
853KINLINE void    sLObject::T_1_2(const skStrategy* strat,
854                                TObject* &T_1, TObject* &T_2)
855{
856  if (p1 == NULL)
857  {
858    T_1 = NULL;
859    T_2 = NULL;
860    return;
861  }
862  assume(p1 != NULL && p2 != NULL);
863  if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl);
864  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
865  assume(i_r1 >= 0 && i_r1 <= strat->tl);
866  assume(i_r2 >= 0 && i_r2 <= strat->tl);
867  T_1 = strat->R[i_r1];
868  T_2 = strat->R[i_r2];
869  assume(T_1->p == p1);
870  assume(T_2->p == p2);
871  return;
872}
873
874/***************************************************************
875 *
876 * Conversion of polys
877 *
878 ***************************************************************/
879
880KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
881{
882
883  poly t_p = p_LmInit(p, currRing, tailRing, tailBin);
884  pNext(t_p) = pNext(p);
885  pSetCoeff0(t_p, pGetCoeff(p));
886  return t_p;
887}
888
889KINLINE poly k_LmInit_tailRing_2_currRing(poly t_p, ring tailRing, omBin lmBin)
890{
891  poly p = p_LmInit(t_p, tailRing, currRing, lmBin);
892  pNext(p) = pNext(t_p);
893  pSetCoeff0(p, pGetCoeff(t_p));
894  return p;
895}
896
897// this should be made more efficient
898KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
899{
900  poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin);
901  p_LmFree(p, currRing);
902  return np;
903}
904
905KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
906{
907  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
908  p_LmFree(p, tailRing);
909  return np;
910}
911
912KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
913{
914  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
915}
916
917KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
918{
919  return  k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
920}
921
922KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing)
923{
924  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
925}
926
927KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing)
928{
929  return  k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
930}
931
932/***************************************************************
933 *
934 * Lcm business
935 *
936 ***************************************************************/
937// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
938//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
939KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
940                               poly &m1, poly &m2, const ring m_r)
941{
942  p_LmCheckPolyRing(p1, p_r);
943  p_LmCheckPolyRing(p2, p_r);
944
945  int i;
946  long x;
947  m1 = p_Init(m_r,m_r->PolyBin);
948  m2 = p_Init(m_r,m_r->PolyBin);
949
950  for (i = p_r->N; i; i--)
951  {
952    x = p_GetExpDiff(p1, p2, i, p_r);
953    if (x > 0)
954    {
955      if (x > (long) m_r->bitmask) goto false_return;
956      p_SetExp(m2,i,x, m_r);
957      p_SetExp(m1,i,0, m_r);
958    }
959    else
960    {
961      if (-x > (long) m_r->bitmask) goto false_return;
962      p_SetExp(m1,i,-x, m_r);
963      p_SetExp(m2,i,0, m_r);
964    }
965  }
966
967  p_Setm(m1, m_r);
968  p_Setm(m2, m_r);
969  return TRUE;
970
971  false_return:
972  p_LmFree(m1, m_r);
973  p_LmFree(m2, m_r);
974  m1 = m2 = NULL;
975  return FALSE;
976}
977
978#ifdef HAVE_RINGS
979// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
980//     m2 = LCM(LM(p1), LM(p2))/LM(p2)   in tailRing
981//    lcm = LCM(LM(p1), LM(p2))          in leadRing
982KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing,
983                               poly &m1, poly &m2, poly &lcm, const ring tailRing)
984{
985  p_LmCheckPolyRing(p1, leadRing);
986  p_LmCheckPolyRing(p2, leadRing);
987
988  int i;
989  int x;
990  int e1;
991  int e2;
992  int s;
993  m1 = p_Init(tailRing,tailRing->PolyBin);
994  m2 = p_Init(tailRing,tailRing->PolyBin);
995  lcm = p_Init(leadRing,leadRing->PolyBin);
996
997  for (i = leadRing->N; i>=0; i--)
998  {
999    e1 = p_GetExp(p1,i,leadRing);
1000    e2 = p_GetExp(p2,i,leadRing);
1001    x = e1 - e2;
1002    if (x > 0)
1003    {
1004      p_SetExp(m2,i,x, tailRing);
1005      //p_SetExp(m1,i,0, tailRing); // done by p_Init
1006      s = e1;
1007    }
1008    else if (x<0)
1009    {
1010      p_SetExp(m1,i,-x, tailRing);
1011      //p_SetExp(m2,i,0, tailRing); // done by p_Init
1012      s = e2;
1013    }
1014    else
1015      s = e1; // e1==e2
1016    p_SetExp(lcm,i,s, leadRing);
1017  }
1018
1019  p_Setm(m1, tailRing);
1020  p_Setm(m2, tailRing);
1021  p_Setm(lcm, leadRing);
1022}
1023#endif
1024
1025/***************************************************************
1026 *
1027 * Misc things
1028 *
1029 ***************************************************************/
1030KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red)
1031{
1032  BOOLEAN ret;
1033  number coef;
1034
1035  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
1036  Red->HeadNormalize();
1037  ret = ksReducePoly(Red, PW, NULL, &coef);
1038
1039  if (!ret)
1040  {
1041    if (! n_IsOne(coef, currRing->cf))
1042    {
1043      PR->Mult_nn(coef);
1044      // HANNES: mark for Normalize
1045    }
1046    n_Delete(&coef, currRing->cf);
1047  }
1048  return ret;
1049}
1050
1051/***************************************************************
1052 *
1053 * Routines for backwards-Compatibility
1054 *
1055 *
1056 ***************************************************************/
1057KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
1058{
1059  LObject L(p2);
1060  TObject T(p1);
1061
1062  ksReducePoly(&L, &T, spNoether);
1063
1064  return L.GetLmCurrRing();
1065}
1066
1067KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
1068{
1069  LObject L(p_Copy(p2, currRing));
1070  TObject T(p1);
1071
1072  ksReducePoly(&L, &T, spNoether);
1073
1074  return L.GetLmCurrRing();
1075}
1076
1077KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
1078{
1079  LObject L(r);
1080  L.p1 = p1;
1081  L.p2 = p2;
1082
1083  ksCreateSpoly(&L, spNoether);
1084  return L.GetLmCurrRing();
1085}
1086
1087void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1088{
1089  LObject L(q,  currRing, r);
1090  TObject T(p1, currRing, r);
1091
1092  ksReducePolyTail(&L, &T, q2, spNoether);
1093}
1094
1095KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize)
1096{
1097  LObject L(p);
1098  return redtailBba(&L, pos, strat,FALSE, normalize);
1099}
1100
1101KINLINE poly redtailBbaBound (poly p,int pos,kStrategy strat,int bound,BOOLEAN normalize)
1102{
1103  LObject L(p, currRing, strat->tailRing); // ? L(p); ??
1104  return redtailBbaBound(&L, pos, strat,bound, FALSE, normalize);
1105}
1106
1107#ifdef HAVE_RINGS
1108KINLINE poly redtailBba_Z (poly p,int pos,kStrategy strat)
1109{
1110  LObject L(p, currRing, strat->tailRing);
1111  return redtailBba_Z(&L, pos, strat);
1112}
1113#endif
1114
1115KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
1116                    kStrategy strat)
1117{
1118  assume(p_sev == pGetShortExpVector(p));
1119  if (strat->noClearS) return;
1120  #ifdef HAVE_RINGS
1121  if(rField_is_Ring(currRing))
1122  {
1123    if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at]))
1124      return;
1125    if(!n_DivBy(pGetCoeff(strat->S[*at]), pGetCoeff(p), currRing->cf))
1126      return;
1127  }
1128  else
1129  #endif
1130  {
1131    if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1132  }
1133  deleteInS((*at),strat);
1134  (*at)--;
1135  (*k)--;
1136}
1137
1138// dummy function for function pointer strat->rewCrit being usable in all
1139// possible choices for criteria
1140KINLINE BOOLEAN arriRewDummy(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy /*strat*/, int /*start=0*/)
1141{
1142  return FALSE;
1143}
1144
1145#endif // defined(KINLINE) || defined(KUTIL_CC)
1146#endif // KINLINE_H
Note: See TracBrowser for help on using the repository browser.