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
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  pp_Test(p_in, currRing, tailRing);
128  p = p_in;
129  }
130 }
131 
133 {
134  Init(r);
135  Set(p_in, r);
136 }
137 
138 KINLINE void sTObject::Set(poly p_in, ring c_r, ring t_r)
139 {
140  if (c_r != t_r)
141  {
142  assume(c_r == currRing && t_r == tailRing);
143  pp_Test(p_in, currRing, t_r);
144  p = p_in;
145  }
146  else
147  {
148  Set(p_in, c_r);
149  }
150 }
151 
152 KINLINE sTObject::sTObject(poly p_in, ring c_r, ring t_r)
153 {
154  Init(t_r);
155  Set(p_in, c_r, t_r);
156 }
157 
159 {
160  *this = *T;
161  if (copy)
162  {
163  if (t_p != NULL)
164  {
165  t_p = p_Copy(t_p, tailRing);
167  }
168  else
169  {
170  p = p_Copy(p, currRing, tailRing);
171  }
172  }
173 }
174 
176 {
177  if (t_p != NULL)
178  {
179  p_Delete(&t_p, tailRing);
180  if (p != NULL)
181  p_LmFree(p, currRing);
182  }
183  else
184  {
186  }
187 }
188 
190 {
191  p = NULL;
192  t_p = NULL;
193  ecart = 0;
194  length = 0;
195  pLength = 0;
196  FDeg = 0;
197  is_normalized = FALSE;
198 }
199 
201 {
202  if (t_p != NULL)
203  {
204  t_p = p_Copy(t_p, tailRing);
205  if (p != NULL)
206  {
207  p = p_Head(p, currRing);
208  if (pNext(t_p) != NULL) pNext(p) = pNext(t_p);
209  }
210  }
211  else
212  {
213  p = p_Copy(p, currRing, tailRing);
214  }
215 }
216 
218 {
219  if (p == NULL && t_p != NULL)
221 
222  return p;
223 }
225 {
226  if (t_p == NULL)
227  {
228  if (p != NULL && tailRing != currRing)
229  {
231  return t_p;
232  }
233  return p;
234  }
235  return t_p;
236 }
238 {
239  assume(r == tailRing || r == currRing);
240  if (r == currRing)
241  return GetLmCurrRing();
242 
243  if (t_p == NULL && p != NULL)
245 
246  return t_p;
247 }
248 
249 KINLINE void sTObject::GetLm(poly &p_r, ring &r_r) const
250 {
251  if (t_p != NULL)
252  {
253  p_r = t_p;
254  r_r = tailRing;
255  }
256  else
257  {
258  p_r = p;
259  r_r = currRing;
260  }
261 }
262 
264 {
265  return (p == NULL && t_p == NULL);
266 }
267 
269 {
270  if (pLength <= 0) pLength = ::pLength(p != NULL ? p : t_p);
271  return pLength;
272 }
273 
275 {
276  if (p == NULL && t_p != NULL)
278 }
279 
281 {
282  assume(p != NULL || t_p != NULL);
283  if (t_p != NULL) return pNext(t_p);
284  return pNext(p);
285 }
286 
287 // Iterations
289 {
290  assume(p != NULL || t_p != NULL);
291  if (t_p != NULL)
292  {
293  t_p = p_LmDeleteAndNext(t_p, tailRing);
294  if (p != NULL)
295  {
296  p_LmFree(p, currRing);
297  p = NULL;
298  }
299  }
300  else
301  {
303  }
304  is_normalized = FALSE;
305 }
306 
307 
308 // arithmetic
310 {
311  if (t_p != NULL)
312  { t_p = p_Mult_nn(t_p, n, tailRing);
313  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
314  }
315  else
316  {
317  p = p_Mult_nn(p, n, currRing, tailRing);
318  }
319 }
320 
322 {
323  if (t_p != NULL)
324  {
325  pNormalize(t_p);
326  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
327  }
328  else
329  {
330  pNormalize(p);
331  }
332 }
333 
335 {
336  if (t_p != NULL)
337  {
338  nNormalize(pGetCoeff(t_p));
339  if (p != NULL) pSetCoeff0(p, pGetCoeff(t_p));
340  }
341  else
342  {
344  }
345 }
346 
347 KINLINE void
348 sTObject::ShallowCopyDelete(ring new_tailRing, omBin new_tailBin,
350  BOOLEAN set_max)
351 {
352  if (new_tailBin == NULL) new_tailBin = new_tailRing->PolyBin;
353  if (t_p != NULL)
354  {
355  t_p = p_shallow_copy_delete(t_p, tailRing, new_tailRing, new_tailBin);
356  if (p != NULL)
357  pNext(p) = pNext(t_p);
358  if (new_tailRing == currRing)
359  {
360  if (p == NULL) p = t_p;
361  else p_LmFree(t_p, tailRing);
362  t_p = NULL;
363  }
364  }
365  else if (p != NULL)
366  {
367  if (pNext(p) != NULL)
368  {
370  tailRing, new_tailRing, new_tailBin);
371  }
372  if (new_tailRing != currRing)
373  {
374  t_p = k_LmInit_currRing_2_tailRing(p, new_tailRing);
375  pNext(t_p) = pNext(p);
376  }
377  }
378  if (max != NULL)
379  {
380  if (new_tailRing == currRing)
381  {
383  max = NULL;
384  }
385  else
386  max = p_shallow_copy_delete(max,tailRing,new_tailRing,new_tailBin);
387  }
388  else if (set_max && new_tailRing != currRing && pNext(t_p) != NULL)
389  {
390  max = p_GetMaxExpP(pNext(t_p), new_tailRing);
391  }
392  tailRing = new_tailRing;
393 }
394 
396 {
397  if (p != NULL) return p_FDeg(p, currRing);
398  return tailRing->pFDeg(t_p, tailRing);
399 }
401 {
402  if (p != NULL) return p_Totaldegree(p, currRing);
403  return p_Totaldegree(t_p,tailRing);
404 }
406 {
407  FDeg = this->pFDeg();
408  return FDeg;
409 }
411 {
412  assume(FDeg == this->pFDeg());
413  return FDeg;
414 }
416 {
417  return tailRing->pLDeg(GetLmTailRing(), &length, tailRing);
418 }
420 {
421  FDeg = this->pFDeg();
422  long d = this->pLDeg();
423  ecart = d - FDeg;
424  return d;
425 }
426 
427 //extern void pCleardenom(poly p);
428 // extern void pNorm(poly p);
429 
430 // manipulations
432 {
433  assume(p != NULL);
434  if (TEST_OPT_CONTENTSB)
435  {
436  number n;
437  if (t_p != NULL)
438  {
439  p_Cleardenom_n(t_p, tailRing, n);
440  pSetCoeff0(p, pGetCoeff(t_p));
441  }
442  else
443  {
445  }
446  if (!nIsOne(n))
447  {
449  denom->n=nInvers(n);
450  denom->next=DENOMINATOR_LIST;
451  DENOMINATOR_LIST=denom;
452  }
453  nDelete(&n);
454  }
455  else
456  {
457  if (t_p != NULL)
458  {
460  pSetCoeff0(p, pGetCoeff(t_p));
461  }
462  else
463  {
464 #ifdef HAVE_RATGRING
466 #else
468 #endif
469  }
470  }
471 }
472 
473 KINLINE void sTObject::pNorm() // pNorm seems to be a _bad_ method name...
474 {
475  assume(p != NULL);
476  if (! is_normalized)
477  {
478  p_Norm(p, currRing);
479  if (t_p != NULL)
480  pSetCoeff0(t_p, pGetCoeff(p));
481  is_normalized = TRUE;
482  }
483 }
484 
485 
486 
487 /***************************************************************
488  *
489  * Operation on LObjects
490  *
491  ***************************************************************/
492 // Initialization
494 {
495  sTObject::Clear();
496  sev = 0;
497 }
498 // Initialization
500 {
502  if (bucket != NULL)
504 }
505 
507 {
508  memset(this, 0, sizeof(sLObject));
509  i_r1 = -1;
510  i_r2 = -1;
511  i_r = -1;
512  Set(r);
513 }
515 {
516  Init(r);
517 }
519 {
520  Init(r);
521  Set(p_in, r);
522 }
523 
524 KINLINE sLObject::sLObject(poly p_in, ring c_r, ring t_r)
525 {
526  Init(t_r);
527  Set(p_in, c_r, t_r);
528 }
529 
531 {
532  if (bucket == NULL)
533  {
534  int l = GetpLength();
535  if (use_bucket && (l > 1))
536  {
537  poly tp = GetLmTailRing();
538  assume(l == ::pLength(tp));
540  kBucketInit(bucket, pNext(tp), l-1);
541  pNext(tp) = NULL;
542  if (p != NULL) pNext(p) = NULL;
543  pLength = 0;
544  }
545  }
546 }
547 
548 KINLINE void sLObject::SetLmTail(poly lm, poly p_tail, int p_Length, int use_bucket, ring _tailRing)
549 {
550 
551  Set(lm, _tailRing);
552  if (use_bucket)
553  {
554  bucket = kBucketCreate(_tailRing);
555  kBucketInit(bucket, p_tail, p_Length);
556  pNext(lm) = NULL;
557  pLength = 0;
558  }
559  else
560  {
561  pNext(lm) = p_tail;
562  pLength = p_Length + 1;
563  }
564 }
565 
567 {
568  if (bucket != NULL)
569  {
571  }
572  else
573  {
574  poly _p = (t_p != NULL ? t_p : p);
575  assume(_p != NULL);
576  pNext(_p) = p_Mult_nn(pNext(_p), n, tailRing);
577  }
578 }
579 
581  poly spNoether)
582 {
583  if (bucket != NULL)
584  {
585  kBucket_Minus_m_Mult_p(bucket, m, q, &lq, spNoether);
586  }
587  else
588  {
589  if (lq<=0) lq= ::pLength(q);
590  poly _p = (t_p != NULL ? t_p : p);
591  assume(_p != NULL);
592 
593  int lp=pLength-1;
594  pNext(_p) = p_Minus_mm_Mult_qq( pNext(_p), m, q, lp, lq,
595  spNoether, tailRing );
596  pLength=lp+1;
597 // tailRing->p_Procs->p_Minus_mm_Mult_qq(pNext(_p), m, q, shorter,spNoether, tailRing, last);
598 // pLength += lq - shorter;
599  }
600 }
601 
603 {
605  if (bucket != NULL)
606  {
608  if (_p == NULL)
609  {
611  p = t_p = NULL;
612  return;
613  }
614  Set(_p, tailRing);
615  }
616  else
617  {
618  pLength--;
619  }
620 }
621 
623 {
624  poly ret = GetLmTailRing();
625  poly pn;
626 
627  assume(p != NULL || t_p != NULL);
628 
629  if (bucket != NULL)
630  {
631  pn = kBucketExtractLm(bucket);
632  if (pn == NULL)
634  }
635  else
636  {
637  pn = pNext(ret);
638  }
639  pLength--;
640  pNext(ret) = NULL;
641  if (p != NULL && t_p != NULL)
642  p_LmFree(p, currRing);
643 
644  Set(pn, tailRing);
645  return ret;
646 }
647 
649 {
650  //kTest_L(this);
651  int i = -1;
652 
653  if (bucket != NULL)
655 
656  if (p == NULL)
658 
659  if (i >= 0) pNext(p) = bucket->buckets[i];
660  return p;
661 }
662 
664 {
665  //kTest_L(this);
666  poly tp = GetLmTailRing();
667  assume(tp != NULL);
668 
669  if (bucket != NULL)
670  {
671  kBucketClear(bucket, &pNext(tp), &pLength);
673  pLength++;
674  }
675  return tp;
676 }
677 
678 
680 {
681  //kTest_L(this);
682  if (p == NULL)
683  {
685  (lmBin!=NULL?lmBin:currRing->PolyBin));
686  FDeg = pFDeg();
687  }
688  else if (lmBin != NULL && lmBin != currRing->PolyBin)
689  {
691  FDeg = pFDeg();
692  }
693 
694  if (bucket != NULL)
695  {
698  pLength++;
699  if (t_p != NULL) pNext(t_p) = pNext(p);
700  }
701  //kTest_L(this);
702  return p;
703 }
704 
705 KINLINE void
706 sLObject::ShallowCopyDelete(ring new_tailRing,
708 {
709  if (bucket != NULL)
710  kBucketShallowCopyDelete(bucket, new_tailRing, new_tailRing->PolyBin,
711  p_shallow_copy_delete);
712  sTObject::ShallowCopyDelete(new_tailRing,
713  new_tailRing->PolyBin,p_shallow_copy_delete,
714  FALSE);
715 }
716 
718 {
719  if (t_p != NULL)
720  {
721  sev = p_GetShortExpVector(t_p, tailRing);
722  }
723  else
724  {
726  }
727 }
728 
730 {
731  if (bucket != NULL)
732  {
734  kBucket_pt new_bucket = kBucketCreate(tailRing);
735  kBucketInit(new_bucket,
736  p_Copy(bucket->buckets[i], tailRing),
737  bucket->buckets_length[i]);
738  bucket = new_bucket;
739  if (t_p != NULL) pNext(t_p) = NULL;
740  if (p != NULL) pNext(p) = NULL;
741  }
742  TObject::Copy();
743 }
744 
746 {
747  if (bucket != NULL)
748  {
750  poly bp = p_Copy(bucket->buckets[i], tailRing);
751  pLength = bucket->buckets_length[i] + 1;
752  if (bp != NULL)
753  {
754  assume(t_p != NULL || p != NULL);
755  if (t_p != NULL) pNext(t_p) = bp;
756  else pNext(p) = bp;
757  }
758  bucket = NULL;
759  }
760  return sLObject::GetP();
761 }
762 
763 
765 {
766  poly tp = GetLmTailRing();
767  assume(tp != NULL);
768  if (bucket != NULL)
769  {
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 #ifdef HAVE_ASSUME
786  if ( pLength == 0)
787  p_Last(GetLmTailRing(), pLength, tailRing);
788  assume ( pLength == length || rIsSyzIndexRing(currRing));
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();
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  {
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 np = p_LmInit(p, currRing, tailRing, tailBin);
909  pNext(np) = pNext(p);
910  pSetCoeff0(np, pGetCoeff(p));
911  return np;
912 }
913 
915 {
916  poly np = p_LmInit(p, tailRing, currRing, lmBin);
917  pNext(np) = pNext(p);
918  pSetCoeff0(np, pGetCoeff(p));
919  return np;
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);
973  m2 = p_Init(m_r);
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);
1019  m2 = p_Init(tailRing);
1020  lcm = p_Init(leadRing);
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 coef;
1059 
1060  assume(PR->GetLmCurrRing() != PW->GetLmCurrRing());
1061  Red->HeadNormalize();
1062  ret = ksReducePoly(Red, PW, NULL, &coef);
1063 
1064  if (!ret)
1065  {
1066  if (! n_IsOne(coef, currRing->cf))
1067  {
1068  PR->Mult_nn(coef);
1069  // HANNES: mark for Normalize
1070  }
1071  n_Delete(&coef, currRing->cf);
1072  }
1073  return ret;
1074 }
1075 
1076 /***************************************************************
1077  *
1078  * Routines for backwards-Compatibility
1079  *
1080  *
1081  ***************************************************************/
1083 {
1084  LObject L(p2);
1085  TObject T(p1);
1086 
1087  ksReducePoly(&L, &T, spNoether);
1088 
1089  return L.GetLmCurrRing();
1090 }
1091 
1093 {
1094  LObject L(p_Copy(p2, currRing));
1095  TObject T(p1);
1096 
1097  ksReducePoly(&L, &T, spNoether);
1098 
1099  return L.GetLmCurrRing();
1100 }
1101 
1103 {
1104  LObject L(r);
1105  L.p1 = p1;
1106  L.p2 = p2;
1107 
1108  ksCreateSpoly(&L, spNoether);
1109  return L.GetLmCurrRing();
1110 }
1111 
1112 void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
1113 {
1114  LObject L(q, currRing, r);
1115  TObject T(p1, currRing, r);
1116 
1117  ksReducePolyTail(&L, &T, q2, spNoether);
1118 }
1119 
1121 {
1122  LObject L(p, currRing, strat->tailRing);
1123  return redtailBba(&L, pos, strat,FALSE, normalize);
1124 }
1125 
1126 #ifdef HAVE_RINGS
1128 {
1129  LObject L(p, currRing, strat->tailRing);
1130  return redtailBba_Z(&L, pos, strat);
1131 }
1132 #endif
1133 
1135 {
1136  LObject L;
1137  L = *T;
1138  poly p = redtailBba(&L, pos, strat, FALSE);
1139  *T = L;
1140  //kTest_T(T);
1141  assume( p == T->p);
1142  return p;
1143 }
1144 
1145 KINLINE void clearS (poly p, unsigned long p_sev, int* at, int* k,
1146  kStrategy strat)
1147 {
1148  assume(p_sev == pGetShortExpVector(p));
1149  if (strat->noClearS) return;
1150  #if HAVE_RINGS
1152  {
1153  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at]))
1154  return;
1155  if(!n_DivBy(pGetCoeff(strat->S[*at]), pGetCoeff(p), currRing))
1156  return;
1157  }
1158  else
1159  {
1160  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1161  }
1162  #else
1163  if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return;
1164  #endif
1165  deleteInS((*at),strat);
1166  (*at)--;
1167  (*k)--;
1168 }
1169 
1170 // dummy function for function pointer strat->rewCrit being usable in all
1171 // possible choices for criteria
1172 KINLINE BOOLEAN arriRewDummy(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy /*strat*/, int /*start=0*/)
1173 {
1174  return FALSE;
1175 }
1176 
1177 #endif // defined(KINLINE) || defined(KUTIL_CC)
1178 #endif // KINLINE_H
KINLINE void Init(ring tailRing=currRing)
Definition: kInline.h:506
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:499
KINLINE int GetpLength()
Definition: kInline.h:809
KINLINE poly GetP(omBin lmBin=NULL)
Definition: kInline.h:679
denominator_list_s * denominator_list
Definition: kutil.h:65
static number Copy(number a, const coeffs r)
Definition: flintcf_Q.cc:233
KINLINE TObject ** initR()
Definition: kInline.h:92
const CanonicalForm int s
Definition: facAbsFact.cc:55
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:1028
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:513
KINLINE void SetShortExpVector()
Definition: kInline.h:717
int lcm(unsigned long *l, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:711
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:471
omBin_t * omBin
Definition: omStructs.h:12
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition: p_polys.h:721
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
KINLINE poly redtailBba_Z(poly p, int pos, kStrategy strat)
Definition: kInline.h:1127
KINLINE void Set(ring r=currRing)
Definition: kInline.h:103
class sLObject LObject
Definition: kutil.h:60
#define nNormalize(n)
Definition: numbers.h:30
BOOLEAN length_pLength
Definition: kutil.h:377
TObject * TSet
Definition: kutil.h:61
KINLINE TSet initT()
Definition: kInline.h:81
KINLINE sLObject & operator=(const sTObject &)
Definition: kInline.h:850
KINLINE poly Next()
Definition: kInline.h:280
#define FALSE
Definition: auxiliary.h:140
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:340
return P p
Definition: myNF.cc:203
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff &#39;n&#39; represents the one element.
Definition: coeffs.h:469
KINLINE int ksReducePolyTail(LObject *PR, TObject *PW, LObject *Red)
Definition: kInline.h:1055
static BOOLEAN rIsSyzIndexRing(const ring r)
Definition: ring.h:714
#define p_GetComp(p, r)
Definition: monomials.h:72
KINLINE poly k_LmInit_tailRing_2_currRing(poly p, ring tailRing, omBin lmBin)
Definition: kInline.h:914
#define TEST_OPT_CONTENTSB
Definition: options.h:121
int kFindInT(poly p, TSet T, int tlength)
returns index of p in TSet, or -1 if not found
Definition: kutil.cc:617
KINLINE sLObject(ring tailRing=currRing)
Definition: kInline.h:514
KINLINE void Init(ring r=currRing)
Definition: kInline.h:107
KINLINE BOOLEAN IsNull() const
Definition: kInline.h:263
poly kNoether
Definition: kutil.h:326
KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
Definition: kInline.h:1102
int tl
Definition: kutil.h:348
KINLINE void HeadNormalize()
Definition: kInline.h:334
static poly p_LmShallowCopyDelete(poly p, const ring r)
Definition: p_polys.h:1321
char noClearS
Definition: kutil.h:392
#define TRUE
Definition: auxiliary.h:144
#define nIsOne(n)
Definition: numbers.h:25
denominator_list DENOMINATOR_LIST
Definition: kutil.cc:81
int ksReducePoly(LObject *PR, TObject *PW, poly spNoether, number *coef, kStrategy strat)
Definition: kspoly.cc:38
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1435
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:942
pShallowCopyDeleteProc p_shallow_copy_delete
Definition: kutil.h:336
int k
Definition: cfEzgcd.cc:93
KINLINE void pNorm()
Definition: kInline.h:473
void p_Norm(poly p1, const ring r)
Definition: p_polys.cc:3565
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
void kBucket_Mult_n(kBucket_pt bucket, number n)
Multiply Bucket by number ,i.e. Bpoly == n*Bpoly.
Definition: kbuckets.cc:576
KINLINE void Tail_Minus_mm_Mult_qq(poly m, poly qq, int lq, poly spNoether)
Definition: kInline.h:580
#define omAlloc(size)
Definition: omAllocDecl.h:210
KINLINE poly redtailBba(poly p, int pos, kStrategy strat, BOOLEAN normalize)
Definition: kInline.h:1120
#define KINLINE
Definition: kutil.h:51
kBucket_pt kBucketCreate(ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:197
static void p_LmFree(poly p, ring)
Definition: p_polys.h:679
static int pLength(poly a)
Definition: p_polys.h:189
poly kBucketExtractLm(kBucket_pt bucket)
Definition: kbuckets.cc:489
KINLINE void PrepareRed(BOOLEAN use_bucket)
Definition: kInline.h:530
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
poly pp
Definition: myNF.cc:296
KINLINE void Tail_Mult_nn(number n)
Definition: kInline.h:566
KINLINE void LmDeleteAndIter()
Definition: kInline.h:288
KINLINE void Copy()
Definition: kInline.h:729
KINLINE void SetLmTail(poly lm, poly new_p, int length, int use_bucket, ring r)
Definition: kInline.h:548
p_Length
Definition: p_Procs_Impl.h:127
KINLINE sTObject(ring tailRing=currRing)
Definition: kInline.h:113
void p_Cleardenom_n(poly ph, const ring r, number &c)
Definition: p_polys.cc:2826
KINLINE int GetpLength()
Definition: kInline.h:268
static long p_GetExpDiff(poly p1, poly p2, int i, ring r)
Definition: p_polys.h:631
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
KINLINE void Copy()
Definition: kInline.h:200
static poly p_Head(poly p, const ring r)
Definition: p_polys.h:819
const ring r
Definition: syzextra.cc:208
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:35
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:204
KINLINE long pLDeg()
Definition: kInline.h:764
#define setmaxT
Definition: kutil.h:32
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:465
static int max(int a, int b)
Definition: fast_mult.cc:264
KINLINE long pTotalDeg() const
Definition: kInline.h:400
KINLINE void Clear()
Definition: kInline.h:189
KINLINE void LmDeleteAndIter()
Definition: kInline.h:602
#define assume(x)
Definition: mod2.h:405
KINLINE TObject * T_2(const skStrategy *strat)
Definition: kInline.h:867
KINLINE poly CanonicalizeP()
Definition: kInline.h:648
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl.cc )
Definition: polys.h:140
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:771
void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
Definition: kInline.h:1112
#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:134
#define pp_Test(p, lmRing, tailRing)
Definition: p_polys.h:162
pNormalize(P.p)
KINLINE void ShallowCopyDelete(ring new_tailRing, omBin new_tailBin, pShallowCopyDeleteProc p_shallow_copy_delete, BOOLEAN set_max=TRUE)
Definition: kInline.h:348
void ksCreateSpoly(LObject *Pair, poly spNoether, int use_buckets, ring tailRing, poly m1, poly m2, TObject **R)
Definition: kspoly.cc:379
P bucket
Definition: myNF.cc:79
static long p_FDeg(const poly p, const ring r)
Definition: p_polys.h:369
KINLINE void SetLmCurrRing()
Definition: kInline.h:274
int m
Definition: cfEzgcd.cc:119
int i
Definition: cfEzgcd.cc:123
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:902
KINLINE void Normalize()
Definition: kInline.h:321
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition: p_polys.h:302
TObject ** R
Definition: kutil.h:338
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:698
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:160
KINLINE void pCleardenom()
Definition: kInline.h:431
KINLINE poly ksOldSpolyRedNew(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1092
int int kStrategy strat
Definition: myNF.cc:68
#define nInvers(a)
Definition: numbers.h:33
Definition: kutil.h:70
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
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:149
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition: p_polys.cc:4557
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:484
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:52
KINLINE poly GetLmCurrRing()
Definition: kInline.h:217
LSet L
Definition: kutil.h:323
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:437
#define NULL
Definition: omList.c:10
KINLINE void Mult_nn(number n)
Definition: kInline.h:309
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition: pDebug.cc:119
ring tailRing
Definition: kutil.h:341
poly p_Last(const poly p, int &l, const ring r)
Definition: p_polys.cc:4398
KINLINE poly GetLmTailRing()
Definition: kInline.h:224
KINLINE long pLDeg()
Definition: kInline.h:415
KINLINE poly GetTP()
Definition: kInline.h:663
denominator_list next
Definition: kutil.h:67
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:419
Variable x
Definition: cfModGcd.cc:4023
#define pNext(p)
Definition: monomials.h:43
static poly p_LmInit(poly p, const ring r)
Definition: p_polys.h:1263
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:436
KINLINE void Delete()
Definition: kInline.h:499
#define pSetCoeff0(p, n)
Definition: monomials.h:67
KINLINE void clearS(poly p, unsigned long p_sev, int *at, int *k, kStrategy strat)
Definition: kInline.h:1145
KINLINE TObject * s_2_t(int i)
Definition: kInline.h:44
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:981
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:1082
int sl
Definition: kutil.h:346
KINLINE long pFDeg() const
Definition: kInline.h:395
TSet T
Definition: kutil.h:322
KINLINE long GetpFDeg() const
Definition: kInline.h:410
omBin lmBin
Definition: kutil.h:342
KINLINE poly LmExtractAndIter()
Definition: kInline.h:622
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete &#39;p&#39;
Definition: coeffs.h:456
KINLINE poly GetLm(ring r)
Definition: kInline.h:237
KINLINE void Clear()
Definition: kInline.h:493
polyrec * poly
Definition: hilb.h:10
KINLINE poly CopyGetP()
Definition: kInline.h:745
int BOOLEAN
Definition: auxiliary.h:131
int kBucketCanonicalize(kBucket_pt bucket)
KINLINE long SetpFDeg()
Definition: kInline.h:405
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
KINLINE poly kNoetherTail()
Definition: kInline.h:63
KINLINE BOOLEAN arriRewDummy(poly, unsigned long, poly, kStrategy, int)
Definition: kInline.h:1172
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:211
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:3008
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94
KINLINE long SetDegStuffReturnLDeg()
Definition: kInline.h:795
class sTObject TObject
Definition: kutil.h:59
KINLINE void Delete()
Definition: kInline.h:175
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:1137
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:706