1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: polys-impl.cc,v 1.3 2008-07-25 14:37:55 Singular Exp $ */ |
---|
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 | #include "mod2.h" |
---|
22 | |
---|
23 | #include "omalloc.h" |
---|
24 | #ifdef PDEBUG |
---|
25 | #undef NO_INLINE3 |
---|
26 | #define NO_INLINE3 |
---|
27 | #endif |
---|
28 | #include "polys-impl.h" |
---|
29 | |
---|
30 | #include "structs.h" |
---|
31 | #include "febase.h" |
---|
32 | #include "numbers.h" |
---|
33 | #include "polys.h" |
---|
34 | #include "ring.h" |
---|
35 | #include "p_Procs.h" |
---|
36 | #include "dError.h" |
---|
37 | |
---|
38 | #ifdef PDEBUG |
---|
39 | int pDBsyzComp=0; |
---|
40 | #endif |
---|
41 | |
---|
42 | /*************************************************************** |
---|
43 | * |
---|
44 | * Storage Managament Routines |
---|
45 | * |
---|
46 | ***************************************************************/ |
---|
47 | |
---|
48 | |
---|
49 | void ppDelete(poly* p, const ring rg) |
---|
50 | { |
---|
51 | ring origRing = currRing; |
---|
52 | rChangeCurrRing(rg); |
---|
53 | pDelete(p); |
---|
54 | rChangeCurrRing(origRing); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | poly pHeadProc(poly p) |
---|
59 | { |
---|
60 | return pHead(p); |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | static inline unsigned long GetBitFields(Exponent_t e, |
---|
65 | unsigned int s, unsigned int n) |
---|
66 | { |
---|
67 | #define Sy_bit_L(x) (((unsigned long)1L)<<(x)) |
---|
68 | unsigned int i = 0; |
---|
69 | unsigned long ev = 0L; |
---|
70 | assume(n > 0 && s < BIT_SIZEOF_LONG); |
---|
71 | do |
---|
72 | { |
---|
73 | assume(s+i < BIT_SIZEOF_LONG); |
---|
74 | if (e > (Exponent_t) i) ev |= Sy_bit_L(s+i); |
---|
75 | else break; |
---|
76 | i++; |
---|
77 | } |
---|
78 | while (i < n); |
---|
79 | return ev; |
---|
80 | } |
---|
81 | |
---|
82 | // Short Exponent Vectors are used for fast divisibility tests |
---|
83 | // ShortExpVectors "squeeze" an exponent vector into one word as follows: |
---|
84 | // Let n = BIT_SIZEOF_LONG / pVariables. |
---|
85 | // If n == 0 (i.e. pVariables > BIT_SIZE_OF_LONG), let m == the number |
---|
86 | // of non-zero exponents. If (m>BIT_SIZEOF_LONG), then sev = ~0, else |
---|
87 | // first m bits of sev are set to 1. |
---|
88 | // Otherwise (i.e. pVariables <= BIT_SIZE_OF_LONG) |
---|
89 | // represented by a bit-field of length n (resp. n+1 for some |
---|
90 | // exponents). If the value of an exponent is greater or equal to n, then |
---|
91 | // all of its respective n bits are set to 1. If the value of an exponent |
---|
92 | // is smaller than n, say m, then only the first m bits of the respective |
---|
93 | // n bits are set to 1, the others are set to 0. |
---|
94 | // This way, we have: |
---|
95 | // exp1 / exp2 ==> (ev1 & ~ev2) == 0, i.e., |
---|
96 | // if (ev1 & ~ev2) then exp1 does not divide exp2 |
---|
97 | unsigned long p_GetShortExpVector(poly p, ring r) |
---|
98 | { |
---|
99 | assume(p != NULL); |
---|
100 | if (p == NULL) return 0; |
---|
101 | unsigned long ev = 0; // short exponent vector |
---|
102 | unsigned int n = BIT_SIZEOF_LONG / r->N; // number of bits per exp |
---|
103 | unsigned int m1; // highest bit which is filled with (n+1) |
---|
104 | unsigned int i = 0, j=1; |
---|
105 | |
---|
106 | if (n == 0) |
---|
107 | { |
---|
108 | if (r->N <2*BIT_SIZEOF_LONG) |
---|
109 | { |
---|
110 | n=1; |
---|
111 | m1=0; |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | for (; j<=(unsigned long) r->N; j++) |
---|
116 | { |
---|
117 | if (p_GetExp(p,j,r) > 0) i++; |
---|
118 | if (i == BIT_SIZEOF_LONG) break; |
---|
119 | } |
---|
120 | if (i>0) |
---|
121 | ev = ~((unsigned long)0) >> ((unsigned long) (BIT_SIZEOF_LONG - i)); |
---|
122 | return ev; |
---|
123 | } |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | m1 = (n+1)*(BIT_SIZEOF_LONG - n*r->N); |
---|
128 | } |
---|
129 | |
---|
130 | n++; |
---|
131 | while (i<m1) |
---|
132 | { |
---|
133 | ev |= GetBitFields(p_GetExp(p, j,r), i, n); |
---|
134 | i += n; |
---|
135 | j++; |
---|
136 | } |
---|
137 | |
---|
138 | n--; |
---|
139 | while (i<BIT_SIZEOF_LONG) |
---|
140 | { |
---|
141 | ev |= GetBitFields(p_GetExp(p, j,r), i, n); |
---|
142 | i += n; |
---|
143 | j++; |
---|
144 | } |
---|
145 | return ev; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | int rComp0_Func(poly p1,poly p2) |
---|
150 | { |
---|
151 | int i; |
---|
152 | for(i=0; i< currRing->CmpL_Size;i++) |
---|
153 | { |
---|
154 | if (p1->exp[i] != p2->exp[i]) |
---|
155 | { |
---|
156 | if (p1->exp[i] > p2->exp[i]) |
---|
157 | return currRing->ordsgn[i]; |
---|
158 | else |
---|
159 | return -currRing->ordsgn[i]; |
---|
160 | } |
---|
161 | } |
---|
162 | return 0; |
---|
163 | } |
---|
164 | |
---|
165 | #ifdef PDEBUG |
---|
166 | int rComp0(poly p1,poly p2) |
---|
167 | { |
---|
168 | int i; |
---|
169 | for(i=0; i<currRing->CmpL_Size;i++) |
---|
170 | { |
---|
171 | if (p1->exp[i] != p2->exp[i]) |
---|
172 | { |
---|
173 | if (p1->exp[i] > p2->exp[i]) |
---|
174 | return currRing->ordsgn[i]; |
---|
175 | else |
---|
176 | return -currRing->ordsgn[i]; |
---|
177 | } |
---|
178 | } |
---|
179 | return 0; |
---|
180 | } |
---|
181 | #endif |
---|
182 | |
---|
183 | #endif // POLYS_IMPL_CC |
---|