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