source: git/kernel/kInline.h @ 359d86d

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