source: git/kernel/kInline.cc @ 3ea5d2f

spielwiese
Last change on this file since 3ea5d2f was 84d8b09, checked in by Hans Schönemann <hannes@…>, 15 years ago
Hannes: syntax git-svn-id: file:///usr/local/Singular/svn/trunk@11481 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.3 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.14 2009-02-26 14:30:23 Singular 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
414//extern void pCleardenom(poly p);
415extern void pNorm(poly p);
416// manipulations
417KINLINE void  sTObject::pCleardenom()
418{
419  assume(p != NULL);
420  #ifdef HAVE_RATGRING
421  p= ::pCleardenom(p);
422  #else
423  ::pCleardenom(p);
424  #endif
425  if (t_p != NULL)
426    pSetCoeff0(t_p, pGetCoeff(p));
427}
428
429KINLINE void  sTObject::pNorm()
430{
431  assume(p != NULL);
432  if (! is_normalized)
433  {
434    ::pNorm(p);
435    if (t_p != NULL)
436      pSetCoeff0(t_p, pGetCoeff(p));
437    is_normalized = TRUE;
438  }
439}
440
441
442
443/***************************************************************
444 *
445 * Operation on LObjects
446 *
447 ***************************************************************/
448// Initialization
449KINLINE void sLObject::Clear()
450{
451  sTObject::Clear();
452  sev = 0;
453}
454// Initialization
455KINLINE void sLObject::Delete()
456{
457  sTObject::Delete();
458  if (bucket != NULL)
459    kBucketDeleteAndDestroy(&bucket);
460}
461
462KINLINE void sLObject::Init(ring r)
463{
464  memset(this, 0, sizeof(sLObject));
465  i_r1 = -1;
466  i_r2 = -1;
467  i_r = -1;
468  Set(r);
469}
470KINLINE sLObject::sLObject(ring r)
471{
472  Init(r);
473}
474KINLINE sLObject::sLObject(poly p_in, ring r)
475{
476  Init(r);
477  Set(p_in, r);
478}
479
480KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r)
481{
482  Init(t_r);
483  Set(p_in, c_r, t_r);
484}
485
486KINLINE void sLObject::PrepareRed(BOOLEAN use_bucket)
487{
488  if (bucket == NULL)
489  {
490    int l = GetpLength();
491    if (use_bucket && l > 1)
492    {
493      poly tp = GetLmTailRing();
494      assume(l == ::pLength(tp));
495      bucket = kBucketCreate(tailRing);
496      kBucketInit(bucket, pNext(tp), l-1);
497      pNext(tp) = NULL;
498      if (p != NULL) pNext(p) = NULL;
499      pLength = 0;
500      last = NULL;
501    }
502  }
503}
504
505KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing, poly _last)
506{
507
508  Set(lm, _tailRing);
509  if (use_bucket)
510  {
511    bucket = kBucketCreate(_tailRing);
512    kBucketInit(bucket, p_tail, p_Length);
513    pNext(lm) = NULL;
514    pLength = 0;
515    last = NULL;
516  }
517  else
518  {
519    pNext(lm) = p_tail;
520    pLength = p_Length + 1;
521    last = _last;
522  }
523
524}
525
526KINLINE void sLObject::Tail_Mult_nn(number n)
527{
528  if (bucket != NULL)
529  {
530    kBucket_Mult_n(bucket, n);
531  }
532  else
533  {
534    poly _p = (t_p != NULL ? t_p : p);
535    assume(_p != NULL);
536    pNext(_p) = tailRing->p_Procs->p_Mult_nn(pNext(_p), n, tailRing);
537  }
538}
539
540KINLINE void sLObject::Tail_Minus_mm_Mult_qq(poly m, poly q, int lq,
541                                             poly spNoether)
542{
543  if (bucket != NULL)
544  {
545    kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether);
546  }
547  else
548  {
549    poly _p = (t_p != NULL ? t_p : p);
550    assume(_p != NULL);
551    int shorter;
552    pNext(_p) = tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q,
553                                                      shorter,spNoether,
554                                                      tailRing, last);
555    pLength += lq - shorter;
556  }
557}
558
559KINLINE void sLObject::LmDeleteAndIter()
560{
561  sTObject::LmDeleteAndIter();
562  if (bucket != NULL)
563  {
564    poly _p = kBucketExtractLm(bucket);
565    if (_p == NULL)
566    {
567      kBucketDestroy(&bucket);
568      p = t_p = NULL;
569      return;
570    }
571    Set(_p, tailRing);
572  }
573  else
574  {
575    pLength--;
576  }
577}
578
579KINLINE poly sLObject::LmExtractAndIter()
580{
581  poly ret = GetLmTailRing();
582  poly pn;
583
584  assume(p != NULL || t_p != NULL);
585
586  if (bucket != NULL)
587  {
588    pn = kBucketExtractLm(bucket);
589    if (pn == NULL)
590      kBucketDestroy(&bucket);
591  }
592  else
593  {
594    pn = pNext(ret);
595  }
596  pLength--;
597  pNext(ret) = NULL;
598  if (p != NULL && t_p != NULL)
599    p_LmFree(p, currRing);
600
601  Set(pn, tailRing);
602  return ret;
603}
604
605KINLINE poly sLObject::CanonicalizeP()
606{
607  //kTest_L(this);
608  int i = -1;
609
610  if (bucket != NULL)
611    i = kBucketCanonicalize(bucket);
612
613  if (p == NULL)
614    p = k_LmInit_tailRing_2_currRing(t_p, tailRing);
615
616  if (i >= 0) pNext(p) = bucket->buckets[i];
617  return p;
618}
619
620KINLINE poly sLObject::GetTP()
621{
622  //kTest_L(this);
623  poly tp = GetLmTailRing();
624  assume(tp != NULL);
625
626  if (bucket != NULL)
627  {
628    kBucketClear(bucket, &pNext(tp), &pLength);
629    kBucketDestroy(&bucket);
630    pLength++;
631  }
632  return tp;
633}
634
635
636KINLINE poly sLObject::GetP(omBin lmBin)
637{
638  //kTest_L(this);
639  if (p == NULL)
640  {
641    p = k_LmInit_tailRing_2_currRing(t_p, tailRing,
642                                     (lmBin!=NULL?lmBin:currRing->PolyBin));
643    FDeg = pFDeg();
644  }
645  else if (lmBin != NULL && lmBin != currRing->PolyBin)
646  {
647    p = p_LmShallowCopyDelete(p, currRing, lmBin);
648    FDeg = pFDeg();
649  }
650
651  if (bucket != NULL)
652  {
653    kBucketClear(bucket, &pNext(p), &pLength);
654    kBucketDestroy(&bucket);
655    pLength++;
656    if (t_p != NULL) pNext(t_p) = pNext(p);
657  }
658  //kTest_L(this);
659  return p;
660}
661
662KINLINE void
663sLObject::ShallowCopyDelete(ring new_tailRing,
664                            pShallowCopyDeleteProc p_shallow_copy_delete)
665{
666  if (bucket != NULL)
667    kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
668                             p_shallow_copy_delete);
669  sTObject::ShallowCopyDelete(new_tailRing,
670                              new_tailRing->PolyBin,p_shallow_copy_delete,
671                              FALSE);
672  last = NULL;
673}
674
675KINLINE void sLObject::SetShortExpVector()
676{
677  if (t_p != NULL)
678  {
679    sev = p_GetShortExpVector(t_p, tailRing);
680  }
681  else
682  {
683    sev = p_GetShortExpVector(p, currRing);
684  }
685}
686
687KINLINE void sLObject::Copy()
688{
689  if (bucket != NULL)
690  {
691    int i = kBucketCanonicalize(bucket);
692    kBucket_pt new_bucket = kBucketCreate(tailRing);
693    kBucketInit(new_bucket,
694                p_Copy(bucket->buckets[i], tailRing),
695                bucket->buckets_length[i]);
696    bucket = new_bucket;
697    if (t_p != NULL) pNext(t_p) = NULL;
698    if (p != NULL) pNext(p) = NULL;
699  }
700  TObject::Copy();
701  last = NULL;
702}
703
704KINLINE poly sLObject::CopyGetP()
705{
706  last = NULL;
707  if (bucket != NULL)
708  {
709    int i = kBucketCanonicalize(bucket);
710    poly bp = p_Copy(bucket->buckets[i], tailRing);
711    pLength = bucket->buckets_length[i] + 1;
712    if (bp != NULL)
713    {
714      assume(t_p != NULL || p != NULL);
715      if (t_p != NULL) pNext(t_p) = bp;
716      else pNext(p) = bp;
717    }
718    bucket = NULL;
719  }
720  return sLObject::GetP();
721}
722
723
724KINLINE long sLObject::pLDeg()
725{
726  poly tp = GetLmTailRing();
727  assume(tp != NULL);
728  if (bucket != NULL)
729  {
730    int i = kBucketCanonicalize(bucket);
731    pNext(tp) = bucket->buckets[i];
732    long ldeg = tailRing->pLDeg(tp, &length, tailRing);
733    pNext(tp) = NULL;
734    return ldeg;
735  }
736  else
737    return tailRing->pLDeg(tp, &length, tailRing);
738}
739KINLINE long sLObject::pLDeg(BOOLEAN deg_last)
740{
741  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
742
743  if (last == NULL || pLength == 0)
744    last = pLast(GetLmTailRing(), pLength);
745#ifdef HAVE_ASSUME
746  long fdeg;
747  fdeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
748  assume (pLength == length && fdeg == tailRing->pFDeg(last, tailRing));
749  return fdeg;
750#else
751  length = pLength;
752  return tailRing->pFDeg(last, tailRing);
753#endif
754}
755
756KINLINE long sLObject::SetDegStuffReturnLDeg()
757{
758  FDeg = this->pFDeg();
759  long d = this->pLDeg();
760  ecart = d - FDeg;
761  return d;
762}
763KINLINE long sLObject::SetDegStuffReturnLDeg(BOOLEAN use_last)
764{
765  FDeg = this->pFDeg();
766  long d = this->pLDeg(use_last);
767  ecart = d - FDeg;
768  return d;
769}
770KINLINE int sLObject::GetpLength()
771{
772  if (bucket == NULL)
773    return sTObject::GetpLength();
774  int i = kBucketCanonicalize(bucket);
775  return bucket->buckets_length[i] + 1;
776}
777KINLINE int sLObject::SetLength(BOOLEAN length_pLength)
778{
779  if (length_pLength)
780  {
781    length = this->GetpLength();
782  }
783  else
784    this->pLDeg();
785  return length;
786}
787KINLINE long sLObject::MinComp()
788{
789  poly tp = GetLmTailRing();
790  assume(tp != NULL);
791  if (bucket != NULL)
792  {
793    int i = kBucketCanonicalize(bucket);
794    pNext(tp) = bucket->buckets[i];
795    long m = p_MinComp(tp, tailRing);
796    pNext(tp) = NULL;
797    return m;
798  }
799  else
800    return p_MinComp(tp, tailRing);
801}
802KINLINE long sLObject::Comp()
803{
804  poly pp;
805  ring r;
806  GetLm(pp, r);
807  assume(pp != NULL);
808  return p_GetComp(pp, r);
809}
810
811KINLINE sLObject& sLObject::operator=(const sTObject& t)
812{
813  memset(this, 0, sizeof(*this));
814  memcpy(this, &t, sizeof(sTObject));
815  return *this;
816}
817
818KINLINE TObject* sLObject::T_1(const skStrategy* s)
819{
820  if (p1 == NULL) return NULL;
821  if (i_r1 == -1) i_r1 = kFindInT(p1, s->T, s->tl);
822  assume(i_r1 >= 0 && i_r1 <= s->tl);
823  TObject* T = s->R[i_r1];
824  assume(T->p == p1);
825  return T;
826}
827
828KINLINE TObject* sLObject::T_2(const skStrategy* strat)
829{
830  if (p1 == NULL) return NULL;
831  assume(p2 != NULL);
832  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
833  assume(i_r2 >= 0 && i_r2 <= strat->tl);
834  TObject* T = strat->R[i_r2];
835  assume(T->p == p2);
836  return T;
837}
838
839KINLINE void    sLObject::T_1_2(const skStrategy* strat,
840                                TObject* &T_1, TObject* &T_2)
841{
842  if (p1 == NULL)
843  {
844    T_1 = NULL;
845    T_2 = NULL;
846    return;
847  }
848  assume(p1 != NULL && p2 != NULL);
849  if (i_r1 == -1) i_r1 = kFindInT(p1, strat->T, strat->tl);
850  if (i_r2 == -1) i_r2 = kFindInT(p2, strat->T, strat->tl);
851  assume(i_r1 >= 0 && i_r1 <= strat->tl);
852  assume(i_r2 >= 0 && i_r2 <= strat->tl);
853  T_1 = strat->R[i_r1];
854  T_2 = strat->R[i_r2];
855  assume(T_1->p == p1);
856  assume(T_2->p == p2);
857  return;
858}
859
860/***************************************************************
861 *
862 * Conversion of polys
863 *
864 ***************************************************************/
865
866KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
867{
868
869  poly np = p_LmInit(p, currRing, tailRing, tailBin);
870  pNext(np) = pNext(p);
871  pSetCoeff0(np, pGetCoeff(p));
872  return np;
873}
874
875KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
876{
877  poly np = p_LmInit(p, tailRing, currRing, lmBin);
878  pNext(np) = pNext(p);
879  pSetCoeff0(np, pGetCoeff(p));
880  return np;
881}
882
883// this should be made more efficient
884KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
885{
886  poly np = k_LmInit_currRing_2_tailRing(p, tailRing, tailBin);
887  p_LmFree(p, currRing);
888  return np;
889}
890
891KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
892{
893  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
894  p_LmFree(p, tailRing);
895  return np;
896}
897
898KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
899{
900  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
901}
902
903KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
904{
905  return  k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
906}
907
908KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing)
909{
910  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
911}
912
913KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing)
914{
915  return  k_LmShallowCopyDelete_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
916}
917
918/***************************************************************
919 *
920 * Lcm business
921 *
922 ***************************************************************/
923// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
924//     m2 = LCM(LM(p1), LM(p2))/LM(p2)
925KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r,
926                               poly &m1, poly &m2, const ring m_r)
927{
928  p_LmCheckPolyRing(p1, p_r);
929  p_LmCheckPolyRing(p2, p_r);
930
931  int i;
932  Exponent_t x;
933  m1 = p_Init(m_r);
934  m2 = p_Init(m_r);
935
936  for (i = p_r->N; i; i--)
937  {
938    x = p_GetExpDiff(p1, p2, i, p_r);
939    if (x > 0)
940    {
941      if (x > (long) m_r->bitmask) goto false_return;
942      p_SetExp(m2,i,x, m_r);
943      p_SetExp(m1,i,0, m_r);
944    }
945    else
946    {
947      if (-x > (long) m_r->bitmask) goto false_return;
948      p_SetExp(m1,i,-x, m_r);
949      p_SetExp(m2,i,0, m_r);
950    }
951  }
952
953  p_Setm(m1, m_r);
954  p_Setm(m2, m_r);
955  return TRUE;
956
957  false_return:
958  p_LmFree(m1, m_r);
959  p_LmFree(m2, m_r);
960  m1 = m2 = NULL;
961  return FALSE;
962}
963
964#ifdef HAVE_RINGS
965// get m1 = LCM(LM(p1), LM(p2))/LM(p1)
966//     m2 = LCM(LM(p1), LM(p2))/LM(p2)   in tailRing
967//    lcm = LCM(LM(p1), LM(p2)           in leadRing
968KINLINE BOOLEAN k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing,
969                               poly &m1, poly &m2, poly &lcm, const ring tailRing)
970{
971  p_LmCheckPolyRing(p1, leadRing);
972  p_LmCheckPolyRing(p2, leadRing);
973
974  int i;
975  Exponent_t x;
976  Exponent_t e1;
977  Exponent_t e2;
978  Exponent_t s;
979  m1 = p_Init(tailRing);
980  m2 = p_Init(tailRing);
981  lcm = p_Init(leadRing);
982
983  int small_index=1;
984  if ((pGetComp(p1)!=0)||(pGetComp(p2)!=0)) small_index=0;
985
986  for (i = leadRing->N; i>=small_index; i--)
987  {
988    e1 = p_GetExp(p1,i,leadRing);
989    e2 = p_GetExp(p2,i,leadRing);
990    x = e1 - e2;
991    if (x > 0)
992    {
993      p_SetExp(m2,i,x, tailRing);
994      p_SetExp(m1,i,0, tailRing);
995      s = e1;
996    }
997    else
998    {
999      p_SetExp(m1,i,-x, tailRing);
1000      p_SetExp(m2,i,0, tailRing);
1001      s = e2;
1002    }
1003    p_SetExp(lcm,i,s, leadRing);
1004  }
1005
1006  p_Setm(m1, tailRing);
1007  p_Setm(m2, tailRing);
1008  p_Setm(lcm, leadRing);
1009}
1010#endif
1011
1012/***************************************************************
1013 *
1014 * Misc things
1015 *
1016 ***************************************************************/
1017KINLINE int ksReducePolyTail(LObject* PR, TObject* PW, LObject* Red)
1018{
1019  BOOLEAN ret;
1020  number coef;
1021
1022  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
1023  Red->HeadNormalize();
1024  ret = ksReducePoly(Red, PW, NULL, &coef);
1025
1026  if (!ret)
1027  {
1028    if (! n_IsOne(coef, currRing))
1029    {
1030      PR->Mult_nn(coef);
1031      // HANNES: mark for Normalize
1032    }
1033    n_Delete(&coef, currRing);
1034  }
1035  return ret;
1036}
1037
1038/***************************************************************
1039 *
1040 * Routines for backwards-Compatibility
1041 *
1042 *
1043 ***************************************************************/
1044KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
1045{
1046  LObject L(p2);
1047  TObject T(p1);
1048
1049  ksReducePoly(&L, &T, spNoether);
1050
1051  return L.GetLmCurrRing();
1052}
1053
1054KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
1055{
1056  LObject L(p_Copy(p2, currRing));
1057  TObject T(p1);
1058
1059  ksReducePoly(&L, &T, spNoether);
1060
1061  return L.GetLmCurrRing();
1062}
1063
1064KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
1065{
1066  LObject L(r);
1067  L.p1 = p1;
1068  L.p2 = p2;
1069
1070  ksCreateSpoly(&L, spNoether);
1071  return L.GetLmCurrRing();
1072}
1073
1074void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1075{
1076  LObject L(q,  currRing, r);
1077  TObject T(p1, currRing, r);
1078
1079  ksReducePolyTail(&L, &T, q2, spNoether);
1080}
1081
1082KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize)
1083{
1084  LObject L(p, currRing, strat->tailRing);
1085  return redtailBba(&L, pos, strat,FALSE, normalize);
1086}
1087
1088KINLINE poly redtailBba(TObject *T, int pos,kStrategy strat)
1089{
1090  LObject L;
1091  L = *T;
1092  poly p = redtailBba(&L, pos, strat, FALSE);
1093  *T = L;
1094  //kTest_T(T);
1095  assume( p == T->p);
1096  return p;
1097}
1098
1099KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
1100                    kStrategy strat)
1101{
1102  assume(p_sev == pGetShortExpVector(p));
1103  if (strat->noClearS) return;
1104  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1105  deleteInS((*at),strat);
1106  (*at)--;
1107  (*k)--;
1108}
1109
1110#endif // defined(KINLINE) || defined(KUTIL_CC)
1111#endif // KINLINE_CC
Note: See TracBrowser for help on using the repository browser.