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 // deletes old coeff before setting the new one???
67 #define pSetCoeff0(p,n) (p)->coef=(n)
68 #define p_SetCoeff0(p,n,r) pSetCoeff0(p,n)
69 
70 
71 #define __p_GetComp(p, r) (p)->exp[r->pCompIndex]
72 #define p_GetComp(p, r) ((long) (r->pCompIndex >= 0 ? __p_GetComp(p, r) : 0))
73 
74 
75 /***************************************************************
76  *
77  * prepare debugging
78  *
79  ***************************************************************/
80 
81 #if defined(PDEBUG)
82 
83 extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...);
84 
85 // macros for checking of polys
86 #define pAssumeReturn(cond) \
87 do \
88 { \
89  if (! (cond)) \
90  { \
91  dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
92  #cond); \
93  return FALSE; \
94  } \
95 } \
96 while (0)
97 
98 #define pAssume(cond) \
99 do \
100 { \
101  if (! (cond)) \
102  { \
103  dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
104  #cond); \
105  } \
106 } \
107 while (0)
108 
109 #define _pPolyAssumeReturn(cond, p, r) \
110 do \
111 { \
112  if (! (cond)) \
113  { \
114  dPolyReportError(p, r, "pPolyAssume violation of: %s", \
115  #cond); \
116  return FALSE; \
117  } \
118 } \
119 while (0)
120 
121 #define _pPolyAssume(cond,p,r) \
122 do \
123 { \
124  if (! (cond)) \
125  { \
126  dPolyReportError(p, r, "pPolyAssume violation of: %s", \
127  #cond); \
128  } \
129 } \
130 while (0)
131 
132 #define _pPolyAssumeReturnMsg(cond, msg, p, r) \
133 do \
134 { \
135  if (! (cond)) \
136  { \
137  dPolyReportError(p, r, "%s ", msg); \
138  return FALSE; \
139  } \
140 } \
141 while (0)
142 
143 #define pPolyAssume(cond) _pPolyAssume(cond, p, r)
144 #define pPolyAssumeReturn(cond) _pPolyAssumeReturn(cond, p, r)
145 #define pPolyAssumeReturnMsg(cond, msg) _pPolyAssumeReturnMsg(cond, msg, p, r)
146 
147 #define pFalseReturn(cond) do {if (! (cond)) return FALSE;} while (0)
148 #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
149 #define p_SetRingOfLm(p, r) omSetCustomOfAddr(p, r)
150 //void p_SetRingOfLeftv(leftv l, ring r);
151 #else
152 #define p_SetRingOfLm(p, r) do {} while (0)
153 //#define p_SetRingOfLeftv(l, r) do {} while (0)
154 #endif
155 
156 #else // ! defined(PDEBUG)
157 #define pFalseReturn(cond) do {} while (0)
158 #define pAssume(cond) do {} while (0)
159 #define pPolyAssume(cond) do {} while (0)
160 #define _pPolyAssume(cond, p,r) do {} while (0)
161 #define pAssumeReturn(cond) do {} while (0)
162 #define pPolyAssumeReturn(cond) do {} while (0)
163 #define _pPolyAssumeReturn(cond,p,r) do {} while (0)
164 #define p_SetRingOfLm(p, r) do {} while (0)
165 //#define p_SetRingOfLeftv(l, r) do {} while (0)
166 #endif // defined(PDEBUG)
167 
168 #if PDEBUG >= 1
169 #define pAssume1 pAssume
170 #define pPolyAssume1 pPolyAssume
171 #define _pPolyAssume1 _pPolyAssume
172 #define pAssumeReturn1 pAssumeReturn
173 #define pPolyAssumeReturn1 pPolyAssumeReturn
174 #define _pPolyAssumeReturn1 _pPolyAssumeReturn
175 #define p_LmCheckPolyRing1 p_LmCheckPolyRing
176 #define p_CheckRing1 p_CheckRing
177 #define pIfThen1 pIfThen
178 #else
179 #define pAssume1(cond) do {} while (0)
180 #define pPolyAssume1(cond) do {} while (0)
181 #define _pPolyAssume1(cond,p,r) do {} while (0)
182 #define pAssumeReturn1(cond) do {} while (0)
183 #define pPolyAssumeReturn1(cond) do {} while (0)
184 #define _pPolyAssumeReturn1(cond,p,r)do {} while (0)
185 #define p_LmCheckPolyRing1(p,r) do {} while (0)
186 #define p_CheckRing1(r) do {} while (0)
187 #define pIfThen1(cond, check) do {} while (0)
188 #endif // PDEBUG >= 1
189 
190 #if PDEBUG >= 2
191 #define pAssume2 pAssume
192 #define pPolyAssume2 pPolyAssume
193 #define _pPolyAssume2 _pPolyAssume
194 #define pAssumeReturn2 pAssumeReturn
195 #define pPolyAssumeReturn2 pPolyAssumeReturn
196 #define _pPolyAssumeReturn2 _pPolyAssumeReturn
197 #define p_LmCheckPolyRing2 p_LmCheckPolyRing
198 #define p_CheckRing2 p_CheckRing
199 #define pIfThen2 pIfThen
200 #else
201 #define pAssume2(cond) do {} while (0)
202 #define pPolyAssume2(cond) do {} while (0)
203 #define _pPolyAssume2(cond,p,r) do {} while (0)
204 #define pAssumeReturn2(cond) do {} while (0)
205 #define pPolyAssumeReturn2(cond) do {} while (0)
206 #define _pPolyAssumeReturn2(cond,p,r)do {} while (0)
207 #define p_LmCheckPolyRing2(p,r) do {} while (0)
208 #define p_CheckRing2(r) do {} while (0)
209 #define pIfThen2(cond, check) do {} while (0)
210 #endif // PDEBUG >= 2
211 
212 /***************************************************************
213  *
214  * Macros for low-level allocation
215  *
216  ***************************************************************/
217 #ifdef PDEBUG
218 #define p_AllocBin(p, bin, r) \
219 do \
220 { \
221  omTypeAllocBin(poly, p, bin); \
222  p_SetRingOfLm(p, r); \
223 } \
224 while (0)
225 #define p_FreeBinAddr(p, r) p_LmFree(p, r)
226 #else
227 #define p_AllocBin(p, bin, r) omTypeAllocBin(poly, p, bin)
228 #define p_FreeBinAddr(p, r) omFreeBinAddr(p)
229 #endif
230 
231 /***************************************************************
232  *
233  * Purpose: low-level and macro definition of polys
234  *
235  * If you touch anything here, you better know what you are doing.
236  * What is here should not be used directly from other routines -- the
237  * encapsulations in polys.h should be used, instead.
238  *
239  ***************************************************************/
240 
241 #define POLYSIZE (sizeof(poly) + sizeof(number))
242 #define POLYSIZEW (POLYSIZE / sizeof(long))
243 #if SIZEOF_LONG == 8
244 #define POLY_NEGWEIGHT_OFFSET (((long)0x80000000) << 32)
245 #else
246 #define POLY_NEGWEIGHT_OFFSET ((long)0x80000000)
247 #endif
248 
249 
250 /***************************************************************
251  *
252  * Macros for low-level allocation
253  *
254  ***************************************************************/
255 #ifdef PDEBUG
256 #define p_AllocBin(p, bin, r) \
257 do \
258 { \
259  omTypeAllocBin(poly, p, bin); \
260  p_SetRingOfLm(p, r); \
261 } \
262 while (0)
263 #define p_FreeBinAddr(p, r) p_LmFree(p, r)
264 #else
265 #define p_AllocBin(p, bin, r) omTypeAllocBin(poly, p, bin)
266 #define p_FreeBinAddr(p, r) omFreeBinAddr(p)
267 #endif
268 
269 /***************************************************************
270  *
271  * Misc macros
272  *
273  ***************************************************************/
274 #define rRing_has_Comp(r) (r->pCompIndex >= 0)
275 
276 #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
return P p
Definition: myNF.cc:203
Definition: ring.h:255
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
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:403
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
polyrec * poly
Definition: hilb.h:10
number coef
Definition: monomials.h:32
int BOOLEAN
Definition: auxiliary.h:88
poly next
Definition: monomials.h:31