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