source: git/coeffs/coeffs.h @ b12b7c

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