source: git/kernel/kInline.cc @ 99bdcf

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