18#ifdef HAVE_COEF_BUCKETS
19#define USE_COEF_BUCKETS
22#ifdef USE_COEF_BUCKETS
24#define MULTIPLY_BUCKET(B,I) do \
25 { if (B->coef[I]!=NULL) \
27 assume(p_IsConstant(B->Coef[i],B->bucket->ring)); \
28 B->buckets[I]=p_Mult_q(B->buckets[I],B->coef[I],B->bucket_ring); \
32 if (rField_is_Ring(B->bucket_ring)) B->buckets_length[i] = pLength(B->buckets[i]);
34#define MULTIPLY_BUCKET(B,I) do \
35 { if (B->coef[I]!=NULL) \
37 B->buckets[I]=p_Mult_q(B->buckets[I],B->coef[I],B->bucket_ring); \
43#define MULTIPLY_BUCKET(B,I)
46#ifdef USE_COEF_BUCKETS
55#ifndef BUCKET_TWO_BASE
58 const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000};
59 const unsigned int S[] = {1, 2, 4, 8, 16};
62 if (
v &
b[4]) {
v >>= S[4]; r |= S[3]; }
63 if (
v &
b[3]) {
v >>= S[3]; r |= S[2]; }
64 if (
v &
b[2]) {
v >>= S[2]; r |= S[1]; }
65 if (
v &
b[1]) {
v >>= S[1]; r |= S[0]; }
93#ifndef HAVE_PSEUDO_BUCKETS
96 #ifdef USE_COEF_BUCKETS
98 if ((bucket->coef[
i]!=
NULL) && (bucket->buckets[
i]==
NULL))
102 if (bucket->coef[
i]!=
NULL)
109 if ((
unsigned)bucket->buckets_length[
i] !=
pLength(bucket->buckets[
i]))
111 dReportError(
"Bucket %d lengths difference should:%d has:%d",
112 i, bucket->buckets_length[
i],
pLength(bucket->buckets[
i]));
114 else if (
i > 0 && (
int)
pLogLength(bucket->buckets_length[
i]) >
i)
117 i, bucket->buckets_length[
i]);
119 if (
i==0 && bucket->buckets_length[0] > 1)
129 #ifdef HAVE_COEF_BUCKETS
133 poly lm = bucket->buckets[0];
137 if (! kbTest_i(bucket, 0))
return FALSE;
138 for (
i=1;
i<= (int) bucket->buckets_used;
i++)
140 if (!kbTest_i(bucket,
i))
return FALSE;
141 if (lm !=
NULL && bucket->buckets[
i] !=
NULL
158 if (bucket->buckets[
i] !=
NULL || bucket->buckets_length[
i] != 0)
166 if (bucket->buckets[
i]!=
NULL)
171 if (bucket->buckets[
j]==bucket->buckets[
i])
178 #ifdef HAVE_COEF_BUCKETS
179 if (bucket->coef[
i]!=
NULL)
184 if (bucket->coef[
j]==bucket->coef[
i])
228 for (
i=0;
i<= bucket->buckets_used;
i++)
231#ifdef USE_COEF_BUCKETS
242#ifndef HAVE_PSEUDO_BUCKETS
247 if (bucket->buckets[0] !=
NULL)
249 poly lm = bucket->buckets[0];
251#ifdef BUCKET_TWO_BASE
253 while ( bucket->buckets_length[
i] >=
l)
260 while ( bucket->buckets_length[
i] >=
l)
266#ifndef USE_COEF_BUCKETS
268 pNext(lm) = bucket->buckets[
i];
269 bucket->buckets[
i] = lm;
270 bucket->buckets_length[
i]++;
271 assume(i <= bucket->buckets_used+1);
272 if (
i > bucket->buckets_used) bucket->buckets_used =
i;
273 bucket->buckets[0] =
NULL;
274 bucket->buckets_length[0] = 0;
277 if (
i > bucket->buckets_used) bucket->buckets_used =
i;
279 if (bucket->buckets[
i]!=
NULL)
282 pNext(lm) = bucket->buckets[
i];
283 bucket->buckets[
i] = lm;
284 bucket->buckets_length[
i]++;
285 assume(i <= bucket->buckets_used+1);
297 bucket->buckets[
i]=lm;
298 bucket->buckets_length[
i]=1;
301 bucket->buckets[
i]=lm;
302 bucket->buckets_length[
i]=1;
305 pNext(lm) = bucket->buckets[
i];
306 bucket->buckets[
i] = lm;
307 bucket->buckets_length[
i]++;
308 assume(i <= bucket->buckets_used+1);
311 bucket->buckets[0]=
NULL;
312 bucket->buckets_length[0] = 0;
313 bucket->coef[0]=
NULL;
327 #ifdef HAVE_COEF_BUCKETS
330 if (bucket->buckets_length[
i] != 0)
return FALSE;
342 if (lm ==
NULL)
return;
347 bucket->buckets[0] = lm;
348 #ifdef HAVE_COEF_BUCKETS
351 #ifdef USE_COEF_BUCKETS
352 bucket->coef[0]=
NULL;
355 bucket->buckets_length[0] = 1;
357 bucket->buckets_length[0]= 0;
361 bucket->buckets[
i] =
pNext(lm);
363 bucket->buckets_length[
i] =
length-1;
364 bucket->buckets_used =
i;
368 bucket->buckets_used = 0;
374#ifndef HAVE_PSEUDO_BUCKETS
378 poly
p = bucket->buckets[1];
380 int pl = bucket->buckets_length[1];
382 bucket->buckets[1] =
NULL;
383 bucket->buckets_length[1] = 0;
384 #ifdef USE_COEF_BUCKETS
390 for (
i=1;
i<=bucket->buckets_used;
i++)
392 #ifdef USE_COEF_BUCKETS
393 if (bucket->coef[
i]!=
NULL)
397 pl, bucket->buckets_length[
i], r);
403 pl, bucket->buckets_length[
i], r);
406 pl, bucket->buckets_length[
i], r);
409 bucket->buckets[
i] =
NULL;
410 bucket->buckets_length[
i] = 0;
412 #ifdef HAVE_COEF_BUCKETS
415 lm = bucket->buckets[0];
421 bucket->buckets[0] =
NULL;
422 bucket->buckets_length[0] = 0;
427 bucket->buckets[
i] =
p;
428 bucket->buckets_length[
i] = pl;
434 bucket->buckets_used =
i;
436 #ifdef USE_COEF_BUCKETS
449#ifdef HAVE_PSEUDO_BUCKETS
453 for (
int i=0;
i<=bucket->buckets_used;
i++)
465 #ifdef USE_COEF_BUCKETS
469 *
p = bucket->buckets[
i];
470 *
length = bucket->buckets_length[
i];
471 bucket->buckets[
i] =
NULL;
472 bucket->buckets_length[
i] = 0;
473 bucket->buckets_used = 0;
485 kBucketMergeLm(bucket);
487 bucket->buckets[0] = lm;
488 bucket->buckets_length[0] = 1;
535void kBucketShallowCopyDelete(kBucket_pt bucket,
536 ring new_tailRing,
omBin new_tailBin,
539#ifndef HAVE_PSEUDO_BUCKETS
543 for (
i=0;
i<= bucket->buckets_used;
i++)
544 if (bucket->buckets[
i] !=
NULL)
547 bucket->buckets[
i] = p_shallow_copy_delete(bucket->buckets[
i],
553 bucket->
p = p_shallow_copy_delete(
p,
569 int l1 = bucket->buckets_length[
i];
570 poly p1 = bucket->buckets[
i];
571 bucket->buckets[
i] =
NULL;
572 bucket->buckets_length[
i] = 0;
575 while (bucket->buckets[
i] !=
NULL)
579 p1 =
p_Add_q(p1, bucket->buckets[
i],
581 bucket->buckets[
i] =
NULL;
582 bucket->buckets_length[
i] = 0;
586 bucket->buckets[
i] = p1;
587 bucket->buckets_length[
i]=l1;
588 if (
i >= bucket->buckets_used)
589 bucket->buckets_used =
i;
591 kBucketAdjustBucketsUsed(bucket);
600#ifndef HAVE_PSEUDO_BUCKETS
605 for (
i=0;
i<= bucket->buckets_used;
i++)
607 if (bucket->buckets[
i] !=
NULL)
609#ifdef USE_COEF_BUCKETS
621 bucket->buckets_length[
i] =
pLength(bucket->buckets[
i]);
625 if (bucket->coef[
i]!=
NULL)
640 for (
i=0;
i<= bucket->buckets_used;
i++)
642 if (bucket->buckets[
i] !=
NULL)
644 bucket->buckets_length[
i] =
pLength(bucket->buckets[
i]);
662 if (q ==
NULL)
return;
676 kBucketMergeLm(bucket);
680 while (bucket->buckets[
i] !=
NULL)
683 #ifdef USE_COEF_BUCKETS
684 if (bucket->coef[
i]!=
NULL)
687 l1, bucket->buckets_length[
i], r);
693 l1, bucket->buckets_length[
i], r);
696 l1, bucket->buckets_length[
i], r);
698 bucket->buckets[
i] =
NULL;
699 bucket->buckets_length[
i] = 0;
706 bucket->buckets[
i] = q;
707 bucket->buckets_length[
i]=l1;
708 if (
i >= bucket->buckets_used)
709 bucket->buckets_used =
i;
711 kBucketAdjustBucketsUsed(bucket);
740#ifndef HAVE_PSEUDO_BUCKETS
741 kBucketMergeLm(bucket);
746 if ((i <= bucket->buckets_used) && (bucket->buckets[
i] !=
NULL))
748 assume(
pLength(bucket->buckets[
i])==(
unsigned)bucket->buckets_length[
i]);
762 bucket->buckets_length[
i], l1,
764 l1 = bucket->buckets_length[
i];
765 bucket->buckets[
i] =
NULL;
766 bucket->buckets_length[
i] = 0;
772 if (spNoether !=
NULL)
775 p1 = r->p_Procs->pp_Mult_mm_Noether(p1,
m, spNoether, l1, r);
780 p1 = r->p_Procs->pp_mm_Mult(p1,
m, r);
786 while (bucket->buckets[
i] !=
NULL)
790 p1 =
p_Add_q(p1, bucket->buckets[
i],
791 l1, bucket->buckets_length[
i], r);
792 bucket->buckets[
i] =
NULL;
793 bucket->buckets_length[
i] = 0;
797 bucket->buckets[
i] = p1;
798 bucket->buckets_length[
i]=l1;
799 if (
i >= bucket->buckets_used)
800 bucket->buckets_used =
i;
802 kBucketAdjustBucketsUsed(bucket);
833 kBucketMergeLm(bucket);
836 #ifdef USE_COEF_BUCKETS
839 if (i <= bucket->buckets_used && bucket->buckets[
i] !=
NULL)
842 #ifdef USE_COEF_BUCKETS
843 if ((bucket->coef[
i]!=
NULL) &&(
i>=coef_start))
849 number
gcd=
n_Gcd(add_coef, orig_coef,r);
857 orig_coef=orig_coef2;
869 bucket->buckets[
i]=
__p_Mult_nn(bucket->buckets[
i],orig_coef,r);
875 bucket->buckets_length[
i], l1, r);
876 l1=bucket->buckets_length[
i];
877 bucket->buckets[
i]=
NULL;
878 bucket->buckets_length[
i] = 0;
889 bucket->buckets_length[
i], l1, r);
890 l1 = bucket->buckets_length[
i];
891 bucket->buckets[
i] =
NULL;
892 bucket->buckets_length[
i] = 0;
898 #ifdef USE_COEF_BUCKETS
907 p1 = r->p_Procs->pp_Mult_mm(p1,
m, r);
908 #ifdef USE_COEF_BUCKETS
914 while ((bucket->buckets[
i] !=
NULL) && (p1!=
NULL))
917 #ifdef USE_COEF_BUCKETS
918 if ((bucket->coef[
i]!=
NULL) &&(
i>=coef_start))
923 number add_coef=
n_Copy(n,r);
924 number
gcd=
n_Gcd(add_coef, orig_coef,r);
933 orig_coef=orig_coef2;
939 bucket->buckets[
i]=
__p_Mult_nn(bucket->buckets[
i],orig_coef,r);
942 p1 =
p_Add_q(p1, bucket->buckets[
i],r);
945 bucket->buckets[
i]=
NULL;
955 #ifdef USE_COEF_BUCKETS
964 p1 =
p_Add_q(p1, bucket->buckets[
i],
965 l1, bucket->buckets_length[
i], r);
966 bucket->buckets[
i] =
NULL;
967 bucket->buckets_length[
i] = 0;
972 bucket->buckets[
i] = p1;
973#ifdef USE_COEF_BUCKETS
982 bucket->coef[
i]=
NULL;
989 bucket->buckets_length[
i]=l1;
990 if (
i > bucket->buckets_used)
991 bucket->buckets_used =
i;
993 kBucketAdjustBucketsUsed(bucket);
1039#ifndef HAVE_PSEUDO_BUCKETS
1040 kBucketMergeLm(bucket);
1041 for (
i=1;
i<=bucket->buckets_used;
i++)
1043 if (bucket->buckets[
i] !=
NULL)
1050 bucket->buckets_length[
i] -=
lq;
1051 assume(
pLength(bucket->buckets[
i]) == (
unsigned)bucket->buckets_length[
i]);
1056 kBucketAdjustBucketsUsed(bucket);
1104 if ((ct == 0) || (ct == 2))
1165 poly tmp=r->p_Procs->pp_Mult_mm(a1, lmRight, r);
1259 poly tmp=r->p_Procs->pp_Mult_mm(a1, lmRight, r);
1282#ifndef USE_COEF_BUCKETS
1285 if (bucket->buckets[0]==
NULL)
return;
1291 if (
cf->cfSubringGcd==
ndGcd)
return;
1293 number nn=
pGetCoeff(bucket->buckets[0]);
1307 for (
int i=1;
i<=bucket->buckets_used;
i++)
1309 if (bucket->buckets[
i]!=
NULL)
1326 for (
int i=0;
i<=bucket->buckets_used;
i++)
1328 if (bucket->buckets[
i]!=
NULL)
1330 poly
p=bucket->buckets[
i];
1346 for (
int i=bucket->buckets_used;
i>=0;
i--)
1348 if (bucket->buckets[
i]!=
NULL)
1350 poly
p=bucket->buckets[
i];
1362static BOOLEAN nIsPseudoUnit(number n, ring r)
1369 return (
n_Size(n,r->cf)==1);
1388 if ((bucket->buckets[
i]!=
NULL) && (bucket->coef[
i]==
NULL))
1399 if ((bucket->buckets[
i]!=
NULL)
1400 && (nIsPseudoUnit(
p_GetCoeff(bucket->coef[
i],r),r)))
1415 if (bucket->buckets[
i]!=
NULL)
1424 if (nIsPseudoUnit(coef,r))
1441 if (bucket->buckets[
i]!=
NULL)
1459 poly
p=bucket->buckets[
i];
1460 bucket->buckets_length[
i]--;
1461#ifdef USE_COEF_BUCKETS
1463 if (bucket->coef[
i]!=
NULL)
1469 p=bucket->buckets[
i];
1470 bucket->buckets[
i]=
NULL;
1475 bucket->buckets[
i]=
next;
1486 bucket->buckets[
i]=
pNext(bucket->buckets[
i]);
1507 number an = *a, bn = *
b;
static int si_max(const int a, const int b)
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
static FORCE_INLINE number n_ExactDiv(number a, number b, const coeffs r)
assume that there is a canonical subring in cf and we know that division is possible for these a and ...
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff 'n' represents the additive inverse of the one element, i.e. -1.
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
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:...
static FORCE_INLINE number n_SubringGcd(number a, number b, const coeffs r)
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
CFFList append(const CFFList &Inputlist, const CFFactor &TheFactor)
const Variable & v
< [in] a sqrfree bivariate poly
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static BOOLEAN length(leftv result, leftv arg)
void kBucketDeleteAndDestroy(kBucket_pt *bucket_pt)
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
BOOLEAN kbTest(kBucket_pt bucket)
Tests.
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...
void kBucketTakeOutComp(kBucket_pt bucket, long comp, poly *r_p, int *l)
void kBucket_Mult_n(kBucket_pt bucket, number n)
Multiply Bucket by number ,i.e. Bpoly == n*Bpoly.
void kBucketDestroy(kBucket_pt *bucket_pt)
void kBucketInit(kBucket_pt bucket, poly lm, int length)
int ksCheckCoeff(number *a, number *b, const coeffs r)
poly kBucketExtractLm(kBucket_pt bucket)
void kBucketAdjust(kBucket_pt bucket, int i)
Bucket number i from bucket is out of length sync, resync.
#define MULTIPLY_BUCKET(B, I)
poly kBucket_ExtractLarger(kBucket_pt bucket, poly q, poly append)
Extract all monomials of bucket which are larger than q Append those to append, and return last monom...
poly kBucketExtractLmOfBucket(kBucket_pt bucket, int i)
STATIC_VAR omBin kBucket_bin
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
static int LOG4(int v)
Some internal stuff.
number kBucketPolyRed(kBucket_pt bucket, poly p1, int l1, poly spNoether)
void kBucket_Plus_mm_Mult_pp(kBucket_pt bucket, poly m, poly p, int l)
Bpoly == Bpoly + m*p; where m is a monom Does not destroy p and m assume (l <= 0 || pLength(p) == l)
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
void kBucketPolyRedNF(kBucket_pt bucket, poly p1, int l1, poly spNoether)
static unsigned int pLogLength(unsigned int l)
const poly kBucketGetLm(kBucket_pt bucket)
void kBucketSimpleContent(kBucket_pt bucket)
void kBucketSetLm(kBucket_pt bucket, poly lm)
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...
BOOLEAN kBucketIsCleared(kBucket_pt bucket)
#define MAX_BUCKET
Bucket definition (should be no one elses business, though)
int dReportError(const char *fmt,...)
#define p_SetCoeff0(p, n, r)
#define pFalseReturn(cond)
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
The main handler for Singular numbers which are suitable for Singular polynomials.
number ndGcd(number, number, const coeffs r)
#define omCheckAddrBin(addr, bin)
#define omFreeBin(addr, bin)
#define omGetSpecBin(size)
void p_Normalize(poly p, const ring r)
poly p_NSet(number n, const ring r)
returns the poly representing the number n, destroys n
number p_InitContent(poly ph, const ring r)
static int pLength(poly a)
static poly p_Add_q(poly p, poly q, const ring r)
static void p_LmDelete(poly p, const ring r)
#define p_LmEqual(p1, p2, r)
static void p_SetCompP(poly p, int i, ring r)
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
static void p_ExpVectorSub(poly p1, poly p2, const ring r)
static void p_Setm(poly p, const ring r)
static number p_SetCoeff(poly p, number n, ring r)
static int p_LmCmp(poly p, poly q, const ring r)
static BOOLEAN p_IsConstant(const poly p, const ring r)
static BOOLEAN p_DivisibleBy(poly a, poly b, const ring r)
static poly p_Mult_nn(poly p, number n, const ring r)
static void p_Delete(poly *p, const ring r)
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)
static poly p_Plus_mm_Mult_qq(poly p, poly m, poly q, int &lp, int lq, const ring r)
#define __p_Mult_nn(p, n, r)
void StringSetS(const char *st)
void StringAppendS(const char *st)
void PrintS(const char *s)
static BOOLEAN rField_is_Zp(const ring r)
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
static BOOLEAN rField_is_Domain(const ring r)
static char const ** rParameter(const ring r)
(r->cf->parameter)
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...
#define rField_is_Ring(R)
int p_mFirstVblock(poly p, const ring ri)
void k_SplitFrame(poly &m1, poly &m2, int at, const ring r)
static int SI_LOG2(int v)