[e471bd] | 1 | #ifndef MONOMIALS_H |
---|
| 2 | #define MONOMIALS_H |
---|
| 3 | /**************************************** |
---|
| 4 | * Computer Algebra System SINGULAR * |
---|
| 5 | ****************************************/ |
---|
| 6 | /* $Id$ */ |
---|
| 7 | /* |
---|
| 8 | * ABSTRACT |
---|
| 9 | */ |
---|
| 10 | |
---|
[20b794] | 11 | #include <omalloc/omalloc.h> |
---|
| 12 | #include <coeffs/coeffs.h> |
---|
| 13 | #include <polys/monomials/ring.h> |
---|
[e471bd] | 14 | |
---|
| 15 | /*************************************************************** |
---|
| 16 | * |
---|
| 17 | * definition of the poly structure and its fields |
---|
| 18 | * |
---|
| 19 | ***************************************************************/ |
---|
| 20 | |
---|
| 21 | struct spolyrec; |
---|
| 22 | typedef struct spolyrec * poly; |
---|
| 23 | struct spolyrec |
---|
| 24 | { |
---|
| 25 | poly next; // next needs to be the first field |
---|
| 26 | number coef; // and coef the second --- do not change this !!! |
---|
| 27 | unsigned long exp[1]; // make sure that exp is aligned |
---|
| 28 | }; |
---|
| 29 | |
---|
[0ceb74] | 30 | |
---|
[e471bd] | 31 | /*************************************************************** |
---|
| 32 | * |
---|
| 33 | * Macros for access/iteration |
---|
| 34 | * |
---|
| 35 | ***************************************************************/ |
---|
[0ceb74] | 36 | // #define pNext(p) ((p)->next) |
---|
| 37 | // #define pIter(p) ((p) = (p)->next) |
---|
[e471bd] | 38 | |
---|
| 39 | // coeff |
---|
[0ceb74] | 40 | //#define pGetCoeff(p) ((p)->coef) |
---|
| 41 | //#define pSetCoeff0(p,n) (p)->coef=n |
---|
| 42 | |
---|
[e471bd] | 43 | #define __p_GetComp(p, r) (p)->exp[r->pCompIndex] |
---|
| 44 | #define p_GetComp(p, r) ((long) (r->pCompIndex >= 0 ? __p_GetComp(p, r) : 0)) |
---|
| 45 | |
---|
| 46 | /*************************************************************** |
---|
| 47 | * |
---|
| 48 | * prepare debugging |
---|
| 49 | * |
---|
| 50 | ***************************************************************/ |
---|
| 51 | |
---|
| 52 | #if defined(PDEBUG) |
---|
| 53 | |
---|
| 54 | extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...); |
---|
| 55 | |
---|
| 56 | // macros for checking of polys |
---|
| 57 | #define pAssumeReturn(cond) \ |
---|
| 58 | do \ |
---|
| 59 | { \ |
---|
| 60 | if (! (cond)) \ |
---|
| 61 | { \ |
---|
| 62 | dPolyReportError(NULL, NULL, "pAssume violation of: %s", \ |
---|
| 63 | #cond); \ |
---|
| 64 | return FALSE; \ |
---|
| 65 | } \ |
---|
| 66 | } \ |
---|
| 67 | while (0) |
---|
| 68 | |
---|
| 69 | #define pAssume(cond) \ |
---|
| 70 | do \ |
---|
| 71 | { \ |
---|
| 72 | if (! (cond)) \ |
---|
| 73 | { \ |
---|
| 74 | dPolyReportError(NULL, NULL, "pAssume violation of: %s", \ |
---|
| 75 | #cond); \ |
---|
| 76 | } \ |
---|
| 77 | } \ |
---|
| 78 | while (0) |
---|
| 79 | |
---|
| 80 | #define _pPolyAssumeReturn(cond, p, r) \ |
---|
| 81 | do \ |
---|
| 82 | { \ |
---|
| 83 | if (! (cond)) \ |
---|
| 84 | { \ |
---|
| 85 | dPolyReportError(p, r, "pPolyAssume violation of: %s", \ |
---|
| 86 | #cond); \ |
---|
| 87 | return FALSE; \ |
---|
| 88 | } \ |
---|
| 89 | } \ |
---|
| 90 | while (0) |
---|
| 91 | |
---|
| 92 | #define _pPolyAssume(cond,p,r) \ |
---|
| 93 | do \ |
---|
| 94 | { \ |
---|
| 95 | if (! (cond)) \ |
---|
| 96 | { \ |
---|
| 97 | dPolyReportError(p, r, "pPolyAssume violation of: %s", \ |
---|
| 98 | #cond); \ |
---|
| 99 | } \ |
---|
| 100 | } \ |
---|
| 101 | while (0) |
---|
| 102 | |
---|
| 103 | #define _pPolyAssumeReturnMsg(cond, msg, p, r) \ |
---|
| 104 | do \ |
---|
| 105 | { \ |
---|
| 106 | if (! (cond)) \ |
---|
| 107 | { \ |
---|
| 108 | dPolyReportError(p, r, "%s ", msg); \ |
---|
| 109 | return FALSE; \ |
---|
| 110 | } \ |
---|
| 111 | } \ |
---|
| 112 | while (0) |
---|
| 113 | |
---|
| 114 | #define pPolyAssume(cond) _pPolyAssume(cond, p, r) |
---|
| 115 | #define pPolyAssumeReturn(cond) _pPolyAssumeReturn(cond, p, r) |
---|
| 116 | #define pPolyAssumeReturnMsg(cond, msg) _pPolyAssumeReturnMsg(cond, msg, p, r) |
---|
| 117 | |
---|
| 118 | #define pFalseReturn(cond) do {if (! (cond)) return FALSE;} while (0) |
---|
| 119 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
| 120 | #define p_SetRingOfLm(p, r) omSetCustomOfAddr(p, r) |
---|
| 121 | void p_SetRingOfLeftv(leftv l, ring r); |
---|
| 122 | #else |
---|
| 123 | #define p_SetRingOfLm(p, r) ((void)0) |
---|
| 124 | #define p_SetRingOfLeftv(l, r) ((void)0) |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | #else // ! defined(PDEBUG) |
---|
| 128 | #define pFalseReturn(cond) ((void)0) |
---|
| 129 | #define pAssume(cond) ((void)0) |
---|
| 130 | #define pPolyAssume(cond) ((void)0) |
---|
| 131 | #define _pPolyAssume(cond, p,r) ((void)0) |
---|
| 132 | #define pAssumeReturn(cond) ((void)0) |
---|
| 133 | #define pPolyAssumeReturn(cond) ((void)0) |
---|
| 134 | #define _pPolyAssumeReturn(cond,p,r) ((void)0) |
---|
| 135 | #define p_SetRingOfLm(p, r) ((void)0) |
---|
| 136 | #define p_SetRingOfLeftv(l, r) ((void)0) |
---|
| 137 | #endif // defined(PDEBUG) |
---|
| 138 | |
---|
| 139 | #if PDEBUG >= 1 |
---|
| 140 | #define pAssume1 pAssume |
---|
| 141 | #define pPolyAssume1 pPolyAssume |
---|
| 142 | #define _pPolyAssume1 _pPolyAssume |
---|
| 143 | #define pAssumeReturn1 pAssumeReturn |
---|
| 144 | #define pPolyAssumeReturn1 pPolyAssumeReturn |
---|
| 145 | #define _pPolyAssumeReturn1 _pPolyAssumeReturn |
---|
| 146 | #define p_LmCheckPolyRing1 p_LmCheckPolyRing |
---|
| 147 | #define p_CheckRing1 p_CheckRing |
---|
| 148 | #define pIfThen1 pIfThen |
---|
| 149 | #else |
---|
| 150 | #define pAssume1(cond) ((void)0) |
---|
| 151 | #define pPolyAssume1(cond) ((void)0) |
---|
| 152 | #define _pPolyAssume1(cond,p,r) ((void)0) |
---|
| 153 | #define pAssumeReturn1(cond) ((void)0) |
---|
| 154 | #define pPolyAssumeReturn1(cond) ((void)0) |
---|
| 155 | #define _pPolyAssumeReturn1(cond,p,r)((void)0) |
---|
| 156 | #define p_LmCheckPolyRing1(p,r) ((void)0) |
---|
| 157 | #define p_CheckRing1(r) ((void)0) |
---|
| 158 | #define pIfThen1(cond, check) ((void)0) |
---|
| 159 | #endif // PDEBUG >= 1 |
---|
| 160 | |
---|
| 161 | #if PDEBUG >= 2 |
---|
| 162 | #define pAssume2 pAssume |
---|
| 163 | #define pPolyAssume2 pPolyAssume |
---|
| 164 | #define _pPolyAssume2 _pPolyAssume |
---|
| 165 | #define pAssumeReturn2 pAssumeReturn |
---|
| 166 | #define pPolyAssumeReturn2 pPolyAssumeReturn |
---|
| 167 | #define _pPolyAssumeReturn2 _pPolyAssumeReturn |
---|
| 168 | #define p_LmCheckPolyRing2 p_LmCheckPolyRing |
---|
| 169 | #define p_CheckRing2 p_CheckRing |
---|
| 170 | #define pIfThen2 pIfThen |
---|
| 171 | #else |
---|
| 172 | #define pAssume2(cond) ((void)0) |
---|
| 173 | #define pPolyAssume2(cond) ((void)0) |
---|
| 174 | #define _pPolyAssume2(cond,p,r) ((void)0) |
---|
| 175 | #define pAssumeReturn2(cond) ((void)0) |
---|
| 176 | #define pPolyAssumeReturn2(cond) ((void)0) |
---|
| 177 | #define _pPolyAssumeReturn2(cond,p,r)((void)0) |
---|
| 178 | #define p_LmCheckPolyRing2(p,r) ((void)0) |
---|
| 179 | #define p_CheckRing2(r) ((void)0) |
---|
| 180 | #define pIfThen2(cond, check) ((void)0) |
---|
| 181 | #endif // PDEBUG >= 2 |
---|
| 182 | |
---|
| 183 | /*************************************************************** |
---|
| 184 | * |
---|
| 185 | * Macros for low-level allocation |
---|
| 186 | * |
---|
| 187 | ***************************************************************/ |
---|
| 188 | #ifdef PDEBUG |
---|
| 189 | #define p_AllocBin(p, bin, r) \ |
---|
| 190 | do \ |
---|
| 191 | { \ |
---|
| 192 | omTypeAllocBin(poly, p, bin); \ |
---|
| 193 | p_SetRingOfLm(p, r); \ |
---|
| 194 | } \ |
---|
| 195 | while (0) |
---|
| 196 | #define p_FreeBinAddr(p, r) p_LmFree(p, r) |
---|
| 197 | #else |
---|
| 198 | #define p_AllocBin(p, bin, r) omTypeAllocBin(poly, p, bin) |
---|
| 199 | #define p_FreeBinAddr(p, r) omFreeBinAddr(p) |
---|
| 200 | #endif |
---|
| 201 | |
---|
[001a38f] | 202 | /*************************************************************** |
---|
| 203 | * |
---|
| 204 | * Purpose: low-level and macro definition of polys |
---|
| 205 | * |
---|
| 206 | * If you touch anything here, you better know what you are doing. |
---|
| 207 | * What is here should not be used directly from other routines -- the |
---|
| 208 | * encapsulations in polys.h should be used, instead. |
---|
| 209 | * |
---|
| 210 | ***************************************************************/ |
---|
| 211 | |
---|
| 212 | #define POLYSIZE (sizeof(poly) + sizeof(number)) |
---|
| 213 | #define POLYSIZEW (POLYSIZE / sizeof(long)) |
---|
| 214 | #if SIZEOF_LONG == 8 |
---|
| 215 | #define POLY_NEGWEIGHT_OFFSET (((long)0x80000000) << 32) |
---|
| 216 | #else |
---|
| 217 | #define POLY_NEGWEIGHT_OFFSET ((long)0x80000000) |
---|
| 218 | #endif |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | /*************************************************************** |
---|
| 222 | * |
---|
| 223 | * Macros for low-level allocation |
---|
| 224 | * |
---|
| 225 | ***************************************************************/ |
---|
| 226 | #ifdef PDEBUG |
---|
| 227 | #define p_AllocBin(p, bin, r) \ |
---|
| 228 | do \ |
---|
| 229 | { \ |
---|
| 230 | omTypeAllocBin(poly, p, bin); \ |
---|
| 231 | p_SetRingOfLm(p, r); \ |
---|
| 232 | } \ |
---|
| 233 | while (0) |
---|
| 234 | #define p_FreeBinAddr(p, r) p_LmFree(p, r) |
---|
| 235 | #else |
---|
| 236 | #define p_AllocBin(p, bin, r) omTypeAllocBin(poly, p, bin) |
---|
| 237 | #define p_FreeBinAddr(p, r) omFreeBinAddr(p) |
---|
| 238 | #endif |
---|
| 239 | |
---|
| 240 | /*************************************************************** |
---|
| 241 | * |
---|
| 242 | * Misc macros |
---|
| 243 | * |
---|
| 244 | ***************************************************************/ |
---|
| 245 | #define rRing_has_Comp(r) (r->pCompIndex >= 0) |
---|
| 246 | |
---|
[e471bd] | 247 | #endif |
---|