source: git/libpolys/polys/monomials/monomials.h @ 85bcd6

fieker-DuValspielwiese
Last change on this file since 85bcd6 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 9.6 KB
Line 
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
12struct snumber;
13typedef struct snumber *   number;
14
15struct ip_sring;
16typedef struct ip_sring *         ring;
17typedef struct ip_sring const *   const_ring;
18
19/***************************************************************
20 *
21 * definition of the poly structure and its fields
22 *
23 ***************************************************************/
24
25struct spolyrec;
26typedef struct spolyrec *          poly;
27
28struct  spolyrec
29{
30  poly      next;           // next needs to be the first field
31  number    coef;           // and coef the second --- do not change this !!!
32  unsigned long exp[1];     // make sure that exp is aligned
33};
34
35/***************************************************************
36 *
37 * Primitives for accessing and setting fields of a poly
38 * poly must be != NULL
39 *
40 ***************************************************************/
41// next
42#define pNext(p)            ((p)->next)
43#define pIter(p)            ((p) = (p)->next)
44
45// coeff
46// #define pGetCoeff(p)        ((p)->coef)
47/// return an alias to the leading coefficient of p
48/// assumes that p != NULL
49/// NOTE: not copy
50static inline number& pGetCoeff(poly p)
51{
52  assume(p != NULL);
53  return p->coef;
54}
55
56#define p_GetCoeff(p,r)     pGetCoeff(p)
57//static inline number& p_GetCoeff(poly p, const ring r)
58//{
59//  assume(r != NULL);
60//  return pGetCoeff(p);
61//}
62
63
64//
65// deletes old coeff before setting the new one???
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
82extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...);
83
84// macros for checking of polys
85#define pAssumeReturn(cond)                                  \
86do                                                          \
87{                                                           \
88  if (! (cond))                                             \
89  {                                                         \
90    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
91                 #cond);                                    \
92    return FALSE;                                           \
93  }                                                         \
94}                                                           \
95while (0)
96
97#define pAssume(cond)                                        \
98do                                                          \
99{                                                           \
100  if (! (cond))                                             \
101  {                                                         \
102    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
103                 #cond);                                    \
104  }                                                         \
105}                                                           \
106while (0)
107
108#define _pPolyAssumeReturn(cond, p, r)                       \
109do                                                          \
110{                                                           \
111  if (! (cond))                                             \
112  {                                                         \
113    dPolyReportError(p, r, "pPolyAssume violation of: %s",   \
114                 #cond);                                    \
115    return FALSE;                                           \
116  }                                                         \
117}                                                           \
118while (0)
119
120#define _pPolyAssume(cond,p,r)                                   \
121do                                                              \
122{                                                               \
123  if (! (cond))                                                 \
124  {                                                             \
125    dPolyReportError(p, r, "pPolyAssume violation of: %s",    \
126                 #cond);                                        \
127  }                                                             \
128}                                                               \
129while (0)
130
131#define _pPolyAssumeReturnMsg(cond, msg, p, r)   \
132do                                              \
133{                                               \
134  if (! (cond))                                 \
135  {                                             \
136    dPolyReportError(p, r, "%s ",  msg);        \
137    return FALSE;                               \
138  }                                             \
139}                                               \
140while (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) ((void)0)
152//#define p_SetRingOfLeftv(l, r) ((void)0)
153#endif
154
155#else // ! defined(PDEBUG)
156#define pFalseReturn(cond)           ((void)0)
157#define pAssume(cond)                ((void)0)
158#define pPolyAssume(cond)            ((void)0)
159#define _pPolyAssume(cond, p,r)      ((void)0)
160#define pAssumeReturn(cond)          ((void)0)
161#define pPolyAssumeReturn(cond)      ((void)0)
162#define _pPolyAssumeReturn(cond,p,r) ((void)0)
163#define p_SetRingOfLm(p, r)          ((void)0)
164//#define p_SetRingOfLeftv(l, r)       ((void)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)               ((void)0)
179#define pPolyAssume1(cond)           ((void)0)
180#define _pPolyAssume1(cond,p,r)      ((void)0)
181#define pAssumeReturn1(cond)         ((void)0)
182#define pPolyAssumeReturn1(cond)     ((void)0)
183#define _pPolyAssumeReturn1(cond,p,r)((void)0)
184#define p_LmCheckPolyRing1(p,r)       ((void)0)
185#define p_CheckRing1(r)             ((void)0)
186#define pIfThen1(cond, check)     ((void)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)               ((void)0)
201#define pPolyAssume2(cond)           ((void)0)
202#define _pPolyAssume2(cond,p,r)      ((void)0)
203#define pAssumeReturn2(cond)         ((void)0)
204#define pPolyAssumeReturn2(cond)     ((void)0)
205#define _pPolyAssumeReturn2(cond,p,r)((void)0)
206#define p_LmCheckPolyRing2(p,r)       ((void)0)
207#define p_CheckRing2(r)             ((void)0)
208#define pIfThen2(cond, check)     ((void)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)                   \
218do                                              \
219{                                               \
220  omTypeAllocBin(poly, p, bin);                 \
221  p_SetRingOfLm(p, r);                        \
222}                                               \
223while (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)                   \
256do                                              \
257{                                               \
258  omTypeAllocBin(poly, p, bin);                 \
259  p_SetRingOfLm(p, r);                        \
260}                                               \
261while (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
Note: See TracBrowser for help on using the repository browser.