source: git/coeffs/inline_coeffs.h @ f92fc2e

spielwiese
Last change on this file since f92fc2e was f92fc2e, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
Further to inlines! ../templates/out/
  • Property mode set to 100644
File size: 10.4 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
121#ifdef HAVE_RINGS
122   int     (*cfDivComp)(number a,number b,const coeffs r);
123   BOOLEAN (*cfIsUnit)(number a,const coeffs r);
124   number  (*cfGetUnit)(number a,const coeffs r);
125   number  (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r);
126#endif
127
128   /// changes argument  inline: a:= -a
129   number  (*cfNeg)(number a, const coeffs r);
130   /// return 1/a
131   number  (*cfInvers)(number a, const coeffs r);
132   /// return a copy of a
133   number  (*cfCopy)(number a, const coeffs r);
134   number  (*cfRePart)(number a, const coeffs r);
135   number  (*cfImPart)(number a, const coeffs r);
136   void    (*cfWrite)(number &a, const coeffs r);
137   const char *  (*cfRead)(const char * s, number * a, const coeffs r);
138   void    (*cfNormalize)(number &a, const coeffs r);
139   BOOLEAN (*cfGreater)(number a,number b, const coeffs r),
140#ifdef HAVE_RINGS
141           (*cfDivBy)(number a, number b, const coeffs r),
142#endif
143            /// tests
144           (*cfEqual)(number a,number b, const coeffs r),
145           (*cfIsZero)(number a, const coeffs r),
146           (*cfIsOne)(number a, const coeffs r),
147           (*cfIsMOne)(number a, const coeffs r),
148           (*cfGreaterZero)(number a, const coeffs r);
149   
150   void    (*cfPower)(number a, int i, number * result, const coeffs r);
151   number  (*cfGetDenom)(number &n, const coeffs r);
152   number  (*cfGetNumerator)(number &n, const coeffs r);
153   number  (*cfGcd)(number a, number b, const coeffs r);
154   number  (*cfLcm)(number a, number b, const coeffs r);
155   void    (*cfDelete)(number * a, const coeffs r);
156   nMapFunc (*cfSetMap)(const coeffs src, const coeffs dst);
157
158   /// For extensions (writes into global string buffer)
159   char *  (*cfName)(number n, const coeffs r);
160
161   /// Inline: a := b
162   void    (*cfInpMult)(number &a, number b, const coeffs r);
163   /// maps the bigint i (from dummy) into the coeffs dst
164   number  (*cfInit_bigint)(number i, const coeffs dummy, const coeffs dst);
165
166#ifdef LDEBUG
167   /// Test: is "a" a correct number?
168   BOOLEAN (*cfDBTest)(number a, const char *f,const int l, const coeffs r);
169#endif
170
171   number nNULL; /* the 0 as constant */
172   int     char_flag;
173   int     ref;
174   n_coeffType type;
175////-----------------------------------------
176  char**     parameter; /* names of parameters, rInit */
177  number     minpoly;  /* for Q_a/Zp_a, rInit */
178
179#ifdef HAVE_RINGS
180  int_number    ringflaga; /* Z/(ringflag^ringflagb)=Z/nrnModul*/
181  unsigned long ringflagb;
182  unsigned long nr2mModul;  /* Z/nr2mModul */
183  int_number    nrnModul;
184#endif
185  int        ch;  /* characteristic, rInit */
186
187  short      float_len; /* additional char-flags, rInit */
188  short      float_len2; /* additional char-flags, rInit */
189
190  BOOLEAN   ShortOut; /// ffields need this.
191
192};
193//
194// test properties and type
195/// Returns the type of coeffs domain
196static inline n_coeffType getCoeffType(const coeffs r)
197{
198  return r->type;
199}
200
201static inline int nInternalChar(const coeffs r)
202{
203  return r->ch;
204}
205
206/// one-time initialisations for new coeffs
207coeffs nInitChar(n_coeffType t, void * parameter);
208/// undo all initialisations
209void nKillChar(coeffs r);
210/// initialisations after each ring change
211inline void nSetChar(coeffs r)
212{
213  if ((r!=NULL) && (r->cfSetChar!=NULL)) r->cfSetChar(r);
214}
215
216// nach einer heissen Diskussion
217void           nNew(number * a);
218#define n_New(n, r)           nNew(n)
219
220
221// the access methods:
222
223/// return a copy of a
224static inline number n_Copy(number n,    const coeffs r){ return (r)->cfCopy(n, r); }
225static inline void   n_Delete(number* p, const coeffs r){ return (r)->cfDelete(p, r); }
226
227static inline BOOLEAN n_AreEqual(number a, number b, const coeffs r){ return (r)->cfEqual(a, b, r); }
228static inline BOOLEAN n_IsZero(number n, const coeffs r){ return (r)->cfIsZero(n,r); }
229static inline BOOLEAN n_IsOne(number n,  const coeffs r){ return (r)->cfIsOne(n,r); }
230static inline BOOLEAN n_IsMOne(number n, const coeffs r){ return (r)->cfIsMOne(n,r); }
231static inline BOOLEAN n_IsGreaterZero(number n, const coeffs r){ return (r)->cfGreaterZero(n,r); }
232// cfGreater?
233
234/// init with an integer
235static inline number n_Init(int i,       const coeffs r){ return (r)->cfInit(i,r); }
236
237/// changes argument  inline: a:= -a
238static inline number n_Neg(number n,     const coeffs r){ return (r)->cfNeg(n,r); }
239
240/// return 1/a
241static inline number n_Invers(number a,  const coeffs r){ return (r)->cfInvers(a,r); }
242
243/// how complicated, (0) => 0, otherwise positive
244static inline int    n_Size(number n,    const coeffs r){ return (r)->cfSize(n,r); }
245
246/// normalize the number. i.e. go to some canonnical representation (inplace)
247static inline void   n_Normalize(number& n, const coeffs r){ return (r)->cfNormalize(n,r); }
248
249/// Normalize and Write
250static inline void   n_Write(number& n,  const coeffs r){ return (r)->cfWrite(n,r); }
251
252/// Normalize and get denomerator
253static inline number n_GetDenom(number& n, const coeffs r){ return (r)->cfGetDenom(n, r); }
254
255/// Normalize and get numerator
256static inline number n_GetNumerator(number& n, const coeffs r){ return (r)->cfGetNumerator(n, r); }
257
258static inline void   n_Power(number a, int b, number *res, const coeffs r){ return (r)->cfPower(a,b,res,r); }
259
260
261static inline number n_Mult(number a, number b, const coeffs r){ return (r)->cfMult(a, b, r); }
262/// Inplace multiplication: a := a * b
263static inline void n_InpMult(number &a, number b, const coeffs r){ return (r)->cfInpMult(a,b,r); }
264
265static inline number n_Sub(number a, number b, const coeffs r){ return (r)->cfSub(a, b, r); }
266static inline number n_Add(number a, number b, const coeffs r){ return (r)->cfAdd(a, b, r); }
267
268static inline number n_Div(number a, number b, const coeffs r){ return (r)->cfDiv(a,b,r); }
269static inline number n_IntDiv(number a, number b, const coeffs r){ return (r)->cfIntDiv(a,b,r); }
270static inline number n_ExactDiv(number a, number b, const coeffs r){ return (r)->cfExactDiv(a,b,r); }
271
272static inline number n_Gcd(number a, number b, const coeffs r){ return (r)->cfGcd(a,b,r); }
273
274/// Tests whether n is a correct number.
275static inline BOOLEAN n_DBTest(number n, const char *filename, const int linenumber, const coeffs r)
276{
277#ifdef LDEBUG
278  return (r)->cfDBTest(n, filename, linenumber, r);
279#else
280  return TRUE;
281#endif
282}
283/// BOOLEAN n_Test(number a, const coeffs r)
284#define n_Test(a,r)  n_DBTest(a, __FILE__, __LINE__, r)
285
286// Missing wrappers for:
287// cfIntMod, cfPar, cfParDeg, cfInt, cfRePart, cfImPart, cfRead, cfLcm, cfSetMap, cfName, cfInit_bigint
288// HAVE_RINGS: cfDivComp, cfIsUnit, cfGetUnit, cfExtGcd... cfDivBy
289
290
291// Deprecated:
292static inline BOOLEAN n_GreaterZero(number n, const coeffs r){ return n_IsGreaterZero(n,r); }
293static inline BOOLEAN n_Equal(number a, number b, const coeffs r){ return n_AreEqual(a, b, r); }
294
295// Deprecated:
296static inline int n_GetChar(const coeffs r){ return nInternalChar(r); }
297
298#endif
299
Note: See TracBrowser for help on using the repository browser.