source: git/kernel/kInline.h @ 6ce030f

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