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