source: git/kernel/kInline.h @ c78bded

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