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