source: git/kernel/kInline.h @ f224d85

spielwiese
Last change on this file since f224d85 was f224d85, checked in by Hans Schoenemann <hannes@…>, 12 years ago
fix: removing last from p_*templates and k* routines
  • Property mode set to 100644
File size: 23.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 *******************************************************************/
10#ifndef KINLINE_H
11#define KINLINE_H
12
13#if !defined(NO_KINLINE) || defined(KUTIL_CC)
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 */
19
20#include <omalloc/omalloc.h>
21#include <misc/options.h>
22
23#include <polys/monomials/p_polys.h>
24#include <polys/kbuckets.h>
25
26#include <kernel/polys.h>
27
28
29#define HAVE_TAIL_BIN
30// This doesn't really work, fixme, if necessary
31// #define HAVE_LM_BIN
32
33
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);
39  TObject* TT = R[S_2_R[i]];
40  assume(TT != NULL && TT->p == S[i]);
41  return TT;
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];
49    if ((sri >= 0) && (sri <= tl))
50    {
51      TObject* t = R[sri];
52      if ((t != NULL) && (t->p == S[i]))
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)
312  {    t_p = p_Mult_nn(t_p, n, tailRing);
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
321KINLINE void sLObject::Normalize()
322{
323  if (t_p != NULL)
324  {
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)
337  {
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
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{
397  if (p != NULL) return p_FDeg(p, currRing);
398  return tailRing->pFDeg(t_p, tailRing);
399}
400KINLINE long sTObject::pTotalDeg() const
401{
402  if (p != NULL) return p_Totaldegree(p, currRing);
403  return p_Totaldegree(t_p,tailRing);
404}
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
427//extern void pCleardenom(poly p);
428// extern void pNorm(poly p);
429
430// manipulations
431KINLINE void  sTObject::pCleardenom()
432{
433  assume(p != NULL);
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
445          p_Cleardenom_n(p, currRing, n);
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    }
459  else
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
469          p_Cleardenom(p, currRing);
470#else
471          p_Cleardenom(p, currRing);
472#endif
473        }
474    }
475}
476
477KINLINE void sTObject::pNorm() // pNorm seems to be a _bad_ method name...
478{
479  assume(p != NULL);
480  if (! is_normalized)
481  {
482    p_Norm(p, currRing);
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
552KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing)
553{
554
555  Set(lm, _tailRing);
556  if (use_bucket)
557  {
558    bucket = kBucketCreate(_tailRing);
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);
580    pNext(_p) = 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
596    pNext(_p) = p_Minus_mm_Mult_qq( pNext(_p), m, q, pLength, lq, 
597                                    spNoether, tailRing );
598//    tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, shorter,spNoether, 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);
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}
717
718KINLINE void sLObject::SetShortExpVector()
719{
720  if (t_p != NULL)
721  {
722    sev = p_GetShortExpVector(t_p, tailRing);
723  }
724  else
725  {
726    sev = p_GetShortExpVector(p, currRing);
727  }
728}
729
730KINLINE void sLObject::Copy()
731{
732  if (bucket != NULL)
733  {
734    int i = kBucketCanonicalize(bucket);
735    kBucket_pt new_bucket = kBucketCreate(tailRing);
736    kBucketInit(new_bucket,
737                p_Copy(bucket->buckets[i], tailRing),
738                bucket->buckets_length[i]);
739    bucket = new_bucket;
740    if (t_p != NULL) pNext(t_p) = NULL;
741    if (p != NULL) pNext(p) = NULL;
742  }
743  TObject::Copy();
744}
745
746KINLINE poly sLObject::CopyGetP()
747{
748  if (bucket != NULL)
749  {
750    int i = kBucketCanonicalize(bucket);
751    poly bp = p_Copy(bucket->buckets[i], tailRing);
752    pLength = bucket->buckets_length[i] + 1;
753    if (bp != NULL)
754    {
755      assume(t_p != NULL || p != NULL);
756      if (t_p != NULL) pNext(t_p) = bp;
757      else pNext(p) = bp;
758    }
759    bucket = NULL;
760  }
761  return sLObject::GetP();
762}
763
764
765KINLINE long sLObject::pLDeg()
766{
767  poly tp = GetLmTailRing();
768  assume(tp != NULL);
769  if (bucket != NULL)
770  {
771    int i = kBucketCanonicalize(bucket);
772    pNext(tp) = bucket->buckets[i];
773    long ldeg = tailRing->pLDeg(tp, &length, tailRing);
774    pNext(tp) = NULL;
775    return ldeg;
776  }
777  else
778    return tailRing->pLDeg(tp, &length, tailRing);
779}
780KINLINE long sLObject::pLDeg(BOOLEAN deg_last)
781{
782  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
783
784  long ldeg;
785  ldeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
786#ifdef HAVE_ASSUME
787  if ( pLength == 0)
788    p_Last(GetLmTailRing(), pLength, tailRing);
789  assume ( pLength == length || rIsSyzIndexRing(currRing));
790#else
791  pLength=length;
792#endif
793  return ldeg;
794}
795
796KINLINE long sLObject::SetDegStuffReturnLDeg()
797{
798  FDeg = this->pFDeg();
799  long d = this->pLDeg();
800  ecart = d - FDeg;
801  return d;
802}
803KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last)
804{
805  FDeg = this->pFDeg();
806  long d = this->pLDeg(use_last);
807  ecart = d - FDeg;
808  return d;
809}
810KINLINE int sLObject::GetpLength()
811{
812  if (bucket == NULL)
813    return sTObject::GetpLength();
814  int i = kBucketCanonicalize(bucket);
815  return bucket->buckets_length[i] + 1;
816}
817KINLINE int sLObject::SetLength(BOOLEAN length_pLength)
818{
819  if (length_pLength)
820  {
821    length = this->GetpLength();
822  }
823  else
824    this->pLDeg();
825  return length;
826}
827KINLINE long sLObject::MinComp()
828{
829  poly tp = GetLmTailRing();
830  assume(tp != NULL);
831  if (bucket != NULL)
832  {
833    int i = kBucketCanonicalize(bucket);
834    pNext(tp) = bucket->buckets[i];
835    long m = p_MinComp(tp, tailRing);
836    pNext(tp) = NULL;
837    return m;
838  }
839  else
840    return p_MinComp(tp, tailRing);
841}
842KINLINE long sLObject::Comp()
843{
844  poly pp;
845  ring r;
846  GetLm(pp, r);
847  assume(pp != NULL);
848  return p_GetComp(pp, r);
849}
850
851KINLINE sLObject& sLObject::operator=(const sTObject& t)
852{
853  memset(this, 0, sizeof(*this));
854  memcpy(this, &t, sizeof(sTObject));
855  return *this;
856}
857
858KINLINE TObject* sLObject::T_1(const skStrategy* s)
859{
860  if (p1 == NULL) return NULL;
861  if (i_r1 == -1) i_r1 = kFindInT(p1, s->T, s->tl);
862  assume(i_r1 >= 0 && i_r1 <= s->tl);
863  TObject* T = s->R[i_r1];
864  assume(T->p == p1);
865  return T;
866}
867
868KINLINE TObject* sLObject::T_2(const skStrategy* strat)
869{
870  if (p1 == NULL) return NULL;
871  assume(p2 != NULL);
872  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
873  assume(i_r2 >= 0 && i_r2 <= strat->tl);
874  TObject* T = strat->R[i_r2];
875  assume(T->p == p2);
876  return T;
877}
878
879KINLINE void    sLObject::T_1_2(const skStrategy* strat,
880                                TObject* &T_1, TObject* &T_2)
881{
882  if (p1 == NULL)
883  {
884    T_1 = NULL;
885    T_2 = NULL;
886    return;
887  }
888  assume(p1 != NULL && p2 != NULL);
889  if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl);
890  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
891  assume(i_r1 >= 0 && i_r1 <= strat->tl);
892  assume(i_r2 >= 0 && i_r2 <= strat->tl);
893  T_1 = strat->R[i_r1];
894  T_2 = strat->R[i_r2];
895  assume(T_1->p == p1);
896  assume(T_2->p == p2);
897  return;
898}
899
900/***************************************************************
901 *
902 * Conversion of polys
903 *
904 ***************************************************************/
905
906KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
907{
908
909  poly np = p_LmInit(p, currRing, tailRing, tailBin);
910  pNext(np) = pNext(p);
911  pSetCoeff0(np, pGetCoeff(p));
912  return np;
913}
914
915KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
916{
917  poly np = p_LmInit(p, tailRing, currRing, lmBin);
918  pNext(np) = pNext(p);
919  pSetCoeff0(np, pGetCoeff(p));
920  return np;
921}
922
923// this should be made more efficient
924KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
925{
926  poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin);
927  p_LmFree(p, currRing);
928  return np;
929}
930
931KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
932{
933  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
934  p_LmFree(p, tailRing);
935  return np;
936}
937
938KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
939{
940  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
941}
942
943KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
944{
945  return  k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
946}
947
948KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing)
949{
950  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
951}
952
953KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing)
954{
955  return  k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
956}
957
958/***************************************************************
959 *
960 * Lcm business
961 *
962 ***************************************************************/
963// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
964//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
965KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
966                               poly &m1, poly &m2, const ring m_r)
967{
968  p_LmCheckPolyRing(p1, p_r);
969  p_LmCheckPolyRing(p2, p_r);
970
971  int i;
972  long x;
973  m1 = p_Init(m_r);
974  m2 = p_Init(m_r);
975
976  for (i = p_r->N; i; i--)
977  {
978    x = p_GetExpDiff(p1, p2, i, p_r);
979    if (x > 0)
980    {
981      if (x > (long) m_r->bitmask) goto false_return;
982      p_SetExp(m2,i,x, m_r);
983      p_SetExp(m1,i,0, m_r);
984    }
985    else
986    {
987      if (-x > (long) m_r->bitmask) goto false_return;
988      p_SetExp(m1,i,-x, m_r);
989      p_SetExp(m2,i,0, m_r);
990    }
991  }
992
993  p_Setm(m1, m_r);
994  p_Setm(m2, m_r);
995  return TRUE;
996
997  false_return:
998  p_LmFree(m1, m_r);
999  p_LmFree(m2, m_r);
1000  m1 = m2 = NULL;
1001  return FALSE;
1002}
1003
1004#ifdef HAVE_RINGS
1005// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
1006//     m2 = LCM(LM(p1), LM(p2))/LM(p2)   in tailRing
1007//    lcm = LCM(LM(p1), LM(p2)           in leadRing
1008KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing,
1009                               poly &m1, poly &m2, poly &lcm, const ring tailRing)
1010{
1011  p_LmCheckPolyRing(p1, leadRing);
1012  p_LmCheckPolyRing(p2, leadRing);
1013
1014  int i;
1015  int x;
1016  int e1;
1017  int e2;
1018  int s;
1019  m1 = p_Init(tailRing);
1020  m2 = p_Init(tailRing);
1021  lcm = p_Init(leadRing);
1022
1023  for (i = leadRing->N; i>=1; i--)
1024  {
1025    e1 = p_GetExp(p1,i,leadRing);
1026    e2 = p_GetExp(p2,i,leadRing);
1027    x = e1 - e2;
1028    if (x > 0)
1029    {
1030      p_SetExp(m2,i,x, tailRing);
1031      //p_SetExp(m1,i,0, tailRing); // done by p_Init
1032      s = e1;
1033    }
1034    else
1035    {
1036      p_SetExp(m1,i,-x, tailRing);
1037      //p_SetExp(m2,i,0, tailRing); // done by p_Init
1038      s = e2;
1039    }
1040    p_SetExp(lcm,i,s, leadRing);
1041  }
1042  if ((s=pGetComp(p1))!=0)
1043  {
1044    p_SetComp(lcm,s, leadRing);
1045  } 
1046  else if ((s=pGetComp(p2))!=0)
1047  {
1048    p_SetComp(lcm,s, leadRing);
1049  } 
1050  // else p_SetComp(lcm,0,tailRing); // done by p_Init
1051
1052  p_Setm(m1, tailRing);
1053  p_Setm(m2, tailRing);
1054  p_Setm(lcm, leadRing);
1055}
1056#endif
1057
1058/***************************************************************
1059 *
1060 * Misc things
1061 *
1062 ***************************************************************/
1063KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red)
1064{
1065  BOOLEAN ret;
1066  number coef;
1067
1068  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
1069  Red->HeadNormalize();
1070  ret = ksReducePoly(Red, PW, NULL, &coef);
1071
1072  if (!ret)
1073  {
1074    if (! n_IsOne(coef, currRing->cf))
1075    {
1076      PR->Mult_nn(coef);
1077      // HANNES: mark for Normalize
1078    }
1079    n_Delete(&coef, currRing->cf);
1080  }
1081  return ret;
1082}
1083
1084/***************************************************************
1085 *
1086 * Routines for backwards-Compatibility
1087 *
1088 *
1089 ***************************************************************/
1090KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
1091{
1092  LObject L(p2);
1093  TObject T(p1);
1094
1095  ksReducePoly(&L, &T, spNoether);
1096
1097  return L.GetLmCurrRing();
1098}
1099
1100KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
1101{
1102  LObject L(p_Copy(p2, currRing));
1103  TObject T(p1);
1104
1105  ksReducePoly(&L, &T, spNoether);
1106
1107  return L.GetLmCurrRing();
1108}
1109
1110KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
1111{
1112  LObject L(r);
1113  L.p1 = p1;
1114  L.p2 = p2;
1115
1116  ksCreateSpoly(&L, spNoether);
1117  return L.GetLmCurrRing();
1118}
1119
1120void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1121{
1122  LObject L(q,  currRing, r);
1123  TObject T(p1, currRing, r);
1124
1125  ksReducePolyTail(&L, &T, q2, spNoether);
1126}
1127
1128KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize)
1129{
1130  LObject L(p, currRing, strat->tailRing);
1131  return redtailBba(&L, pos, strat,FALSE, normalize);
1132}
1133
1134#ifdef HAVE_RINGS
1135KINLINE poly redtailBba_Z (poly p,int pos,kStrategy strat)
1136{
1137  LObject L(p, currRing, strat->tailRing);
1138  return redtailBba_Z(&L, pos, strat);
1139}
1140#endif
1141
1142KINLINE poly redtailBba(TObject *T, int pos,kStrategy strat)
1143{
1144  LObject L;
1145  L = *T;
1146  poly p = redtailBba(&L, pos, strat, FALSE);
1147  *T = L;
1148  //kTest_T(T);
1149  assume( p == T->p);
1150  return p;
1151}
1152
1153KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
1154                    kStrategy strat)
1155{
1156  assume(p_sev == pGetShortExpVector(p));
1157  if (strat->noClearS) return;
1158  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1159  deleteInS((*at),strat);
1160  (*at)--;
1161  (*k)--;
1162}
1163
1164// dummy function for function pointer strat->rewCrit being usable in all
1165// possible choices for criteria
1166KINLINE BOOLEAN arriRewDummy(poly /*sig*/, unsigned long /*not_sevSig*/, kStrategy /*strat*/, int start=0)
1167{
1168  return FALSE;
1169}
1170
1171#endif // defined(KINLINE) || defined(KUTIL_CC)
1172#endif // KINLINE_H
Note: See TracBrowser for help on using the repository browser.