source: git/kernel/kInline.h @ f0a8c59

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