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