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