source: git/libpolys/coeffs/coeffs.h @ 014b65

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