source: git/coeffs/inline_coeffs.h @ e26570

spielwiese
Last change on this file since e26570 was e26570, checked in by Oleksandr Motsak <motsak@…>, 14 years ago
Macro -> inline for numbers
  • Property mode set to 100644
File size: 9.7 KB
Line 
1#ifndef COEFFS_H
2#define COEFFS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT
9*/
10
11#include <auxiliary.h>
12
13enum n_coeffType
14{
15  n_unknown=0,
16  n_Zp,
17  n_Q,
18  n_R,
19  n_GF,
20  n_long_R,
21  n_Zp_a,
22  n_Q_a,
23  n_long_C,
24  // only used if HAVE_RINGS is defined
25  n_Z,
26  n_Zm,
27  n_Zpn,
28  n_Z2n
29};
30
31struct snumber;
32typedef struct snumber *   number;
33
34// and the routines w.r.t. currRing:
35// (should only be used in the context of currRing, i.e. in the interpreter)
36#define nCopy(n)          n_Copy(n, currRing->cf)
37#define nDelete(n)        n_Delete(n, currRing->cf)
38#define nMult(n1, n2)     n_Mult(n1, n2, currRing->cf)
39#define nAdd(n1, n2)      n_Add(n1, n2, currRing->cf)
40#define nIsZero(n)        n_IsZero(m, currRing->cf)
41#define nEqual(n1, n2)    n_Equal(n1, n2, currRing->cf)
42#define nNeg(n)           n_Neg(n, currRing->cf)
43#define nSub(n1, n2)      n_Sub(n1, n2, currRing->cf)
44#define nGetChar()        nInternalChar(currRing->cf)
45#define nInit(i)          n_Init(i, currRing->cf)
46#define nIsOne(n)         n_IsOne(n, currRing->cf)
47#define nIsMOne(n)        n_IsMOne(n, currRing->cf)
48#define nGreaterZero(n)   n_GreaterZero(n, currRing->cf)
49#define nWrite(n)         n_Write(n,currRing->cf)
50#define nNormalize(n)     n_Normalize(n,currRing->cf)
51#define nGcd(a, b)        n_Gcd(a,b,currRing->cf)
52#define nIntDiv(a, b)     n_IntDiv(a,b,currRing->cf)
53#define nDiv(a, b)        n_Div(a,b,currRing->cf)
54#define nInvers(a)        n_Invers(a,currRing->cf)
55#define nExactDiv(a, b)   n_ExactDiv(a,b,currRing->cf)
56#define nTest(a)          n_Test(a,currRing->cf)
57
58#define nInpMult(a, b)    n_InpMult(a,b,currRing->cf)
59#define nPower(a, b, res) n_Power(a,b,res,currRing->cf)
60#define nSize(n)          n_Size(n,currRing->cf)
61#define nGetDenom(N)      n_GetDenom((N),currRing->cf)
62#define nGetNumerator(N)  n_GetNumerator((N),currRing->cf)
63
64#define nSetMap(R)        n_SetMap(R,currRing->cf)
65
66struct n_Procs_s;
67typedef struct  n_Procs_s  n_Procs_s;
68typedef struct  n_Procs_s  *coeffs;
69
70typedef number (*numberfunc)(number a, number b, const coeffs r);
71
72/// maps "a", which lives in src, into dst
73typedef number (*nMapFunc)(number a, const coeffs src, const coeffs dst);
74
75struct n_Procs_s
76{
77   coeffs next;
78   unsigned int  ringtype;  /* 0 => coefficient field, 1 => coeffs from Z/2^m */
79
80   // general properties:
81   /// TRUE, if nNew/nDelete/nCopy are dummies
82   BOOLEAN has_simple_Alloc;
83   /// TRUE, if std should make polynomials monic (if nInvers is cheap)
84   /// if false, then a gcd routine is required for a content computation
85   BOOLEAN has_simple_Inverse;
86
87   // tests for numbers.cc:
88   BOOLEAN (*nCoeffIsEqual)(const coeffs r, n_coeffType n, void * parameter);
89
90   // the union stuff
91
92   // Zp:
93   int npPrimeM;
94   int npPminus1M;
95   #ifdef HAVE_DIV_MOD
96   unsigned short *npInvTable;
97   #endif
98   #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
99   unsigned short *npExpTable;
100   unsigned short *npLogTable;
101   #endif
102   // Zp_a, Q_a
103   // ?
104   // initialisation:
105   //void (*cfInitChar)(coeffs r, int parameter); // do one-time initialisations
106   void (*cfKillChar)(coeffs r); //  undo all initialisations
107                                // or NULL
108   void (*cfSetChar)(const coeffs r); // initialisations after each ring change
109                                // or NULL
110   // general stuff
111   numberfunc cfMult, cfSub ,cfAdd ,cfDiv, cfIntDiv, cfIntMod, cfExactDiv;
112   /// init with an integer
113   number  (*cfInit)(int i,const coeffs r);
114   number  (*cfPar)(int i, const coeffs r);
115   int     (*cfParDeg)(number n, const coeffs r);
116   /// how complicated, (0) => 0, or positive
117   int     (*cfSize)(number n, const coeffs r);
118   /// convertion, 0 if impossible
119   int     (*cfInt)(number &n, const coeffs r);
120#ifdef HAVE_RINGS
121   int     (*cfDivComp)(number a,number b,const coeffs r);
122   BOOLEAN (*cfIsUnit)(number a,const coeffs r);
123   number  (*cfGetUnit)(number a,const coeffs r);
124   number  (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r);
125#endif
126   /// changes argument  inline: a:= -a
127   number  (*cfNeg)(number a, const coeffs r);
128   /// return 1/a
129   number  (*cfInvers)(number a, const coeffs r);
130   /// return a copy of a
131   number  (*cfCopy)(number a, const coeffs r);
132   number  (*cfRePart)(number a, const coeffs r);
133   number  (*cfImPart)(number a, const coeffs r);
134   void    (*cfWrite)(number &a, const coeffs r);
135   const char *  (*cfRead)(const char * s, number * a, const coeffs r);
136   void    (*cfNormalize)(number &a, const coeffs r);
137   BOOLEAN (*cfGreater)(number a,number b, const coeffs r),
138#ifdef HAVE_RINGS
139           (*cfDivBy)(number a, number b, const coeffs r),
140#endif
141            /// tests
142           (*cfEqual)(number a,number b, const coeffs r),
143           (*cfIsZero)(number a, const coeffs r),
144           (*cfIsOne)(number a, const coeffs r),
145           (*cfIsMOne)(number a, const coeffs r),
146           (*cfGreaterZero)(number a, const coeffs r);
147   void    (*cfPower)(number a, int i, number * result, const coeffs r);
148   number  (*cfGetDenom)(number &n, const coeffs r);
149   number  (*cfGetNumerator)(number &n, const coeffs r);
150   number  (*cfGcd)(number a, number b, const coeffs r);
151   number  (*cfLcm)(number a, number b, const coeffs r);
152   void    (*cfDelete)(number * a, const coeffs r);
153   nMapFunc (*cfSetMap)(const coeffs src, const coeffs dst);
154
155   /// For extensions (writes into global string buffer)
156   char *  (*cfName)(number n, const coeffs r);
157
158   /// Inline: a := b
159   void    (*cfInpMult)(number &a, number b, const coeffs r);
160   /// maps the bigint i (from dummy) into the coeffs dst
161   number  (*cfInit_bigint)(number i, const coeffs dummy, const coeffs dst);
162
163#ifdef LDEBUG
164   /// Test: is "a" a correct number?
165   BOOLEAN (*cfDBTest)(number a, const char *f,const int l, const coeffs r);
166#endif
167
168   number nNULL; /* the 0 as constant */
169   int     char_flag;
170   int     ref;
171   n_coeffType type;
172////-----------------------------------------
173  char**     parameter; /* names of parameters, rInit */
174  number     minpoly;  /* for Q_a/Zp_a, rInit */
175
176#ifdef HAVE_RINGS
177  int_number    ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/
178  unsigned long ringflagb;
179  unsigned long nr2mModul;  /* Z/nr2mModul */
180  int_number    nrnModul;
181#endif
182  int        ch;  /* characteristic, rInit */
183
184  short      float_len; /* additional char-flags, rInit */
185  short      float_len2; /* additional char-flags, rInit */
186
187  BOOLEAN   ShortOut; /// ffields need this.
188
189};
190//
191// test properties and type
192/// Returns the type of coeffs domain
193static inline n_coeffType getCoeffType(const coeffs r)
194{
195  return r->type;
196}
197
198static inline int nInternalChar(const coeffs r)
199{
200  return r->ch;
201}
202
203/// one-time initialisations for new coeffs
204coeffs nInitChar(n_coeffType t, void * parameter);
205/// undo all initialisations
206void nKillChar(coeffs r);
207/// initialisations after each ring change
208inline void nSetChar(coeffs r)
209{
210  if ((r!=NULL) && (r->cfSetChar!=NULL)) r->cfSetChar(r);
211}
212
213// nach einer heissen Diskussion
214void           nNew(number * a);
215#define n_New(n, r)           nNew(n)
216
217
218// the access methods:
219static inline number n_Copy(number n,    const coeffs r){ return (r)->cfCopy(n, r); }
220static inline void   n_Delete(number* p, const coeffs r){ return (r)->cfDelete(p, r); }
221static inline BOOLEAN n_IsZero(number n, const coeffs r){ return (r)->cfIsZero(n,r); }
222static inline BOOLEAN n_IsOne(number n,  const coeffs r){ return (r)->cfIsOne(n,r); }
223static inline BOOLEAN n_IsMOne(number n, const coeffs r){ return (r)->cfIsMOne(n,r); }
224static inline BOOLEAN n_IsGreaterZero(number n, const coeffs r){ return (r)->cfGreaterZero(n,r); }
225static inline number n_Neg(number n,     const coeffs r){ return (r)->cfNeg(n,r); }
226static inline number n_Init(int i,       const coeffs r){ return (r)->cfInit(i,r); }
227static inline void   n_Write(number& n,  const coeffs r){ return (r)->cfWrite(n,r); }
228static inline void   n_Normalize(number& n, const coeffs r){ return (r)->cfNormalize(n,r); }
229static inline number n_Invers(number a,  const coeffs r){ return (r)->cfInvers(a,r); }
230static inline int    n_Size(number n,    const coeffs r){ return (r)->cfSize(n,r); }
231static inline number n_GetDenom(number& n, const coeffs r){ return (r)->cfGetDenom(n, r); }
232static inline number n_GetNumerator(number& n, const coeffs r){ return (r)->cfGetNumerator(n, r); }
233
234static inline void   n_Power(number a, int b, number *res, const coeffs r){ return (r)->cfPower(a,b,res,r); }
235
236static inline number n_Mult(number n1, number n2, const coeffs r){ return (r)->cfMult(n1, n2, r); }
237static inline number n_Add(number n1, number n2, const coeffs r){ return (r)->cfAdd(n1, n2, r); }
238static inline number n_Equal(number n1, number n2, const coeffs r){ return (r)->cfEqual(n1, n2, r); }
239static inline number n_Sub(number n1, number n2, const coeffs r){ return (r)->cfSub(n1, n2, r); }
240static inline number n_Gcd(number a, number b, const coeffs r){ return (r)->cfGcd(a,b,r); }
241static inline number n_IntDiv(number a, number b, const coeffs r){ return (r)->cfIntDiv(a,b,r); }
242static inline number n_Div(number a, number b, const coeffs r){ return (r)->cfDiv(a,b,r); }
243static inline number n_ExactDiv(number a, number b, const coeffs r){ return (r)->cfExactDiv(a,b,r); }
244static inline number n_InpMult(number a, number b, const coeffs r){ return (r)->cfInpMult(a,b,r); }
245
246
247static inline BOOLEAN n_DBTest(number a, const char *filename, const int linenumber, const coeffs r)
248{
249#ifdef LDEBUG
250  return (r)->cfDBTest(a, filename, linenumber, r);
251#else
252  return TRUE;
253#endif
254}
255/// BOOLEAN n_Test(number a, const coeffs r)
256#define n_Test(a,r)  n_DBTest(a, __FILE__, __LINE__, r)
257
258// Deprecated:
259static inline BOOLEAN n_GreaterZero(number n, const coeffs r){ return n_IsGreaterZero(n,r); }
260
261// Deprecated:
262static inline int n_GetChar(const coeffs r){ return nInternalChar(r); }
263
264#endif
265
Note: See TracBrowser for help on using the repository browser.