source: git/kernel/kInline.h @ a497a1

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