1 | #ifndef RING_H |
---|
2 | #define RING_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* |
---|
7 | * ABSTRACT - the interpreter related ring operations |
---|
8 | */ |
---|
9 | /* $Id: ring.h,v 1.25 2008-02-01 13:46:08 Singular Exp $ */ |
---|
10 | |
---|
11 | /* includes */ |
---|
12 | #include "structs.h" |
---|
13 | #include "structs.h" // we need ABS |
---|
14 | #include "polys-impl.h" |
---|
15 | |
---|
16 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
17 | |
---|
18 | |
---|
19 | void rChangeCurrRing(ring r); |
---|
20 | void rSetHdl(idhdl h); |
---|
21 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord); |
---|
22 | idhdl rDefault(char *s); |
---|
23 | ring rDefault(int ch, int N, char **n); |
---|
24 | #define rIsRingVar(A) r_IsRingVar(A,currRing) |
---|
25 | int r_IsRingVar(const char *n, ring r); |
---|
26 | void rWrite(ring r); |
---|
27 | void rKill(idhdl h); |
---|
28 | void rKill(ring r); |
---|
29 | ring rCopy(ring r); |
---|
30 | ring rCopy0(ring r, BOOLEAN copy_qideal = TRUE, BOOLEAN copy_ordering = TRUE); |
---|
31 | void rNameCheck(ring R); |
---|
32 | ring rOpposite(ring r); |
---|
33 | ring rEnvelope(ring r); |
---|
34 | |
---|
35 | // we must always have this test! |
---|
36 | inline bool rIsPluralRing(const ring r) |
---|
37 | { |
---|
38 | #ifdef HAVE_PLURAL |
---|
39 | return (r != NULL) && (r->nc != NULL) && (r->nc->type != nc_error); |
---|
40 | #else |
---|
41 | return false; |
---|
42 | #endif |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | #ifdef PDEBUG |
---|
49 | #define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l) |
---|
50 | #define rGetSComps(c,s,l) rDBGetSComps(c,s,l) |
---|
51 | void rDBChangeSComps(int* currComponents, |
---|
52 | long* currShiftedComponents, |
---|
53 | int length, |
---|
54 | ring r = currRing); |
---|
55 | void rDBGetSComps(int** currComponents, |
---|
56 | long** currShiftedComponents, |
---|
57 | int *length, |
---|
58 | ring r = currRing); |
---|
59 | #else |
---|
60 | #define rChangeSComps(c,s,l) rNChangeSComps(c,s) |
---|
61 | #define rGetSComps(c,s,l) rNGetSComps(c,s) |
---|
62 | #endif |
---|
63 | |
---|
64 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing); |
---|
65 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing); |
---|
66 | |
---|
67 | idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
68 | idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n); |
---|
69 | const char * rSimpleOrdStr(int ord); |
---|
70 | int rOrderName(char * ordername); |
---|
71 | char * rOrdStr(ring r); |
---|
72 | char * rVarStr(ring r); |
---|
73 | char * rCharStr(ring r); |
---|
74 | char * rString(ring r); |
---|
75 | int rChar(ring r=currRing); |
---|
76 | #define rPar(r) (r->P) |
---|
77 | #define rVar(r) (r->N) |
---|
78 | char * rParStr(ring r); |
---|
79 | int rIsExtension(ring r); |
---|
80 | int rIsExtension(); |
---|
81 | int rSum(ring r1, ring r2, ring &sum); |
---|
82 | |
---|
83 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1); |
---|
84 | BOOLEAN rSamePolyRep(ring r1, ring r2); |
---|
85 | void rUnComplete(ring r); |
---|
86 | |
---|
87 | #define rInternalChar(r) ((r)->ch) |
---|
88 | |
---|
89 | BOOLEAN rRing_is_Homog(ring r=currRing); |
---|
90 | BOOLEAN rRing_has_CompLastBlock(ring r=currRing); |
---|
91 | |
---|
92 | #ifdef HAVE_RING2TOM |
---|
93 | inline BOOLEAN rField_is_Ring_2toM(ring r=currRing) |
---|
94 | { return (r->ringtype == 1); } |
---|
95 | #endif |
---|
96 | |
---|
97 | #ifdef HAVE_RINGMODN |
---|
98 | inline BOOLEAN rField_is_Ring_ModN(ring r=currRing) |
---|
99 | { return (r->ringtype == 2); } |
---|
100 | |
---|
101 | inline BOOLEAN rField_is_Ring_PtoM(ring r=currRing) |
---|
102 | { return (r->ringtype == 3); } |
---|
103 | #endif |
---|
104 | |
---|
105 | #ifdef HAVE_RINGZ |
---|
106 | inline BOOLEAN rField_is_Ring_Z(ring r=currRing) |
---|
107 | { return (r->ringtype == 4); } |
---|
108 | #endif |
---|
109 | |
---|
110 | #ifdef HAVE_RINGS |
---|
111 | inline BOOLEAN rField_is_Ring(ring r=currRing) |
---|
112 | { return (r->ringtype != 0); } |
---|
113 | |
---|
114 | inline BOOLEAN rField_is_Domain(ring r=currRing) |
---|
115 | { return (r->ringtype == 4 || r->ringtype == 0); } |
---|
116 | |
---|
117 | inline BOOLEAN rField_has_Units(ring r=currRing) |
---|
118 | { return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); } |
---|
119 | #endif |
---|
120 | |
---|
121 | #ifdef HAVE_RINGS |
---|
122 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
123 | { return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); } |
---|
124 | |
---|
125 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
126 | { return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
127 | |
---|
128 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
129 | { return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); } |
---|
130 | |
---|
131 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
132 | { return (r->ringtype == 0) && (r->ch == -1); } |
---|
133 | |
---|
134 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
135 | { |
---|
136 | if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH)) |
---|
137 | return (r->ringtype == 0) && (r->parameter==NULL); |
---|
138 | return FALSE; |
---|
139 | } |
---|
140 | |
---|
141 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
142 | { return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); } |
---|
143 | |
---|
144 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
145 | { return (r->ringtype == 0) && (r->ch == q); } |
---|
146 | |
---|
147 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
148 | { return (r->ringtype == 0) && (r->ch < -1); } |
---|
149 | |
---|
150 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
151 | { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
152 | |
---|
153 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
154 | { return (r->ringtype == 0) && (r->ch == 1); } |
---|
155 | |
---|
156 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
157 | { |
---|
158 | if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH)) |
---|
159 | return (r->ringtype == 0) && (r->parameter==NULL); |
---|
160 | return FALSE; |
---|
161 | } |
---|
162 | |
---|
163 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
164 | { |
---|
165 | if (rField_is_numeric(r)) |
---|
166 | return (r->ringtype == 0) && (r->parameter!=NULL); |
---|
167 | return FALSE; |
---|
168 | } |
---|
169 | #else |
---|
170 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
171 | { return (r->ch > 1) && (r->parameter==NULL); } |
---|
172 | |
---|
173 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
174 | { return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
175 | |
---|
176 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
177 | { return (r->ch == 0) && (r->parameter==NULL); } |
---|
178 | |
---|
179 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
180 | { return (r->ch == -1); } |
---|
181 | |
---|
182 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
183 | { |
---|
184 | if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH)) |
---|
185 | return (r->parameter==NULL); |
---|
186 | return FALSE; |
---|
187 | } |
---|
188 | |
---|
189 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
190 | { return (r->ch > 1) && (r->parameter!=NULL); } |
---|
191 | |
---|
192 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
193 | { return (r->ch == q); } |
---|
194 | |
---|
195 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
196 | { return (r->ch < -1); } |
---|
197 | |
---|
198 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
199 | { return (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
200 | |
---|
201 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
202 | { return (r->ch == 1); } |
---|
203 | |
---|
204 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
205 | { |
---|
206 | if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH)) |
---|
207 | return (r->parameter==NULL); |
---|
208 | return FALSE; |
---|
209 | } |
---|
210 | |
---|
211 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
212 | { |
---|
213 | if (rField_is_numeric(r)) |
---|
214 | return (r->parameter!=NULL); |
---|
215 | return FALSE; |
---|
216 | } |
---|
217 | #endif |
---|
218 | |
---|
219 | inline BOOLEAN rField_has_simple_inverse(ring r=currRing) |
---|
220 | /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
221 | #ifdef HAVE_RINGS |
---|
222 | { return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/ |
---|
223 | #else |
---|
224 | { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
225 | #endif |
---|
226 | |
---|
227 | inline BOOLEAN rField_has_simple_Alloc(ring r=currRing) |
---|
228 | { return (rField_is_Zp(r) |
---|
229 | || rField_is_GF(r) |
---|
230 | #ifdef HAVE_RING2TOM |
---|
231 | || rField_is_Ring_2toM(r) |
---|
232 | #endif |
---|
233 | #ifdef HAVE_RINGMODN |
---|
234 | || rField_is_Ring_ModN(r) |
---|
235 | #endif |
---|
236 | || rField_is_R(r)); } |
---|
237 | |
---|
238 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
239 | inline BOOLEAN rField_is_Extension(ring r=currRing) |
---|
240 | { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
241 | |
---|
242 | n_coeffType rFieldType(ring r); |
---|
243 | |
---|
244 | // this needs to be called whenever a new ring is created: new fields |
---|
245 | // in ring are created (like VarOffset), unless they already exist |
---|
246 | // with force == 1, new fields are _always_ created (overwritten), |
---|
247 | // even if they exist |
---|
248 | BOOLEAN rComplete(ring r, int force = 0); |
---|
249 | // use this to free fields created by rComplete |
---|
250 | |
---|
251 | BOOLEAN nc_rComplete(ring src, ring dest); |
---|
252 | |
---|
253 | void rUnComplete(ring r); |
---|
254 | inline int rBlocks(ring r) |
---|
255 | { |
---|
256 | int i=0; |
---|
257 | while (r->order[i]!=0) i++; |
---|
258 | return i+1; |
---|
259 | } |
---|
260 | |
---|
261 | // misc things |
---|
262 | inline char* rRingVar(short i) |
---|
263 | { |
---|
264 | return currRing->names[i]; |
---|
265 | } |
---|
266 | inline char* rRingVar(short i, ring r) |
---|
267 | { |
---|
268 | return r->names[i]; |
---|
269 | } |
---|
270 | inline BOOLEAN rShortOut(ring r) |
---|
271 | { |
---|
272 | return (r->ShortOut); |
---|
273 | } |
---|
274 | |
---|
275 | // order stuff |
---|
276 | typedef enum rRingOrder_t |
---|
277 | { |
---|
278 | ringorder_no = 0, |
---|
279 | ringorder_a, |
---|
280 | ringorder_a64, // for int64 weights |
---|
281 | ringorder_c, |
---|
282 | ringorder_C, |
---|
283 | ringorder_M, |
---|
284 | ringorder_S, |
---|
285 | ringorder_s, |
---|
286 | ringorder_lp, |
---|
287 | ringorder_dp, |
---|
288 | ringorder_rp, |
---|
289 | ringorder_Dp, |
---|
290 | ringorder_wp, |
---|
291 | ringorder_Wp, |
---|
292 | ringorder_ls, |
---|
293 | ringorder_ds, |
---|
294 | ringorder_Ds, |
---|
295 | ringorder_ws, |
---|
296 | ringorder_Ws, |
---|
297 | ringorder_L, |
---|
298 | // the following are only used internally |
---|
299 | ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it |
---|
300 | ringorder_rs, |
---|
301 | ringorder_unspec |
---|
302 | } rRingOrder_t; |
---|
303 | |
---|
304 | typedef enum rOrderType_t |
---|
305 | { |
---|
306 | rOrderType_General = 0, // non-simple ordering as specified by currRing |
---|
307 | rOrderType_CompExp, // simple ordering, component has priority |
---|
308 | rOrderType_ExpComp, // simple ordering, exponent vector has priority |
---|
309 | // component not compatible with exp-vector order |
---|
310 | rOrderType_Exp, // simple ordering, exponent vector has priority |
---|
311 | // component is compatible with exp-vector order |
---|
312 | rOrderType_Syz, // syzygy ordering |
---|
313 | rOrderType_Schreyer, // Schreyer ordering |
---|
314 | rOrderType_Syz2dpc, // syzcomp2dpc |
---|
315 | rOrderType_ExpNoComp // simple ordering, differences in component are |
---|
316 | // not considered |
---|
317 | } rOrderType_t; |
---|
318 | |
---|
319 | inline BOOLEAN rIsSyzIndexRing(ring r) |
---|
320 | { return r->order[0] == ringorder_s;} |
---|
321 | |
---|
322 | inline int rGetCurrSyzLimit(ring r = currRing) |
---|
323 | { return (r->order[0] == ringorder_s ? |
---|
324 | r->typ[0].data.syz.limit : 0);} |
---|
325 | |
---|
326 | // Ring Manipulations |
---|
327 | ring rAssure_HasComp(ring r); |
---|
328 | ring rCurrRingAssure_SyzComp(); |
---|
329 | void rSetSyzComp(int k); |
---|
330 | ring rCurrRingAssure_dp_S(); |
---|
331 | ring rCurrRingAssure_dp_C(); |
---|
332 | ring rCurrRingAssure_C_dp(); |
---|
333 | // makes sure that c/C ordering is last ordering |
---|
334 | ring rCurrRingAssure_CompLastBlock(); |
---|
335 | // makes sure that c/C ordering is last ordering and SyzIndex is first |
---|
336 | ring rCurrRingAssure_SyzComp_CompLastBlock(); |
---|
337 | |
---|
338 | // return the max-comonent wchich has syzIndex i |
---|
339 | // Assume: i<= syzIndex_limit |
---|
340 | int rGetMaxSyzComp(int i); |
---|
341 | |
---|
342 | BOOLEAN rHasSimpleOrder(ring r); |
---|
343 | // returns TRUE, if simple lp or ls ordering |
---|
344 | BOOLEAN rHasSimpleLexOrder(ring r); |
---|
345 | // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */ |
---|
346 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing); |
---|
347 | // return TRUE if p_SetComp requires p_Setm |
---|
348 | BOOLEAN rOrd_SetCompRequiresSetm(ring r); |
---|
349 | rOrderType_t rGetOrderType(ring r); |
---|
350 | /* returns TRUE if var(i) belongs to p-block */ |
---|
351 | BOOLEAN rIsPolyVar(int i, ring r = currRing); |
---|
352 | |
---|
353 | inline BOOLEAN rOrd_is_Comp_dp(ring r) |
---|
354 | { |
---|
355 | return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) && |
---|
356 | r->order[1] == ringorder_dp && |
---|
357 | r->order[2] == 0); |
---|
358 | } |
---|
359 | |
---|
360 | #ifdef RDEBUG |
---|
361 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
362 | extern BOOLEAN rDBTest(ring r, char* fn, int l); |
---|
363 | #else |
---|
364 | #define rTest(r) |
---|
365 | #endif |
---|
366 | |
---|
367 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
368 | BOOLEAN omit_comp, |
---|
369 | unsigned long exp_limit); |
---|
370 | // construct Wp, C ring |
---|
371 | ring rModifyRing_Wp(ring r, int* weights); |
---|
372 | void rModify_a_to_A(ring r); |
---|
373 | |
---|
374 | void rKillModifiedRing(ring r); |
---|
375 | // also frees weights |
---|
376 | void rKillModified_Wp_Ring(ring r); |
---|
377 | |
---|
378 | ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple); |
---|
379 | void rKillModifiedRing_Simple(ring r); |
---|
380 | |
---|
381 | void rDebugPrint(ring r); |
---|
382 | void pDebugPrint(poly p); |
---|
383 | |
---|
384 | int64 * rGetWeightVec(ring r); |
---|
385 | void rSetWeightVec(ring r, int64 *wv); |
---|
386 | |
---|
387 | lists rDecompose(const ring r); |
---|
388 | ring rCompose(const lists L); |
---|
389 | ///////////////////////////// |
---|
390 | // Auxillary functions |
---|
391 | // |
---|
392 | |
---|
393 | BOOLEAN rCheckIV(intvec *iv); |
---|
394 | int rTypeOfMatrixOrder(intvec * order); |
---|
395 | void rDelete(ring r); |
---|
396 | |
---|
397 | #endif |
---|