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