[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> |
---|
[9144617] | 14 | |
---|
[2d805a] | 15 | #include <coeffs/si_gmp.h> |
---|
[7d90aa] | 16 | |
---|
[eca225] | 17 | #ifdef HAVE_FACTORY |
---|
[9eb0f9] | 18 | class CanonicalForm; |
---|
[eca225] | 19 | #endif |
---|
| 20 | |
---|
[7d90aa] | 21 | enum n_coeffType |
---|
| 22 | { |
---|
| 23 | n_unknown=0, |
---|
| 24 | n_Zp, |
---|
| 25 | n_Q, |
---|
| 26 | n_R, |
---|
| 27 | n_GF, |
---|
| 28 | n_long_R, |
---|
[e676cd] | 29 | n_algExt, /**< used for all algebraic extensions, i.e., |
---|
[141342] | 30 | the top-most extension in an extension tower |
---|
| 31 | is algebraic */ |
---|
[e676cd] | 32 | n_transExt, /**< used for all transcendental extensions, i.e., |
---|
[141342] | 33 | the top-most extension in an extension tower |
---|
| 34 | is transcendental */ |
---|
[8e0242] | 35 | n_long_C, |
---|
[eca225] | 36 | // only used if HAVE_RINGS is defined: |
---|
[8e0242] | 37 | n_Z, |
---|
[21dc6a] | 38 | n_Zn, |
---|
| 39 | n_Zpn, // does no longer exist? |
---|
[e9d796] | 40 | n_Z2m, |
---|
| 41 | n_CF |
---|
[7d90aa] | 42 | }; |
---|
| 43 | |
---|
[91a305] | 44 | struct snumber; |
---|
| 45 | typedef struct snumber * number; |
---|
| 46 | |
---|
[2bd9ca] | 47 | /* standard types */ |
---|
| 48 | #ifdef HAVE_RINGS |
---|
| 49 | typedef unsigned long NATNUMBER; |
---|
| 50 | typedef mpz_ptr int_number; |
---|
| 51 | #endif |
---|
| 52 | |
---|
[4c6e420] | 53 | struct ip_sring; |
---|
| 54 | typedef struct ip_sring * ring; |
---|
| 55 | |
---|
[7d90aa] | 56 | struct n_Procs_s; |
---|
| 57 | typedef struct n_Procs_s *coeffs; |
---|
| 58 | |
---|
[94b759] | 59 | typedef number (*numberfunc)(number a, number b, const coeffs r); |
---|
[7d90aa] | 60 | |
---|
[dc093ce] | 61 | /// maps "a", which lives in src, into dst |
---|
| 62 | typedef number (*nMapFunc)(number a, const coeffs src, const coeffs dst); |
---|
[94b759] | 63 | |
---|
[7d90aa] | 64 | struct n_Procs_s |
---|
| 65 | { |
---|
| 66 | coeffs next; |
---|
[fba6f18] | 67 | unsigned int ringtype; /* =0 => coefficient field, |
---|
[f0797c] | 68 | !=0 => coeffs from one of the rings: |
---|
| 69 | =1 => Z/2^mZ |
---|
| 70 | =2 => Z/nZ, n not a prime |
---|
| 71 | =3 => Z/p^mZ |
---|
| 72 | =4 => Z */ |
---|
[8e0242] | 73 | |
---|
[8f8b75] | 74 | // general properties: |
---|
[193c6b] | 75 | /// TRUE, if nNew/nDelete/nCopy are dummies |
---|
| 76 | BOOLEAN has_simple_Alloc; |
---|
| 77 | /// TRUE, if std should make polynomials monic (if nInvers is cheap) |
---|
[3dbe0bf] | 78 | /// if false, then a gcd routine is used for a content computation |
---|
[193c6b] | 79 | BOOLEAN has_simple_Inverse; |
---|
[8f8b75] | 80 | |
---|
| 81 | // tests for numbers.cc: |
---|
[aff5ae] | 82 | BOOLEAN (*nCoeffIsEqual)(const coeffs r, n_coeffType n, void * parameter); |
---|
[8f8b75] | 83 | |
---|
[c7e3d7] | 84 | /// output of coeff description via Print |
---|
| 85 | void (*cfCoeffWrite)(const coeffs r); |
---|
| 86 | |
---|
[7d90aa] | 87 | // the union stuff |
---|
| 88 | |
---|
| 89 | // Zp: |
---|
| 90 | int npPrimeM; |
---|
| 91 | int npPminus1M; |
---|
| 92 | #ifdef HAVE_DIV_MOD |
---|
| 93 | unsigned short *npInvTable; |
---|
| 94 | #endif |
---|
| 95 | #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD) |
---|
| 96 | unsigned short *npExpTable; |
---|
| 97 | unsigned short *npLogTable; |
---|
| 98 | #endif |
---|
[4c6e420] | 99 | |
---|
[94b759] | 100 | // ? |
---|
[3de81d0] | 101 | // initialisation: |
---|
[4d92d7] | 102 | //void (*cfInitChar)(coeffs r, int parameter); // do one-time initialisations |
---|
[3de81d0] | 103 | void (*cfKillChar)(coeffs r); // undo all initialisations |
---|
| 104 | // or NULL |
---|
[2336d0] | 105 | void (*cfSetChar)(const coeffs r); // initialisations after each ring change |
---|
[3de81d0] | 106 | // or NULL |
---|
[7d90aa] | 107 | // general stuff |
---|
[7bbbef] | 108 | numberfunc cfMult, cfSub ,cfAdd ,cfDiv, cfIntDiv, cfIntMod, cfExactDiv; |
---|
[8e0242] | 109 | /// init with an integer |
---|
[7d90aa] | 110 | number (*cfInit)(int i,const coeffs r); |
---|
[7bbbef] | 111 | number (*cfPar)(int i, const coeffs r); |
---|
| 112 | int (*cfParDeg)(number n, const coeffs r); |
---|
[77e585] | 113 | /// how complicated, (0) => 0, or positive |
---|
[7bbbef] | 114 | int (*cfSize)(number n, const coeffs r); |
---|
[77e585] | 115 | /// convertion, 0 if impossible |
---|
[7bbbef] | 116 | int (*cfInt)(number &n, const coeffs r); |
---|
[b12b7c] | 117 | |
---|
[7d90aa] | 118 | #ifdef HAVE_RINGS |
---|
[7bbbef] | 119 | int (*cfDivComp)(number a,number b,const coeffs r); |
---|
| 120 | BOOLEAN (*cfIsUnit)(number a,const coeffs r); |
---|
| 121 | number (*cfGetUnit)(number a,const coeffs r); |
---|
| 122 | number (*cfExtGcd)(number a, number b, number *s, number *t,const coeffs r); |
---|
[7d90aa] | 123 | #endif |
---|
[b12b7c] | 124 | |
---|
[db3180c] | 125 | /// changes argument inline: a:= -a |
---|
[7bbbef] | 126 | number (*cfNeg)(number a, const coeffs r); |
---|
[db3180c] | 127 | /// return 1/a |
---|
[7bbbef] | 128 | number (*cfInvers)(number a, const coeffs r); |
---|
[db3180c] | 129 | /// return a copy of a |
---|
[7d90aa] | 130 | number (*cfCopy)(number a, const coeffs r); |
---|
[7bbbef] | 131 | number (*cfRePart)(number a, const coeffs r); |
---|
| 132 | number (*cfImPart)(number a, const coeffs r); |
---|
[7d90aa] | 133 | void (*cfWrite)(number &a, const coeffs r); |
---|
[7bbbef] | 134 | const char * (*cfRead)(const char * s, number * a, const coeffs r); |
---|
| 135 | void (*cfNormalize)(number &a, const coeffs r); |
---|
| 136 | BOOLEAN (*cfGreater)(number a,number b, const coeffs r), |
---|
[7d90aa] | 137 | #ifdef HAVE_RINGS |
---|
[7bbbef] | 138 | (*cfDivBy)(number a, number b, const coeffs r), |
---|
[7d90aa] | 139 | #endif |
---|
[77e585] | 140 | /// tests |
---|
[7bbbef] | 141 | (*cfEqual)(number a,number b, const coeffs r), |
---|
| 142 | (*cfIsZero)(number a, const coeffs r), |
---|
| 143 | (*cfIsOne)(number a, const coeffs r), |
---|
| 144 | (*cfIsMOne)(number a, const coeffs r), |
---|
| 145 | (*cfGreaterZero)(number a, const coeffs r); |
---|
[8a8c9e] | 146 | |
---|
[7bbbef] | 147 | void (*cfPower)(number a, int i, number * result, const coeffs r); |
---|
[7d90aa] | 148 | number (*cfGetDenom)(number &n, const coeffs r); |
---|
| 149 | number (*cfGetNumerator)(number &n, const coeffs r); |
---|
[7bbbef] | 150 | number (*cfGcd)(number a, number b, const coeffs r); |
---|
| 151 | number (*cfLcm)(number a, number b, const coeffs r); |
---|
[7d90aa] | 152 | void (*cfDelete)(number * a, const coeffs r); |
---|
| 153 | nMapFunc (*cfSetMap)(const coeffs src, const coeffs dst); |
---|
[77e585] | 154 | |
---|
| 155 | /// For extensions (writes into global string buffer) |
---|
[7bbbef] | 156 | char * (*cfName)(number n, const coeffs r); |
---|
[77e585] | 157 | |
---|
[eca225] | 158 | /// Inplace: a *= b |
---|
[7bbbef] | 159 | void (*cfInpMult)(number &a, number b, const coeffs r); |
---|
[719c71] | 160 | /// maps the bigint i (from dummy) into the coeffs dst |
---|
[7bbbef] | 161 | number (*cfInit_bigint)(number i, const coeffs dummy, const coeffs dst); |
---|
[77e585] | 162 | |
---|
[eca225] | 163 | #ifdef HAVE_FACTORY |
---|
| 164 | number (*convFactoryNSingN)( const CanonicalForm n, const coeffs r); |
---|
[abb4787] | 165 | CanonicalForm (*convSingNFactoryN)( number n, BOOLEAN setChar, const coeffs r ); |
---|
[eca225] | 166 | #endif |
---|
| 167 | |
---|
| 168 | |
---|
[7d90aa] | 169 | #ifdef LDEBUG |
---|
[bd6142] | 170 | /// Test: is "a" a correct number? |
---|
[b12b7c] | 171 | BOOLEAN (*cfDBTest)(number a, const char *f, const int l, const coeffs r); |
---|
[7d90aa] | 172 | #endif |
---|
| 173 | |
---|
| 174 | number nNULL; /* the 0 as constant */ |
---|
| 175 | int char_flag; |
---|
| 176 | int ref; |
---|
| 177 | n_coeffType type; |
---|
[01c1d0] | 178 | //------------------------------------------- |
---|
[4c6e420] | 179 | |
---|
[488808e] | 180 | /* for extension fields we need to be able to represent polynomials, |
---|
| 181 | so here is the polynomial ring: */ |
---|
[6ccdd3a] | 182 | ring extRing; |
---|
[488808e] | 183 | |
---|
[e676cd] | 184 | //number minpoly; //< no longer needed: replaced by |
---|
[6ccdd3a] | 185 | // //< extRing->minideal->[0] |
---|
[4c6e420] | 186 | |
---|
| 187 | |
---|
| 188 | //------------------------------------------- |
---|
[aec5c9] | 189 | char* complex_parameter; //< the name of sqrt(-1), i.e. 'i' or 'j' etc...? |
---|
[7d90aa] | 190 | |
---|
| 191 | #ifdef HAVE_RINGS |
---|
[e90dfd6] | 192 | /* The following members are for representing the ring Z/n, |
---|
[aec5c9] | 193 | where n is not a prime. We distinguish four cases: |
---|
[e90dfd6] | 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; |
---|
[7d90aa] | 215 | #endif |
---|
[73a9ffb] | 216 | int ch; /* characteristic, set by the local *InitChar methods; |
---|
| 217 | In field extensions or extensions towers, the |
---|
| 218 | characteristic can be accessed from any of the |
---|
| 219 | intermediate extension fields, i.e., in this case |
---|
| 220 | it is redundant along the chain of field extensions; |
---|
[488808e] | 221 | CONTRARY to SINGULAR as it was, we do NO LONGER use |
---|
| 222 | negative values for ch; |
---|
| 223 | for rings, ch will also be set and is - per def - |
---|
| 224 | the smallest number of 1's that sum up to zero; |
---|
| 225 | however, in this case ch may not fit in an int, |
---|
| 226 | thus ch may contain a faulty value */ |
---|
[7d90aa] | 227 | |
---|
| 228 | short float_len; /* additional char-flags, rInit */ |
---|
| 229 | short float_len2; /* additional char-flags, rInit */ |
---|
[d0a51ee] | 230 | |
---|
[8a8c9e] | 231 | BOOLEAN ShortOut; /// ffields need this. |
---|
[d0a51ee] | 232 | |
---|
[5e3046] | 233 | // --------------------------------------------------- |
---|
| 234 | // for n_GF |
---|
| 235 | |
---|
[488808e] | 236 | int m_nfCharQ; ///< the number of elements: q |
---|
[5e3046] | 237 | int m_nfM1; ///< representation of -1 |
---|
| 238 | int m_nfCharP; ///< the characteristic: p |
---|
| 239 | int m_nfCharQ1; ///< q-1 |
---|
| 240 | unsigned short *m_nfPlus1Table; |
---|
| 241 | int *m_nfMinPoly; |
---|
[dc06550] | 242 | char * m_nfParameter; |
---|
[7d90aa] | 243 | }; |
---|
[7bbbef] | 244 | // |
---|
| 245 | // test properties and type |
---|
| 246 | /// Returns the type of coeffs domain |
---|
| 247 | static inline n_coeffType getCoeffType(const coeffs r) |
---|
| 248 | { |
---|
[17e473] | 249 | assume(r != NULL); |
---|
[7bbbef] | 250 | return r->type; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | static inline int nInternalChar(const coeffs r) |
---|
| 254 | { |
---|
[17e473] | 255 | assume(r != NULL); |
---|
[7bbbef] | 256 | return r->ch; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | /// one-time initialisations for new coeffs |
---|
[1cce47] | 260 | /// in case of an error return NULL |
---|
[7bbbef] | 261 | coeffs nInitChar(n_coeffType t, void * parameter); |
---|
[16f8f1] | 262 | |
---|
[7bbbef] | 263 | /// undo all initialisations |
---|
| 264 | void nKillChar(coeffs r); |
---|
[16f8f1] | 265 | |
---|
[7bbbef] | 266 | /// initialisations after each ring change |
---|
[ef3790] | 267 | static inline void nSetChar(const coeffs r) |
---|
[7bbbef] | 268 | { |
---|
[227efd] | 269 | assume(r!=NULL); // r==NULL is an error |
---|
| 270 | if (r->cfSetChar!=NULL) r->cfSetChar(r); |
---|
[7bbbef] | 271 | } |
---|
| 272 | |
---|
| 273 | void nNew(number * a); |
---|
[91a305] | 274 | #define n_New(n, r) nNew(n) |
---|
[7d90aa] | 275 | |
---|
[b12b7c] | 276 | |
---|
[227efd] | 277 | // the access methods (part 2): |
---|
[b12b7c] | 278 | |
---|
| 279 | /// return a copy of a |
---|
[8a8c9e] | 280 | static inline number n_Copy(number n, const coeffs r) |
---|
[6c084af] | 281 | { assume(r != NULL); assume(r->cfCopy!=NULL); return r->cfCopy(n, r); } |
---|
[16f8f1] | 282 | |
---|
[8a8c9e] | 283 | static inline void n_Delete(number* p, const coeffs r) |
---|
[6c084af] | 284 | { assume(r != NULL); assume(r->cfDelete!= NULL); r->cfDelete(p, r); } |
---|
[8a8c9e] | 285 | |
---|
| 286 | static inline BOOLEAN n_Equal(number a, number b, const coeffs r) |
---|
[6c084af] | 287 | { assume(r != NULL); assume(r->cfEqual!=NULL); return r->cfEqual(a, b, r); } |
---|
[16f8f1] | 288 | |
---|
[8a8c9e] | 289 | static inline BOOLEAN n_IsZero(number n, const coeffs r) |
---|
[6c084af] | 290 | { assume(r != NULL); assume(r->cfIsZero!=NULL); return r->cfIsZero(n,r); } |
---|
[16f8f1] | 291 | |
---|
[8a8c9e] | 292 | static inline BOOLEAN n_IsOne(number n, const coeffs r) |
---|
[6c084af] | 293 | { assume(r != NULL); assume(r->cfIsOne!=NULL); return r->cfIsOne(n,r); } |
---|
[16f8f1] | 294 | |
---|
[8a8c9e] | 295 | static inline BOOLEAN n_IsMOne(number n, const coeffs r) |
---|
[6c084af] | 296 | { assume(r != NULL); assume(r->cfIsMOne!=NULL); return r->cfIsMOne(n,r); } |
---|
[16f8f1] | 297 | |
---|
[8a8c9e] | 298 | static inline BOOLEAN n_GreaterZero(number n, const coeffs r) |
---|
[6c084af] | 299 | { assume(r != NULL); assume(r->cfGreaterZero!=NULL); return r->cfGreaterZero(n,r); } |
---|
[529fa4] | 300 | static inline BOOLEAN n_Greater(number a, number b, const coeffs r) |
---|
| 301 | { assume(r != NULL); assume(r->cfGreater!=NULL); return r->cfGreater(a,b,r); } |
---|
[16f8f1] | 302 | |
---|
[1b816a3] | 303 | #ifdef HAVE_RINGS |
---|
[8a8c9e] | 304 | static inline BOOLEAN n_IsUnit(number n, const coeffs r) |
---|
[6c084af] | 305 | { assume(r != NULL); assume(r->cfIsUnit!=NULL); return r->cfIsUnit(n,r); } |
---|
[16f8f1] | 306 | |
---|
[5679049] | 307 | static inline number n_GetUnit(number n, const coeffs r) |
---|
[6c084af] | 308 | { assume(r != NULL); assume(r->cfGetUnit!=NULL); return r->cfGetUnit(n,r); } |
---|
[44d898] | 309 | #endif |
---|
[16f8f1] | 310 | |
---|
[5469a9] | 311 | /// Test whether a can be divided by b? |
---|
[8a8c9e] | 312 | static inline BOOLEAN n_DivBy(number a, number b, const coeffs r) |
---|
[44d898] | 313 | { |
---|
| 314 | assume(r != NULL); |
---|
| 315 | #ifdef HAVE_RINGS |
---|
[5469a9] | 316 | if( nCoeff_is_Ring(r) ) |
---|
| 317 | { |
---|
| 318 | assume(r->cfDivBy!=NULL); return r->cfDivBy(a,b,r); |
---|
| 319 | } |
---|
[1b816a3] | 320 | #endif |
---|
[44d898] | 321 | return !n_IsZero(b, r); |
---|
| 322 | } |
---|
| 323 | |
---|
[b12b7c] | 324 | |
---|
| 325 | /// init with an integer |
---|
[8a8c9e] | 326 | static inline number n_Init(int i, const coeffs r) |
---|
[6c084af] | 327 | { assume(r != NULL); assume(r->cfInit!=NULL); return r->cfInit(i,r); } |
---|
[b12b7c] | 328 | |
---|
[fba6f18] | 329 | /// conversion to int; 0 if not possible |
---|
[d12f186] | 330 | static inline int n_Int(number &n, const coeffs r) |
---|
[fba6f18] | 331 | { assume(r != NULL); assume(r->cfInt!=NULL); return r->cfInt(n,r); } |
---|
| 332 | |
---|
[b12b7c] | 333 | /// changes argument inline: a:= -a |
---|
[8a8c9e] | 334 | static inline number n_Neg(number n, const coeffs r) |
---|
[6c084af] | 335 | { assume(r != NULL); assume(r->cfNeg!=NULL); return r->cfNeg(n,r); } |
---|
[b12b7c] | 336 | |
---|
| 337 | /// return 1/a |
---|
[8a8c9e] | 338 | static inline number n_Invers(number a, const coeffs r) |
---|
[6c084af] | 339 | { assume(r != NULL); assume(r->cfInvers!=NULL); return r->cfInvers(a,r); } |
---|
[b12b7c] | 340 | |
---|
[227efd] | 341 | /// use for pivot strategies, (0) => 0, otherwise positive |
---|
[8a8c9e] | 342 | static inline int n_Size(number n, const coeffs r) |
---|
[6c084af] | 343 | { assume(r != NULL); assume(r->cfSize!=NULL); return r->cfSize(n,r); } |
---|
[b12b7c] | 344 | |
---|
| 345 | /// normalize the number. i.e. go to some canonnical representation (inplace) |
---|
[8a8c9e] | 346 | static inline void n_Normalize(number& n, const coeffs r) |
---|
[6c084af] | 347 | { assume(r != NULL); assume(r->cfNormalize!=NULL); r->cfNormalize(n,r); } |
---|
[b12b7c] | 348 | |
---|
[227efd] | 349 | /// Normalize and Write to the output buffer of reporter |
---|
[8a8c9e] | 350 | static inline void n_Write(number& n, const coeffs r) |
---|
[6c084af] | 351 | { assume(r != NULL); assume(r->cfWrite!=NULL); r->cfWrite(n,r); } |
---|
[b12b7c] | 352 | |
---|
[353caa] | 353 | /// @todo: Describe me!!! |
---|
| 354 | static inline const char *n_Read(const char * s, number * a, const coeffs r) |
---|
| 355 | { assume(r != NULL); assume(r->cfRead!=NULL); return r->cfRead(s, a, r); } |
---|
| 356 | |
---|
[b12b7c] | 357 | /// Normalize and get denomerator |
---|
[8a8c9e] | 358 | static inline number n_GetDenom(number& n, const coeffs r) |
---|
[6c084af] | 359 | { assume(r != NULL); assume(r->cfGetDenom!=NULL); return r->cfGetDenom(n, r); } |
---|
[b12b7c] | 360 | |
---|
| 361 | /// Normalize and get numerator |
---|
[8a8c9e] | 362 | static inline number n_GetNumerator(number& n, const coeffs r) |
---|
[6c084af] | 363 | { assume(r != NULL); assume(r->cfGetNumerator!=NULL); return r->cfGetNumerator(n, r); } |
---|
[b12b7c] | 364 | |
---|
[8a8c9e] | 365 | static inline void n_Power(number a, int b, number *res, const coeffs r) |
---|
[6c084af] | 366 | { assume(r != NULL); assume(r->cfPower!=NULL); r->cfPower(a,b,res,r); } |
---|
[b12b7c] | 367 | |
---|
[8a8c9e] | 368 | static inline number n_Mult(number a, number b, const coeffs r) |
---|
[6c084af] | 369 | { assume(r != NULL); assume(r->cfMult!=NULL); return r->cfMult(a, b, r); } |
---|
[227efd] | 370 | |
---|
[b12b7c] | 371 | /// Inplace multiplication: a := a * b |
---|
[8a8c9e] | 372 | static inline void n_InpMult(number &a, number b, const coeffs r) |
---|
[6c084af] | 373 | { assume(r != NULL); assume(r->cfInpMult!=NULL); r->cfInpMult(a,b,r); } |
---|
[8a8c9e] | 374 | |
---|
| 375 | static inline number n_Sub(number a, number b, const coeffs r) |
---|
[6c084af] | 376 | { assume(r != NULL); assume(r->cfSub!=NULL); return r->cfSub(a, b, r); } |
---|
[8a8c9e] | 377 | |
---|
| 378 | static inline number n_Add(number a, number b, const coeffs r) |
---|
[6c084af] | 379 | { assume(r != NULL); assume(r->cfAdd!=NULL); return r->cfAdd(a, b, r); } |
---|
[b12b7c] | 380 | |
---|
[8a8c9e] | 381 | static inline number n_Div(number a, number b, const coeffs r) |
---|
[6c084af] | 382 | { assume(r != NULL); assume(r->cfDiv!=NULL); return r->cfDiv(a,b,r); } |
---|
[b12b7c] | 383 | |
---|
[8a8c9e] | 384 | static inline number n_IntDiv(number a, number b, const coeffs r) |
---|
[6c084af] | 385 | { assume(r != NULL); assume(r->cfIntDiv!=NULL); return r->cfIntDiv(a,b,r); } |
---|
[b12b7c] | 386 | |
---|
[8a8c9e] | 387 | static inline number n_ExactDiv(number a, number b, const coeffs r) |
---|
[6c084af] | 388 | { assume(r != NULL); assume(r->cfExactDiv!=NULL); return r->cfExactDiv(a,b,r); } |
---|
[8a8c9e] | 389 | |
---|
| 390 | static inline number n_Gcd(number a, number b, const coeffs r) |
---|
[6c084af] | 391 | { assume(r != NULL); assume(r->cfGcd!=NULL); return r->cfGcd(a,b,r); } |
---|
[b12b7c] | 392 | |
---|
[5679049] | 393 | static inline number n_Lcm(number a, number b, const coeffs r) |
---|
[6c084af] | 394 | { assume(r != NULL); assume(r->cfLcm!=NULL); return r->cfLcm(a,b,r); } |
---|
[1389a4] | 395 | |
---|
| 396 | static inline nMapFunc n_SetMap(const coeffs src, const coeffs dst) |
---|
[6c084af] | 397 | { assume(src != NULL && dst != NULL); assume(dst->cfSetMap!=NULL); return dst->cfSetMap(src,dst); } |
---|
[1389a4] | 398 | |
---|
[4581a96] | 399 | static inline number n_Par(int n, const coeffs r) |
---|
[6c084af] | 400 | { assume(r != NULL); assume(r->cfPar!=NULL); return r->cfPar(n,r); } |
---|
[4581a96] | 401 | |
---|
[1389a4] | 402 | static inline int n_ParDeg(number n, const coeffs r) |
---|
[6c084af] | 403 | { assume(r != NULL); assume(r->cfParDeg!=NULL); return r->cfParDeg(n,r); } |
---|
[5679049] | 404 | |
---|
[227efd] | 405 | /// Tests whether n is a correct number: only used if LDEBUG is defined |
---|
[b12b7c] | 406 | static inline BOOLEAN n_DBTest(number n, const char *filename, const int linenumber, const coeffs r) |
---|
[2bd9ca] | 407 | { |
---|
[17e473] | 408 | assume(r != NULL); |
---|
[8a8c9e] | 409 | #ifdef LDEBUG |
---|
[6c084af] | 410 | assume(r->cfDBTest != NULL); |
---|
| 411 | return r->cfDBTest(n, filename, linenumber, r); |
---|
[5e3046] | 412 | #else |
---|
| 413 | return TRUE; |
---|
| 414 | #endif |
---|
[2bd9ca] | 415 | } |
---|
[a0ce49] | 416 | |
---|
[c7e3d7] | 417 | /// output the coeff description |
---|
| 418 | static inline void n_CoeffWrite(const coeffs r) |
---|
[6c084af] | 419 | { assume(r != NULL); assume(r->cfCoeffWrite != NULL); r->cfCoeffWrite(r); } |
---|
[c7e3d7] | 420 | |
---|
[0ef3f51] | 421 | // Tests: |
---|
| 422 | static inline BOOLEAN nCoeff_is_Ring_2toM(const coeffs r) |
---|
[17e473] | 423 | { assume(r != NULL); return (r->ringtype == 1); } |
---|
[0ef3f51] | 424 | |
---|
| 425 | static inline BOOLEAN nCoeff_is_Ring_ModN(const coeffs r) |
---|
[17e473] | 426 | { assume(r != NULL); return (r->ringtype == 2); } |
---|
[0ef3f51] | 427 | |
---|
| 428 | static inline BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r) |
---|
[17e473] | 429 | { assume(r != NULL); return (r->ringtype == 3); } |
---|
[0ef3f51] | 430 | |
---|
| 431 | static inline BOOLEAN nCoeff_is_Ring_Z(const coeffs r) |
---|
[17e473] | 432 | { assume(r != NULL); return (r->ringtype == 4); } |
---|
[0ef3f51] | 433 | |
---|
| 434 | static inline BOOLEAN nCoeff_is_Ring(const coeffs r) |
---|
[17e473] | 435 | { assume(r != NULL); return (r->ringtype != 0); } |
---|
[0ef3f51] | 436 | |
---|
[7dce2d7] | 437 | /// returns TRUE, if r is not a field and r has no zero divisors (i.e is a domain) |
---|
[0ef3f51] | 438 | static inline BOOLEAN nCoeff_is_Domain(const coeffs r) |
---|
[17e473] | 439 | { |
---|
| 440 | assume(r != NULL); |
---|
| 441 | #ifdef HAVE_RINGS |
---|
| 442 | return (r->ringtype == 4 || r->ringtype == 0); |
---|
| 443 | #else |
---|
| 444 | return TRUE; |
---|
| 445 | #endif |
---|
| 446 | } |
---|
[0ef3f51] | 447 | |
---|
[7dce2d7] | 448 | /// returns TRUE, if r is not a field and r has non-trivial units |
---|
[0ef3f51] | 449 | static inline BOOLEAN nCoeff_has_Units(const coeffs r) |
---|
[17e473] | 450 | { assume(r != NULL); return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); } |
---|
[0ef3f51] | 451 | |
---|
| 452 | static inline BOOLEAN nCoeff_is_Zp(const coeffs r) |
---|
[17e473] | 453 | { assume(r != NULL); return getCoeffType(r)==n_Zp; } |
---|
[0ef3f51] | 454 | |
---|
| 455 | static inline BOOLEAN nCoeff_is_Zp(const coeffs r, int p) |
---|
[488808e] | 456 | { assume(r != NULL); return (getCoeffType(r) && (r->ch == p)); } |
---|
[0ef3f51] | 457 | |
---|
| 458 | static inline BOOLEAN nCoeff_is_Q(const coeffs r) |
---|
[17e473] | 459 | { assume(r != NULL); return getCoeffType(r)==n_Q; } |
---|
[0ef3f51] | 460 | |
---|
| 461 | static inline BOOLEAN nCoeff_is_numeric(const coeffs r) /* R, long R, long C */ |
---|
[17e473] | 462 | { assume(r != NULL); return (getCoeffType(r)==n_R) || (getCoeffType(r)==n_long_R) || (getCoeffType(r)==n_long_C); } |
---|
| 463 | // (r->ringtype == 0) && (r->ch == -1); ?? |
---|
| 464 | |
---|
[0ef3f51] | 465 | static inline BOOLEAN nCoeff_is_R(const coeffs r) |
---|
[17e473] | 466 | { assume(r != NULL); return getCoeffType(r)==n_R; } |
---|
[0ef3f51] | 467 | |
---|
| 468 | static inline BOOLEAN nCoeff_is_GF(const coeffs r) |
---|
[17e473] | 469 | { assume(r != NULL); return getCoeffType(r)==n_GF; } |
---|
[0ef3f51] | 470 | |
---|
| 471 | static inline BOOLEAN nCoeff_is_GF(const coeffs r, int q) |
---|
[17e473] | 472 | { assume(r != NULL); return (getCoeffType(r)==n_GF) && (r->ch == q); } |
---|
[0ef3f51] | 473 | |
---|
[488808e] | 474 | /* TRUE iff r represents an algebraic or transcendental extension field */ |
---|
| 475 | static inline BOOLEAN nCoeff_is_Extension(const coeffs r) |
---|
| 476 | { |
---|
| 477 | assume(r != NULL); |
---|
| 478 | return (getCoeffType(r)==n_algExt) || (getCoeffType(r)==n_transExt); |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | /* DO NOT USE (only kept for compatibility reasons towards the SINGULAR |
---|
| 482 | svn trunk); |
---|
| 483 | intension: should be TRUE iff the given r is an extension field above |
---|
| 484 | some Z/pZ; |
---|
| 485 | actually: TRUE iff the given r is an extension tower of arbitrary |
---|
| 486 | height above some field of characteristic p (may be Z/pZ or some |
---|
| 487 | Galois field of characteristic p) */ |
---|
[0ef3f51] | 488 | static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r) |
---|
[fba6f18] | 489 | { |
---|
| 490 | assume(r != NULL); |
---|
[488808e] | 491 | return ((r->ringtype == 0) && (r->ch != 0) && nCoeff_is_Extension(r)); |
---|
[fba6f18] | 492 | } |
---|
[0ef3f51] | 493 | |
---|
[488808e] | 494 | /* DO NOT USE (only kept for compatibility reasons towards the SINGULAR |
---|
| 495 | svn trunk); |
---|
| 496 | intension: should be TRUE iff the given r is an extension field above |
---|
| 497 | Z/pZ (with p as provided); |
---|
| 498 | actually: TRUE iff the given r is an extension tower of arbitrary |
---|
| 499 | height above some field of characteristic p (may be Z/pZ or some |
---|
| 500 | Galois field of characteristic p) */ |
---|
[0ef3f51] | 501 | static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r, int p) |
---|
[fba6f18] | 502 | { |
---|
| 503 | assume(r != NULL); |
---|
[488808e] | 504 | return ((r->ringtype == 0) && (r->ch == p) && nCoeff_is_Extension(r)); |
---|
[fba6f18] | 505 | } |
---|
[0ef3f51] | 506 | |
---|
[488808e] | 507 | /* DO NOT USE (only kept for compatibility reasons towards the SINGULAR |
---|
| 508 | svn trunk); |
---|
| 509 | intension: should be TRUE iff the given r is an extension field |
---|
| 510 | above Q; |
---|
| 511 | actually: TRUE iff the given r is an extension tower of arbitrary |
---|
| 512 | height above some field of characteristic 0 (may be Q, R, or C) */ |
---|
[0ef3f51] | 513 | static inline BOOLEAN nCoeff_is_Q_a(const coeffs r) |
---|
[fba6f18] | 514 | { |
---|
| 515 | assume(r != NULL); |
---|
[488808e] | 516 | return ((r->ringtype == 0) && (r->ch == 0) && nCoeff_is_Extension(r)); |
---|
[fba6f18] | 517 | } |
---|
[0ef3f51] | 518 | |
---|
| 519 | static inline BOOLEAN nCoeff_is_long_R(const coeffs r) |
---|
[17e473] | 520 | { assume(r != NULL); return getCoeffType(r)==n_long_R; } |
---|
[0ef3f51] | 521 | |
---|
| 522 | static inline BOOLEAN nCoeff_is_long_C(const coeffs r) |
---|
[17e473] | 523 | { assume(r != NULL); return getCoeffType(r)==n_long_C; } |
---|
[0ef3f51] | 524 | |
---|
| 525 | static inline BOOLEAN nCoeff_is_CF(const coeffs r) |
---|
[17e473] | 526 | { assume(r != NULL); return getCoeffType(r)==n_CF; } |
---|
[0ef3f51] | 527 | |
---|
[7dce2d7] | 528 | /// TRUE, if the computation of the inverse is fast (i.e. prefer leading coeff. 1 over content) |
---|
[0ef3f51] | 529 | static inline BOOLEAN nCoeff_has_simple_inverse(const coeffs r) |
---|
[17e473] | 530 | { assume(r != NULL); return r->has_simple_Inverse; } |
---|
[0ef3f51] | 531 | /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/ |
---|
[17e473] | 532 | // /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
| 533 | // #ifdef HAVE_RINGS |
---|
| 534 | // { return (r->ringtype > 0) || (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/ |
---|
| 535 | // #else |
---|
| 536 | // { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
| 537 | // #endif |
---|
| 538 | |
---|
[7dce2d7] | 539 | /// TRUE if n_Delete/n_New are empty operations |
---|
[0ef3f51] | 540 | static inline BOOLEAN nCoeff_has_simple_Alloc(const coeffs r) |
---|
[17e473] | 541 | { assume(r != NULL); return r->has_simple_Alloc; } |
---|
[0ef3f51] | 542 | /* Z/p, GF(p,n), R, Ring_2toM: nCopy, nNew, nDelete are dummies*/ |
---|
[17e473] | 543 | // return (rField_is_Zp(r) |
---|
| 544 | // || rField_is_GF(r) |
---|
| 545 | // #ifdef HAVE_RINGS |
---|
| 546 | // || rField_is_Ring_2toM(r) |
---|
| 547 | // #endif |
---|
| 548 | // || rField_is_R(r)); } |
---|
| 549 | |
---|
[141342] | 550 | /* TRUE iff r represents an algebraic extension field */ |
---|
| 551 | static inline BOOLEAN nCoeff_is_algExt(const coeffs r) |
---|
| 552 | { assume(r != NULL); return (getCoeffType(r)==n_algExt); } |
---|
| 553 | |
---|
| 554 | /* TRUE iff r represents a transcendental extension field */ |
---|
| 555 | static inline BOOLEAN nCoeff_is_transExt(const coeffs r) |
---|
| 556 | { assume(r != NULL); return (getCoeffType(r)==n_transExt); } |
---|
[0ef3f51] | 557 | |
---|
[2bd9ca] | 558 | /// BOOLEAN n_Test(number a, const coeffs r) |
---|
| 559 | #define n_Test(a,r) n_DBTest(a, __FILE__, __LINE__, r) |
---|
| 560 | |
---|
[44d898] | 561 | // Missing wrappers for: (TODO: review this?) |
---|
[fba6f18] | 562 | // cfIntMod, cfRePart, cfImPart, cfRead, cfName, cfInit_bigint |
---|
[44d898] | 563 | // HAVE_RINGS: cfDivComp, cfExtGcd... |
---|
[b12b7c] | 564 | |
---|
| 565 | |
---|
[3159bc] | 566 | |
---|
[b12b7c] | 567 | // Deprecated: |
---|
[8a8c9e] | 568 | static inline int n_GetChar(const coeffs r) |
---|
[17e473] | 569 | { assume(r != NULL); return nInternalChar(r); } |
---|
[b12b7c] | 570 | |
---|
[7d90aa] | 571 | #endif |
---|
| 572 | |
---|