1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | |
---|
6 | /*************************************************************** |
---|
7 | * |
---|
8 | * File: polys-impl.cc |
---|
9 | * Purpose: low-level procuders for polys. |
---|
10 | * |
---|
11 | * If you touch anything here, you better know what you are doing. |
---|
12 | * What is here should not be used directly from other routines -- the |
---|
13 | * encapsulations in polys.[h,cc] should be used, instead. |
---|
14 | * |
---|
15 | ***************************************************************/ |
---|
16 | #ifndef POLYS_IMPL_CC |
---|
17 | #define POLYS_IMPL_CC |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | |
---|
22 | #include "config.h" |
---|
23 | |
---|
24 | #include <omalloc/omalloc.h> |
---|
25 | #include <misc/auxiliary.h> |
---|
26 | |
---|
27 | #ifdef PDEBUG |
---|
28 | #undef NO_INLINE3 |
---|
29 | #define NO_INLINE3 |
---|
30 | #endif |
---|
31 | #include <polys/monomials/polys-impl.h> |
---|
32 | |
---|
33 | #include <polys/monomials/ring.h> |
---|
34 | #include <reporter/reporter.h> |
---|
35 | #include <coeffs/numbers.h> |
---|
36 | #include <polys/monomials/ring.h> |
---|
37 | #include <polys/monomials/p_polys.h> |
---|
38 | #include <polys/templates/p_Procs.h> |
---|
39 | #include <reporter/reporter.h> |
---|
40 | |
---|
41 | #ifdef PDEBUG |
---|
42 | int pDBsyzComp=0; |
---|
43 | #endif |
---|
44 | |
---|
45 | /*************************************************************** |
---|
46 | * |
---|
47 | * Storage Managament Routines |
---|
48 | * |
---|
49 | ***************************************************************/ |
---|
50 | |
---|
51 | |
---|
52 | static inline unsigned long GetBitFields(long e, |
---|
53 | unsigned int s, unsigned int n) |
---|
54 | { |
---|
55 | #define Sy_bit_L(x) (((unsigned long)1L)<<(x)) |
---|
56 | unsigned int i = 0; |
---|
57 | unsigned long ev = 0L; |
---|
58 | assume(n > 0 && s < BIT_SIZEOF_LONG); |
---|
59 | do |
---|
60 | { |
---|
61 | assume(s+i < BIT_SIZEOF_LONG); |
---|
62 | if (e > (long) i) ev |= Sy_bit_L(s+i); |
---|
63 | else break; |
---|
64 | i++; |
---|
65 | } |
---|
66 | while (i < n); |
---|
67 | return ev; |
---|
68 | } |
---|
69 | |
---|
70 | // Short Exponent Vectors are used for fast divisibility tests |
---|
71 | // ShortExpVectors "squeeze" an exponent vector into one word as follows: |
---|
72 | // Let n = BIT_SIZEOF_LONG / pVariables. |
---|
73 | // If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number |
---|
74 | // of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else |
---|
75 | // first m bits of sev are set to 1. |
---|
76 | // Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG) |
---|
77 | // represented by a bit-field of length n (resp. n+1 for some |
---|
78 | // exponents). If the value of an exponent is greater or equal to n, then |
---|
79 | // all of its respective n bits are set to 1. If the value of an exponent |
---|
80 | // is smaller than n, say m, then only the first m bits of the respective |
---|
81 | // n bits are set to 1, the others are set to 0. |
---|
82 | // This way, we have: |
---|
83 | // exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e., |
---|
84 | // if (ev1 & ~ev2) then exp1 does not divide exp2 |
---|
85 | unsigned long p_GetShortExpVector(poly p, ring r) |
---|
86 | { |
---|
87 | assume(p != NULL); |
---|
88 | if (p == NULL) return 0; |
---|
89 | unsigned long ev = 0; // short exponent vector |
---|
90 | unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp |
---|
91 | unsigned int m1; // highest bit which is filled with (n+1) |
---|
92 | unsigned int i = 0, j=1; |
---|
93 | |
---|
94 | if (n == 0) |
---|
95 | { |
---|
96 | if (r->N <2*BIT_SIZEOF_LONG) |
---|
97 | { |
---|
98 | n=1; |
---|
99 | m1=0; |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | for (; j<=(unsigned long) r->N; j++) |
---|
104 | { |
---|
105 | if (p_GetExp(p,j,r) > 0) i++; |
---|
106 | if (i == BIT_SIZEOF_LONG) break; |
---|
107 | } |
---|
108 | if (i>0) |
---|
109 | ev = ~((unsigned long)0) >> ((unsigned long) (BIT_SIZEOF_LONG - i)); |
---|
110 | return ev; |
---|
111 | } |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N); |
---|
116 | } |
---|
117 | |
---|
118 | n++; |
---|
119 | while (i<m1) |
---|
120 | { |
---|
121 | ev |= GetBitFields(p_GetExp(p, j,r), i, n); |
---|
122 | i += n; |
---|
123 | j++; |
---|
124 | } |
---|
125 | |
---|
126 | n--; |
---|
127 | while (i<BIT_SIZEOF_LONG) |
---|
128 | { |
---|
129 | ev |= GetBitFields(p_GetExp(p, j,r), i, n); |
---|
130 | i += n; |
---|
131 | j++; |
---|
132 | } |
---|
133 | return ev; |
---|
134 | } |
---|
135 | |
---|
136 | #endif // POLYS_IMPL_CC |
---|