My Project  UNKNOWN_GIT_VERSION
kInline.h
Go to the documentation of this file.
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 
24 #include "polys/kbuckets.h"
25 
26 #include "kernel/polys.h"
27 
28 
29 #define HAVE_TAIL_BIN
30 // This doesn't really work, fixme, if necessary
31 // #define HAVE_LM_BIN
32 
33 
34 
36 {
37  assume(i>= 0 && i<=sl);
38  assume(S_2_R[i] >= 0 && S_2_R[i] <= tl);
39  TObject* TT = R[S_2_R[i]];
40  assume(TT != NULL && TT->p == S[i]);
41  return TT;
42 }
43 
45 {
46  if (i >= 0 && i <= sl)
47  {
48  int sri= S_2_R[i];
49  if ((sri >= 0) && (sri <= tl))
50  {
51  TObject* t = R[sri];
52  if ((t != NULL) && (t->p == S[i]))
53  return t;
54  }
55  // last but not least, try kFindInT
56  sri = kFindInT(S[i], T, tl);
57  if (sri >= 0)
58  return &(T[sri]);
59  }
60  return NULL;
61 }
62 
64 {
65  if (tailRing == currRing)
66  return kNoether;
67  else
68  {
69  assume((kNoether == NULL && t_kNoether == NULL) ||
70  (kNoether != NULL && t_kNoether != NULL));
71  return t_kNoether;
72  }
73 }
74 
75 /***************************************************************
76  *
77  * Operation on TObjects
78  *
79  ***************************************************************/
80 
82 {
83  TSet T = (TSet)omAlloc0(setmaxT*sizeof(TObject));
84  for (int i=setmaxT-1; i>=0; i--)
85  {
86  T[i].tailRing = currRing;
87  T[i].i_r = -1;
88  }
89  return T;
90 }
91 
93 {
94  return (TObject**) omAlloc0(setmaxT*sizeof(TObject*));
95 }
96 
97 KINLINE unsigned long* initsevT()
98 {
99  return (unsigned long*) omAlloc0(setmaxT*sizeof(unsigned long));
100 }
101 
102 // initialization
103 KINLINE void sTObject::Set(ring r)
104 {
105  tailRing = r;
106 }
108 {
109  memset(this, 0, sizeof(sTObject));
110  i_r = -1;
111  Set(r);
112 }
114 {
115  Init(r);
116 }
117 KINLINE void sTObject::Set(poly p_in, ring r)
118 {
119  if (r != currRing)
120  {
121  assume(r == tailRing);
122  p_Test(p_in, r);
123  t_p = p_in;
124  }
125  else
126  {
127  p_Test(p_in, currRing);
128  p = p_in;
129  }
130  pLength=::pLength(p_in);
131 }
132 
133 KINLINE sTObject::sTObject(poly p_in, ring r)
134 {
135  Init(r);
136  Set(p_in, r);
137 }
138 
139 KINLINE 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  p_Test(p_in, currRing);
145  p = p_in;
146  pLength=::pLength(p_in);
147  }
148  else
149  {
150  Set(p_in, c_r);
151  }
152 }
153 
154 KINLINE sTObject::sTObject(poly p_in, ring c_r, ring t_r)
155 {
156  Init(t_r);
157  Set(p_in, c_r, t_r);
158 }
159 
161 {
162  *this = *T;
163  if (copy)
164  {
165  if (t_p != NULL)
166  {
167  t_p = p_Copy(t_p, tailRing);
169  }
170  else
171  {
172  p = p_Copy(p, currRing);
173  }
174  }
175 }
176 
178 {
179  if (t_p != NULL)
180  {
181  p_Delete(&t_p, tailRing);
182  if (p != NULL)
183  p_LmFree(p, currRing);
184  }
185  else
186  {
187  p_Delete(&p, currRing);
188  }
189 }
190 
192 {
193  p = NULL;
194  t_p = NULL;
195  ecart = 0;
196  length = 0;
197  pLength = 0;
198  FDeg = 0;
200 }
201 
203 {
204  if (t_p != NULL)
205  {
206  t_p = p_Copy(t_p, tailRing);
207  if (p != NULL) /* and t_p!=NULL*/
208  {
209  p = p_LmInit(p, currRing);
211  pNext(p) = pNext(t_p);
212  }
213  }
214  else
215  {
216  p = p_Copy(p, currRing);
217  }
218 }
219 
221 {
222  if (p == NULL && t_p != NULL)
224 
225  return p;
226 }
228 {
229  if (t_p == NULL)
230  {
231  if (p != NULL && tailRing != currRing)
232  {
234  return t_p;
235  }
236  return p;
237  }
238  return t_p;
239 }
241 {
242  assume(r == tailRing || r == currRing);
243  if (r == currRing)
244  return GetLmCurrRing();
245 
246  if (t_p == NULL && p != NULL)
248 
249  return t_p;
250 }
251 
252 KINLINE void sTObject::GetLm(poly &p_r, ring &r_r) const
253 {
254  if (t_p != NULL)
255  {
256  p_r = t_p;
257  r_r = tailRing;
258  }
259  else
260  {
261  p_r = p;
262  r_r = currRing;
263  }
264 }
265 
267 {
268  return (p == NULL && t_p == NULL);
269 }
270 
272 {
273  if (pLength <= 0) pLength = ::pLength(p != NULL ? p : t_p);
274  return pLength;
275 }
276 
278 {
279  if (p == NULL && t_p != NULL)
281 }
282 
284 {
285  assume(p != NULL || t_p != NULL);
286  if (t_p != NULL) return pNext(t_p);
287  return pNext(p);
288 }
289 
290 // Iterations
292 {
293  assume(p != NULL || t_p != NULL);
294  if (t_p != NULL)
295  {
297  if (p != NULL)
298  {
299  p_LmFree(p, currRing);
300  p = NULL;
301  }
302  }
303  else
304  {
306  }
308 }
309 
310 
311 // arithmetic
313 {
314  if (t_p != NULL)
315  {
316  t_p = p_Mult_nn(t_p, n, tailRing);
317  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
318  }
319  else
320  {
321  p = p_Mult_nn(p, n, currRing, tailRing);
322  }
323 }
324 
326 {
327  if (t_p != NULL)
328  {
329  pNormalize(t_p);
330  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
331  }
332  else
333  {
334  pNormalize(p);
335  }
337 }
338 
340 {
341  if (bucket != NULL)
343 }
344 
346 {
347  if (t_p != NULL)
348  {
350  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
351  }
352  else
353  {
355  }
356 }
357 
358 KINLINE void
359 sTObject::ShallowCopyDelete(ring new_tailRing, omBin new_tailBin,
360  pShallowCopyDeleteProc p_shallow_copy_delete,
361  BOOLEAN set_max)
362 {
363  if (new_tailBin == NULL) new_tailBin = new_tailRing->PolyBin;
364  if (t_p != NULL)
365  {
366  t_p = p_shallow_copy_delete(t_p, tailRing, new_tailRing, new_tailBin);
367  if (p != NULL)
368  pNext(p) = pNext(t_p);
369  if (new_tailRing == currRing)
370  {
371  if (p == NULL) p = t_p;
372  else p_LmFree(t_p, tailRing);
373  t_p = NULL;
374  }
375  }
376  else if (p != NULL) /* && t_p==NULL */
377  {
378  if (pNext(p) != NULL)
379  {
380  pNext(p) = p_shallow_copy_delete(pNext(p),
381  tailRing, new_tailRing, new_tailBin);
382  }
383  if (new_tailRing != currRing)
384  {
385  t_p = k_LmInit_currRing_2_tailRing(p, new_tailRing);
386  pNext(t_p) = pNext(p);
387  }
388  }
389  if (max_exp != NULL)
390  {
391  max_exp = p_shallow_copy_delete(max_exp,tailRing,new_tailRing,new_tailBin);
392  }
393  else if (set_max && pNext(t_p) != NULL)
394  {
395  max_exp = p_GetMaxExpP(pNext(t_p), new_tailRing);
396  }
397  tailRing = new_tailRing;
398 }
399 
401 {
402  if (p != NULL) return p_FDeg(p, currRing);
403  return tailRing->pFDeg(t_p, tailRing);
404 }
406 {
407  if (p != NULL) return p_Totaldegree(p, currRing);
408  return p_Totaldegree(t_p,tailRing);
409 }
411 {
412  FDeg = this->pFDeg();
413  return FDeg;
414 }
416 {
417  assume(FDeg == this->pFDeg());
418  return FDeg;
419 }
421 {
422  return tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
423 }
425 {
426  FDeg = this->pFDeg();
427  long d = this->pLDeg();
428  ecart = d - FDeg;
429  return d;
430 }
431 
432 //extern void pCleardenom(poly p);
433 // extern void pNorm(poly p);
434 
435 // manipulations
437 {
438  assume(p != NULL);
439  if (TEST_OPT_CONTENTSB)
440  {
441  number n;
442  if (t_p != NULL)
443  {
446  }
447  else
448  {
450  }
451  if (!nIsOne(n))
452  {
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  {
466  }
467  else
468  {
470  }
471  }
472 }
473 
474 KINLINE void sTObject::pNorm() // pNorm seems to be a _bad_ method name...
475 {
476  assume(p != NULL);
477  if (! is_normalized)
478  {
479  p_Norm(p, currRing);
480  if (t_p != NULL)
483  }
484 }
485 
486 
487 
488 /***************************************************************
489  *
490  * Operation on LObjects
491  *
492  ***************************************************************/
493 // Initialization
495 {
496  sTObject::Clear();
497  sev = 0;
498 }
499 // Initialization
501 {
503  if (bucket != NULL)
505 }
506 
508 {
509  memset(this, 0, sizeof(sLObject));
510  i_r1 = -1;
511  i_r2 = -1;
512  i_r = -1;
513  Set(r);
514 }
516 {
517  Init(r);
518 }
519 KINLINE sLObject::sLObject(poly p_in, ring r)
520 {
521  Init(r);
522  Set(p_in, r);
523 }
524 
525 KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r)
526 {
527  Init(t_r);
528  Set(p_in, c_r, t_r);
529 }
530 
532 {
533  if (bucket == NULL)
534  {
535  unsigned l = GetpLength();
536  if (use_bucket && (l > 1))
537  {
538  poly tp = GetLmTailRing();
539  assume(l == ::pLength(tp));
541  kBucketInit(bucket, pNext(tp), l-1);
542  pNext(tp) = NULL;
543  if (p != NULL) pNext(p) = NULL;
544  pLength = 0;
545  }
546  }
547 }
548 
549 KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing)
550 {
551 
552  Set(lm, _tailRing);
553  if (use_bucket)
554  {
555  bucket = kBucketCreate(_tailRing);
556  kBucketInit(bucket, p_tail, p_Length);
557  pNext(lm) = NULL;
558  pLength = 0;
559  }
560  else
561  {
562  pNext(lm) = p_tail;
563  pLength = p_Length + 1;
564  }
565 }
566 
568 {
569  if (bucket != NULL)
570  {
572  }
573  else
574  {
575  poly _p = (t_p != NULL ? t_p : p);
576  assume(_p != NULL);
577  pNext(_p) = __p_Mult_nn(pNext(_p), n, tailRing);
578  }
579 }
580 
582  poly spNoether)
583 {
584  if (bucket != NULL)
585  {
586  kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether);
587  }
588  else
589  {
590  if (lq<=0) lq= ::pLength(q);
591  poly _p = (t_p != NULL ? t_p : p);
592  assume(_p != NULL);
593 
594  int lp=pLength-1;
595  pNext(_p) = p_Minus_mm_Mult_qq( pNext(_p), m, q, lp, lq,
596  spNoether, tailRing );
597  pLength=lp+1;
598 // tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, shorter,spNoether, tailRing, last);
599 // pLength += lq - shorter;
600  }
601 }
602 
604 {
606  if (bucket != NULL)
607  {
608  poly _p = kBucketExtractLm(bucket);
609  if (_p == NULL)
610  {
612  p = t_p = NULL;
613  return;
614  }
615  Set(_p, tailRing);
616  }
617  else
618  {
619  pLength--;
620  }
621 }
622 
624 {
625  poly ret = GetLmTailRing();
626  poly pn;
627 
628  assume(p != NULL || t_p != NULL);
629 
630  if (bucket != NULL)
631  {
632  pn = kBucketExtractLm(bucket);
633  if (pn == NULL)
635  }
636  else
637  {
638  pn = pNext(ret);
639  }
640  pLength--;
641  pNext(ret) = NULL;
642  if (p != NULL && t_p != NULL)
643  p_LmFree(p, currRing);
644 
645  Set(pn, tailRing);
646  return ret;
647 }
648 
650 {
651  //kTest_L(this);
652  poly tp = GetLmTailRing();
653  assume(tp != NULL);
654 
655  if (bucket != NULL)
656  {
657  kBucketClear(bucket, &pNext(tp), &pLength);
659  pLength++;
660  }
661  return tp;
662 }
663 
664 
666 {
667  //kTest_L(this);
668  if (p == NULL)
669  {
671  (lmBin!=NULL?lmBin:currRing->PolyBin));
672  FDeg = pFDeg();
673  }
674  else if (lmBin != NULL && lmBin != currRing->PolyBin)
675  {
677  FDeg = pFDeg();
678  }
679 
680  if (bucket != NULL)
681  {
684  pLength++;
685  if (t_p != NULL) pNext(t_p) = pNext(p);
686  }
687  //kTest_L(this);
688  return p;
689 }
690 
691 KINLINE void
692 sLObject::ShallowCopyDelete(ring new_tailRing,
693  pShallowCopyDeleteProc p_shallow_copy_delete)
694 {
695  if (bucket != NULL)
696  kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
697  p_shallow_copy_delete);
698  sTObject::ShallowCopyDelete(new_tailRing,
699  new_tailRing->PolyBin,p_shallow_copy_delete,
700  FALSE);
701 }
702 
704 {
705  if (t_p != NULL)
706  {
708  }
709  else
710  {
712  }
713 }
714 
716 {
717  if (bucket != NULL)
718  {
720  kBucket_pt new_bucket = kBucketCreate(tailRing);
721  kBucketInit(new_bucket,
722  p_Copy(bucket->buckets[i], tailRing),
723  bucket->buckets_length[i]);
724  bucket = new_bucket;
725  if (t_p != NULL) pNext(t_p) = NULL;
726  if (p != NULL) pNext(p) = NULL;
727  }
728  TObject::Copy();
729 }
730 
732 {
733  poly tp = GetLmTailRing();
734  assume(tp != NULL);
735  if (bucket != NULL)
736  {
738  pNext(tp) = bucket->buckets[i];
739  long ldeg = tailRing->pLDeg(tp, &length, tailRing);
740  pNext(tp) = NULL;
741  return ldeg;
742  }
743  else
744  return tailRing->pLDeg(tp, &length, tailRing);
745 }
747 {
748  if (! deg_last || bucket != NULL) return sLObject::pLDeg();
749 
750  long ldeg;
751  ldeg = tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
752 #ifndef SING_NDEBUG
753  if ( pLength == 0)
756 #else
757  pLength=length;
758 #endif
759  return ldeg;
760 }
761 
763 {
764  FDeg = this->pFDeg();
765  long d = this->pLDeg();
766  ecart = d - FDeg;
767  return d;
768 }
770 {
771  FDeg = this->pFDeg();
772  long d = this->pLDeg(use_last);
773  ecart = d - FDeg;
774  return d;
775 }
777 {
778  if (bucket == NULL)
779  return sTObject::GetpLength();
781  return bucket->buckets_length[i] + 1;
782 }
784 {
785  if (length_pLength)
786  {
787  length = this->GetpLength();
788  }
789  else
790  this->pLDeg();
791  return length;
792 }
794 {
795  poly tp = GetLmTailRing();
796  assume(tp != NULL);
797  if (bucket != NULL)
798  {
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 }
809 {
810  poly pp;
811  ring r;
812  GetLm(pp, r);
813  assume(pp != NULL);
814  return p_GetComp(pp, r);
815 }
816 
818 {
819  memset(this, 0, sizeof(*this));
820  memcpy(this, &t, sizeof(sTObject));
821  return *this;
822 }
823 
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 
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 
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 
872 KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
873 {
874 
875  poly t_p = p_LmInit(p, currRing, tailRing, tailBin);
876  pNext(t_p) = pNext(p);
877  pSetCoeff0(t_p, pGetCoeff(p));
878  return t_p;
879 }
880 
881 KINLINE poly k_LmInit_tailRing_2_currRing(poly t_p, ring tailRing, omBin lmBin)
882 {
883  poly p = p_LmInit(t_p, tailRing, currRing, lmBin);
884  pNext(p) = pNext(t_p);
885  pSetCoeff0(p, pGetCoeff(t_p));
886  return p;
887 }
888 
889 // this should be made more efficient
890 KINLINE 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 
898 {
899  poly np = k_LmInit_tailRing_2_currRing(p, tailRing, lmBin);
900  p_LmFree(p, tailRing);
901  return np;
902 }
903 
904 KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing)
905 {
906  return k_LmInit_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
907 }
908 
909 KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing)
910 {
911  return k_LmInit_tailRing_2_currRing(p, tailRing, currRing->PolyBin);
912 }
913 
915 {
916  return k_LmShallowCopyDelete_currRing_2_tailRing(p, tailRing, tailRing->PolyBin);
917 }
918 
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)
931 KINLINE 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  long x;
939  m1 = p_Init(m_r,m_r->PolyBin);
940  m2 = p_Init(m_r,m_r->PolyBin);
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
974 KINLINE 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  int x;
982  int e1;
983  int e2;
984  int s;
985  m1 = p_Init(tailRing,tailRing->PolyBin);
986  m2 = p_Init(tailRing,tailRing->PolyBin);
987  lcm = p_Init(leadRing,leadRing->PolyBin);
988 
989  for (i = leadRing->N; i>=0; i--)
990  {
991  e1 = p_GetExp(p1,i,leadRing);
992  e2 = p_GetExp(p2,i,leadRing);
993  x = e1 - e2;
994  if (x > 0)
995  {
996  p_SetExp(m2,i,x, tailRing);
997  //p_SetExp(m1,i,0, tailRing); // done by p_Init
998  s = e1;
999  }
1000  else if (x<0)
1001  {
1002  p_SetExp(m1,i,-x, tailRing);
1003  //p_SetExp(m2,i,0, tailRing); // done by p_Init
1004  s = e2;
1005  }
1006  else
1007  s = e1; // e1==e2
1008  p_SetExp(lcm,i,s, leadRing);
1009  }
1010 
1011  p_Setm(m1, tailRing);
1012  p_Setm(m2, tailRing);
1013  p_Setm(lcm, leadRing);
1014 }
1015 #endif
1016 
1017 /***************************************************************
1018  *
1019  * Misc things
1020  *
1021  ***************************************************************/
1023 {
1024  BOOLEAN ret;
1025  number coef;
1026 
1027  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
1028  Red->HeadNormalize();
1029  ret = ksReducePoly(Red, PW, NULL, &coef);
1030 
1031  if (!ret)
1032  {
1033  if (! n_IsOne(coef, currRing->cf))
1034  {
1035  PR->Mult_nn(coef);
1036  // HANNES: mark for Normalize
1037  }
1038  n_Delete(&coef, currRing->cf);
1039  }
1040  return ret;
1041 }
1042 
1043 /***************************************************************
1044  *
1045  * Routines for backwards-Compatibility
1046  *
1047  *
1048  ***************************************************************/
1049 KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
1050 {
1051  LObject L(p2);
1052  TObject T(p1);
1053 
1054  ksReducePoly(&L, &T, spNoether);
1055 
1056  return L.GetLmCurrRing();
1057 }
1058 
1059 KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
1060 {
1061  LObject L(p_Copy(p2, currRing));
1062  TObject T(p1);
1063 
1064  ksReducePoly(&L, &T, spNoether);
1065 
1066  return L.GetLmCurrRing();
1067 }
1068 
1069 KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
1070 {
1071  LObject L(r);
1072  L.p1 = p1;
1073  L.p2 = p2;
1074 
1075  ksCreateSpoly(&L, spNoether);
1076  return L.GetLmCurrRing();
1077 }
1078 
1079 void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1080 {
1081  LObject L(q, currRing, r);
1082  TObject T(p1, currRing, r);
1083 
1084  ksReducePolyTail(&L, &T, q2, spNoether);
1085 }
1086 
1087 KINLINE poly redtailBba (poly p,int pos,kStrategy strat,BOOLEAN normalize)
1088 {
1089  LObject L(p);
1090  return redtailBba(&L, pos, strat,FALSE, normalize);
1091 }
1092 
1094 {
1095  LObject L(p, currRing, strat->tailRing); // ? L(p); ??
1096  return redtailBbaBound(&L, pos, strat,bound, FALSE, normalize);
1097 }
1098 
1099 #ifdef HAVE_RINGS
1100 KINLINE poly redtailBba_Z (poly p,int pos,kStrategy strat)
1101 {
1102  LObject L(p, currRing, strat->tailRing);
1103  return redtailBba_Z(&L, pos, strat);
1104 }
1105 #endif
1106 
1107 KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
1108  kStrategy strat)
1109 {
1110  assume(p_sev == pGetShortExpVector(p));
1111  if (strat->noClearS) return;
1112  #ifdef HAVE_RINGS
1114  {
1115  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at]))
1116  return;
1117  if(!n_DivBy(pGetCoeff(strat->S[*at]), pGetCoeff(p), currRing->cf))
1118  return;
1119  }
1120  else
1121  #endif
1122  {
1123  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1124  }
1125  deleteInS((*at),strat);
1126  (*at)--;
1127  (*k)--;
1128 }
1129 
1130 // dummy function for function pointer strat->rewCrit being usable in all
1131 // possible choices for criteria
1132 KINLINE BOOLEAN arriRewDummy(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy /*strat*/, int /*start=0*/)
1133 {
1134  return FALSE;
1135 }
1136 
1137 #endif // defined(KINLINE) || defined(KUTIL_CC)
1138 #endif // KINLINE_H
int BOOLEAN
Definition: auxiliary.h:85
#define TRUE
Definition: auxiliary.h:98
#define FALSE
Definition: auxiliary.h:94
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
int l
Definition: cfEzgcd.cc:93
int m
Definition: cfEzgcd.cc:121
int i
Definition: cfEzgcd.cc:125
int k
Definition: cfEzgcd.cc:92
Variable x
Definition: cfModGcd.cc:4023
int p
Definition: cfModGcd.cc:4019
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
KINLINE long SetDegStuffReturnLDeg()
Definition: kInline.h:762
KINLINE void Tail_Mult_nn(number n)
Definition: kInline.h:567
int i_r1
Definition: kutil.h:183
KINLINE void Copy()
Definition: kInline.h:715
KINLINE void Delete()
Definition: kInline.h:500
KINLINE void LmDeleteAndIter()
Definition: kInline.h:603
KINLINE TObject * T_2(const skStrategy *strat)
Definition: kInline.h:834
KINLINE void PrepareRed(BOOLEAN use_bucket)
Definition: kInline.h:531
KINLINE void CanonicalizeP()
Definition: kInline.h:339
KINLINE void SetLmTail(poly lm, poly new_p, int length, int use_bucket, ring r)
Definition: kInline.h:549
KINLINE void T_1_2(const skStrategy *strat, TObject *&T_1, TObject *&T_2)
Definition: kInline.h:845
KINLINE void Normalize()
Definition: kInline.h:325
unsigned long sev
Definition: kutil.h:177
KINLINE void Init(ring tailRing=currRing)
Definition: kInline.h:507
KINLINE long MinComp()
Definition: kInline.h:793
kBucket_pt bucket
Definition: kutil.h:182
poly p2
Definition: kutil.h:178
KINLINE TObject * T_1(const skStrategy *strat)
Definition: kInline.h:824
KINLINE int GetpLength()
Definition: kInline.h:776
KINLINE int SetLength(BOOLEAN lengt_pLength=FALSE)
Definition: kInline.h:783
KINLINE void Clear()
Definition: kInline.h:494
KINLINE void Tail_Minus_mm_Mult_qq(poly m, poly qq, int lq, poly spNoether)
Definition: kInline.h:581
KINLINE void ShallowCopyDelete(ring new_tailRing, pShallowCopyDeleteProc p_shallow_copy_delete)
Definition: kInline.h:692
KINLINE poly GetTP()
Definition: kInline.h:649
KINLINE long pLDeg()
Definition: kInline.h:731
KINLINE sLObject & operator=(const sTObject &)
Definition: kInline.h:817
KINLINE void SetShortExpVector()
Definition: kInline.h:703
KINLINE void HeadNormalize()
Definition: kInline.h:345
KINLINE poly GetP(omBin lmBin=(omBin) NULL)
Definition: kInline.h:665
KINLINE sLObject(ring tailRing=currRing)
Definition: kInline.h:515
poly p1
Definition: kutil.h:178
KINLINE long Comp()
Definition: kInline.h:808
KINLINE poly LmExtractAndIter()
Definition: kInline.h:623
int i_r2
Definition: kutil.h:183
Definition: kutil.h:65
KINLINE poly GetLm(ring r)
Definition: kInline.h:240
KINLINE poly GetLmCurrRing()
Definition: kInline.h:220
KINLINE void Init(ring r=currRing)
Definition: kInline.h:107
KINLINE void Mult_nn(number n)
Definition: kInline.h:312
int length
Definition: kutil.h:75
KINLINE long SetDegStuffReturnLDeg()
Definition: kInline.h:424
KINLINE poly GetLmTailRing()
Definition: kInline.h:227
KINLINE void pCleardenom()
Definition: kInline.h:436
int ecart
Definition: kutil.h:74
KINLINE long GetpFDeg() const
Definition: kInline.h:415
KINLINE sTObject(ring tailRing=currRing)
Definition: kInline.h:113
KINLINE void ShallowCopyDelete(ring new_tailRing, omBin new_tailBin, pShallowCopyDeleteProc p_shallow_copy_delete, BOOLEAN set_max=TRUE)
Definition: kInline.h:359
KINLINE void SetLmCurrRing()
Definition: kInline.h:277
poly max_exp
Definition: kutil.h:71
char is_normalized
Definition: kutil.h:78
KINLINE long pLDeg()
Definition: kInline.h:420
KINLINE void LmDeleteAndIter()
Definition: kInline.h:291
int pLength
Definition: kutil.h:76
KINLINE long pFDeg() const
Definition: kInline.h:400
int i_r
Definition: kutil.h:77
poly p
Definition: kutil.h:69
KINLINE BOOLEAN IsNull() const
Definition: kInline.h:266
KINLINE void Set(ring r=currRing)
Definition: kInline.h:103
KINLINE void Delete()
Definition: kInline.h:177
poly t_p
Definition: kutil.h:70
ring tailRing
Definition: kutil.h:72
KINLINE int GetpLength()
Definition: kInline.h:271
KINLINE void pNorm()
Definition: kInline.h:474
KINLINE void Clear()
Definition: kInline.h:191
long FDeg
Definition: kutil.h:73
KINLINE poly Next()
Definition: kInline.h:283
KINLINE long pTotalDeg() const
Definition: kInline.h:405
KINLINE long SetpFDeg()
Definition: kInline.h:410
KINLINE void Copy()
Definition: kInline.h:202
KINLINE poly kNoetherTail()
Definition: kInline.h:63
poly t_kNoether
Definition: kutil.h:324
int * S_2_R
Definition: kutil.h:335
ring tailRing
Definition: kutil.h:336
TSet T
Definition: kutil.h:317
polyset S
Definition: kutil.h:297
poly kNoether
Definition: kutil.h:321
TObject ** R
Definition: kutil.h:333
int tl
Definition: kutil.h:343
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:44
KINLINE TObject * S_2_T(int i)
Definition: kInline.h:35
char noClearS
Definition: kutil.h:396
int sl
Definition: kutil.h:341
unsigned long * sevS
Definition: kutil.h:313
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static FORCE_INLINE BOOLEAN n_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition: coeffs.h:775
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition: coeffs.h:468
const CanonicalForm int s
Definition: facAbsFact.cc:55
CFArray copy(const CFList &list)
write elements of list into an array
static number Copy(number a, const coeffs r)
Definition: flintcf_Q.cc:201
static jList * T
Definition: janet.cc:31
KINLINE poly k_LmShallowCopyDelete_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
Definition: kInline.h:897
KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
Definition: kInline.h:1069
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
Definition: kInline.h:1079
KINLINE poly k_LmShallowCopyDelete_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:890
KINLINE poly k_LmInit_currRing_2_tailRing(poly p, ring tailRing, omBin tailBin)
Definition: kInline.h:872
KINLINE TSet initT()
Definition: kInline.h:81
KINLINE void k_GetStrongLeadTerms(const poly p1, const poly p2, const ring leadRing, poly &m1, poly &m2, poly &lcm, const ring tailRing)
Definition: kInline.h:974
KINLINE poly redtailBba(poly p, int pos, kStrategy strat, BOOLEAN normalize)
Definition: kInline.h:1087
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1049
KINLINE poly k_LmInit_tailRing_2_currRing(poly t_p, ring tailRing, omBin lmBin)
Definition: kInline.h:881
KINLINE poly redtailBbaBound(poly p, int pos, kStrategy strat, int bound, BOOLEAN normalize)
Definition: kInline.h:1093
KINLINE BOOLEAN arriRewDummy(poly, unsigned long, poly, kStrategy, int)
Definition: kInline.h:1132
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1022
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1059
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1107
KINLINE TObject ** initR()
Definition: kInline.h:92
KINLINE BOOLEAN k_GetLeadTerms(const poly p1, const poly p2, const ring p_r, poly &m1, poly &m2, const ring m_r)
Definition: kInline.h:931
KINLINE poly redtailBba_Z(poly p, int pos, kStrategy strat)
Definition: kInline.h:1100
void kBucketDeleteAndDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:220
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:518
void kBucketShallowCopyDelete(kBucket_pt bucket, ring new_tailRing, omBin new_tailBin, pShallowCopyDeleteProc p_shallow_copy_delete)
For changing the ring of the Bpoly to new_tailBin.
Definition: kbuckets.cc:532
void kBucket_Minus_m_Mult_p(kBucket_pt bucket, poly m, poly p, int *l, poly spNoether)
Bpoly == Bpoly - m*p; where m is a monom Does not destroy p and m assume (*l <= 0 || pLength(p) == *l...
Definition: kbuckets.cc:713
void kBucket_Mult_n(kBucket_pt bucket, number n)
Multiply Bucket by number ,i.e. Bpoly == n*Bpoly.
Definition: kbuckets.cc:595
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:213
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:490
poly kBucketExtractLm(kBucket_pt bucket)
Definition: kbuckets.cc:508
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:206
void kBucketNormalize(kBucket_pt bucket)
apply n_Normalize to all coefficients
int kBucketCanonicalize(kBucket_pt bucket)
Canonicalizes Bpoly, i.e. converts polys of buckets into one poly in one bucket: Returns number of bu...
int ksReducePoly(LObject *PR, TObject *PW, poly spNoether, number *coef, kStrategy strat)
Definition: kspoly.cc:41
void ksCreateSpoly(LObject *Pair, poly spNoether, int use_buckets, ring tailRing, poly m1, poly m2, TObject **R)
Definition: kspoly.cc:752
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:87
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:704
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:1069
denominator_list_s * denominator_list
Definition: kutil.h:59
TObject * TSet
Definition: kutil.h:55
denominator_list next
Definition: kutil.h:61
#define setmaxT
Definition: kutil.h:33
#define KINLINE
Definition: kutil.h:45
class sTObject TObject
Definition: kutil.h:53
class sLObject LObject
Definition: kutil.h:54
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:709
#define assume(x)
Definition: mod2.h:390
#define p_GetComp(p, r)
Definition: monomials.h:65
#define pNext(p)
Definition: monomials.h:37
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:45
#define pSetCoeff0(p, n)
Definition: monomials.h:60
Definition: lq.h:40
#define nDelete(n)
Definition: numbers.h:17
#define nInvers(a)
Definition: numbers.h:34
#define nIsOne(n)
Definition: numbers.h:26
#define nNormalize(n)
Definition: numbers.h:31
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:10
omBin_t * omBin
Definition: omStructs.h:12
#define TEST_OPT_CONTENTSB
Definition: options.h:125
p_Length
Definition: p_Procs_Impl.h:123
poly p_GetMaxExpP(poly p, const ring r)
return monomial r such that GetExp(r,i) is maximum of all monomials in p; coeff == 0,...
Definition: p_polys.cc:1130
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2891
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3670
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4679
void p_ProjectiveUnique(poly ph, const ring r)
Definition: p_polys.cc:3080
poly p_Last(const poly p, int &l, const ring r)
Definition: p_polys.cc:4519
static long p_GetExpDiff(poly p1, poly p2, int i, ring r)
Definition: p_polys.h:636
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition: pDebug.cc:120
static poly p_LmInit(poly p, const ring r)
Definition: p_polys.h:1272
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:381
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:489
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:314
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:234
static poly p_LmShallowCopyDelete(poly p, const ring r)
Definition: p_polys.h:1330
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:470
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:915
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:858
static void p_LmFree(poly p, ring)
Definition: p_polys.h:684
static poly p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, int lq, const poly spNoether, const ring r)
Definition: p_polys.h:1007
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1257
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:726
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:813
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1444
#define p_Test(p, r)
Definition: p_polys.h:164
#define __p_Mult_nn(p, n, r)
Definition: p_polys.h:928
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatiblity layer for legacy polynomial operations (over currRing)
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:146
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl....
Definition: polys.h:152
#define pNormalize(p)
Definition: polys.h:311
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:475
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:710
poly(* pShallowCopyDeleteProc)(poly s_p, ring source_r, ring dest_r, omBin dest_bin)
returns a poly from dest_r which is a ShallowCopy of s_p from source_r assumes that source_r->N == de...
Definition: ring.h:45
static poly normalize(poly next_p, ideal add_generators, syStrategy syzstr, int *g_l, int *p_l, int crit_comp)
Definition: syz3.cc:1027