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.h" |
---|
11 | |
---|
12 | /// Returns the type of coeffs domain |
---|
13 | static inline n_coeffType getCoeffType(const coeffs r) |
---|
14 | { |
---|
15 | return r->type; |
---|
16 | } |
---|
17 | |
---|
18 | static inline int nInternalChar(const coeffs r) |
---|
19 | { |
---|
20 | return r->ch; |
---|
21 | } |
---|
22 | |
---|
23 | #define SHORT_REAL_LENGTH 6 // use short reals for real <= 6 digits |
---|
24 | |
---|
25 | #define n_Copy(n, r) (r)->cfCopy(n,r) |
---|
26 | #define n_Delete(n, r) (r)->cfDelete(n,r) |
---|
27 | #define n_Mult(n1, n2, r) (r)->nMult(n1, n2,r) |
---|
28 | #define n_Add(n1, n2, r) (r)->nAdd(n1, n2,r) |
---|
29 | #define n_IsZero(n, r) (r)->nIsZero(n,r) |
---|
30 | #define n_Equal(n1, n2, r) (r)->nEqual(n1, n2,r) |
---|
31 | #define n_Neg(n, r) (r)->nNeg(n,r) |
---|
32 | #define n_Sub(n1, n2, r) (r)->nSub(n1, n2,r) |
---|
33 | #define n_GetChar(r) ((r)->ch) |
---|
34 | #define n_Init(i, r) (r)->cfInit(i,r) |
---|
35 | #define n_IsOne(n, r) (r)->nIsOne(n,r) |
---|
36 | #define n_IsMOne(n, r) (r)->nIsMOne(n,r) |
---|
37 | #define n_GreaterZero(n, r) (r)->nGreaterZero(n,r) |
---|
38 | #define n_Write(n, r) (r)->cfWrite(n,r) |
---|
39 | #define n_Normalize(n, r) (r)->nNormalize(n,r) |
---|
40 | #define n_Gcd(a, b, r) (r)->nGcd(a,b,r) |
---|
41 | #define n_IntDiv(a, b, r) (r)->nIntDiv(a,b,r) |
---|
42 | #define n_Div(a, b, r) (r)->nDiv(a,b,r) |
---|
43 | #define n_Invers(a, r) (r)->nInvers(a,r) |
---|
44 | #define n_ExactDiv(a, b, r) (r)->nExactDiv(a,b,r) |
---|
45 | #define n_Test(a,r) (r)->nDBTest(a,r,__FILE__,__LINE__) |
---|
46 | |
---|
47 | #define n_InpMult(a, b, r) (r)->nInpMult(a,b,r) |
---|
48 | #define n_Power(a, b, res, r) (r)->nPower(a,b,res,r) |
---|
49 | #define n_Size(n,r) (r)->nSize(n,r) |
---|
50 | #define n_GetDenom(N,r) (r)->cfGetDenom((N),r) |
---|
51 | #define n_GetNumerator(N,r) (r)->cfGetNumerator((N),r) |
---|
52 | |
---|
53 | #define n_New(n, r) nNew(n) |
---|
54 | |
---|
55 | /* variables */ |
---|
56 | extern unsigned short fftable[]; |
---|
57 | |
---|
58 | /* prototypes */ |
---|
59 | void nNew(number * a); |
---|
60 | #define nInit(i) n_Init(i,currRing) |
---|
61 | #define nWrite(A) n_Write(A,currRing) |
---|
62 | |
---|
63 | #define nTest(a) (1) |
---|
64 | |
---|
65 | // please use n_* counterparts instead!!! |
---|
66 | // #define nDelete(A) (currRing)->cf->cfDelete(A,currRing) |
---|
67 | // #define nGetDenom(N) (currRing->cf->cfGetDenom((N),currRing)) |
---|
68 | // #define nGetNumerator(N) (currRing->cf->cfGetNumerator((N),currRing)) |
---|
69 | |
---|
70 | |
---|
71 | #define nSetMap(R) (currRing->cf->cfSetMap(R,currRing)) |
---|
72 | |
---|
73 | /* the dummy routines: */ |
---|
74 | void nDummy1(number* d); |
---|
75 | void ndDelete(number* d, const coeffs r); |
---|
76 | number ndGcd(number a, number b, const coeffs); |
---|
77 | number ndCopy(number a, const coeffs r); |
---|
78 | number ndCopyMap(number a, const coeffs src, const coeffs dst); |
---|
79 | int ndSize(number a, const coeffs r); |
---|
80 | char * ndName(number n, const coeffs r); |
---|
81 | number ndPar(int i, const coeffs r); |
---|
82 | int ndParDeg(number n, const coeffs r); |
---|
83 | number ndGetDenom(number &n, const coeffs r); |
---|
84 | number ndGetNumerator(number &a,const coeffs r); |
---|
85 | number ndReturn0(number n, const coeffs r); |
---|
86 | number ndIntMod(number a, number b, const coeffs r); |
---|
87 | |
---|
88 | void ndInpMult(number &a, number b, const coeffs r); |
---|
89 | number ndInpAdd(number &a, number b, const coeffs r); |
---|
90 | |
---|
91 | #ifdef LDEBUG |
---|
92 | void nDBDummy1(number* d,char *f, int l); |
---|
93 | #endif |
---|
94 | #define nGetChar() n_GetChar(currRing) |
---|
95 | |
---|
96 | void nInitChar(coeffs r); // do one-time initialisations |
---|
97 | void nKillChar(coeffs r); // undo all initialisations |
---|
98 | void nSetChar(coeffs r); // initialisations after each ring chage |
---|
99 | |
---|
100 | #define nDivBy0 "div by 0" |
---|
101 | |
---|
102 | // dummy routines |
---|
103 | void ndNormalize(number& d, const coeffs); // nNormalize... |
---|
104 | |
---|
105 | // Tests: |
---|
106 | static inline BOOLEAN nField_is_Ring_2toM(const coeffs r) |
---|
107 | { return (r->ringtype == 1); } |
---|
108 | |
---|
109 | static inline BOOLEAN nField_is_Ring_ModN(const coeffs r) |
---|
110 | { return (r->ringtype == 2); } |
---|
111 | |
---|
112 | static inline BOOLEAN nField_is_Ring_PtoM(const coeffs r) |
---|
113 | { return (r->ringtype == 3); } |
---|
114 | |
---|
115 | static inline BOOLEAN nField_is_Ring_Z(const coeffs r) |
---|
116 | { return (r->ringtype == 4); } |
---|
117 | |
---|
118 | static inline BOOLEAN nField_is_Ring(const coeffs r) |
---|
119 | { return (r->ringtype != 0); } |
---|
120 | |
---|
121 | static inline BOOLEAN nField_is_Domain(const coeffs r) |
---|
122 | { return (r->ringtype == 4 || r->ringtype == 0); } |
---|
123 | |
---|
124 | static inline BOOLEAN nField_has_Units(const coeffs r) |
---|
125 | { return ((r->ringtype == 1) || (r->ringtype == 2) || (r->ringtype == 3)); } |
---|
126 | |
---|
127 | static inline BOOLEAN nField_is_Zp(const coeffs r) |
---|
128 | { return getCoeffType(r)==n_Zp; } |
---|
129 | |
---|
130 | static inline BOOLEAN nField_is_Zp(const coeffs r, int p) |
---|
131 | { return (getCoeffType(r) && (r->ch == ABS(p))); } |
---|
132 | |
---|
133 | static inline BOOLEAN nField_is_Q(const coeffs r) |
---|
134 | { return getCoeffType(r)==n_Q; } |
---|
135 | |
---|
136 | static inline BOOLEAN nField_is_numeric(const coeffs r) /* R, long R, long C */ |
---|
137 | { return (getCoeffType(r)==n_R) || (getCoeffType(r)==n_long_R) || (getCoeffType(r)==n_long_C); } |
---|
138 | |
---|
139 | static inline BOOLEAN nField_is_R(const coeffs r) |
---|
140 | { return getCoeffType(r)==n_R; } |
---|
141 | |
---|
142 | static inline BOOLEAN nField_is_GF(const coeffs r) |
---|
143 | { return getCoeffType(r)==n_GF; } |
---|
144 | |
---|
145 | static inline BOOLEAN nField_is_GF(const coeffs r, int q) |
---|
146 | { return (getCoeffType(r)==n_GF) && (r->ch == q); } |
---|
147 | |
---|
148 | static inline BOOLEAN nField_is_Zp_a(const coeffs r) |
---|
149 | { return (r->ringtype == 0) && (r->ch < -1); } |
---|
150 | |
---|
151 | static inline BOOLEAN nField_is_Zp_a(const coeffs r, int p) |
---|
152 | { return (r->ringtype == 0) && (r->ch < -1 ) && (-(r->ch) == ABS(p)); } |
---|
153 | |
---|
154 | static inline BOOLEAN nField_is_Q_a(const coeffs r) |
---|
155 | { return (r->ringtype == 0) && (r->ch == 1); } |
---|
156 | |
---|
157 | static inline BOOLEAN nField_is_long_R(const coeffs r) |
---|
158 | { return getCoeffType(r)==n_long_R; } |
---|
159 | |
---|
160 | static inline BOOLEAN nField_is_long_C(const coeffs r) |
---|
161 | { return getCoeffType(r)==n_long_C; } |
---|
162 | |
---|
163 | static inline BOOLEAN nField_has_simple_inverse(const coeffs r) |
---|
164 | /* { return (r->ch>1) || (r->ch== -1); } *//* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
165 | #ifdef HAVE_RINGS |
---|
166 | { 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*/ |
---|
167 | #else |
---|
168 | { return (r->ch>1) || ((r->ch== -1) && (r->float_len < 10)); } /* Z/p, GF(p,n), R, long_R, long_C*/ |
---|
169 | #endif |
---|
170 | |
---|
171 | static inline BOOLEAN nField_has_simple_Alloc(const coeffs r) |
---|
172 | { return (nField_is_Zp(r) |
---|
173 | || nField_is_GF(r) |
---|
174 | #ifdef HAVE_RINGS |
---|
175 | || nField_is_Ring_2toM(r) |
---|
176 | #endif |
---|
177 | || nField_is_R(r)); |
---|
178 | } |
---|
179 | /* Z/p, GF(p,n), R: nCopy, nNew, nDelete are dummies*/ |
---|
180 | |
---|
181 | static inline BOOLEAN nField_is_Extension(const coeffs r) |
---|
182 | { return (nField_is_Q_a(r)) || (nField_is_Zp_a(r)); } /* Z/p(a) and Q(a)*/ |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | #endif |
---|