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