source: git/kernel/kInline.cc @ 899741

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