source: git/kernel/kInline.h @ d30a399

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