source: git/kernel/kInline.h @ c25b56c

spielwiese
Last change on this file since c25b56c was c25b56c, checked in by Adrian Popescu <adi_popescum@…>, 11 years ago
SB over rings with local ordering add: new tests
  • 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)
[088e67]14/* this file is a header file with inline routines,
[8bb03b]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)
[088e67]438        {
439          p_Cleardenom_n(t_p, tailRing, n);
440          pSetCoeff0(p, pGetCoeff(t_p));
441        }
[526e40d]442      else
[088e67]443        {
444          p_Cleardenom_n(p, currRing, n);
445        }
[526e40d]446      if (!nIsOne(n))
[088e67]447        {
448          denominator_list denom=(denominator_list)omAlloc(sizeof(denominator_list_s));
449          denom->n=nInvers(n);
450          denom->next=DENOMINATOR_LIST;
451          DENOMINATOR_LIST=denom;
452        }
[526e40d]453      nDelete(&n);
454    }
[a0d9be]455  else
[526e40d]456    {
457      if (t_p != NULL)
[dc42daf]458        {
459          p_ProjectiveUnique(t_p, tailRing);
460          pSetCoeff0(p, pGetCoeff(t_p));
461        }
[526e40d]462      else
[dc42daf]463        {
464#ifdef HAVE_RATGRING
465          p_ProjectiveUnique(p, currRing);
466#else
467          p_ProjectiveUnique(p, currRing);
468#endif
469        }
[526e40d]470    }
[35aab3]471}
472
[f0a8c59]473KINLINE void sTObject::pNorm() // pNorm seems to be a _bad_ method name...
[35aab3]474{
475  assume(p != NULL);
476  if (! is_normalized)
477  {
[f0a8c59]478    p_Norm(p, currRing);
[35aab3]479    if (t_p != NULL)
480      pSetCoeff0(t_p, pGetCoeff(p));
481    is_normalized = TRUE;
482  }
483}
484
485
486
487/***************************************************************
488 *
489 * Operation on LObjects
490 *
491 ***************************************************************/
492// Initialization
493KINLINE void sLObject::Clear()
494{
495  sTObject::Clear();
496  sev = 0;
497}
498// Initialization
499KINLINE void sLObject::Delete()
500{
501  sTObject::Delete();
502  if (bucket != NULL)
503    kBucketDeleteAndDestroy(&bucket);
504}
505
506KINLINE void sLObject::Init(ring r)
507{
508  memset(this, 0, sizeof(sLObject));
509  i_r1 = -1;
510  i_r2 = -1;
511  i_r = -1;
512  Set(r);
513}
514KINLINE sLObject::sLObject(ring r)
515{
516  Init(r);
517}
518KINLINE sLObject::sLObject(poly p_in, ring r)
519{
520  Init(r);
521  Set(p_in, r);
522}
523
524KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r)
525{
526  Init(t_r);
527  Set(p_in, c_r, t_r);
528}
529
530KINLINE void sLObject::PrepareRed(BOOLEAN use_bucket)
531{
532  if (bucket == NULL)
533  {
534    int l = GetpLength();
535    if (use_bucket && l > 1)
536    {
537      poly tp = GetLmTailRing();
538      assume(l == ::pLength(tp));
539      bucket = kBucketCreate(tailRing);
540      kBucketInit(bucket, pNext(tp), l-1);
541      pNext(tp) = NULL;
542      if (p != NULL) pNext(p) = NULL;
543      pLength = 0;
544    }
545  }
546}
547
[f224d85]548KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing)
[35aab3]549{
550
[8c7e81]551  Set(lm, _tailRing);
[35aab3]552  if (use_bucket)
553  {
[8c7e81]554    bucket = kBucketCreate(_tailRing);
[35aab3]555    kBucketInit(bucket, p_tail, p_Length);
556    pNext(lm) = NULL;
557    pLength = 0;
558  }
559  else
560  {
561    pNext(lm) = p_tail;
562    pLength = p_Length + 1;
563  }
564}
565
566KINLINE void sLObject::Tail_Mult_nn(number n)
567{
568  if (bucket != NULL)
569  {
570    kBucket_Mult_n(bucket, n);
571  }
572  else
573  {
574    poly _p = (t_p != NULL ? t_p : p);
575    assume(_p != NULL);
[a497a1]576    pNext(_p) = p_Mult_nn(pNext(_p), n, tailRing);
[35aab3]577  }
578}
579
580KINLINE void sLObject::Tail_Minus_mm_Mult_qq(poly m, poly q, int lq,
581                                             poly spNoether)
582{
583  if (bucket != NULL)
584  {
585    kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether);
586  }
587  else
588  {
[d30a399]589    if (lq<=0) lq= ::pLength(q);
[35aab3]590    poly _p = (t_p != NULL ? t_p : p);
591    assume(_p != NULL);
[a497a1]592
[e9927f]593    int lp=pLength-1;
[088e67]594    pNext(_p) = p_Minus_mm_Mult_qq( pNext(_p), m, q, lp, lq,
[abe5c8]595                                    spNoether, tailRing );
[e9927f]596    pLength=lp+1;
[a497a1]597//    tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, shorter,spNoether, tailRing, last);
598//    pLength += lq - shorter;
[35aab3]599  }
600}
601
602KINLINE void sLObject::LmDeleteAndIter()
603{
604  sTObject::LmDeleteAndIter();
605  if (bucket != NULL)
606  {
607    poly _p = kBucketExtractLm(bucket);
608    if (_p == NULL)
609    {
610      kBucketDestroy(&bucket);
611      p = t_p = NULL;
612      return;
613    }
614    Set(_p, tailRing);
615  }
616  else
617  {
618    pLength--;
619  }
620}
621
622KINLINE poly sLObject::LmExtractAndIter()
623{
624  poly ret = GetLmTailRing();
625  poly pn;
626
627  assume(p != NULL || t_p != NULL);
628
629  if (bucket != NULL)
630  {
631    pn = kBucketExtractLm(bucket);
632    if (pn == NULL)
633      kBucketDestroy(&bucket);
634  }
635  else
636  {
637    pn = pNext(ret);
638  }
639  pLength--;
640  pNext(ret) = NULL;
641  if (p != NULL && t_p != NULL)
642    p_LmFree(p, currRing);
643
644  Set(pn, tailRing);
645  return ret;
646}
647
648KINLINE poly sLObject::CanonicalizeP()
649{
[015bba]650  //kTest_L(this);
[35aab3]651  int i = -1;
652
653  if (bucket != NULL)
654    i = kBucketCanonicalize(bucket);
655
656  if (p == NULL)
657    p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
658
659  if (i >= 0) pNext(p) = bucket->buckets[i];
660  return p;
661}
662
663KINLINE poly sLObject::GetTP()
664{
[015bba]665  //kTest_L(this);
[35aab3]666  poly tp = GetLmTailRing();
667  assume(tp != NULL);
668
669  if (bucket != NULL)
670  {
671    kBucketClear(bucket, &pNext(tp), &pLength);
672    kBucketDestroy(&bucket);
673    pLength++;
674  }
675  return tp;
676}
677
678
679KINLINE poly sLObject::GetP(omBin lmBin)
680{
[015bba]681  //kTest_L(this);
[35aab3]682  if (p == NULL)
683  {
684    p = k_LmInit_tailRing_2_currRing(t_p, tailRing,
685                                     (lmBin!=NULL?lmBin:currRing->PolyBin));
686    FDeg = pFDeg();
687  }
688  else if (lmBin != NULL && lmBin != currRing->PolyBin)
689  {
[99cfa5e]690    p = p_LmShallowCopyDelete(p, currRing);
[35aab3]691    FDeg = pFDeg();
692  }
693
694  if (bucket != NULL)
695  {
696    kBucketClear(bucket, &pNext(p), &pLength);
697    kBucketDestroy(&bucket);
698    pLength++;
699    if (t_p != NULL) pNext(t_p) = pNext(p);
700  }
[015bba]701  //kTest_L(this);
[35aab3]702  return p;
703}
704
705KINLINE void
706sLObject::ShallowCopyDelete(ring new_tailRing,
707                            pShallowCopyDeleteProc p_shallow_copy_delete)
708{
709  if (bucket != NULL)
710    kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
711                             p_shallow_copy_delete);
712  sTObject::ShallowCopyDelete(new_tailRing,
713                              new_tailRing->PolyBin,p_shallow_copy_delete,
714                              FALSE);
715}
716
717KINLINE void sLObject::SetShortExpVector()
718{
719  if (t_p != NULL)
720  {
721    sev = p_GetShortExpVector(t_p, tailRing);
722  }
723  else
724  {
725    sev = p_GetShortExpVector(p, currRing);
726  }
727}
728
729KINLINE void sLObject::Copy()
730{
731  if (bucket != NULL)
732  {
733    int i = kBucketCanonicalize(bucket);
734    kBucket_pt new_bucket = kBucketCreate(tailRing);
735    kBucketInit(new_bucket,
736                p_Copy(bucket->buckets[i], tailRing),
737                bucket->buckets_length[i]);
738    bucket = new_bucket;
739    if (t_p != NULL) pNext(t_p) = NULL;
740    if (p != NULL) pNext(p) = NULL;
741  }
742  TObject::Copy();
743}
744
745KINLINE poly sLObject::CopyGetP()
746{
747  if (bucket != NULL)
748  {
749    int i = kBucketCanonicalize(bucket);
750    poly bp = p_Copy(bucket->buckets[i], tailRing);
751    pLength = bucket->buckets_length[i] + 1;
752    if (bp != NULL)
753    {
754      assume(t_p != NULL || p != NULL);
755      if (t_p != NULL) pNext(t_p) = bp;
756      else pNext(p) = bp;
757    }
758    bucket = NULL;
759  }
760  return sLObject::GetP();
761}
762
763
764KINLINE long sLObject::pLDeg()
765{
766  poly tp = GetLmTailRing();
767  assume(tp != NULL);
768  if (bucket != NULL)
769  {
770    int i = kBucketCanonicalize(bucket);
771    pNext(tp) = bucket->buckets[i];
772    long ldeg = tailRing->pLDeg(tp, &length, tailRing);
773    pNext(tp) = NULL;
774    return ldeg;
775  }
776  else
777    return tailRing->pLDeg(tp, &length, tailRing);
778}
779KINLINE long sLObject::pLDeg(BOOLEAN deg_last)
780{
781  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
782
[1cf7b9]783  long ldeg;
784  ldeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
[f224d85]785#ifdef HAVE_ASSUME
786  if ( pLength == 0)
787    p_Last(GetLmTailRing(), pLength, tailRing);
[54c558]788  assume ( pLength == length || rIsSyzIndexRing(currRing));
[35aab3]789#else
[f224d85]790  pLength=length;
[35aab3]791#endif
[f224d85]792  return ldeg;
[35aab3]793}
794
795KINLINE long sLObject::SetDegStuffReturnLDeg()
796{
797  FDeg = this->pFDeg();
798  long d = this->pLDeg();
799  ecart = d - FDeg;
800  return d;
801}
802KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last)
803{
804  FDeg = this->pFDeg();
805  long d = this->pLDeg(use_last);
806  ecart = d - FDeg;
807  return d;
808}
809KINLINE int sLObject::GetpLength()
810{
811  if (bucket == NULL)
812    return sTObject::GetpLength();
813  int i = kBucketCanonicalize(bucket);
814  return bucket->buckets_length[i] + 1;
815}
816KINLINE int sLObject::SetLength(BOOLEAN length_pLength)
817{
818  if (length_pLength)
819  {
820    length = this->GetpLength();
821  }
822  else
823    this->pLDeg();
824  return length;
825}
826KINLINE long sLObject::MinComp()
827{
828  poly tp = GetLmTailRing();
829  assume(tp != NULL);
830  if (bucket != NULL)
831  {
832    int i = kBucketCanonicalize(bucket);
833    pNext(tp) = bucket->buckets[i];
834    long m = p_MinComp(tp, tailRing);
835    pNext(tp) = NULL;
836    return m;
837  }
838  else
839    return p_MinComp(tp, tailRing);
840}
841KINLINE long sLObject::Comp()
842{
[8c7e81]843  poly pp;
[35aab3]844  ring r;
[8c7e81]845  GetLm(pp, r);
846  assume(pp != NULL);
847  return p_GetComp(pp, r);
[35aab3]848}
849
850KINLINE sLObject& sLObject::operator=(const sTObject& t)
851{
852  memset(this, 0, sizeof(*this));
853  memcpy(this, &t, sizeof(sTObject));
854  return *this;
855}
856
857KINLINE TObject* sLObject::T_1(const skStrategy* s)
858{
859  if (p1 == NULL) return NULL;
860  if (i_r1 == -1) i_r1 = kFindInT(p1, s->T, s->tl);
861  assume(i_r1 >= 0 && i_r1 <= s->tl);
862  TObject* T = s->R[i_r1];
863  assume(T->p == p1);
864  return T;
865}
866
867KINLINE TObject* sLObject::T_2(const skStrategy* strat)
868{
869  if (p1 == NULL) return NULL;
870  assume(p2 != NULL);
871  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
872  assume(i_r2 >= 0 && i_r2 <= strat->tl);
873  TObject* T = strat->R[i_r2];
874  assume(T->p == p2);
875  return T;
876}
877
878KINLINE void    sLObject::T_1_2(const skStrategy* strat,
879                                TObject* &T_1, TObject* &T_2)
880{
881  if (p1 == NULL)
882  {
883    T_1 = NULL;
884    T_2 = NULL;
885    return;
886  }
887  assume(p1 != NULL && p2 != NULL);
888  if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl);
889  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
890  assume(i_r1 >= 0 && i_r1 <= strat->tl);
891  assume(i_r2 >= 0 && i_r2 <= strat->tl);
892  T_1 = strat->R[i_r1];
893  T_2 = strat->R[i_r2];
894  assume(T_1->p == p1);
895  assume(T_2->p == p2);
896  return;
897}
898
899/***************************************************************
900 *
901 * Conversion of polys
902 *
903 ***************************************************************/
904
905KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
906{
907
908  poly np = p_LmInit(p, currRing, tailRing, tailBin);
909  pNext(np) = pNext(p);
910  pSetCoeff0(np, pGetCoeff(p));
911  return np;
912}
913
914KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
915{
916  poly np = p_LmInit(p, tailRing, currRing, lmBin);
917  pNext(np) = pNext(p);
918  pSetCoeff0(np, pGetCoeff(p));
919  return np;
920}
921
922// this should be made more efficient
923KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
924{
925  poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin);
926  p_LmFree(p, currRing);
927  return np;
928}
929
930KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
931{
932  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
933  p_LmFree(p, tailRing);
934  return np;
935}
936
937KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
938{
939  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
940}
941
942KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
943{
944  return  k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
945}
946
947KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing)
948{
949  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
950}
951
952KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing)
953{
954  return  k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
955}
956
957/***************************************************************
958 *
959 * Lcm business
960 *
961 ***************************************************************/
962// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
963//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
964KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
965                               poly &m1, poly &m2, const ring m_r)
966{
967  p_LmCheckPolyRing(p1, p_r);
968  p_LmCheckPolyRing(p2, p_r);
969
970  int i;
[0b5e3d]971  long x;
[35aab3]972  m1 = p_Init(m_r);
973  m2 = p_Init(m_r);
974
975  for (i = p_r->N; i; i--)
976  {
977    x = p_GetExpDiff(p1, p2, i, p_r);
978    if (x > 0)
979    {
980      if (x > (long) m_r->bitmask) goto false_return;
981      p_SetExp(m2,i,x, m_r);
982      p_SetExp(m1,i,0, m_r);
983    }
984    else
985    {
986      if (-x > (long) m_r->bitmask) goto false_return;
987      p_SetExp(m1,i,-x, m_r);
988      p_SetExp(m2,i,0, m_r);
989    }
990  }
991
992  p_Setm(m1, m_r);
993  p_Setm(m2, m_r);
994  return TRUE;
995
996  false_return:
997  p_LmFree(m1, m_r);
998  p_LmFree(m2, m_r);
999  m1 = m2 = NULL;
1000  return FALSE;
1001}
1002
[d681e8]1003#ifdef HAVE_RINGS
1004// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
1005//     m2 = LCM(LM(p1), LM(p2))/LM(p2)   in tailRing
[c25b56c]1006//    lcm = LCM(LM(p1), LM(p2))          in leadRing
[ca371d]1007KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing,
[d681e8]1008                               poly &m1, poly &m2, poly &lcm, const ring tailRing)
1009{
1010  p_LmCheckPolyRing(p1, leadRing);
1011  p_LmCheckPolyRing(p2, leadRing);
1012
1013  int i;
[a0d9be]1014  int x;
1015  int e1;
1016  int e2;
1017  int s;
[d681e8]1018  m1 = p_Init(tailRing);
1019  m2 = p_Init(tailRing);
1020  lcm = p_Init(leadRing);
1021
[a0d9be]1022  for (i = leadRing->N; i>=1; i--)
[d681e8]1023  {
1024    e1 = p_GetExp(p1,i,leadRing);
1025    e2 = p_GetExp(p2,i,leadRing);
1026    x = e1 - e2;
1027    if (x > 0)
1028    {
1029      p_SetExp(m2,i,x, tailRing);
[a0d9be]1030      //p_SetExp(m1,i,0, tailRing); // done by p_Init
[8f898b]1031      s = e1;
[d681e8]1032    }
1033    else
1034    {
1035      p_SetExp(m1,i,-x, tailRing);
[a0d9be]1036      //p_SetExp(m2,i,0, tailRing); // done by p_Init
[8f898b]1037      s = e2;
[d681e8]1038    }
1039    p_SetExp(lcm,i,s, leadRing);
1040  }
[a0d9be]1041  if ((s=pGetComp(p1))!=0)
1042  {
1043    p_SetComp(lcm,s, leadRing);
[088e67]1044  }
[a0d9be]1045  else if ((s=pGetComp(p2))!=0)
1046  {
1047    p_SetComp(lcm,s, leadRing);
[088e67]1048  }
[a0d9be]1049  // else p_SetComp(lcm,0,tailRing); // done by p_Init
[d681e8]1050
1051  p_Setm(m1, tailRing);
1052  p_Setm(m2, tailRing);
1053  p_Setm(lcm, leadRing);
1054}
1055#endif
1056
[35aab3]1057/***************************************************************
1058 *
1059 * Misc things
1060 *
1061 ***************************************************************/
1062KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red)
1063{
1064  BOOLEAN ret;
1065  number coef;
1066
1067  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
[88f583]1068  Red->HeadNormalize();
[35aab3]1069  ret = ksReducePoly(Red, PW, NULL, &coef);
1070
1071  if (!ret)
1072  {
[359d86d]1073    if (! n_IsOne(coef, currRing->cf))
[88f583]1074    {
[35aab3]1075      PR->Mult_nn(coef);
[88f583]1076      // HANNES: mark for Normalize
1077    }
[359d86d]1078    n_Delete(&coef, currRing->cf);
[35aab3]1079  }
1080  return ret;
1081}
1082
1083/***************************************************************
1084 *
1085 * Routines for backwards-Compatibility
1086 *
1087 *
1088 ***************************************************************/
1089KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
1090{
1091  LObject L(p2);
1092  TObject T(p1);
1093
1094  ksReducePoly(&L, &T, spNoether);
1095
1096  return L.GetLmCurrRing();
1097}
1098
1099KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
1100{
1101  LObject L(p_Copy(p2, currRing));
1102  TObject T(p1);
1103
1104  ksReducePoly(&L, &T, spNoether);
1105
1106  return L.GetLmCurrRing();
1107}
1108
1109KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
1110{
1111  LObject L(r);
1112  L.p1 = p1;
1113  L.p2 = p2;
1114
1115  ksCreateSpoly(&L, spNoether);
1116  return L.GetLmCurrRing();
1117}
1118
1119void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1120{
1121  LObject L(q,  currRing, r);
1122  TObject T(p1, currRing, r);
1123
1124  ksReducePolyTail(&L, &T, q2, spNoether);
1125}
1126
[015bba]1127KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize)
[35aab3]1128{
1129  LObject L(p, currRing, strat->tailRing);
[015bba]1130  return redtailBba(&L, pos, strat,FALSE, normalize);
[35aab3]1131}
1132
[5eb865]1133#ifdef HAVE_RINGS
1134KINLINE poly redtailBba_Z (poly p,int pos,kStrategy strat)
1135{
1136  LObject L(p, currRing, strat->tailRing);
1137  return redtailBba_Z(&L, pos, strat);
1138}
1139#endif
1140
[015bba]1141KINLINE poly redtailBba(TObject *T, int pos,kStrategy strat)
[35aab3]1142{
1143  LObject L;
1144  L = *T;
1145  poly p = redtailBba(&L, pos, strat, FALSE);
1146  *T = L;
[015bba]1147  //kTest_T(T);
[35aab3]1148  assume( p == T->p);
1149  return p;
1150}
1151
[ec69aa]1152KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
[c903a3]1153                    kStrategy strat)
1154{
1155  assume(p_sev == pGetShortExpVector(p));
1156  if (strat->noClearS) return;
1157  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1158  deleteInS((*at),strat);
1159  (*at)--;
1160  (*k)--;
1161}
1162
[0758b5]1163// dummy function for function pointer strat->rewCrit being usable in all
1164// possible choices for criteria
[2e4ec14]1165KINLINE BOOLEAN arriRewDummy(poly /*sig*/, unsigned long /*not_sevSig*/, kStrategy /*strat*/, int /*start=0*/)
[0758b5]1166{
1167  return FALSE;
1168}
1169
[35aab3]1170#endif // defined(KINLINE) || defined(KUTIL_CC)
[99cfa5e]1171#endif // KINLINE_H
Note: See TracBrowser for help on using the repository browser.