source: git/coeffs/coeffs.h @ 227efd

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