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

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