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