source: git/kernel/GBEngine/kInline.h @ 1eb3ab

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