[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 | */ |
---|
[4c7d73] | 9 | /* $Id: ring.h,v 1.10 2005-05-04 15:25:46 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) |
---|
| 25 | int r_IsRingVar(char *n, ring r); |
---|
| 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); |
---|
[6b5dd2] | 31 | ring rOpposite(ring r); |
---|
| 32 | ring rEnvelope(ring r); |
---|
[35aab3] | 33 | |
---|
| 34 | |
---|
| 35 | |
---|
[4c7d73] | 36 | |
---|
[35aab3] | 37 | #ifdef PDEBUG |
---|
| 38 | #define rChangeSComps(c,s,l) rDBChangeSComps(c,s,l) |
---|
| 39 | #define rGetSComps(c,s,l) rDBGetSComps(c,s,l) |
---|
| 40 | void rDBChangeSComps(int* currComponents, |
---|
| 41 | long* currShiftedComponents, |
---|
| 42 | int length, |
---|
| 43 | ring r = currRing); |
---|
| 44 | void rDBGetSComps(int** currComponents, |
---|
| 45 | long** currShiftedComponents, |
---|
| 46 | int *length, |
---|
| 47 | ring r = currRing); |
---|
| 48 | #else |
---|
| 49 | #define rChangeSComps(c,s,l) rNChangeSComps(c,s) |
---|
| 50 | #define rGetSComps(c,s,l) rNGetSComps(c,s) |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | void rNChangeSComps(int* currComponents, long* currShiftedComponents, ring r = currRing); |
---|
| 54 | void rNGetSComps(int** currComponents, long** currShiftedComponents, ring r = currRing); |
---|
| 55 | |
---|
| 56 | idhdl rFindHdl(ring r, idhdl n, idhdl w); |
---|
| 57 | idhdl rSimpleFindHdl(ring r, idhdl root, idhdl n); |
---|
| 58 | const char * rSimpleOrdStr(int ord); |
---|
| 59 | int rOrderName(char * ordername); |
---|
| 60 | char * rOrdStr(ring r); |
---|
| 61 | char * rVarStr(ring r); |
---|
| 62 | char * rCharStr(ring r); |
---|
| 63 | char * rString(ring r); |
---|
| 64 | int rChar(ring r=currRing); |
---|
| 65 | #define rPar(r) (r->P) |
---|
[98a77e] | 66 | #define rVar(r) (r->N) |
---|
[35aab3] | 67 | char * rParStr(ring r); |
---|
| 68 | int rIsExtension(ring r); |
---|
| 69 | int rIsExtension(); |
---|
| 70 | int rSum(ring r1, ring r2, ring &sum); |
---|
| 71 | |
---|
| 72 | BOOLEAN rEqual(ring r1, ring r2, BOOLEAN qr = 1); |
---|
| 73 | void rUnComplete(ring r); |
---|
| 74 | |
---|
| 75 | #define rInternalChar(r) ((r)->ch) |
---|
| 76 | |
---|
| 77 | BOOLEAN rRing_is_Homog(ring r=currRing); |
---|
| 78 | BOOLEAN rRing_has_CompLastBlock(ring r=currRing); |
---|
| 79 | |
---|
| 80 | inline BOOLEAN rField_is_Zp(ring r=currRing) |
---|
| 81 | { return (r->ch > 1) && (r->parameter==NULL); } |
---|
| 82 | |
---|
| 83 | inline BOOLEAN rField_is_Zp(ring r, int p) |
---|
| 84 | { return (r->ch > 1 && r->ch == ABS(p) && r->parameter==NULL); } |
---|
| 85 | |
---|
| 86 | inline BOOLEAN rField_is_Q(ring r=currRing) |
---|
| 87 | { return (r->ch == 0) && (r->parameter==NULL); } |
---|
| 88 | |
---|
| 89 | inline BOOLEAN rField_is_numeric(ring r=currRing) /* R, long R, long C */ |
---|
| 90 | { return (r->ch == -1); } |
---|
| 91 | |
---|
| 92 | inline BOOLEAN rField_is_R(ring r=currRing) |
---|
| 93 | { |
---|
| 94 | if (rField_is_numeric(r) && (r->float_len <= (short)SHORT_REAL_LENGTH)) |
---|
| 95 | return (r->parameter==NULL); |
---|
| 96 | return FALSE; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | inline BOOLEAN rField_is_GF(ring r=currRing) |
---|
| 100 | { return (r->ch > 1) && (r->parameter!=NULL); } |
---|
| 101 | |
---|
| 102 | inline BOOLEAN rField_is_GF(ring r, int q) |
---|
| 103 | { return (r->ch == q); } |
---|
| 104 | |
---|
| 105 | inline BOOLEAN rField_is_Zp_a(ring r=currRing) |
---|
| 106 | { return (r->ch < -1); } |
---|
| 107 | |
---|
| 108 | inline BOOLEAN rField_is_Zp_a(ring r, int p) |
---|
| 109 | { return (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
| 110 | |
---|
| 111 | inline BOOLEAN rField_is_Q_a(ring r=currRing) |
---|
| 112 | { return (r->ch == 1); } |
---|
| 113 | |
---|
| 114 | inline BOOLEAN rField_is_long_R(ring r=currRing) |
---|
| 115 | { |
---|
| 116 | if (rField_is_numeric(r) && (r->float_len >(short)SHORT_REAL_LENGTH)) |
---|
| 117 | return (r->parameter==NULL); |
---|
| 118 | return FALSE; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | inline BOOLEAN rField_is_long_C(ring r=currRing) |
---|
| 122 | { |
---|
| 123 | if (rField_is_numeric(r)) |
---|
| 124 | return (r->parameter!=NULL); |
---|
| 125 | return FALSE; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | inline BOOLEAN rField_has_simple_inverse(ring r=currRing) |
---|
| 129 | /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
| 130 | { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
| 131 | |
---|
| 132 | inline BOOLEAN rField_has_simple_Alloc(ring r=currRing) |
---|
| 133 | { return (rField_is_Zp(r) || rField_is_GF(r) || rField_is_R(r)); } |
---|
| 134 | |
---|
| 135 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
| 136 | inline BOOLEAN rField_is_Extension(ring r=currRing) |
---|
| 137 | { return (rField_is_Q_a(r)) || (rField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
| 138 | |
---|
| 139 | n_coeffType rFieldType(ring r); |
---|
| 140 | |
---|
| 141 | // this needs to be called whenever a new ring is created: new fields |
---|
| 142 | // in ring are created (like VarOffset), unless they already exist |
---|
| 143 | // with force == 1, new fields are _always_ created (overwritten), |
---|
| 144 | // even if they exist |
---|
| 145 | BOOLEAN rComplete(ring r, int force = 0); |
---|
| 146 | // use this to free fields created by rComplete |
---|
[ea68ed] | 147 | |
---|
| 148 | BOOLEAN nc_rComplete(ring src, ring dest); |
---|
| 149 | |
---|
[35aab3] | 150 | void rUnComplete(ring r); |
---|
| 151 | inline int rBlocks(ring r) |
---|
| 152 | { |
---|
| 153 | int i=0; |
---|
| 154 | while (r->order[i]!=0) i++; |
---|
| 155 | return i+1; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | // misc things |
---|
| 159 | inline char* rRingVar(short i) |
---|
| 160 | { |
---|
| 161 | return currRing->names[i]; |
---|
| 162 | } |
---|
| 163 | inline char* rRingVar(short i, ring r) |
---|
| 164 | { |
---|
| 165 | return r->names[i]; |
---|
| 166 | } |
---|
| 167 | inline BOOLEAN rShortOut(ring r) |
---|
| 168 | { |
---|
| 169 | return (r->ShortOut); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | // order stuff |
---|
| 173 | typedef enum rRingOrder_t |
---|
| 174 | { |
---|
| 175 | ringorder_no = 0, |
---|
| 176 | ringorder_a, |
---|
[fc5095] | 177 | ringorder_a64, // for int64 weights |
---|
[35aab3] | 178 | ringorder_c, |
---|
| 179 | ringorder_C, |
---|
| 180 | ringorder_M, |
---|
| 181 | ringorder_S, |
---|
| 182 | ringorder_s, |
---|
| 183 | ringorder_lp, |
---|
| 184 | ringorder_dp, |
---|
| 185 | ringorder_rp, |
---|
| 186 | ringorder_Dp, |
---|
| 187 | ringorder_wp, |
---|
| 188 | ringorder_Wp, |
---|
| 189 | ringorder_ls, |
---|
| 190 | ringorder_ds, |
---|
| 191 | ringorder_Ds, |
---|
| 192 | ringorder_ws, |
---|
| 193 | ringorder_Ws, |
---|
| 194 | ringorder_L, |
---|
| 195 | // the following are only used internally |
---|
| 196 | ringorder_aa, // for idElimination, like a, except pFDeg, pWeigths ignore it |
---|
| 197 | ringorder_unspec |
---|
| 198 | } rRingOrder_t; |
---|
| 199 | |
---|
| 200 | typedef enum rOrderType_t |
---|
| 201 | { |
---|
| 202 | rOrderType_General = 0, // non-simple ordering as specified by currRing |
---|
| 203 | rOrderType_CompExp, // simple ordering, component has priority |
---|
| 204 | rOrderType_ExpComp, // simple ordering, exponent vector has priority |
---|
| 205 | // component not compatible with exp-vector order |
---|
| 206 | rOrderType_Exp, // simple ordering, exponent vector has priority |
---|
| 207 | // component is compatible with exp-vector order |
---|
| 208 | rOrderType_Syz, // syzygy ordering |
---|
| 209 | rOrderType_Schreyer, // Schreyer ordering |
---|
| 210 | rOrderType_Syz2dpc, // syzcomp2dpc |
---|
| 211 | rOrderType_ExpNoComp // simple ordering, differences in component are |
---|
| 212 | // not considered |
---|
| 213 | } rOrderType_t; |
---|
| 214 | |
---|
| 215 | inline BOOLEAN rIsSyzIndexRing(ring r) |
---|
| 216 | { return r->order[0] == ringorder_s;} |
---|
| 217 | |
---|
| 218 | inline int rGetCurrSyzLimit(ring r = currRing) |
---|
| 219 | { return (r->order[0] == ringorder_s ? |
---|
| 220 | r->typ[0].data.syz.limit : 0);} |
---|
| 221 | |
---|
| 222 | // Ring Manipulations |
---|
| 223 | ring rCurrRingAssure_SyzComp(); |
---|
| 224 | void rSetSyzComp(int k); |
---|
| 225 | ring rCurrRingAssure_dp_S(); |
---|
| 226 | ring rCurrRingAssure_dp_C(); |
---|
| 227 | ring rCurrRingAssure_C_dp(); |
---|
| 228 | // makes sure that c/C ordering is last ordering |
---|
| 229 | ring rCurrRingAssure_CompLastBlock(); |
---|
| 230 | // makes sure that c/C ordering is last ordering and SyzIndex is first |
---|
| 231 | ring rCurrRingAssure_SyzComp_CompLastBlock(); |
---|
| 232 | |
---|
| 233 | // return the max-comonent wchich has syzIndex i |
---|
| 234 | // Assume: i<= syzIndex_limit |
---|
| 235 | int rGetMaxSyzComp(int i); |
---|
| 236 | |
---|
| 237 | BOOLEAN rHasSimpleOrder(ring r); |
---|
| 238 | // returns TRUE, if simple lp or ls ordering |
---|
| 239 | BOOLEAN rHasSimpleLexOrder(ring r); |
---|
| 240 | // return TRUE if p->exp[r->pOrdIndex] holds total degree of p */ |
---|
| 241 | BOOLEAN rOrd_is_Totaldegree_Ordering(ring r =currRing); |
---|
| 242 | // return TRUE if p_SetComp requires p_Setm |
---|
| 243 | BOOLEAN rOrd_SetCompRequiresSetm(ring r); |
---|
| 244 | rOrderType_t rGetOrderType(ring r); |
---|
| 245 | /* returns TRUE if var(i) belongs to p-block */ |
---|
| 246 | BOOLEAN rIsPolyVar(int i, ring r = currRing); |
---|
| 247 | |
---|
| 248 | inline BOOLEAN rOrd_is_Comp_dp(ring r) |
---|
| 249 | { |
---|
| 250 | return ((r->order[0] == ringorder_c || r->order[0] == ringorder_C) && |
---|
| 251 | r->order[1] == ringorder_dp && |
---|
| 252 | r->order[2] == 0); |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | #ifdef HAVE_PLURAL |
---|
| 256 | inline BOOLEAN rIsPluralRing(ring r) |
---|
| 257 | { |
---|
[1a28c1] | 258 | return ((r != NULL) && (r->nc != NULL)); |
---|
[35aab3] | 259 | } |
---|
| 260 | #else |
---|
| 261 | #define rIsPluralRing(r) (0) |
---|
| 262 | #endif |
---|
| 263 | |
---|
| 264 | #ifdef RDEBUG |
---|
| 265 | #define rTest(r) rDBTest(r, __FILE__, __LINE__) |
---|
| 266 | extern BOOLEAN rDBTest(ring r, char* fn, int l); |
---|
| 267 | #else |
---|
| 268 | #define rTest(r) |
---|
| 269 | #endif |
---|
| 270 | |
---|
| 271 | ring rModifyRing(ring r, BOOLEAN omit_degree, |
---|
| 272 | BOOLEAN omit_comp, |
---|
| 273 | unsigned long exp_limit); |
---|
| 274 | // construct Wp, C ring |
---|
| 275 | ring rModifyRing_Wp(ring r, int* weights); |
---|
[4c7d73] | 276 | void rModify_a_to_A(ring r); |
---|
[35aab3] | 277 | |
---|
| 278 | void rKillModifiedRing(ring r); |
---|
| 279 | // also frees weights |
---|
| 280 | void rKillModified_Wp_Ring(ring r); |
---|
| 281 | |
---|
| 282 | ring rModifyRing_Simple(ring r, BOOLEAN omit_degree, BOOLEAN omit_comp, unsigned long exp_limit, BOOLEAN &simple); |
---|
| 283 | void rKillModifiedRing_Simple(ring r); |
---|
| 284 | |
---|
| 285 | void rDebugPrint(ring r); |
---|
| 286 | void pDebugPrint(poly p); |
---|
| 287 | |
---|
[4c7d73] | 288 | int64 * rGetWeightVec(ring r); |
---|
| 289 | void rSetWeightVec(ring r, int64 *wv); |
---|
[35aab3] | 290 | |
---|
[9b9c0b] | 291 | lists rDecompose(const ring r); |
---|
| 292 | ring rCompose(const lists L); |
---|
[a830d2b] | 293 | ///////////////////////////// |
---|
| 294 | // Auxillary functions |
---|
| 295 | // |
---|
| 296 | |
---|
| 297 | BOOLEAN rCheckIV(intvec *iv); |
---|
| 298 | int rTypeOfMatrixOrder(intvec * order); |
---|
| 299 | void rDelete(ring r); |
---|
| 300 | |
---|
[35aab3] | 301 | #endif |
---|