source: git/kernel/kInline.cc @ 1673386

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