1 | #ifndef NUMBERS_H |
---|
2 | #define NUMBERS_H |
---|
3 | /**************************************** |
---|
4 | * Computer Algebra System SINGULAR * |
---|
5 | ****************************************/ |
---|
6 | /* $Id$ */ |
---|
7 | /* |
---|
8 | * ABSTRACT: interface to coefficient aritmetics |
---|
9 | */ |
---|
10 | #include <coeffs/coeffs.h> |
---|
11 | |
---|
12 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
13 | |
---|
14 | /* the dummy routines: */ |
---|
15 | void nDummy1(number* d); |
---|
16 | void ndDelete(number* d, const coeffs r); |
---|
17 | number ndGcd(number a, number b, const coeffs); |
---|
18 | number ndCopy(number a, const coeffs r); |
---|
19 | number ndCopyMap(number a, const coeffs src, const coeffs dst); |
---|
20 | int ndSize(number a, const coeffs r); |
---|
21 | char * ndName(number n, const coeffs r); |
---|
22 | number ndPar(int i, const coeffs r); |
---|
23 | int ndParDeg(number n, const coeffs r); |
---|
24 | number ndGetDenom(number &n, const coeffs r); |
---|
25 | number ndGetNumerator(number &a,const coeffs r); |
---|
26 | number ndReturn0(number n, const coeffs r); |
---|
27 | number ndIntMod(number a, number b, const coeffs r); |
---|
28 | |
---|
29 | void ndInpMult(number &a, number b, const coeffs r); |
---|
30 | void ndInpAdd(number &a, number b, const coeffs r); |
---|
31 | |
---|
32 | #ifdef LDEBUG |
---|
33 | void nDBDummy1(number* d,char *f, int l); |
---|
34 | BOOLEAN ndDBTest(number a, const char *f, const int l, const coeffs r); |
---|
35 | #endif |
---|
36 | |
---|
37 | #define nDivBy0 "div by 0" |
---|
38 | |
---|
39 | // dummy routines |
---|
40 | void ndNormalize(number& d, const coeffs); // nNormalize... |
---|
41 | |
---|
42 | // Tests: |
---|
43 | static inline BOOLEAN nCoeff_is_Ring_2toM(const coeffs r) |
---|
44 | { return (r->ringtype == 1); } |
---|
45 | |
---|
46 | static inline BOOLEAN nCoeff_is_Ring_ModN(const coeffs r) |
---|
47 | { return (r->ringtype == 2); } |
---|
48 | |
---|
49 | static inline BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r) |
---|
50 | { return (r->ringtype == 3); } |
---|
51 | |
---|
52 | static inline BOOLEAN nCoeff_is_Ring_Z(const coeffs r) |
---|
53 | { return (r->ringtype == 4); } |
---|
54 | |
---|
55 | static inline BOOLEAN nCoeff_is_Ring(const coeffs r) |
---|
56 | { return (r->ringtype != 0); } |
---|
57 | |
---|
58 | static inline BOOLEAN nCoeff_is_Domain(const coeffs r) |
---|
59 | { return (r->ringtype == 4 || r->ringtype == 0); } |
---|
60 | |
---|
61 | static inline BOOLEAN nCoeff_has_Units(const coeffs r) |
---|
62 | { return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); } |
---|
63 | |
---|
64 | static inline BOOLEAN nCoeff_is_Zp(const coeffs r) |
---|
65 | { return getCoeffType(r)==n_Zp; } |
---|
66 | |
---|
67 | static inline BOOLEAN nCoeff_is_Zp(const coeffs r, int p) |
---|
68 | { return (getCoeffType(r) && (r->ch == ABS(p))); } |
---|
69 | |
---|
70 | static inline BOOLEAN nCoeff_is_Q(const coeffs r) |
---|
71 | { return getCoeffType(r)==n_Q; } |
---|
72 | |
---|
73 | static inline BOOLEAN nCoeff_is_numeric(const coeffs r) /* R, long R, long C */ |
---|
74 | { return (getCoeffType(r)==n_R) || (getCoeffType(r)==n_long_R) || (getCoeffType(r)==n_long_C); } |
---|
75 | |
---|
76 | static inline BOOLEAN nCoeff_is_R(const coeffs r) |
---|
77 | { return getCoeffType(r)==n_R; } |
---|
78 | |
---|
79 | static inline BOOLEAN nCoeff_is_GF(const coeffs r) |
---|
80 | { return getCoeffType(r)==n_GF; } |
---|
81 | |
---|
82 | static inline BOOLEAN nCoeff_is_GF(const coeffs r, int q) |
---|
83 | { return (getCoeffType(r)==n_GF) && (r->ch == q); } |
---|
84 | |
---|
85 | static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r) |
---|
86 | { return (r->ringtype == 0) && (r->ch < -1); } |
---|
87 | |
---|
88 | static inline BOOLEAN nCoeff_is_Zp_a(const coeffs r, int p) |
---|
89 | { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
90 | |
---|
91 | static inline BOOLEAN nCoeff_is_Q_a(const coeffs r) |
---|
92 | { return (r->ringtype == 0) && (r->ch == 1); } |
---|
93 | |
---|
94 | static inline BOOLEAN nCoeff_is_long_R(const coeffs r) |
---|
95 | { return getCoeffType(r)==n_long_R; } |
---|
96 | |
---|
97 | static inline BOOLEAN nCoeff_is_long_C(const coeffs r) |
---|
98 | { return getCoeffType(r)==n_long_C; } |
---|
99 | |
---|
100 | static inline BOOLEAN nCoeff_is_CF(const coeffs r) |
---|
101 | { return getCoeffType(r)==n_CF; } |
---|
102 | |
---|
103 | static inline BOOLEAN nCoeff_has_simple_inverse(const coeffs r) |
---|
104 | { return r->has_simple_Inverse; } |
---|
105 | /* Z/2^n, Z/p, GF(p,n), R, long_R, long_C*/ |
---|
106 | |
---|
107 | static inline BOOLEAN nCoeff_has_simple_Alloc(const coeffs r) |
---|
108 | { return r->has_simple_Alloc; } |
---|
109 | /* Z/p, GF(p,n), R, Ring_2toM: nCopy, nNew, nDelete are dummies*/ |
---|
110 | |
---|
111 | static inline BOOLEAN nCoeff_is_Extension(const coeffs r) |
---|
112 | { return (nCoeff_is_Q_a(r)) || (nCoeff_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
113 | |
---|
114 | /// initialize an object of type coeff, return FALSE in case of success |
---|
115 | typedef BOOLEAN (*cfInitCharProc)(coeffs, void *); |
---|
116 | n_coeffType nRegister(n_coeffType n, cfInitCharProc p); |
---|
117 | |
---|
118 | #endif |
---|