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 <omalloc/omalloc.h> |
---|
13 | #include <misc/auxiliary.h> |
---|
14 | #include <coeffs/coeffs.h> |
---|
15 | //#include <polys/monomials/polys-impl.h> |
---|
16 | // |
---|
17 | |
---|
18 | /* constants */ |
---|
19 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
20 | |
---|
21 | /* forward declaration of types */ |
---|
22 | class idrec; |
---|
23 | typedef idrec * idhdl; |
---|
24 | struct spolyrec; |
---|
25 | typedef struct spolyrec polyrec; |
---|
26 | typedef polyrec * poly; |
---|
27 | struct ip_sring; |
---|
28 | typedef struct ip_sring * ring; |
---|
29 | class intvec; |
---|
30 | class int64vec; |
---|
31 | struct p_Procs_s; |
---|
32 | typedef struct p_Procs_s p_Procs_s; |
---|
33 | //class slists; |
---|
34 | //typedef slists * lists; |
---|
35 | class kBucket; |
---|
36 | typedef kBucket* kBucket_pt; |
---|
37 | |
---|
38 | struct sip_sideal; |
---|
39 | typedef struct sip_sideal * ideal; |
---|
40 | |
---|
41 | struct sip_smap; |
---|
42 | typedef struct sip_smap * map; |
---|
43 | |
---|
44 | |
---|
45 | #if SIZEOF_LONG == 4 |
---|
46 | typedef long long int64; |
---|
47 | #elif SIZEOF_LONG == 8 |
---|
48 | typedef long int64; |
---|
49 | #else |
---|
50 | #error int64 undefined |
---|
51 | #endif |
---|
52 | |
---|
53 | /* the function pointer types */ |
---|
54 | |
---|
55 | typedef long (*pLDegProc)(poly p, int *length, ring r); |
---|
56 | typedef long (*pFDegProc)(poly p, ring r); |
---|
57 | typedef void (*p_SetmProc)(poly p, const ring r); |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | typedef enum |
---|
62 | { |
---|
63 | ro_dp, // ordering is a degree ordering |
---|
64 | ro_wp, // ordering is a weighted degree ordering |
---|
65 | ro_wp64, // ordering is a weighted64 degree ordering |
---|
66 | ro_wp_neg, // ordering is a weighted degree ordering |
---|
67 | // with possibly negative weights |
---|
68 | ro_cp, // ordering duplicates variables |
---|
69 | ro_syzcomp, // ordering indicates "subset" of component number (ringorder_S) |
---|
70 | ro_syz, // ordering with component number >syzcomp is lower (ringorder_s) |
---|
71 | ro_isTemp, ro_is, // Induced Syzygy (Schreyer) ordering (and prefix data placeholder dummy) (ringorder_IS) |
---|
72 | ro_none |
---|
73 | } |
---|
74 | ro_typ; |
---|
75 | |
---|
76 | // ordering is a degree ordering |
---|
77 | struct sro_dp |
---|
78 | { |
---|
79 | short place; // where degree is stored (in L): |
---|
80 | short start; // bounds of ordering (in E): |
---|
81 | short end; |
---|
82 | }; |
---|
83 | typedef struct sro_dp sro_dp; |
---|
84 | |
---|
85 | // ordering is a weighted degree ordering |
---|
86 | struct sro_wp |
---|
87 | { |
---|
88 | short place; // where weighted degree is stored (in L) |
---|
89 | short start; // bounds of ordering (in E) |
---|
90 | short end; |
---|
91 | int *weights; // pointers into wvhdl field |
---|
92 | }; |
---|
93 | typedef struct sro_wp sro_wp; |
---|
94 | |
---|
95 | // ordering is a weighted degree ordering |
---|
96 | struct sro_wp64 |
---|
97 | { |
---|
98 | short place; // where weighted degree is stored (in L) |
---|
99 | short start; // bounds of ordering (in E) |
---|
100 | short end; |
---|
101 | int64 *weights64; // pointers into wvhdl field |
---|
102 | }; |
---|
103 | typedef struct sro_wp64 sro_wp64; |
---|
104 | |
---|
105 | // ordering duplicates variables |
---|
106 | struct sro_cp |
---|
107 | { |
---|
108 | short place; // where start is copied to (in E) |
---|
109 | short start; // bounds of sources of copied variables (in E) |
---|
110 | short end; |
---|
111 | }; |
---|
112 | typedef struct sro_cp sro_cp; |
---|
113 | |
---|
114 | // ordering indicates "subset" of component number |
---|
115 | struct sro_syzcomp |
---|
116 | { |
---|
117 | short place; // where the index is stored (in L) |
---|
118 | long *ShiftedComponents; // pointer into index field |
---|
119 | int* Components; |
---|
120 | #ifdef PDEBUG |
---|
121 | long length; |
---|
122 | #endif |
---|
123 | }; |
---|
124 | typedef struct sro_syzcomp sro_syzcomp; |
---|
125 | |
---|
126 | // ordering with component number >syzcomp is lower |
---|
127 | struct sro_syz |
---|
128 | { |
---|
129 | short place; // where the index is stored (in L) |
---|
130 | int limit; // syzcomp |
---|
131 | int* syz_index; // mapping Component -> SyzIndex for Comp <= limit |
---|
132 | int curr_index; // SyzIndex for Component > limit |
---|
133 | }; |
---|
134 | |
---|
135 | typedef struct sro_syz sro_syz; |
---|
136 | // Induced Syzygy (Schreyer) ordering is built inductively as follows: |
---|
137 | // we look for changes made by ordering blocks which are between prefix/suffix markers: |
---|
138 | // that is: which variables where placed by them and where (judging by v) |
---|
139 | |
---|
140 | // due to prefix/suffix nature we need some placeholder: |
---|
141 | // prefix stores here initial state |
---|
142 | // suffix cleares this up |
---|
143 | struct sro_ISTemp |
---|
144 | { |
---|
145 | short start; // 1st member SHOULD be short "place" |
---|
146 | int suffixpos; |
---|
147 | int* pVarOffset; // copy! |
---|
148 | }; |
---|
149 | |
---|
150 | // So this is the actuall thing! |
---|
151 | // suffix uses last sro_ISTemp (cleares it up afterwards) and |
---|
152 | // creates this block |
---|
153 | struct sro_IS |
---|
154 | { |
---|
155 | short start, end; // which part of L we want to want to update... |
---|
156 | int* pVarOffset; // same as prefix! |
---|
157 | |
---|
158 | int limit; // first referenced component |
---|
159 | |
---|
160 | // reference poly set?? // Should it be owned by ring?!!! |
---|
161 | ideal F; // reference leading (module)-monomials set. owned by ring... |
---|
162 | const intvec* componentWeights; // component weights! owned by ring... |
---|
163 | }; |
---|
164 | |
---|
165 | typedef struct sro_IS sro_IS; |
---|
166 | typedef struct sro_ISTemp sro_ISTemp; |
---|
167 | |
---|
168 | struct sro_ord |
---|
169 | { |
---|
170 | ro_typ ord_typ; |
---|
171 | int order_index; // comes from r->order[order_index] |
---|
172 | union |
---|
173 | { |
---|
174 | sro_dp dp; |
---|
175 | sro_wp wp; |
---|
176 | sro_wp64 wp64; |
---|
177 | sro_cp cp; |
---|
178 | sro_syzcomp syzcomp; |
---|
179 | sro_syz syz; |
---|
180 | sro_IS is; |
---|
181 | sro_ISTemp isTemp; |
---|
182 | } data; |
---|
183 | }; |
---|
184 | |
---|
185 | #ifdef HAVE_PLURAL |
---|
186 | struct nc_struct; |
---|
187 | typedef struct nc_struct nc_struct; |
---|
188 | #endif |
---|
189 | |
---|
190 | struct ip_sring |
---|
191 | { |
---|
192 | // each entry must have a description and a procedure defining it, |
---|
193 | // general ordering: pointer/structs, long, int, short, BOOLEAN/char/enum |
---|
194 | // general defining procedures: rInit, rComplete, interpreter, ?? |
---|
195 | idhdl idroot; /* local objects , interpreter*/ |
---|
196 | int* order; /* array of orderings, rInit/rSleftvOrdering2Ordering */ |
---|
197 | int* block0; /* starting pos., rInit/rSleftvOrdering2Ordering*/ |
---|
198 | int* block1; /* ending pos., rInit/rSleftvOrdering2Ordering*/ |
---|
199 | // char** parameter; /* names of parameters, rInit */ |
---|
200 | // number minpoly; /* replaced by minideal->m[0] */ |
---|
201 | ideal minideal; /* for Q_a/Zp_a, rInit; |
---|
202 | for a start, we assume that there is either no |
---|
203 | or exactly one generator in minideal, playing |
---|
204 | the role of the former minpoly; minideal may |
---|
205 | also be NULL which coincides with the |
---|
206 | no-generator-case */ |
---|
207 | int** wvhdl; /* array of weight vectors, rInit/rSleftvOrdering2Ordering */ |
---|
208 | char ** names; /* array of variable names, rInit */ |
---|
209 | |
---|
210 | // what follows below here should be set by rComplete, _only_ |
---|
211 | long *ordsgn; /* array of +/- 1 (or 0) for comparing monomials */ |
---|
212 | /* ExpL_Size entries*/ |
---|
213 | |
---|
214 | // is NULL for lp or N == 1, otherwise non-NULL (with OrdSize > 0 entries) */ |
---|
215 | sro_ord* typ; /* array of orderings + sizes, OrdSize entries */ |
---|
216 | /* if NegWeightL_Size > 0, then NegWeightL_Offset[0..size_1] is index of longs |
---|
217 | in ExpVector whose values need an offset due to negative weights */ |
---|
218 | /* array of NegWeigtL_Size indicies */ |
---|
219 | int* NegWeightL_Offset; |
---|
220 | |
---|
221 | int* VarOffset; |
---|
222 | |
---|
223 | ideal qideal; /* extension to the ring structure: qring, rInit */ |
---|
224 | |
---|
225 | int* firstwv; |
---|
226 | |
---|
227 | omBin PolyBin; /* Bin from where monoms are allocated */ |
---|
228 | intvec * pModW; /* std: module weights */ |
---|
229 | poly ppNoether; /* variables, set by procedures from hecke/kstd1: |
---|
230 | |
---|
231 | the highest monomial below pHEdge */ |
---|
232 | // #ifdef HAVE_RINGS |
---|
233 | // unsigned int cf->ringtype; /* cring = 0 => coefficient field, cring = 1 => coeffs from Z/2^m */ |
---|
234 | // int_number cf->modBase; /* Z/(ringflag^cf->modExponent)=Z/cf->modNumber*/ |
---|
235 | // unsigned long cf->modExponent; |
---|
236 | // unsigned long cf->modNumber; /* Z/cf->modNumber */ |
---|
237 | // int_number cf->modNumber; |
---|
238 | // #endif |
---|
239 | |
---|
240 | unsigned long options; /* ring dependent options */ |
---|
241 | |
---|
242 | // int ch; /* characteristic, rInit */ |
---|
243 | int ref; /* reference counter to the ring, interpreter */ |
---|
244 | |
---|
245 | short float_len; /* additional char-flags, rInit */ |
---|
246 | short float_len2; /* additional char-flags, rInit */ |
---|
247 | |
---|
248 | short N; /* number of vars, rInit */ |
---|
249 | |
---|
250 | short OrdSgn; /* 1 for polynomial rings, -1 otherwise, rInit */ |
---|
251 | |
---|
252 | short firstBlockEnds; |
---|
253 | #ifdef HAVE_PLURAL |
---|
254 | short real_var_start, real_var_end; |
---|
255 | #endif |
---|
256 | |
---|
257 | #ifdef HAVE_SHIFTBBA |
---|
258 | short isLPring; /* 0 for non-letterplace rings, otherwise the number of LP blocks, at least 1, known also as lV */ |
---|
259 | #endif |
---|
260 | |
---|
261 | BOOLEAN VectorOut; |
---|
262 | BOOLEAN ShortOut; |
---|
263 | BOOLEAN CanShortOut; |
---|
264 | BOOLEAN LexOrder; // TRUE if the monomial ordering has polynomial and power series blocks |
---|
265 | BOOLEAN MixedOrder; // TRUE for global/local mixed orderings, FALSE otherwise |
---|
266 | BOOLEAN pLexOrder; /* TRUE if the monomial ordering is not compatible with pFDeg */ |
---|
267 | |
---|
268 | BOOLEAN ComponentOrder; // ??? |
---|
269 | |
---|
270 | // what follows below here should be set by rComplete, _only_ |
---|
271 | // contains component, but no weight fields in E */ |
---|
272 | short ExpL_Size; // size of exponent vector in long |
---|
273 | short CmpL_Size; // portions which need to be compared |
---|
274 | /* number of long vars in exp vector: |
---|
275 | long vars are those longs in the exponent vector which are |
---|
276 | occupied by variables, only */ |
---|
277 | short VarL_Size; |
---|
278 | short BitsPerExp; /* number of bits per exponent */ |
---|
279 | short ExpPerLong; /* maximal number of Exponents per long */ |
---|
280 | short pCompIndex; /* p->exp.e[pCompIndex] is the component */ |
---|
281 | short pOrdIndex; /* p->exp[pOrdIndex] is pGetOrd(p) */ |
---|
282 | short OrdSize; /* size of ord vector (in sro_ord) */ |
---|
283 | |
---|
284 | /* if >= 0, long vars in exp vector are consecutive and start there |
---|
285 | if < 0, long vars in exp vector are not consecutive */ |
---|
286 | short VarL_LowIndex; |
---|
287 | // number of exponents in r->VarL_Offset[0] |
---|
288 | // is minimal number of exponents in a long var |
---|
289 | short MinExpPerLong; |
---|
290 | |
---|
291 | short NegWeightL_Size; |
---|
292 | /* array of size VarL_Size, |
---|
293 | VarL_Offset[i] gets i-th long var in exp vector */ |
---|
294 | int* VarL_Offset; |
---|
295 | |
---|
296 | /* mask for getting single exponents */ |
---|
297 | unsigned long bitmask; |
---|
298 | /* mask used for divisiblity tests */ |
---|
299 | unsigned long divmask; // rComplete |
---|
300 | |
---|
301 | p_Procs_s* p_Procs; // rComplete/p_ProcsSet |
---|
302 | |
---|
303 | /* FDeg and LDeg */ |
---|
304 | pFDegProc pFDeg; // rComplete/rSetDegStuff |
---|
305 | pLDegProc pLDeg; // rComplete/rSetDegStuff |
---|
306 | |
---|
307 | /* as it was determined by rComplete */ |
---|
308 | pFDegProc pFDegOrig; |
---|
309 | /* and as it was determined before rOptimizeLDeg */ |
---|
310 | pLDegProc pLDegOrig; |
---|
311 | |
---|
312 | p_SetmProc p_Setm; |
---|
313 | n_Procs_s* cf; |
---|
314 | #ifdef HAVE_PLURAL |
---|
315 | private: |
---|
316 | nc_struct* _nc; // private |
---|
317 | public: |
---|
318 | inline const nc_struct* GetNC() const { return _nc; }; // public!!! |
---|
319 | inline nc_struct*& GetNC() { return _nc; }; // public!!! |
---|
320 | #endif |
---|
321 | public: |
---|
322 | operator coeffs() const { return cf; } |
---|
323 | }; |
---|
324 | |
---|
325 | enum tHomog |
---|
326 | { |
---|
327 | isNotHomog = FALSE, |
---|
328 | isHomog = TRUE, |
---|
329 | testHomog |
---|
330 | }; |
---|
331 | |
---|
332 | ////////// DEPRECATED |
---|
333 | /////// void rChangeCurrRing(ring r); |
---|
334 | //void rSetHdl(idhdl h); |
---|
335 | //ring rInit(sleftv* pn, sleftv* rv, sleftv* ord); |
---|
336 | idhdl rDefault(const char *s); |
---|
337 | ring rDefault(int ch, int N, char **n); |
---|
338 | ring rDefault(const coeffs cf, int N, char **n); |
---|
339 | ring rDefault(int ch, int N, char **n,int ord_size, int *ord, int *block0, int *block1); |
---|
340 | ring rDefault(const coeffs cf, int N, char **n,int ord_size, int *ord, int *block0, int *block1); |
---|
341 | |
---|
342 | // #define rIsRingVar(A) r_IsRingVar(A,currRing) |
---|
343 | int r_IsRingVar(const char *n, ring r); |
---|
344 | void rWrite(ring r); |
---|
345 | //void rKill(idhdl h); |
---|
346 | void rKill(ring r); |
---|
347 | ring rCopy(ring r); |
---|
348 | ring rCopy0(const ring r, BOOLEAN copy_qideal = TRUE, BOOLEAN copy_ordering = TRUE); |
---|
349 | ring rCopy0AndAddA(ring r, int64vec *wv64, BOOLEAN copy_qideal = TRUE, |
---|
350 | BOOLEAN copy_ordering = TRUE); |
---|
351 | ring rOpposite(ring r); |
---|
352 | ring rEnvelope(ring r); |
---|
353 | |
---|
354 | /// we must always have this test! |
---|
355 | static inline bool rIsPluralRing(const ring r) |
---|
356 | { |
---|
357 | assume(r != NULL); |
---|
358 | #ifdef HAVE_PLURAL |
---|
359 | nc_struct *n; |
---|
360 | return (r != NULL) && ((n=r->GetNC()) != NULL) /*&& (n->type != nc_error)*/; |
---|
361 | #else |
---|
362 | return false; |
---|
363 | #endif |
---|
364 | } |
---|
365 | |
---|
366 | static inline bool rIsRatGRing(const ring r) |
---|
367 | { |
---|
368 | assume(r != NULL); |
---|
369 | #ifdef HAVE_PLURAL |
---|
370 | /* nc_struct *n; */ |
---|
371 | return (r != NULL) /* && ((n=r->GetNC()) != NULL) */ |
---|
372 | && (r->real_var_start>1); |
---|
373 | #else |
---|
374 | return false; |
---|
375 | #endif |
---|
376 | } |
---|
377 | |
---|
378 | |
---|
379 | |
---|
380 | |
---|
381 | // The following are for LaScala3 only! |
---|
382 | void rChangeSComps(int* currComponents, long* currShiftedComponents, int length, ring r); |
---|
383 | void rGetSComps(int** currComponents, long** currShiftedComponents, int *length, ring r); |
---|
384 | |
---|
385 | |
---|
386 | |
---|
387 | //idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
388 | //idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n); |
---|
389 | const char * rSimpleOrdStr(int ord); |
---|
390 | int rOrderName(char * ordername); |
---|
391 | char * rOrdStr(ring r); |
---|
392 | char * rVarStr(ring r); |
---|
393 | char * rCharStr(ring r); |
---|
394 | char * rString(ring r); |
---|
395 | int rChar(ring r); |
---|
396 | |
---|
397 | char * rParStr(ring r); |
---|
398 | |
---|
399 | int rSum(ring r1, ring r2, ring &sum); |
---|
400 | int rSumInternal(ring r1, ring r2, ring &sum, BOOLEAN vartest, BOOLEAN dp_dp); |
---|
401 | |
---|
402 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1); |
---|
403 | BOOLEAN rSamePolyRep(ring r1, ring r2); |
---|
404 | void rUnComplete(ring r); |
---|
405 | |
---|
406 | BOOLEAN rRing_is_Homog(ring r); |
---|
407 | BOOLEAN rRing_has_CompLastBlock(ring r); |
---|
408 | |
---|
409 | #ifdef HAVE_RINGS |
---|
410 | static inline BOOLEAN rField_is_Ring_2toM(const ring r) |
---|
411 | { assume(r != NULL); return ( getCoeffType(r->cf) == n_Z2m && nCoeff_is_Ring_2toM(r->cf) ); } |
---|
412 | |
---|
413 | static inline BOOLEAN rField_is_Ring_ModN(const ring r) |
---|
414 | { assume(r != NULL); return ( getCoeffType(r->cf) == n_Zn && nCoeff_is_Ring_ModN(r->cf) ); } |
---|
415 | |
---|
416 | static inline BOOLEAN rField_is_Ring_PtoM(const ring r) |
---|
417 | { assume(r != NULL); return (getCoeffType(r->cf) == n_Zpn && nCoeff_is_Ring_PtoM(r->cf) ); } |
---|
418 | |
---|
419 | static inline BOOLEAN rField_is_Ring_Z(const ring r) |
---|
420 | { assume(r != NULL); return (getCoeffType(r->cf) == n_Z && nCoeff_is_Ring_Z(r->cf) ); } |
---|
421 | |
---|
422 | static inline BOOLEAN rField_is_Ring(const ring r) |
---|
423 | { assume(r != NULL); return nCoeff_is_Ring(r->cf); } |
---|
424 | |
---|
425 | static inline BOOLEAN rField_is_Domain(const ring r) |
---|
426 | { assume(r != NULL); return nCoeff_is_Domain(r->cf); } |
---|
427 | |
---|
428 | static inline BOOLEAN rField_has_Units(const ring r) |
---|
429 | { assume(r != NULL); return nCoeff_has_Units(r->cf); } |
---|
430 | #else |
---|
431 | #define rField_is_Ring(A) (0) |
---|
432 | #define rField_is_Ring_2toM(A) (0) |
---|
433 | #define rField_is_Ring_ModN(A) (0) |
---|
434 | #define rField_is_Ring_PtoM(A) (0) |
---|
435 | #define rField_is_Ring_Z(A) (0) |
---|
436 | #define rField_is_Domain(A) (1) |
---|
437 | #define rField_has_Units(A) (1) |
---|
438 | #endif |
---|
439 | |
---|
440 | static inline BOOLEAN rField_is_Zp(const ring r) |
---|
441 | { assume(r != NULL); return (getCoeffType(r->cf) == n_Zp); } |
---|
442 | |
---|
443 | static inline BOOLEAN rField_is_Zp(const ring r, int p) |
---|
444 | { assume(r != NULL); return (getCoeffType(r->cf) == n_Zp) && (r->cf->ch == p); } |
---|
445 | |
---|
446 | static inline BOOLEAN rField_is_Q(const ring r) |
---|
447 | { assume(r != NULL); return nCoeff_is_Q(r->cf); } |
---|
448 | |
---|
449 | static inline BOOLEAN rField_is_numeric(const ring r) /* R, long R, long C */ |
---|
450 | { assume(r != NULL); return nCoeff_is_numeric(r->cf); } |
---|
451 | |
---|
452 | static inline BOOLEAN rField_is_R(const ring r) |
---|
453 | { assume(r != NULL); return nCoeff_is_R(r->cf); } |
---|
454 | |
---|
455 | static inline BOOLEAN rField_is_GF(const ring r) |
---|
456 | { assume(r != NULL); return nCoeff_is_GF(r->cf); } |
---|
457 | |
---|
458 | static inline BOOLEAN rField_is_GF(const ring r, int q) |
---|
459 | { assume(r != NULL); return nCoeff_is_GF(r->cf, q); } |
---|
460 | |
---|
461 | /* DO NOT USE; just here for compatibility reasons towards |
---|
462 | the SINGULAR svn trunk */ |
---|
463 | static inline BOOLEAN rField_is_Zp_a(const ring r) |
---|
464 | { assume(r != NULL); return nCoeff_is_Zp_a(r->cf); } |
---|
465 | |
---|
466 | /* DO NOT USE; just here for compatibility reasons towards |
---|
467 | the SINGULAR svn trunk */ |
---|
468 | static inline BOOLEAN rField_is_Zp_a(const ring r, int p) |
---|
469 | { assume(r != NULL); return nCoeff_is_Zp_a(r->cf, p); } |
---|
470 | |
---|
471 | /* DO NOT USE; just here for compatibility reasons towards |
---|
472 | the SINGULAR svn trunk */ |
---|
473 | static inline BOOLEAN rField_is_Q_a(const ring r) |
---|
474 | { assume(r != NULL); return nCoeff_is_Q_a(r->cf); } |
---|
475 | |
---|
476 | static inline BOOLEAN rField_is_long_R(const ring r) |
---|
477 | { assume(r != NULL); return nCoeff_is_long_R(r->cf); } |
---|
478 | |
---|
479 | static inline BOOLEAN rField_is_long_C(const ring r) |
---|
480 | { assume(r != NULL); return nCoeff_is_long_C(r->cf); } |
---|
481 | |
---|
482 | static inline BOOLEAN rField_has_simple_inverse(const ring r) |
---|
483 | { assume(r != NULL); return nCoeff_has_simple_inverse(r->cf); } |
---|
484 | |
---|
485 | static inline BOOLEAN rField_has_simple_Alloc(const ring r) |
---|
486 | { assume(r != NULL); return nCoeff_has_simple_Alloc(r->cf); } |
---|
487 | |
---|
488 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
489 | static inline BOOLEAN rField_is_Extension(const ring r) |
---|
490 | { assume(r != NULL); return nCoeff_is_Extension(r->cf); } /* Z/p(a) and Q(a)*/ |
---|
491 | |
---|
492 | n_coeffType rFieldType(const ring r); |
---|
493 | |
---|
494 | /// this needs to be called whenever a new ring is created: new fields |
---|
495 | /// in ring are created (like VarOffset), unless they already exist |
---|
496 | /// with force == 1, new fields are _always_ created (overwritten), |
---|
497 | /// even if they exist |
---|
498 | BOOLEAN rComplete(ring r, int force = 0); |
---|
499 | // use this to free fields created by rComplete //? |
---|
500 | |
---|
501 | static inline int rBlocks(ring r) |
---|
502 | { |
---|
503 | assume(r != NULL); |
---|
504 | int i=0; |
---|
505 | while (r->order[i]!=0) i++; |
---|
506 | return i+1; |
---|
507 | } |
---|
508 | |
---|
509 | // misc things |
---|
510 | static inline char* rRingVar(short i, const ring r) |
---|
511 | { |
---|
512 | assume(r != NULL); return r->names[i]; |
---|
513 | } |
---|
514 | static inline BOOLEAN rShortOut(const ring r) |
---|
515 | { |
---|
516 | assume(r != NULL); return (r->ShortOut); |
---|
517 | } |
---|
518 | |
---|
519 | /// #define rVar(r) (r->N) |
---|
520 | static inline short rVar(const ring r) |
---|
521 | { |
---|
522 | assume(r != NULL); |
---|
523 | return r->N; |
---|
524 | } |
---|
525 | |
---|
526 | /// (r->cf->P) |
---|
527 | static inline short rPar(const ring r) |
---|
528 | { |
---|
529 | assume(r != NULL); |
---|
530 | const coeffs C = r->cf; |
---|
531 | assume(C != NULL); |
---|
532 | |
---|
533 | if( rField_is_Extension(r) ) |
---|
534 | { |
---|
535 | const ring R = C->extRing; |
---|
536 | assume( R != NULL ); |
---|
537 | return rVar( R ); |
---|
538 | } |
---|
539 | return 0; |
---|
540 | } |
---|
541 | |
---|
542 | |
---|
543 | /// (r->cf->parameter) |
---|
544 | static inline char** rParameter(const ring r) |
---|
545 | { |
---|
546 | assume(r != NULL); |
---|
547 | const coeffs C = r->cf; |
---|
548 | assume(C != NULL); |
---|
549 | |
---|
550 | if( rField_is_Extension(r) ) |
---|
551 | { |
---|
552 | const ring R = C->extRing; |
---|
553 | assume( R != NULL ); |
---|
554 | return R->names; |
---|
555 | } |
---|
556 | return NULL; |
---|
557 | } |
---|
558 | |
---|
559 | /* R, Q, Fp: FALSE */ |
---|
560 | static inline BOOLEAN rIsExtension(const ring r) |
---|
561 | { |
---|
562 | assume( (rParameter(r)!=NULL) == rField_is_Extension(r) ); // ? |
---|
563 | return rField_is_Extension(r); |
---|
564 | } |
---|
565 | |
---|
566 | /// Tests whether '(r->cf->minpoly) == NULL' |
---|
567 | BOOLEAN rMinpolyIsNULL(const ring r); |
---|
568 | |
---|
569 | |
---|
570 | /// order stuff |
---|
571 | typedef enum rRingOrder_t |
---|
572 | { |
---|
573 | ringorder_no = 0, |
---|
574 | ringorder_a, |
---|
575 | ringorder_a64, ///< for int64 weights |
---|
576 | ringorder_c, |
---|
577 | ringorder_C, |
---|
578 | ringorder_M, |
---|
579 | ringorder_S, ///< S? |
---|
580 | ringorder_s, ///< s? |
---|
581 | ringorder_lp, |
---|
582 | ringorder_dp, |
---|
583 | ringorder_rp, |
---|
584 | ringorder_Dp, |
---|
585 | ringorder_wp, |
---|
586 | ringorder_Wp, |
---|
587 | ringorder_ls, |
---|
588 | ringorder_ds, |
---|
589 | ringorder_Ds, |
---|
590 | ringorder_ws, |
---|
591 | ringorder_Ws, |
---|
592 | ringorder_L, |
---|
593 | // the following are only used internally |
---|
594 | ringorder_aa, ///< for idElimination, like a, except pFDeg, pWeigths ignore it |
---|
595 | ringorder_rs, ///< ??? |
---|
596 | ringorder_IS, ///< Induced (Schreyer) ordering |
---|
597 | ringorder_unspec |
---|
598 | } rRingOrder_t; |
---|
599 | |
---|
600 | typedef enum rOrderType_t |
---|
601 | { |
---|
602 | rOrderType_General = 0, ///< non-simple ordering as specified by currRing |
---|
603 | rOrderType_CompExp, ///< simple ordering, component has priority |
---|
604 | rOrderType_ExpComp, ///< simple ordering, exponent vector has priority |
---|
605 | ///< component not compatible with exp-vector order |
---|
606 | rOrderType_Exp, ///< simple ordering, exponent vector has priority |
---|
607 | ///< component is compatible with exp-vector order |
---|
608 | rOrderType_Syz, ///< syzygy ordering |
---|
609 | rOrderType_Schreyer, ///< Schreyer ordering |
---|
610 | rOrderType_Syz2dpc, ///< syzcomp2dpc |
---|
611 | rOrderType_ExpNoComp ///< simple ordering, differences in component are |
---|
612 | ///< not considered |
---|
613 | } rOrderType_t; |
---|
614 | |
---|
615 | static inline BOOLEAN rIsSyzIndexRing(const ring r) |
---|
616 | { assume(r != NULL); return r->order[0] == ringorder_s;} |
---|
617 | |
---|
618 | static inline int rGetCurrSyzLimit(const ring r) |
---|
619 | { assume(r != NULL); return (rIsSyzIndexRing(r)? r->typ[0].data.syz.limit : 0);} |
---|
620 | |
---|
621 | void rSetSyzComp(int k, const ring r); |
---|
622 | |
---|
623 | // Ring Manipulations |
---|
624 | ring rAssure_HasComp(const ring r, BOOLEAN complete = TRUE); |
---|
625 | ring rAssure_SyzComp(const ring r, BOOLEAN complete = TRUE); |
---|
626 | ring rAssure_dp_S(const ring r, BOOLEAN complete = TRUE); |
---|
627 | ring rAssure_dp_C(const ring r, BOOLEAN complete = TRUE); |
---|
628 | ring rAssure_C_dp(const ring r, BOOLEAN complete = TRUE); |
---|
629 | /// makes sure that c/C ordering is last ordering |
---|
630 | ring rAssure_CompLastBlock(const ring r, BOOLEAN complete = TRUE); |
---|
631 | |
---|
632 | /// makes sure that c/C ordering is last ordering and SyzIndex is first |
---|
633 | ring rAssure_SyzComp_CompLastBlock(const ring r, BOOLEAN complete = TRUE); |
---|
634 | ring rAssure_TDeg(const ring r, int start_var, int end_var, int &pos, BOOLEAN complete = TRUE); |
---|
635 | |
---|
636 | /// return the max-comonent wchich has syzIndex i |
---|
637 | /// Assume: i<= syzIndex_limit |
---|
638 | int rGetMaxSyzComp(int i, const ring r); |
---|
639 | |
---|
640 | BOOLEAN rHasSimpleOrder(const ring r); |
---|
641 | |
---|
642 | /// returns TRUE, if simple lp or ls ordering |
---|
643 | BOOLEAN rHasSimpleLexOrder(const ring r); |
---|
644 | |
---|
645 | //???? return TRUE if p->exp[r->pOrdIndex] holds total degree of p ??? |
---|
646 | |
---|
647 | |
---|
648 | inline BOOLEAN rHasGlobalOrdering(const ring r){ return (r->OrdSgn==1); } |
---|
649 | inline BOOLEAN rHasLocalOrMixedOrdering(const ring r){ return (r->OrdSgn==-1); } |
---|
650 | |
---|
651 | // #define rHasGlobalOrdering(R) ((R)->OrdSgn==1) |
---|
652 | // #define rHasLocalOrMixedOrdering(R) ((R)->OrdSgn==-1) |
---|
653 | |
---|
654 | #define rHasGlobalOrdering_currRing() rHasGlobalOrdering(currRing) |
---|
655 | #define rHasLocalOrMixedOrdering_currRing() rHasLocalOrMixedOrdering(currRing) |
---|
656 | |
---|
657 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r ); |
---|
658 | |
---|
659 | /// return TRUE if p_SetComp requires p_Setm |
---|
660 | BOOLEAN rOrd_SetCompRequiresSetm(ring r); |
---|
661 | rOrderType_t rGetOrderType(ring r); |
---|
662 | |
---|
663 | /// returns TRUE if var(i) belongs to p-block |
---|
664 | BOOLEAN rIsPolyVar(int i, ring r); |
---|
665 | |
---|
666 | static inline BOOLEAN rOrd_is_Comp_dp(ring r) |
---|
667 | { |
---|
668 | assume(r != NULL); |
---|
669 | return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) && |
---|
670 | r->order[1] == ringorder_dp && |
---|
671 | r->order[2] == 0); |
---|
672 | } |
---|
673 | |
---|
674 | #ifdef RDEBUG |
---|
675 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
676 | extern BOOLEAN rDBTest(ring r, const char* fn, const int l); |
---|
677 | #else |
---|
678 | #define rTest(r) |
---|
679 | #endif |
---|
680 | |
---|
681 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
682 | BOOLEAN omit_comp, |
---|
683 | unsigned long exp_limit); |
---|
684 | |
---|
685 | /// construct Wp, C ring |
---|
686 | ring rModifyRing_Wp(ring r, int* weights); |
---|
687 | void rModify_a_to_A(ring r); |
---|
688 | |
---|
689 | void rKillModifiedRing(ring r); |
---|
690 | // also frees weights |
---|
691 | void rKillModified_Wp_Ring(ring r); |
---|
692 | |
---|
693 | ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple); |
---|
694 | void rKillModifiedRing_Simple(ring r); |
---|
695 | |
---|
696 | #ifdef RDEBUG |
---|
697 | void rDebugPrint(ring r); |
---|
698 | void pDebugPrint(poly p); |
---|
699 | void p_DebugPrint(poly p, const ring r); |
---|
700 | #endif |
---|
701 | |
---|
702 | #ifndef NDEBUG |
---|
703 | /// debug-print at most nTerms (2 by default) terms from poly/vector p, |
---|
704 | /// assuming that lt(p) lives in lmRing and tail(p) lives in tailRing. |
---|
705 | void p_DebugPrint(const poly p, const ring lmRing, const ring tailRing, const int nTerms = 2); |
---|
706 | #endif |
---|
707 | |
---|
708 | int64 * rGetWeightVec(ring r); |
---|
709 | void rSetWeightVec(ring r, int64 *wv); |
---|
710 | |
---|
711 | //lists rDecompose(const ring r); |
---|
712 | //ring rCompose(const lists L); |
---|
713 | ///////////////////////////// |
---|
714 | // Auxillary functions |
---|
715 | // |
---|
716 | |
---|
717 | /* return the varIndex-th ring variable as a poly; |
---|
718 | varIndex starts at index 1 */ |
---|
719 | poly rGetVar(const int varIndex, const ring r); |
---|
720 | |
---|
721 | BOOLEAN rSetISReference(const ring r, const ideal F, const int i = 0, const int p = 0, const intvec * componentWeights = NULL); |
---|
722 | |
---|
723 | BOOLEAN rCheckIV(intvec *iv); |
---|
724 | int rTypeOfMatrixOrder(intvec * order); |
---|
725 | void rDelete(ring r); |
---|
726 | |
---|
727 | extern omBin sip_sring_bin; |
---|
728 | #endif |
---|