source: git/polys/monomials/monomials.h @ 51372b

spielwiese
Last change on this file since 51372b was e471bd, checked in by Hans Schoenemann <hannes@…>, 14 years ago
monomials.h defines poly
  • Property mode set to 100644
File size: 8.5 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.h>
12#include <coeffs.h>
13#include "ring.h"
14
15/***************************************************************
16 *
17 * definition of the poly structure and its fields
18 *
19 ***************************************************************/
20
21struct spolyrec;
22typedef struct spolyrec *          poly;
23struct  spolyrec
24{
25  poly      next;           // next needs to be the first field
26  number    coef;           // and coef the second --- do not change this !!!
27  unsigned long exp[1];     // make sure that exp is aligned
28};
29
30/***************************************************************
31 *
32 * Macros for access/iteration
33 *
34 ***************************************************************/
35#define pNext(p)           ((p)->next)
36#define pIter(p)           ((p) = (p)->next)
37
38// coeff
39#define pGetCoeff(p)       ((p)->coef)
40#define pSetCoeff0(p,n)    (p)->coef=n
41#define __p_GetComp(p, r)   (p)->exp[r->pCompIndex]
42#define p_GetComp(p, r)    ((long) (r->pCompIndex >= 0 ? __p_GetComp(p, r) : 0))
43
44/***************************************************************
45 *
46 * What should be inlined and debugged?
47 *
48 ***************************************************************/
49// determines inlining of poly procs which iter through polys
50#if defined(DO_PINLINE0) && !defined(PDEBUG)
51#define PINLINE0 static inline
52#else
53#define PINLINE0
54#endif
55
56// determines inlining of poly procs which iter over ExpVector
57#undef NO_PINLINE1
58#if PDEBUG <= 0 && !defined(NO_INLINE1)
59#define PINLINE1 static inline
60#else
61#define PINLINE1
62#define NO_PINLINE1 1
63#endif
64
65// determines inlining of constant time poly procs
66#undef NO_PINLINE2
67#if PDEBUG <= 1 && !defined(NO_INLINE2)
68#define PINLINE2 static inline
69#else
70#define PINLINE2
71#define NO_PINLINE2 1
72#endif
73
74// determines inlining of stuff from polys-impl.h
75#undef NO_PINLINE3
76#if PDEBUG <= 2 && !defined(NO_INLINE3)
77#define PINLINE3 static inline
78#else
79#define PINLINE3
80#define NO_PINLINE3 1
81#endif
82
83/***************************************************************
84 *
85 * prepare debugging
86 *
87 ***************************************************************/
88
89#if defined(PDEBUG)
90
91extern BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...);
92
93// macros for checking of polys
94#define pAssumeReturn(cond)                                  \
95do                                                          \
96{                                                           \
97  if (! (cond))                                             \
98  {                                                         \
99    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
100                 #cond);                                    \
101    return FALSE;                                           \
102  }                                                         \
103}                                                           \
104while (0)
105
106#define pAssume(cond)                                        \
107do                                                          \
108{                                                           \
109  if (! (cond))                                             \
110  {                                                         \
111    dPolyReportError(NULL, NULL, "pAssume violation of: %s", \
112                 #cond);                                    \
113  }                                                         \
114}                                                           \
115while (0)
116
117#define _pPolyAssumeReturn(cond, p, r)                       \
118do                                                          \
119{                                                           \
120  if (! (cond))                                             \
121  {                                                         \
122    dPolyReportError(p, r, "pPolyAssume violation of: %s",   \
123                 #cond);                                    \
124    return FALSE;                                           \
125  }                                                         \
126}                                                           \
127while (0)
128
129#define _pPolyAssume(cond,p,r)                                   \
130do                                                              \
131{                                                               \
132  if (! (cond))                                                 \
133  {                                                             \
134    dPolyReportError(p, r, "pPolyAssume violation of: %s",    \
135                 #cond);                                        \
136  }                                                             \
137}                                                               \
138while (0)
139
140#define _pPolyAssumeReturnMsg(cond, msg, p, r)   \
141do                                              \
142{                                               \
143  if (! (cond))                                 \
144  {                                             \
145    dPolyReportError(p, r, "%s ",  msg);        \
146    return FALSE;                               \
147  }                                             \
148}                                               \
149while (0)
150
151#define pPolyAssume(cond)        _pPolyAssume(cond, p, r)
152#define pPolyAssumeReturn(cond)  _pPolyAssumeReturn(cond, p, r)
153#define pPolyAssumeReturnMsg(cond, msg)  _pPolyAssumeReturnMsg(cond, msg, p, r)
154
155#define pFalseReturn(cond)  do {if (! (cond)) return FALSE;} while (0)
156#if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM)
157#define p_SetRingOfLm(p, r) omSetCustomOfAddr(p, r)
158void p_SetRingOfLeftv(leftv l, ring r);
159#else
160#define p_SetRingOfLm(p, r) ((void)0)
161#define p_SetRingOfLeftv(l, r) ((void)0)
162#endif
163
164#else // ! defined(PDEBUG)
165#define pFalseReturn(cond)           ((void)0)
166#define pAssume(cond)                ((void)0)
167#define pPolyAssume(cond)            ((void)0)
168#define _pPolyAssume(cond, p,r)      ((void)0)
169#define pAssumeReturn(cond)          ((void)0)
170#define pPolyAssumeReturn(cond)      ((void)0)
171#define _pPolyAssumeReturn(cond,p,r) ((void)0)
172#define p_SetRingOfLm(p, r)          ((void)0)
173#define p_SetRingOfLeftv(l, r)       ((void)0)
174#endif // defined(PDEBUG)
175
176#if PDEBUG >= 1
177#define pAssume1             pAssume
178#define pPolyAssume1         pPolyAssume
179#define _pPolyAssume1        _pPolyAssume
180#define pAssumeReturn1       pAssumeReturn
181#define pPolyAssumeReturn1   pPolyAssumeReturn
182#define _pPolyAssumeReturn1  _pPolyAssumeReturn
183#define p_LmCheckPolyRing1    p_LmCheckPolyRing
184#define p_CheckRing1        p_CheckRing
185#define pIfThen1          pIfThen
186#else
187#define pAssume1(cond)               ((void)0)
188#define pPolyAssume1(cond)           ((void)0)
189#define _pPolyAssume1(cond,p,r)      ((void)0)
190#define pAssumeReturn1(cond)         ((void)0)
191#define pPolyAssumeReturn1(cond)     ((void)0)
192#define _pPolyAssumeReturn1(cond,p,r)((void)0)
193#define p_LmCheckPolyRing1(p,r)       ((void)0)
194#define p_CheckRing1(r)             ((void)0)
195#define pIfThen1(cond, check)     ((void)0)
196#endif // PDEBUG >= 1
197
198#if PDEBUG >= 2
199#define pAssume2             pAssume
200#define pPolyAssume2         pPolyAssume
201#define _pPolyAssume2        _pPolyAssume
202#define pAssumeReturn2       pAssumeReturn
203#define pPolyAssumeReturn2   pPolyAssumeReturn
204#define _pPolyAssumeReturn2  _pPolyAssumeReturn
205#define p_LmCheckPolyRing2    p_LmCheckPolyRing
206#define p_CheckRing2        p_CheckRing
207#define pIfThen2          pIfThen
208#else
209#define pAssume2(cond)               ((void)0)
210#define pPolyAssume2(cond)           ((void)0)
211#define _pPolyAssume2(cond,p,r)      ((void)0)
212#define pAssumeReturn2(cond)         ((void)0)
213#define pPolyAssumeReturn2(cond)     ((void)0)
214#define _pPolyAssumeReturn2(cond,p,r)((void)0)
215#define p_LmCheckPolyRing2(p,r)       ((void)0)
216#define p_CheckRing2(r)             ((void)0)
217#define pIfThen2(cond, check)     ((void)0)
218#endif // PDEBUG >= 2
219
220/***************************************************************
221 *
222 * Macros for low-level allocation
223 *
224 ***************************************************************/
225#ifdef PDEBUG
226#define p_AllocBin(p, bin, r)                   \
227do                                              \
228{                                               \
229  omTypeAllocBin(poly, p, bin);                 \
230  p_SetRingOfLm(p, r);                        \
231}                                               \
232while (0)
233#define p_FreeBinAddr(p, r) p_LmFree(p, r)
234#else
235#define p_AllocBin(p, bin, r)   omTypeAllocBin(poly, p, bin)
236#define p_FreeBinAddr(p, r)     omFreeBinAddr(p)
237#endif
238
239#endif
Note: See TracBrowser for help on using the repository browser.