Macaulay2 Engine
Loading...
Searching...
No Matches
aring.hpp
Go to the documentation of this file.
1// Copyright 2011 Michael E. Stillman
2
3#ifndef _aring_hpp_
4#define _aring_hpp_
5
49
50#include <cassert>
51#include <memory>
52#include "ringelem.hpp"
53#include "buffer.hpp"
54
55#ifdef HAVE_FLINT_RAND_INIT
56#define FLINT_RAND_INIT(x) flint_rand_init(x)
57#define FLINT_RAND_CLEAR(x) flint_rand_clear(x)
58#else
59#define FLINT_RAND_INIT(x) flint_randinit(x)
60#define FLINT_RAND_CLEAR(x) flint_randclear(x)
61#endif
62
63class PolynomialRing;
64class RingMap;
65
66namespace M2 {
67
69// Programming level interfaces ////////////////////////
71
96
101{
102};
103
104
115template <class ElementType>
117{
118 protected:
119 ElementType mValue;
120 ElementImpl() = default;
121 ElementImpl(const ElementType &value) : mValue(value) {}
122 ElementImpl(ElementType &&value) : mValue(value) {}
123 ElementImpl(const ElementImpl &other) noexcept = default;
124 ElementImpl(ElementImpl &&other) noexcept = default;
125 ElementImpl &operator=(const ElementImpl &other) noexcept = default;
126 ElementImpl &operator=(ElementImpl &&other) noexcept = default;
127 ~ElementImpl() noexcept = default;
128
129 public:
130 operator const ElementType &() const { return mValue; }
131 operator ElementType &() { return mValue; }
132 const ElementType &value() const { return mValue; }
133 ElementType &value() { return mValue; }
134};
135
145template <class ARing>
147{
148 public:
152 class Element : public ElementImpl<typename ARing::ElementType>
153 {
154 typedef typename ARing::ElementType ElementType;
156
157 public:
158 explicit Element(const ARing &ring)
159 {
160 // without the Impl::, the compiler can't figure out where mValue comes
161 // from
162 ring.init(Impl::mValue);
163 }
164 Element(const ARing &ring, const ElementType& other)
165 {
166 ring.init_set(Impl::mValue,other);
167 }
168 ~Element() { ARing::clear(Impl::mValue); }
169 };
170
177 {
178 typedef typename ARing::ElementType ElementType;
179 const size_t mSize;
180 std::unique_ptr<ElementType[]> mData;
181
182 public:
183 ElementArray(const ARing &ring, size_t size)
184 : mSize(size), mData(new ElementType[size])
185 {
186 for (size_t i = 0; i < size; i++) ring.init(mData[i]);
187 }
189 {
190 for (size_t i = 0; i < mSize; i++) ARing::clear(mData[i]);
191 }
192 ElementType &operator[](size_t idx) { return mData[idx]; }
193 const ElementType &operator[](size_t idx) const { return mData[idx]; }
194 ElementType *data() { return mData.get(); }
195 const ElementType *data() const { return mData.get(); }
196 };
197};
198
212class DummyRing : public SimpleARing<DummyRing>
213{
214 public:
216 typedef long FieldType;
217 typedef long ElementType;
218
220 typedef std::vector<elem> ElementContainerType;
221
222 int characteristic() const { return 0; }
223 unsigned int computeHashValue(const elem &a) const
224 {
225 return static_cast<unsigned int>(a);
226 }
227
228 M2_arrayint getModPolynomialCoeffs() const { return nullptr; }
229 M2_arrayint getGeneratorCoeffs() const { return nullptr; }
230 void getGenerator(elem &result) const { result = 0; }
231 const PolynomialRing &originalRing() const { return *mOriginalRing; }
232 long coerceToLongInteger(ElementType a) const { return a; }
234 {
235 (void) result;
236 (void) f;
237 }
239 {
240 (void) el;
241 return nullptr;
242 }
244 {
245 (void) result;
246 (void) a;
247 }
249 {
250 (void) result;
251 (void) a;
252 }
253 bool promote(const Ring *Rf, const ring_elem f, ElementType &result) const
254 {
255 (void) Rf;
256 (void) f;
257 (void) result;
258 return false;
259 }
260
261 bool lift(const Ring *Rg, const ElementType f, ring_elem &result) const
262 {
263 (void) Rg;
264 (void) f;
265 (void) result;
266 return false;
267 }
268
269 void eval(const RingMap *map,
270 const elem f,
271 int first_var,
272 ring_elem &result) const
273 {
274 (void) map;
275 (void) f;
276 (void) first_var;
277 (void) result;
278 }
279
280 void text_out(buffer &o) const { o << "GF(dummy)"; }
282 const ElementType a,
283 bool p_one,
284 bool p_plus,
285 bool p_parens) const
286 {
287 (void) o;
288 (void) a;
289 (void) p_one;
290 (void) p_plus;
291 (void) p_parens;
292 }
293
294 void init_set(elem &result, elem a) const { result = a; }
295 void set(elem &result, elem a) const { result = a; }
296 void set_from_long(elem &result, long a) const { result = a; }
297 void init(elem &result) const { result = 0; }
298 void set_from_mpz(elem &result, mpz_srcptr a) const
299 {
300 (void) a;
301 result = 0;
302 }
303 bool set_from_mpq(elem &result, mpq_srcptr a) const
304 {
305 (void) result;
306 (void) a;
307 return false;
308 }
310 {
311 (void) result;
312 (void) a;
313 return false;
314 }
315 void set_var(elem &result, int v) const
316 {
317 (void) v;
318 result = 1;
319 }
320 bool is_unit(const ElementType f) const
321 {
322 (void) f;
323 return false;
324 }
325 bool is_zero(const ElementType f) const
326 {
327 (void) f;
328 return true;
329 }
330 bool is_equal(const ElementType f, const ElementType g) const
331 {
332 (void) f;
333 (void) g;
334 return false;
335 }
336 int compare_elems(const ElementType f, const ElementType g) const
337 {
338 (void) f;
339 (void) g;
340 return 1;
341 }
342
343 static void clear(elem &result) { result = 0; }
344 void set_zero(elem &result) const { result = 0; }
345 void copy(elem &result, const elem a) const { result = a; }
346 void negate(elem &result, const elem a) const
347 {
348 (void) result;
349 (void) a;
350 }
351
352 void invert(elem &result, const elem a) const
353 {
354 (void) result;
355 (void) a;
356 }
357
358 void add(elem &result, const elem a, const elem b) const
359 {
360 (void) result;
361 (void) a;
362 (void) b;
363 }
364
366 const ElementType a,
367 const ElementType b) const
368 {
369 (void) result;
370 (void) a;
371 (void) b;
372 }
373
374 void subtract_multiple(elem &result, const elem a, const elem b) const
375 {
376 (void) result;
377 (void) a;
378 (void) b;
379 }
380
381 void mult(elem &result, const elem a, const elem b) const
382 {
383 (void) result;
384 (void) a;
385 (void) b;
386 }
387
389 void divide(elem &result, const elem a, const elem b) const
390 {
391 (void) result;
392 (void) a;
393 (void) b;
394 }
395
396 void power(elem &result, const elem a, const int n) const
397 {
398 (void) result;
399 (void) a;
400 (void) n;
401 }
402
403 void power_mpz(elem &result, const elem a, mpz_srcptr n) const
404 {
405 (void) result;
406 (void) a;
407 (void) n;
408 }
409
410 void syzygy(const ElementType a,
411 const ElementType b,
412 ElementType &x,
413 ElementType &y) const
414 {
415 (void) a;
416 (void) b;
417 (void) x;
418 (void) y;
419 }
420 void random(ElementType &result) const { result = 0; }
421 void swap(ElementType &a, ElementType &b) const
422 {
423 (void) a;
424 (void) b;
425 assert(false);
426 }
427};
428
429}; // namespace M2
430
431#endif
432
433// Local Variables:
434// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
435// indent-tabs-mode: nil
436// End:
Append-only GC-backed byte buffer used throughout the engine for text output.
void subtract_multiple(elem &result, const elem a, const elem b) const
Definition aring.hpp:374
unsigned int computeHashValue(const elem &a) const
Definition aring.hpp:223
static void clear(elem &result)
Definition aring.hpp:343
void set_zero(elem &result) const
Definition aring.hpp:344
void mult(elem &result, const elem a, const elem b) const
Definition aring.hpp:381
void set_from_long(elem &result, long a) const
Definition aring.hpp:296
M2_arrayint getModPolynomialCoeffs() const
Definition aring.hpp:228
void lift_to_original_ring(ring_elem &result, const ElementType &f) const
Definition aring.hpp:233
long ElementType
Definition aring.hpp:217
void set_var(elem &result, int v) const
Definition aring.hpp:315
void copy(elem &result, const elem a) const
Definition aring.hpp:345
const PolynomialRing * mOriginalRing
Definition aring.hpp:215
void text_out(buffer &o) const
Definition aring.hpp:280
bool is_unit(const ElementType f) const
Definition aring.hpp:320
bool promote(const Ring *Rf, const ring_elem f, ElementType &result) const
Definition aring.hpp:253
void power(elem &result, const elem a, const int n) const
Definition aring.hpp:396
long coerceToLongInteger(ElementType a) const
Definition aring.hpp:232
void add(elem &result, const elem a, const elem b) const
Definition aring.hpp:358
void set(elem &result, elem a) const
Definition aring.hpp:295
void init(elem &result) const
Definition aring.hpp:297
void eval(const RingMap *map, const elem f, int first_var, ring_elem &result) const
Definition aring.hpp:269
bool is_zero(const ElementType f) const
Definition aring.hpp:325
int compare_elems(const ElementType f, const ElementType g) const
Definition aring.hpp:336
void subtract(ElementType &result, const ElementType a, const ElementType b) const
Definition aring.hpp:365
void elem_text_out(buffer &o, const ElementType a, bool p_one, bool p_plus, bool p_parens) const
Definition aring.hpp:281
void syzygy(const ElementType a, const ElementType b, ElementType &x, ElementType &y) const
Definition aring.hpp:410
void power_mpz(elem &result, const elem a, mpz_srcptr n) const
Definition aring.hpp:403
int characteristic() const
Definition aring.hpp:222
M2_arrayint getGeneratorCoeffs() const
Definition aring.hpp:229
void swap(ElementType &a, ElementType &b) const
Definition aring.hpp:421
void from_ring_elem(ElementType &result, const ring_elem &a) const
Definition aring.hpp:248
bool set_from_mpq(elem &result, mpq_srcptr a) const
Definition aring.hpp:303
void init_set(elem &result, elem a) const
Definition aring.hpp:294
bool is_equal(const ElementType f, const ElementType g) const
Definition aring.hpp:330
void to_ring_elem(ring_elem &result, const ElementType &a) const
Definition aring.hpp:243
void getGenerator(elem &result) const
Definition aring.hpp:230
bool lift(const Ring *Rg, const ElementType f, ring_elem &result) const
Definition aring.hpp:261
long FieldType
Definition aring.hpp:216
bool set_from_BigReal(elem &result, gmp_RR a) const
Definition aring.hpp:309
ElementType elem
Definition aring.hpp:219
void divide(elem &result, const elem a, const elem b) const
test doc
Definition aring.hpp:389
std::vector< elem > ElementContainerType
Definition aring.hpp:220
void random(ElementType &result) const
Definition aring.hpp:420
void set_from_mpz(elem &result, mpz_srcptr a) const
Definition aring.hpp:298
void negate(elem &result, const elem a) const
Definition aring.hpp:346
const PolynomialRing & originalRing() const
Definition aring.hpp:231
M2_arrayint fieldElementToM2Array(ElementType el) const
Definition aring.hpp:238
void invert(elem &result, const elem a) const
Definition aring.hpp:352
Placeholder aring used as a default / fallback for code paths that need an ARing-shaped object but no...
Definition aring.hpp:213
const ElementType & value() const
Definition aring.hpp:132
ElementImpl(const ElementType &value)
Definition aring.hpp:121
~ElementImpl() noexcept=default
ElementImpl(ElementType &&value)
Definition aring.hpp:122
ElementImpl(ElementImpl &&other) noexcept=default
ElementImpl()=default
ElementType mValue
Definition aring.hpp:119
ElementImpl & operator=(ElementImpl &&other) noexcept=default
ElementImpl & operator=(const ElementImpl &other) noexcept=default
ElementType & value()
Definition aring.hpp:133
ElementImpl(const ElementImpl &other) noexcept=default
Element(const ARing &ring, const ElementType &other)
Definition aring.hpp:164
ElementImpl< ElementType > Impl
Definition aring.hpp:155
ARing::ElementType ElementType
Definition aring.hpp:154
Element(const ARing &ring)
Definition aring.hpp:158
ElementType & operator[](size_t idx)
Definition aring.hpp:192
ARing::ElementType ElementType
Definition aring.hpp:178
ElementArray(const ARing &ring, size_t size)
Definition aring.hpp:183
const ElementType * data() const
Definition aring.hpp:195
const ElementType & operator[](size_t idx) const
Definition aring.hpp:193
std::unique_ptr< ElementType[]> mData
Definition aring.hpp:180
A base class for simple ARings.
Definition aring.hpp:147
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
xxx xxx xxx
Definition ring.hpp:102
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
RingID
Definition aring.hpp:75
@ ring_CCC
Definition aring.hpp:90
@ ring_old
refers to all rings which are not ConcreteRing's.
Definition aring.hpp:94
@ ring_GFM2
Definition aring.hpp:84
@ ring_RR
Definition aring.hpp:87
@ ring_ZZpFfpack
Definition aring.hpp:82
@ ring_QQFlint
Definition aring.hpp:80
@ ring_ZZpFlint
Definition aring.hpp:83
@ ring_GFFlintZech
Definition aring.hpp:86
@ ring_RRR
Definition aring.hpp:89
@ ring_RRi
Definition aring.hpp:91
@ ring_GFFlintBig
Definition aring.hpp:85
@ ring_CCi
Definition aring.hpp:92
@ ring_ZZp
Definition aring.hpp:81
@ ring_QQ
Definition aring.hpp:79
@ ring_ZZ
Definition aring.hpp:77
@ ring_tower_ZZp
Definition aring.hpp:93
@ ring_ZZFlint
Definition aring.hpp:78
@ ring_CC
Definition aring.hpp:88
@ ring_example
Definition aring.hpp:76
VALGRIND_MAKE_MEM_DEFINED & result(result)
mpfr_srcptr gmp_RR
Definition m2-types.h:148
Definition aring-CC.cpp:3
volatile int x
ring_elem — the universal value type carried by every Ring* in the engine.