source: git/libpolys/polys/monomials/monomials.h @ 805d0b1

spielwiese
Last change on this file since 805d0b1 was 805d0b1, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
improved (standalone!) header for polynomials (polys/monomials/monomials.h) chg: moved the basic primitives for accessing and setting fields of a poly from p_polys.h into monomials.h NOTE: these basic functions either do NOT need a ring or are macros (or both) chg: no need to include coeffs/coeffs.h and polys/monomials/ring.h in polys/monomials/monomials.h NOTE: just forward-declare structures and typedef pointers at them. chg: minor cleanup of includes in p_polys.cc
  • 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/* $Id$ */
7/*
8* ABSTRACT
9*/
10
11#include <omalloc/omalloc.h>
12
13struct snumber;
14typedef struct snumber *   number;
15
16struct ip_sring;
17typedef struct ip_sring *         ring;
18typedef struct ip_sring const *   const_ring;
19
20/***************************************************************
21 *
22 * definition of the poly structure and its fields
23 *
24 ***************************************************************/
25
26struct spolyrec;
27typedef struct spolyrec *          poly;
28
29struct  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)            ((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
51static 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
83extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...);
84
85// macros for checking of polys
86#define pAssumeReturn(cond)                                  \
87do                                                          \
88{                                                           \
89  if (! (cond))                                             \
90  {                                                         \
91    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
92                 #cond);                                    \
93    return FALSE;                                           \
94  }                                                         \
95}                                                           \
96while (0)
97
98#define pAssume(cond)                                        \
99do                                                          \
100{                                                           \
101  if (! (cond))                                             \
102  {                                                         \
103    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
104                 #cond);                                    \
105  }                                                         \
106}                                                           \
107while (0)
108
109#define _pPolyAssumeReturn(cond, p, r)                       \
110do                                                          \
111{                                                           \
112  if (! (cond))                                             \
113  {                                                         \
114    dPolyReportError(p, r, "pPolyAssume violation of: %s",   \
115                 #cond);                                    \
116    return FALSE;                                           \
117  }                                                         \
118}                                                           \
119while (0)
120
121#define _pPolyAssume(cond,p,r)                                   \
122do                                                              \
123{                                                               \
124  if (! (cond))                                                 \
125  {                                                             \
126    dPolyReportError(p, r, "pPolyAssume violation of: %s",    \
127                 #cond);                                        \
128  }                                                             \
129}                                                               \
130while (0)
131
132#define _pPolyAssumeReturnMsg(cond, msg, p, r)   \
133do                                              \
134{                                               \
135  if (! (cond))                                 \
136  {                                             \
137    dPolyReportError(p, r, "%s ",  msg);        \
138    return FALSE;                               \
139  }                                             \
140}                                               \
141while (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) ((void)0)
153//#define p_SetRingOfLeftv(l, r) ((void)0)
154#endif
155
156#else // ! defined(PDEBUG)
157#define pFalseReturn(cond)           ((void)0)
158#define pAssume(cond)                ((void)0)
159#define pPolyAssume(cond)            ((void)0)
160#define _pPolyAssume(cond, p,r)      ((void)0)
161#define pAssumeReturn(cond)          ((void)0)
162#define pPolyAssumeReturn(cond)      ((void)0)
163#define _pPolyAssumeReturn(cond,p,r) ((void)0)
164#define p_SetRingOfLm(p, r)          ((void)0)
165//#define p_SetRingOfLeftv(l, r)       ((void)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)               ((void)0)
180#define pPolyAssume1(cond)           ((void)0)
181#define _pPolyAssume1(cond,p,r)      ((void)0)
182#define pAssumeReturn1(cond)         ((void)0)
183#define pPolyAssumeReturn1(cond)     ((void)0)
184#define _pPolyAssumeReturn1(cond,p,r)((void)0)
185#define p_LmCheckPolyRing1(p,r)       ((void)0)
186#define p_CheckRing1(r)             ((void)0)
187#define pIfThen1(cond, check)     ((void)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)               ((void)0)
202#define pPolyAssume2(cond)           ((void)0)
203#define _pPolyAssume2(cond,p,r)      ((void)0)
204#define pAssumeReturn2(cond)         ((void)0)
205#define pPolyAssumeReturn2(cond)     ((void)0)
206#define _pPolyAssumeReturn2(cond,p,r)((void)0)
207#define p_LmCheckPolyRing2(p,r)       ((void)0)
208#define p_CheckRing2(r)             ((void)0)
209#define pIfThen2(cond, check)     ((void)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)                   \
219do                                              \
220{                                               \
221  omTypeAllocBin(poly, p, bin);                 \
222  p_SetRingOfLm(p, r);                        \
223}                                               \
224while (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)                   \
257do                                              \
258{                                               \
259  omTypeAllocBin(poly, p, bin);                 \
260  p_SetRingOfLm(p, r);                        \
261}                                               \
262while (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
Note: See TracBrowser for help on using the repository browser.