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