[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 | */ |
---|
[7d1574] | 9 | /* $Id: ring.h,v 1.21 2007-05-24 13:42:17 Singular Exp $ */ |
---|
[35aab3] | 10 | |
---|
| 11 | /* includes */ |
---|
| 12 | #include "structs.h" |
---|
| 13 | #include "structs.h" // we need ABS |
---|
| 14 | #include "polys-impl.h" |
---|
| 15 | |
---|
| 16 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | void rChangeCurrRing(ring r); |
---|
| 20 | void rSetHdl(idhdl h); |
---|
| 21 | ring rInit(sleftv* pn, sleftv* rv, sleftv* ord); |
---|
| 22 | idhdl rDefault(char *s); |
---|
| 23 | ring rDefault(int ch, int N, char **n); |
---|
| 24 | #define rIsRingVar(A) r_IsRingVar(A,currRing) |
---|
[8837a0] | 25 | int r_IsRingVar(const char *n, ring r); |
---|
[35aab3] | 26 | void rWrite(ring r); |
---|
| 27 | void rKill(idhdl h); |
---|
| 28 | void rKill(ring r); |
---|
| 29 | ring rCopy(ring r); |
---|
[4c7d73] | 30 | ring rCopy0(ring r, BOOLEAN copy_qideal = TRUE, BOOLEAN copy_ordering = TRUE); |
---|
[8f42a46] | 31 | void rNameCheck(ring R); |
---|
[6b5dd2] | 32 | ring rOpposite(ring r); |
---|
| 33 | ring rEnvelope(ring r); |
---|
[35aab3] | 34 | |
---|
[86016d] | 35 | // we must always have this test! |
---|
| 36 | inline bool rIsPluralRing(const ring r) |
---|
[d312f6] | 37 | { |
---|
[86016d] | 38 | #ifdef HAVE_PLURAL |
---|
| 39 | return (r != NULL) && (r->nc != NULL) && (r->nc->type != nc_error); |
---|
[d312f6] | 40 | #else |
---|
[86016d] | 41 | return false; |
---|
[d312f6] | 42 | #endif |
---|
[86016d] | 43 | } |
---|
[d312f6] | 44 | |
---|
[35aab3] | 45 | |
---|
| 46 | |
---|
[4c7d73] | 47 | |
---|
[35aab3] | 48 | #ifdef PDEBUG |
---|
| 49 | #define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l) |
---|
| 50 | #define rGetSComps(c,s,l) rDBGetSComps(c,s,l) |
---|
| 51 | void rDBChangeSComps(int* currComponents, |
---|
| 52 | long* currShiftedComponents, |
---|
| 53 | int length, |
---|
| 54 | ring r = currRing); |
---|
| 55 | void rDBGetSComps(int** currComponents, |
---|
| 56 | long** currShiftedComponents, |
---|
| 57 | int *length, |
---|
| 58 | ring r = currRing); |
---|
| 59 | #else |
---|
| 60 | #define rChangeSComps(c,s,l) rNChangeSComps(c,s) |
---|
| 61 | #define rGetSComps(c,s,l) rNGetSComps(c,s) |
---|
| 62 | #endif |
---|
| 63 | |
---|
| 64 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing); |
---|
| 65 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing); |
---|
| 66 | |
---|
| 67 | idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
| 68 | idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n); |
---|
| 69 | const char * rSimpleOrdStr(int ord); |
---|
| 70 | int rOrderName(char * ordername); |
---|
| 71 | char * rOrdStr(ring r); |
---|
| 72 | char * rVarStr(ring r); |
---|
| 73 | char * rCharStr(ring r); |
---|
| 74 | char * rString(ring r); |
---|
| 75 | int rChar(ring r=currRing); |
---|
| 76 | #define rPar(r) (r->P) |
---|
[98a77e] | 77 | #define rVar(r) (r->N) |
---|
[35aab3] | 78 | char * rParStr(ring r); |
---|
| 79 | int rIsExtension(ring r); |
---|
| 80 | int rIsExtension(); |
---|
| 81 | int rSum(ring r1, ring r2, ring &sum); |
---|
| 82 | |
---|
| 83 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1); |
---|
| 84 | void rUnComplete(ring r); |
---|
| 85 | |
---|
| 86 | #define rInternalChar(r) ((r)->ch) |
---|
| 87 | |
---|
| 88 | BOOLEAN rRing_is_Homog(ring r=currRing); |
---|
| 89 | BOOLEAN rRing_has_CompLastBlock(ring r=currRing); |
---|
| 90 | |
---|
[585bbcb] | 91 | #ifdef HAVE_RING2TOM |
---|
| 92 | inline BOOLEAN rField_is_Ring_2toM(ring r=currRing) |
---|
[009d80] | 93 | { return (r->ringtype == 1); } |
---|
[994445] | 94 | #endif |
---|
| 95 | |
---|
| 96 | #ifdef HAVE_RINGMODN |
---|
| 97 | inline BOOLEAN rField_is_Ring_ModN(ring r=currRing) |
---|
[009d80] | 98 | { return (r->ringtype == 2); } |
---|
[994445] | 99 | #endif |
---|
[585bbcb] | 100 | |
---|
[009d80] | 101 | #ifdef HAVE_RINGS |
---|
| 102 | inline BOOLEAN rField_is_Ring(ring r=currRing) |
---|
[206e158] | 103 | { return (r->ringtype != 0); } |
---|
| 104 | |
---|
| 105 | inline BOOLEAN rField_is_Domain(ring r=currRing) |
---|
| 106 | { return (r->ringtype < 0); } |
---|
[009d80] | 107 | #endif |
---|
| 108 | |
---|
| 109 | #ifdef HAVE_RINGS |
---|
[585bbcb] | 110 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
[009d80] | 111 | { return (r->ringtype == 0) && (r->ch > 1) && (r->parameter==NULL); } |
---|
[585bbcb] | 112 | |
---|
| 113 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
[009d80] | 114 | { return (r->ringtype == 0) && (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
[585bbcb] | 115 | |
---|
| 116 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
[009d80] | 117 | { return (r->ringtype == 0) && (r->ch == 0) && (r->parameter==NULL); } |
---|
[585bbcb] | 118 | |
---|
| 119 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
[009d80] | 120 | { return (r->ringtype == 0) && (r->ch == -1); } |
---|
[585bbcb] | 121 | |
---|
| 122 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
| 123 | { |
---|
| 124 | if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH)) |
---|
[009d80] | 125 | return (r->ringtype == 0) && (r->parameter==NULL); |
---|
[585bbcb] | 126 | return FALSE; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
[009d80] | 130 | { return (r->ringtype == 0) && (r->ch > 1) && (r->parameter!=NULL); } |
---|
[585bbcb] | 131 | |
---|
| 132 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
[009d80] | 133 | { return (r->ringtype == 0) && (r->ch == q); } |
---|
[585bbcb] | 134 | |
---|
| 135 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
[009d80] | 136 | { return (r->ringtype == 0) && (r->ch < -1); } |
---|
[585bbcb] | 137 | |
---|
| 138 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
[009d80] | 139 | { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
[585bbcb] | 140 | |
---|
| 141 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
[009d80] | 142 | { return (r->ringtype == 0) && (r->ch == 1); } |
---|
[585bbcb] | 143 | |
---|
| 144 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
| 145 | { |
---|
| 146 | if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH)) |
---|
[009d80] | 147 | return (r->ringtype == 0) && (r->parameter==NULL); |
---|
[585bbcb] | 148 | return FALSE; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
| 152 | { |
---|
| 153 | if (rField_is_numeric(r)) |
---|
[009d80] | 154 | return (r->ringtype == 0) && (r->parameter!=NULL); |
---|
[585bbcb] | 155 | return FALSE; |
---|
| 156 | } |
---|
| 157 | #else |
---|
[35aab3] | 158 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
| 159 | { return (r->ch > 1) && (r->parameter==NULL); } |
---|
| 160 | |
---|
| 161 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
| 162 | { return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
| 163 | |
---|
| 164 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
| 165 | { return (r->ch == 0) && (r->parameter==NULL); } |
---|
| 166 | |
---|
| 167 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
| 168 | { return (r->ch == -1); } |
---|
| 169 | |
---|
| 170 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
| 171 | { |
---|
| 172 | if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH)) |
---|
| 173 | return (r->parameter==NULL); |
---|
| 174 | return FALSE; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
| 178 | { return (r->ch > 1) && (r->parameter!=NULL); } |
---|
| 179 | |
---|
| 180 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
| 181 | { return (r->ch == q); } |
---|
| 182 | |
---|
| 183 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
| 184 | { return (r->ch < -1); } |
---|
| 185 | |
---|
| 186 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
| 187 | { return (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
| 188 | |
---|
| 189 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
| 190 | { return (r->ch == 1); } |
---|
| 191 | |
---|
| 192 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
| 193 | { |
---|
| 194 | if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH)) |
---|
| 195 | return (r->parameter==NULL); |
---|
| 196 | return FALSE; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
| 200 | { |
---|
| 201 | if (rField_is_numeric(r)) |
---|
| 202 | return (r->parameter!=NULL); |
---|
| 203 | return FALSE; |
---|
| 204 | } |
---|
[585bbcb] | 205 | #endif |
---|
[35aab3] | 206 | |
---|
| 207 | inline BOOLEAN rField_has_simple_inverse(ring r=currRing) |
---|
| 208 | /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
[009d80] | 209 | #ifdef HAVE_RINGS |
---|
| 210 | { return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/ |
---|
[585bbcb] | 211 | #else |
---|
[35aab3] | 212 | { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
[585bbcb] | 213 | #endif |
---|
[35aab3] | 214 | |
---|
| 215 | inline BOOLEAN rField_has_simple_Alloc(ring r=currRing) |
---|
[009d80] | 216 | { return (rField_is_Zp(r) |
---|
| 217 | || rField_is_GF(r) |
---|
| 218 | #ifdef HAVE_RING2TOM |
---|
| 219 | || rField_is_Ring_2toM(r) |
---|
| 220 | #endif |
---|
| 221 | #ifdef HAVE_RINGMODN |
---|
| 222 | || rField_is_Ring_ModN(r) |
---|
[585bbcb] | 223 | #endif |
---|
[009d80] | 224 | || rField_is_R(r)); } |
---|
[35aab3] | 225 | |
---|
| 226 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
| 227 | inline BOOLEAN rField_is_Extension(ring r=currRing) |
---|
| 228 | { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
| 229 | |
---|
| 230 | n_coeffType rFieldType(ring r); |
---|
| 231 | |
---|
| 232 | // this needs to be called whenever a new ring is created: new fields |
---|
| 233 | // in ring are created (like VarOffset), unless they already exist |
---|
| 234 | // with force == 1, new fields are _always_ created (overwritten), |
---|
| 235 | // even if they exist |
---|
| 236 | BOOLEAN rComplete(ring r, int force = 0); |
---|
| 237 | // use this to free fields created by rComplete |
---|
[ea68ed] | 238 | |
---|
| 239 | BOOLEAN nc_rComplete(ring src, ring dest); |
---|
| 240 | |
---|
[35aab3] | 241 | void rUnComplete(ring r); |
---|
| 242 | inline int rBlocks(ring r) |
---|
| 243 | { |
---|
| 244 | int i=0; |
---|
| 245 | while (r->order[i]!=0) i++; |
---|
| 246 | return i+1; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | // misc things |
---|
| 250 | inline char* rRingVar(short i) |
---|
| 251 | { |
---|
| 252 | return currRing->names[i]; |
---|
| 253 | } |
---|
| 254 | inline char* rRingVar(short i, ring r) |
---|
| 255 | { |
---|
| 256 | return r->names[i]; |
---|
| 257 | } |
---|
| 258 | inline BOOLEAN rShortOut(ring r) |
---|
| 259 | { |
---|
| 260 | return (r->ShortOut); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | // order stuff |
---|
| 264 | typedef enum rRingOrder_t |
---|
| 265 | { |
---|
| 266 | ringorder_no = 0, |
---|
| 267 | ringorder_a, |
---|
[fc5095] | 268 | ringorder_a64, // for int64 weights |
---|
[35aab3] | 269 | ringorder_c, |
---|
| 270 | ringorder_C, |
---|
| 271 | ringorder_M, |
---|
| 272 | ringorder_S, |
---|
| 273 | ringorder_s, |
---|
| 274 | ringorder_lp, |
---|
| 275 | ringorder_dp, |
---|
| 276 | ringorder_rp, |
---|
| 277 | ringorder_Dp, |
---|
| 278 | ringorder_wp, |
---|
| 279 | ringorder_Wp, |
---|
| 280 | ringorder_ls, |
---|
| 281 | ringorder_ds, |
---|
| 282 | ringorder_Ds, |
---|
| 283 | ringorder_ws, |
---|
| 284 | ringorder_Ws, |
---|
| 285 | ringorder_L, |
---|
| 286 | // the following are only used internally |
---|
| 287 | ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it |
---|
[7d1574] | 288 | ringorder_rs, |
---|
[35aab3] | 289 | ringorder_unspec |
---|
| 290 | } rRingOrder_t; |
---|
| 291 | |
---|
| 292 | typedef enum rOrderType_t |
---|
| 293 | { |
---|
| 294 | rOrderType_General = 0, // non-simple ordering as specified by currRing |
---|
| 295 | rOrderType_CompExp, // simple ordering, component has priority |
---|
| 296 | rOrderType_ExpComp, // simple ordering, exponent vector has priority |
---|
| 297 | // component not compatible with exp-vector order |
---|
| 298 | rOrderType_Exp, // simple ordering, exponent vector has priority |
---|
| 299 | // component is compatible with exp-vector order |
---|
| 300 | rOrderType_Syz, // syzygy ordering |
---|
| 301 | rOrderType_Schreyer, // Schreyer ordering |
---|
| 302 | rOrderType_Syz2dpc, // syzcomp2dpc |
---|
| 303 | rOrderType_ExpNoComp // simple ordering, differences in component are |
---|
| 304 | // not considered |
---|
| 305 | } rOrderType_t; |
---|
| 306 | |
---|
| 307 | inline BOOLEAN rIsSyzIndexRing(ring r) |
---|
| 308 | { return r->order[0] == ringorder_s;} |
---|
| 309 | |
---|
| 310 | inline int rGetCurrSyzLimit(ring r = currRing) |
---|
| 311 | { return (r->order[0] == ringorder_s ? |
---|
| 312 | r->typ[0].data.syz.limit : 0);} |
---|
| 313 | |
---|
| 314 | // Ring Manipulations |
---|
| 315 | ring rCurrRingAssure_SyzComp(); |
---|
| 316 | void rSetSyzComp(int k); |
---|
| 317 | ring rCurrRingAssure_dp_S(); |
---|
| 318 | ring rCurrRingAssure_dp_C(); |
---|
| 319 | ring rCurrRingAssure_C_dp(); |
---|
| 320 | // makes sure that c/C ordering is last ordering |
---|
| 321 | ring rCurrRingAssure_CompLastBlock(); |
---|
| 322 | // makes sure that c/C ordering is last ordering and SyzIndex is first |
---|
| 323 | ring rCurrRingAssure_SyzComp_CompLastBlock(); |
---|
| 324 | |
---|
| 325 | // return the max-comonent wchich has syzIndex i |
---|
| 326 | // Assume: i<= syzIndex_limit |
---|
| 327 | int rGetMaxSyzComp(int i); |
---|
| 328 | |
---|
| 329 | BOOLEAN rHasSimpleOrder(ring r); |
---|
| 330 | // returns TRUE, if simple lp or ls ordering |
---|
| 331 | BOOLEAN rHasSimpleLexOrder(ring r); |
---|
| 332 | // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */ |
---|
| 333 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing); |
---|
| 334 | // return TRUE if p_SetComp requires p_Setm |
---|
| 335 | BOOLEAN rOrd_SetCompRequiresSetm(ring r); |
---|
| 336 | rOrderType_t rGetOrderType(ring r); |
---|
| 337 | /* returns TRUE if var(i) belongs to p-block */ |
---|
| 338 | BOOLEAN rIsPolyVar(int i, ring r = currRing); |
---|
| 339 | |
---|
| 340 | inline BOOLEAN rOrd_is_Comp_dp(ring r) |
---|
| 341 | { |
---|
| 342 | return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) && |
---|
| 343 | r->order[1] == ringorder_dp && |
---|
| 344 | r->order[2] == 0); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | #ifdef RDEBUG |
---|
| 348 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
| 349 | extern BOOLEAN rDBTest(ring r, char* fn, int l); |
---|
| 350 | #else |
---|
| 351 | #define rTest(r) |
---|
| 352 | #endif |
---|
| 353 | |
---|
| 354 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
| 355 | BOOLEAN omit_comp, |
---|
| 356 | unsigned long exp_limit); |
---|
| 357 | // construct Wp, C ring |
---|
| 358 | ring rModifyRing_Wp(ring r, int* weights); |
---|
[4c7d73] | 359 | void rModify_a_to_A(ring r); |
---|
[35aab3] | 360 | |
---|
| 361 | void rKillModifiedRing(ring r); |
---|
| 362 | // also frees weights |
---|
| 363 | void rKillModified_Wp_Ring(ring r); |
---|
| 364 | |
---|
| 365 | ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple); |
---|
| 366 | void rKillModifiedRing_Simple(ring r); |
---|
| 367 | |
---|
| 368 | void rDebugPrint(ring r); |
---|
| 369 | void pDebugPrint(poly p); |
---|
| 370 | |
---|
[4c7d73] | 371 | int64 * rGetWeightVec(ring r); |
---|
| 372 | void rSetWeightVec(ring r, int64 *wv); |
---|
[35aab3] | 373 | |
---|
[9b9c0b] | 374 | lists rDecompose(const ring r); |
---|
| 375 | ring rCompose(const lists L); |
---|
[a830d2b] | 376 | ///////////////////////////// |
---|
| 377 | // Auxillary functions |
---|
| 378 | // |
---|
| 379 | |
---|
| 380 | BOOLEAN rCheckIV(intvec *iv); |
---|
| 381 | int rTypeOfMatrixOrder(intvec * order); |
---|
| 382 | void rDelete(ring r); |
---|
| 383 | |
---|
[35aab3] | 384 | #endif |
---|