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