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