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