source: git/kernel/kInline.cc @ 8099fc

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