source: git/libpolys/coeffs/coeffs.h @ 028192

spielwiese
Last change on this file since 028192 was 028192, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: p_polys.cc, ring.cc (mostly NC-stuff + ideals/matrices/numbers)
  • Property mode set to 100644
File size: 12.6 KB
RevLine 
[7d90aa]1#ifndef COEFFS_H
2#define COEFFS_H
3/****************************************
4*  Computer Algebra System SINGULAR     *
5****************************************/
6/* $Id$ */
7/*
8* ABSTRACT
9*/
10
[18cb65]11#include <misc/auxiliary.h>
[227efd]12/* for assume: */
[18cb65]13#include <reporter/reporter.h>
[2d805a]14#include <coeffs/si_gmp.h>
[7d90aa]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,
[8e0242]26  n_long_C,
27  // only used if HAVE_RINGS is defined
28  n_Z,
[21dc6a]29  n_Zn,
30  n_Zpn, // does no longer exist?
[e9d796]31  n_Z2m,
32  n_CF
[7d90aa]33};
34
[91a305]35struct snumber;
36typedef struct snumber *   number;
37
[2bd9ca]38/* standard types */
39#ifdef HAVE_RINGS
40typedef unsigned long NATNUMBER;
41typedef mpz_ptr int_number;
42#endif
43
[91a305]44
45
[028192]46
[91a305]47
[7d90aa]48struct n_Procs_s;
49typedef struct  n_Procs_s  n_Procs_s;
50typedef struct  n_Procs_s  *coeffs;
51
[94b759]52typedef number (*numberfunc)(number a, number b, const coeffs r);
[7d90aa]53
[dc093ce]54/// maps "a", which lives in src, into dst
55typedef number (*nMapFunc)(number a, const coeffs src, const coeffs dst);
[94b759]56
[7d90aa]57struct n_Procs_s
58{
59   coeffs next;
[8e0242]60   unsigned int  ringtype;  /* 0 => coefficient field, 1 => coeffs from Z/2^m */
61
[8f8b75]62   // general properties:
[193c6b]63   /// TRUE, if nNew/nDelete/nCopy are dummies
64   BOOLEAN has_simple_Alloc;
65   /// TRUE, if std should make polynomials monic (if nInvers is cheap)
66   /// if false, then a gcd routine is required for a content computation
67   BOOLEAN has_simple_Inverse;
[8f8b75]68
69   // tests for numbers.cc:
[aff5ae]70   BOOLEAN (*nCoeffIsEqual)(const coeffs r, n_coeffType n, void * parameter);
[8f8b75]71
[7d90aa]72   // the union stuff
73
74   // Zp:
75   int npPrimeM;
76   int npPminus1M;
77   #ifdef HAVE_DIV_MOD
78   unsigned short *npInvTable;
79   #endif
80   #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
81   unsigned short *npExpTable;
82   unsigned short *npLogTable;
83   #endif
84   // Zp_a, Q_a
[94b759]85   // ?
[3de81d0]86   // initialisation:
[4d92d7]87   //void (*cfInitChar)(coeffs r, int parameter); // do one-time initialisations
[3de81d0]88   void (*cfKillChar)(coeffs r); //  undo all initialisations
89                                // or NULL
[2336d0]90   void (*cfSetChar)(const coeffs r); // initialisations after each ring change
[3de81d0]91                                // or NULL
[7d90aa]92   // general stuff
[7bbbef]93   numberfunc cfMult, cfSub ,cfAdd ,cfDiv, cfIntDiv, cfIntMod, cfExactDiv;
[8e0242]94   /// init with an integer
[7d90aa]95   number  (*cfInit)(int i,const coeffs r);
[7bbbef]96   number  (*cfPar)(int i, const coeffs r);
97   int     (*cfParDeg)(number n, const coeffs r);
[77e585]98   /// how complicated, (0) => 0, or positive
[7bbbef]99   int     (*cfSize)(number n, const coeffs r);
[77e585]100   /// convertion, 0 if impossible
[7bbbef]101   int     (*cfInt)(number &n, const coeffs r);
[b12b7c]102
[7d90aa]103#ifdef HAVE_RINGS
[7bbbef]104   int     (*cfDivComp)(number a,number b,const coeffs r);
105   BOOLEAN (*cfIsUnit)(number a,const coeffs r);
106   number  (*cfGetUnit)(number a,const coeffs r);
107   number  (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r);
[7d90aa]108#endif
[b12b7c]109
[db3180c]110   /// changes argument  inline: a:= -a
[7bbbef]111   number  (*cfNeg)(number a, const coeffs r);
[db3180c]112   /// return 1/a
[7bbbef]113   number  (*cfInvers)(number a, const coeffs r);
[db3180c]114   /// return a copy of a
[7d90aa]115   number  (*cfCopy)(number a, const coeffs r);
[7bbbef]116   number  (*cfRePart)(number a, const coeffs r);
117   number  (*cfImPart)(number a, const coeffs r);
[7d90aa]118   void    (*cfWrite)(number &a, const coeffs r);
[7bbbef]119   const char *  (*cfRead)(const char * s, number * a, const coeffs r);
120   void    (*cfNormalize)(number &a, const coeffs r);
121   BOOLEAN (*cfGreater)(number a,number b, const coeffs r),
[7d90aa]122#ifdef HAVE_RINGS
[7bbbef]123           (*cfDivBy)(number a, number b, const coeffs r),
[7d90aa]124#endif
[77e585]125            /// tests
[7bbbef]126           (*cfEqual)(number a,number b, const coeffs r),
127           (*cfIsZero)(number a, const coeffs r),
128           (*cfIsOne)(number a, const coeffs r),
129           (*cfIsMOne)(number a, const coeffs r),
130           (*cfGreaterZero)(number a, const coeffs r);
[8a8c9e]131
[7bbbef]132   void    (*cfPower)(number a, int i, number * result, const coeffs r);
[7d90aa]133   number  (*cfGetDenom)(number &n, const coeffs r);
134   number  (*cfGetNumerator)(number &n, const coeffs r);
[7bbbef]135   number  (*cfGcd)(number a, number b, const coeffs r);
136   number  (*cfLcm)(number a, number b, const coeffs r);
[7d90aa]137   void    (*cfDelete)(number * a, const coeffs r);
138   nMapFunc (*cfSetMap)(const coeffs src, const coeffs dst);
[77e585]139
140   /// For extensions (writes into global string buffer)
[7bbbef]141   char *  (*cfName)(number n, const coeffs r);
[77e585]142
143   /// Inline: a := b
[7bbbef]144   void    (*cfInpMult)(number &a, number b, const coeffs r);
[719c71]145   /// maps the bigint i (from dummy) into the coeffs dst
[7bbbef]146   number  (*cfInit_bigint)(number i, const coeffs dummy, const coeffs dst);
[77e585]147
[7d90aa]148#ifdef LDEBUG
[bd6142]149   /// Test: is "a" a correct number?
[b12b7c]150   BOOLEAN (*cfDBTest)(number a, const char *f, const int l, const coeffs r);
[7d90aa]151#endif
152
153   number nNULL; /* the 0 as constant */
154   int     char_flag;
155   int     ref;
156   n_coeffType type;
157////-----------------------------------------
158  char**     parameter; /* names of parameters, rInit */
159  number     minpoly;  /* for Q_a/Zp_a, rInit */
160
161#ifdef HAVE_RINGS
[e90dfd6]162  /* The following members are for representing the ring Z/n,
163     where n is not a prime. We distinguish three cases:
164     1.) n has at least two distinct prime factors. Then
165         modBase stores n, modExponent stores 1, modNumber
166         stores n, and mod2mMask is not used;
167     2.) n = p^k for some odd prime p and k > 1. Then
168         modBase stores p, modExponent stores k, modNumber
169         stores n, and mod2mMask is not used;
170     3.) n = 2^k for some k > 1; moreover, 2^k - 1 fits in
171         an unsigned long. Then modBase stores 2, modExponent
172         stores k, modNumber is not used, and mod2mMask stores
173         2^k - 1, i.e., the bit mask '111..1' of length k.
174     4.) n = 2^k for some k > 1; but 2^k - 1 does not fit in
175         an unsigned long. Then modBase stores 2, modExponent
176         stores k, modNumber stores n, and mod2mMask is not
177         used;
178     Cases 1.), 2.), and 4.) are covered by the implementation
179     in the files rmodulon.h and rmodulon.cc, whereas case 3.)
180     is implemented in the files rmodulo2m.h and rmodulo2m.cc. */
181  int_number    modBase;
182  unsigned long modExponent;
183  int_number    modNumber;
184  unsigned long mod2mMask;
[7d90aa]185#endif
186  int        ch;  /* characteristic, rInit */
187
188  short      float_len; /* additional char-flags, rInit */
189  short      float_len2; /* additional char-flags, rInit */
[d0a51ee]190
[8a8c9e]191  BOOLEAN   ShortOut; /// ffields need this.
[d0a51ee]192
[5e3046]193// ---------------------------------------------------
194  // for n_GF
195
196  int m_nfCharQ;  ///< the number of elemts: q
197  int m_nfM1;       ///< representation of -1
198  int m_nfCharP;  ///< the characteristic: p
199  int m_nfCharQ1; ///< q-1
200  unsigned short *m_nfPlus1Table;
201  int *m_nfMinPoly;
[dc06550]202  char * m_nfParameter;
[7d90aa]203};
[7bbbef]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
[e69b7c]212/// returns true for coeffs being a domain
213static inline bool nField_is_Domain(const coeffs r)
214{
215#ifdef HAVE_RINGS
216  return (r->ringtype == 4 || r->ringtype == 0);
217#else
218  return true;
219#endif
220}
221
222
[7bbbef]223static inline int nInternalChar(const coeffs r)
224{
225  return r->ch;
226}
227
228/// one-time initialisations for new coeffs
[1cce47]229/// in case of an error return NULL
[7bbbef]230coeffs nInitChar(n_coeffType t, void * parameter);
[16f8f1]231
[7bbbef]232/// undo all initialisations
233void nKillChar(coeffs r);
[16f8f1]234
[7bbbef]235/// initialisations after each ring change
[ef3790]236static inline void nSetChar(const coeffs r)
[7bbbef]237{
[227efd]238  assume(r!=NULL); // r==NULL is an error
239  if (r->cfSetChar!=NULL) r->cfSetChar(r);
[7bbbef]240}
241
242void           nNew(number * a);
[91a305]243#define n_New(n, r)           nNew(n)
[7d90aa]244
[b12b7c]245
[227efd]246// the access methods (part 2):
[b12b7c]247
248/// return a copy of a
[8a8c9e]249static inline number n_Copy(number n,    const coeffs r)
[1389a4]250{ return r->cfCopy(n, r); }
[16f8f1]251
[8a8c9e]252static inline void   n_Delete(number* p, const coeffs r)
[35eaf8]253{ r->cfDelete(p, r); }
[8a8c9e]254
255static inline BOOLEAN n_Equal(number a, number b, const coeffs r)
[1389a4]256{ return r->cfEqual(a, b, r); }
[16f8f1]257
[8a8c9e]258static inline BOOLEAN n_IsZero(number n, const coeffs r)
[1389a4]259{ return r->cfIsZero(n,r); }
[16f8f1]260
[8a8c9e]261static inline BOOLEAN n_IsOne(number n,  const coeffs r)
[1389a4]262{ return r->cfIsOne(n,r); }
[16f8f1]263
[8a8c9e]264static inline BOOLEAN n_IsMOne(number n, const coeffs r)
[1389a4]265{ return r->cfIsMOne(n,r); }
[16f8f1]266
[8a8c9e]267static inline BOOLEAN n_GreaterZero(number n, const coeffs r)
[1389a4]268{ return r->cfGreaterZero(n,r); }
[b12b7c]269// cfGreater?
[16f8f1]270
[1b816a3]271#ifdef HAVE_RINGS
[8a8c9e]272static inline BOOLEAN n_IsUnit(number n, const coeffs r)
273{ return r->cfIsUnit(n,r); }
[16f8f1]274
[5679049]275static inline number n_GetUnit(number n, const coeffs r)
276{ return r->cfGetUnit(n,r); }
[16f8f1]277
[8a8c9e]278static inline BOOLEAN n_DivBy(number a, number b, const coeffs r)
279{ return r->cfDivBy(a,b,r); }
[1b816a3]280#endif
[b12b7c]281
282/// init with an integer
[8a8c9e]283static inline number n_Init(int i,       const coeffs r)
[1389a4]284{ return r->cfInit(i,r); }
[b12b7c]285
286/// changes argument  inline: a:= -a
[8a8c9e]287static inline number n_Neg(number n,     const coeffs r)
[1389a4]288{ return r->cfNeg(n,r); }
[b12b7c]289
290/// return 1/a
[8a8c9e]291static inline number n_Invers(number a,  const coeffs r)
[1389a4]292{ return r->cfInvers(a,r); }
[b12b7c]293
[227efd]294/// use for pivot strategies, (0) => 0, otherwise positive
[8a8c9e]295static inline int    n_Size(number n,    const coeffs r)
[1389a4]296{ return r->cfSize(n,r); }
[b12b7c]297
298/// normalize the number. i.e. go to some canonnical representation (inplace)
[8a8c9e]299static inline void   n_Normalize(number& n, const coeffs r)
[1389a4]300{ return r->cfNormalize(n,r); }
[b12b7c]301
[227efd]302/// Normalize and Write to the output buffer of reporter
[8a8c9e]303static inline void   n_Write(number& n,  const coeffs r)
[1389a4]304{ return r->cfWrite(n,r); }
[b12b7c]305
306/// Normalize and get denomerator
[8a8c9e]307static inline number n_GetDenom(number& n, const coeffs r)
[1389a4]308{ return r->cfGetDenom(n, r); }
[b12b7c]309
310/// Normalize and get numerator
[8a8c9e]311static inline number n_GetNumerator(number& n, const coeffs r)
[1389a4]312{ return r->cfGetNumerator(n, r); }
[b12b7c]313
[8a8c9e]314static inline void   n_Power(number a, int b, number *res, const coeffs r)
[35eaf8]315{ r->cfPower(a,b,res,r); }
[b12b7c]316
[8a8c9e]317static inline number n_Mult(number a, number b, const coeffs r)
[1389a4]318{ return r->cfMult(a, b, r); }
[227efd]319
[b12b7c]320/// Inplace multiplication: a := a * b
[8a8c9e]321static inline void n_InpMult(number &a, number b, const coeffs r)
[35eaf8]322{ r->cfInpMult(a,b,r); }
[8a8c9e]323
324static inline number n_Sub(number a, number b, const coeffs r)
[1389a4]325{ return r->cfSub(a, b, r); }
[8a8c9e]326
327static inline number n_Add(number a, number b, const coeffs r)
[1389a4]328{ return r->cfAdd(a, b, r); }
[b12b7c]329
[8a8c9e]330static inline number n_Div(number a, number b, const coeffs r)
[1389a4]331{ return r->cfDiv(a,b,r); }
[b12b7c]332
[8a8c9e]333static inline number n_IntDiv(number a, number b, const coeffs r)
[1389a4]334{ return r->cfIntDiv(a,b,r); }
[b12b7c]335
[8a8c9e]336static inline number n_ExactDiv(number a, number b, const coeffs r)
[1389a4]337{ return r->cfExactDiv(a,b,r); }
[8a8c9e]338
339static inline number n_Gcd(number a, number b, const coeffs r)
[1389a4]340{ return r->cfGcd(a,b,r); }
[b12b7c]341
[5679049]342static inline number n_Lcm(number a, number b, const coeffs r)
[1389a4]343{ return r->cfLcm(a,b,r); }
344
345static inline nMapFunc n_SetMap(const coeffs src, const coeffs dst)
346{ return dst->cfSetMap(src,dst); }
347
[4581a96]348static inline number n_Par(int n, const coeffs r)
349{ return r->cfPar(n,r); }
350
[1389a4]351static inline int n_ParDeg(number n, const coeffs r)
352{ return r->cfParDeg(n,r); }
[5679049]353
[227efd]354/// Tests whether n is a correct number: only used if LDEBUG is defined
[b12b7c]355static inline BOOLEAN n_DBTest(number n, const char *filename, const int linenumber, const coeffs r)
[2bd9ca]356{
[8a8c9e]357#ifdef LDEBUG
[b12b7c]358  return (r)->cfDBTest(n, filename, linenumber, r);
[5e3046]359#else
360  return TRUE;
361#endif
[2bd9ca]362}
[a0ce49]363
[2bd9ca]364/// BOOLEAN n_Test(number a, const coeffs r)
365#define n_Test(a,r)  n_DBTest(a, __FILE__, __LINE__, r)
366
[b12b7c]367// Missing wrappers for:
[4581a96]368// cfIntMod, cfInt, cfRePart, cfImPart, cfRead, cfName, cfInit_bigint
[5679049]369// HAVE_RINGS: cfDivComp, cfExtGcd... cfDivBy
[b12b7c]370
371
372// Deprecated:
[8a8c9e]373static inline int n_GetChar(const coeffs r)
374{ return nInternalChar(r); }
[b12b7c]375
[028192]376
377
378/*
379// the access methods (part 1) (see also part2 below):
380//
381// the routines w.r.t. currRing:
382// (should only be used in the context of currRing, i.e. in the interpreter)
383#define nCopy(n)          n_Copy(n, currRing->cf)
384#define nDelete(n)        n_Delete(n, currRing->cf)
385#define nMult(n1, n2)     n_Mult(n1, n2, currRing->cf)
386#define nAdd(n1, n2)      n_Add(n1, n2, currRing->cf)
387#define nIsZero(n)        n_IsZero(n, currRing->cf)
388#define nEqual(n1, n2)    n_Equal(n1, n2, currRing->cf)
389#define nNeg(n)           n_Neg(n, currRing->cf)
390#define nSub(n1, n2)      n_Sub(n1, n2, currRing->cf)
391#define nGetChar()        nInternalChar(currRing->cf)
392#define nInit(i)          n_Init(i, currRing->cf)
393#define nIsOne(n)         n_IsOne(n, currRing->cf)
394#define nIsMOne(n)        n_IsMOne(n, currRing->cf)
395#define nGreaterZero(n)   n_GreaterZero(n, currRing->cf)
396#define nWrite(n)         n_Write(n,currRing->cf)
397#define nNormalize(n)     n_Normalize(n,currRing->cf)
398#define nGcd(a, b)        n_Gcd(a,b,currRing->cf)
399#define nIntDiv(a, b)     n_IntDiv(a,b,currRing->cf)
400#define nDiv(a, b)        n_Div(a,b,currRing->cf)
401#define nInvers(a)        n_Invers(a,currRing->cf)
402#define nExactDiv(a, b)   n_ExactDiv(a,b,currRing->cf)
403#define nTest(a)          n_Test(a,currRing->cf)
404
405#define nInpMult(a, b)    n_InpMult(a,b,currRing->cf)
406#define nPower(a, b, res) n_Power(a,b,res,currRing->cf)
407#define nSize(n)          n_Size(n,currRing->cf)
408#define nGetDenom(N)      n_GetDenom((N),currRing->cf)
409#define nGetNumerator(N)  n_GetNumerator((N),currRing->cf)
410
411#define nSetMap(R)        n_SetMap(R,currRing->cf)
412*/
413
[7d90aa]414#endif
415
Note: See TracBrowser for help on using the repository browser.