My Project
Loading...
Searching...
No Matches
Number.h
Go to the documentation of this file.
1#ifndef NUMBERCPP_HEADER
2#define NUMBERCPP_HEADER
3#include <boost/intrusive_ptr.hpp>
4#include "kernel/mod2.h"
5#include "coeffs/numbers.h"
6#include "kernel/polys.h"
8using namespace boost;
9inline void intrusive_ptr_add_ref(ring r)
10{
11 r->ref++;
12 //Print("ref count after add: %d", r->ref);
13}
14inline void intrusive_ptr_release(ring r)
15{
16 if (r->ref<=0) rDelete(r);
17 else
18 {
19 r->ref--;
20 }
21 //Print("ref count after release: %d", r->ref);
22}
23
25{
28};
29template<poly_variant,class,class> class PolyBase;
30class Poly;
31//class TrivialErrorHandler;
32class Vector;
33class Number
34{
35 public:
36 friend Number operator+(const Number& n1, const Number& n2);
37 friend Number operator-(const Number& n1, const Number& n2);
38 friend Number operator/(const Number& n1, const Number& n2);
39 friend Number operator*(const Number& n1, const Number& n2);
40 friend bool operator==(const Number& n1, const Number& n2);
41 friend Number operator+(const Number& n1, int n2);
42 friend Number operator-(const Number& n1, int n2);
43 friend Number operator/(const Number& n1, int n2);
44 friend Number operator*(const Number& n1, int n2);
45 friend bool operator==(const Number& n1, int n2);
46 friend Number operator+(int n1, const Number& n2);
47 friend Number operator-(int n1, const Number& n2);
48 friend Number operator/(int n1, const Number& n2);
49 friend Number operator*(int n1, const Number& n2);
50 friend bool operator==(int n1, const Number& n2);
51 friend class Poly;
52 friend class Vector;
53 //friend class PolyBase<POLY_VARIANT_RING,Poly,TrivialErrorHandler>;
54// friend class PolyBase <poly_variant variant,
55// class create_type_input,
56// class error_handle_traits>;
57 template <poly_variant,class,class> friend class PolyBase;
58 friend class PolyImpl;
59 number as_number() const
60 {
61 return n_Copy(n,r.get()->cf);
62 }
64 {
65 //durch Reihenfolge Selbstzuweisungen berücksichtigt
66 number nc=n_Copy(n2.n,n2.r.get()->cf);
67 n_Delete(&n,r.get()->cf);
68 r=n2.r;
69 n=nc;
70 return *this;
71 }
73 {
74 Number t(*this);
75 //t.n=n_Copy(n,r);
76 t.n=n_InpNeg(t.n,r.get()->cf);
77 return t;
78 }
80 {
81 if (r!=n2.r)
82 {
83 WerrorS("not the same ring");
84 return *this;
85 }
86 number nv=n_Add(n,n2.n,r.get()->cf);
87 n_Delete(&n,r.get()->cf);
88 n=nv;
89 return *this;
90 }
92 {
93 if (r!=n2.r)
94 {
95 WerrorS("not the same ring");
96 return *this;
97 }
98 number nv=n_Mult(n,n2.n,r.get()->cf);
99 n_Delete(&n,r.get()->cf);
100 n=nv;
101 return *this;
102 }
104 {
105 if (r!=n2.r)
106 {
107 WerrorS("not the same ring");
108 return *this;
109 }
110 number nv=n_Sub(n,n2.n,r.get()->cf);
111 n_Delete(&n,r.get()->cf);
112 n=nv;
113 return *this;
114 }
116 {
117 if (r!=n2.r)
118 {
119 WerrorS("not the same ring");
120 return *this;
121 }
122 number nv=n_Div(n,n2.n,r.get()->cf);
123 n_Delete(&n,r.get()->cf);
124 n=nv;
125 return *this;
126 }
128 {
129 n_Delete(&n,r.get()->cf);
130 n=n_Init(n2,r.get()->cf);
131 return *this;
132 }
134 {
135 number n2n=n_Init(n2,r.get()->cf);
136 number nv=n_Add(n,n2n,r.get()->cf);
137 n_Delete(&n,r.get()->cf);
138 n_Delete(&n2n,r.get()->cf);
139 n=nv;
140 return *this;
141 }
143 {
144 number n2n=n_Init(n2,r.get()->cf);
145 number nv=n_Mult(n,n2n,r.get()->cf);
146 n_Delete(&n,r.get()->cf);
147 n_Delete(&n2n,r.get()->cf);
148 n=nv;
149 return *this;
150 }
152 {
153 number n2n=n_Init(n2,r.get()->cf);
154 number nv=n_Sub(n,n2n,r.get()->cf);
155 n_Delete(&n,r.get()->cf);
156 n_Delete(&n2n,r.get()->cf);
157 n=nv;
158 return *this;
159 }
161 {
162 number n2n=n_Init(n2,r.get()->cf);
163 number nv=n_Div(n,n2n,r.get()->cf);
164 n_Delete(&n,r.get()->cf);
165 n_Delete(&n2n,r.get()->cf);
166 n=nv;
167 return *this;
168 }
170 {
171 r=currRing;
172 if (r.get()!=NULL)
173 n=n_Init(0,r.get()->cf);
174 else
175 n=(number) NULL;
176 }
177 Number(const Number & n)
178 {
179 r=n.r;
180 this->n=n_Copy(n.n,r.get()->cf);
181 }
182 Number(number n, ring r)
183 {
184 this->n=n_Copy(n,r->cf);
185 this->r=r;
186 }
187 Number(int n, ring r)
188 {
189 this->r=r;
190 this->n=n_Init(n,r->cf);
191 }
192 Number(int n, intrusive_ptr<ip_sring> r)
193 {
194 this->r=r;
195 this->n=n_Init(n,r.get()->cf);
196 }
197 explicit Number(int n)
198 {
199 r=currRing;
200 this->n=n_Init(n,r.get()->cf);
201 }
202 void write() const
203 {
204 number towrite=n;
205 n_Write(towrite,r.get()->cf);
206 }
208 {
209 if (r!=NULL)
210 n_Delete(&n,r.get()->cf);
211 }
212 ring getRing() const
213 {
214 return r.get();
215 }
216 protected:
217 number n;
218 intrusive_ptr<ip_sring> r;
219};
220
221inline Number operator+(const Number &n1, const Number& n2)
222{
223 Number erg(n1);
224 erg+=n2;
225 return erg;
226}
227inline Number operator*(const Number &n1, const Number& n2)
228{
229 Number erg(n1);
230 erg*=n2;
231 return erg;
232}
233inline Number operator-(const Number &n1, const Number& n2)
234{
235 Number erg(n1);
236 erg-=n2;
237 return erg;
238}
239inline Number operator/(const Number &n1, const Number& n2)
240{
241 Number erg(n1);
242 erg/=n2;
243 return erg;
244}
245inline bool operator==(const Number &n1, const Number& n2)
246{
247 if(n1.r!=n2.r)
248 return false;
249 return n_Equal(n1.n,n2.n,n1.r.get()->cf);
250}
251inline Number operator+(const Number &n1, int n2)
252{
253 Number erg(n1);
254 erg+=Number(n2,n1.r);
255 return erg;
256}
257inline Number operator*(const Number &n1, int n2)
258{
259 Number erg(n1);
260 erg*=Number(n2,n1.r);
261 return erg;
262}
263inline Number operator-(const Number &n1, int n2)
264{
265 Number erg(n1);
266 erg-=Number(n2,n1.r);
267 return erg;
268}
269inline Number operator/(const Number &n1, int n2)
270{
271 Number erg(n1);
272 erg/=Number(n2,n1.r);
273 return erg;
274}
275inline bool operator==(const Number &n1, int n2)
276{
277 return n_Equal(n1.n,Number(n2,n1.r).n,n1.r.get()->cf);
278}
279inline Number operator+(int n1, const Number& n2)
280{
281 Number erg(n2);
282 return erg+=Number(n1,n2.r);
283}
284inline Number operator-(int n1, const Number& n2)
285{
286 Number erg(n1,n2.r);
287 return erg-=n2;
288}
289inline Number operator/(int n1, const Number& n2)
290{
291 Number erg(n1,n2.r);
292 return erg/=n2;
293}
294inline Number operator*(int n1, const Number& n2)
295{
296 Number erg(n2);
297 return erg*=Number(n1,n2.r);
298}
299inline bool operator==(int n1, const Number& n2)
300{
301 return n2==Number(n1,n2.r);
302}
303#endif
Number operator-(const Number &n1, const Number &n2)
Definition: Number.h:233
poly_variant
Definition: Number.h:25
@ POLY_VARIANT_MODUL
Definition: Number.h:27
@ POLY_VARIANT_RING
Definition: Number.h:26
bool operator==(const Number &n1, const Number &n2)
Definition: Number.h:245
void intrusive_ptr_add_ref(ring r)
Definition: Number.h:9
Number operator+(const Number &n1, const Number &n2)
Definition: Number.h:221
Number operator*(const Number &n1, const Number &n2)
Definition: Number.h:227
Number operator/(const Number &n1, const Number &n2)
Definition: Number.h:239
void intrusive_ptr_release(ring r)
Definition: Number.h:14
Definition: Number.h:34
Number & operator*=(int n2)
Definition: Number.h:142
Number(const Number &n)
Definition: Number.h:177
friend Number operator-(const Number &n1, const Number &n2)
Definition: Number.h:233
Number(int n)
Definition: Number.h:197
ring getRing() const
Definition: Number.h:212
~Number()
Definition: Number.h:207
Number()
Definition: Number.h:169
Number & operator/=(int n2)
Definition: Number.h:160
friend bool operator==(const Number &n1, const Number &n2)
Definition: Number.h:245
Number(int n, ring r)
Definition: Number.h:187
friend Number operator+(const Number &n1, const Number &n2)
Definition: Number.h:221
void write() const
Definition: Number.h:202
Number operator-()
Definition: Number.h:72
Number & operator-=(const Number &n2)
Definition: Number.h:103
friend Number operator*(const Number &n1, const Number &n2)
Definition: Number.h:227
intrusive_ptr< ip_sring > r
Definition: Number.h:218
Number & operator=(const Number &n2)
Definition: Number.h:63
Number & operator+=(int n2)
Definition: Number.h:133
friend Number operator/(const Number &n1, const Number &n2)
Definition: Number.h:239
Number & operator+=(const Number &n2)
Definition: Number.h:79
Number & operator*=(const Number &n2)
Definition: Number.h:91
Number(number n, ring r)
Definition: Number.h:182
Number & operator-=(int n2)
Definition: Number.h:151
Number & operator=(int n2)
Definition: Number.h:127
Number(int n, intrusive_ptr< ip_sring > r)
Definition: Number.h:192
Number & operator/=(const Number &n2)
Definition: Number.h:115
number as_number() const
Definition: Number.h:59
number n
Definition: Number.h:217
Definition: Poly.h:330
Definition: Poly.h:45
Definition: Poly.h:509
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition: coeffs.h:633
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:448
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition: coeffs.h:647
static FORCE_INLINE number n_InpNeg(number n, const coeffs r)
in-place negation of n MUST BE USED: n = n_InpNeg(n) (no copy is returned)
Definition: coeffs.h:554
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:612
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition: coeffs.h:652
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:452
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:588
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:535
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition: coeffs.h:457
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define NULL
Definition: omList.c:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:450
Definition: janet.h:15