Macaulay2 Engine
Loading...
Searching...
No Matches
aring-zz-flint.cpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
3#include "aring-zz-flint.hpp"
4#include "ringmap.hpp"
5
6namespace M2 {
7
9{
11 fmpz_init(mMaxHeight);
12 fmpz_set_ui(mMaxHeight, 100);
13}
14
15// This function will likely not ever get called.
21
22void ARingZZ::eval(const RingMap* map,
23 const ElementType& f,
24 int first_var,
25 ring_elem& result) const
26{
27 mpz_t temp;
28
29 (void) first_var;
30 flint_mpz_init_set_readonly(temp, &f);
31 result = map->get_ring()->from_int(temp);
32 flint_mpz_clear_readonly(temp);
33}
34
36 const ElementType& a,
37 bool p_one,
38 bool p_plus,
39 bool p_parens) const
40{
41 char* str;
42
43 (void) p_parens;
44 bool is_neg = (fmpz_cmp_si(&a, 0) == -1);
45 bool is_one = (fmpz_cmp_si(&a, 1) == 0 || fmpz_cmp_si(&a, -1) == 0);
46
47 if (!is_neg && p_plus) o << '+';
48 if (is_one)
49 {
50 if (is_neg) o << '-';
51 if (p_one) o << '1';
52 }
53 else
54 {
55 str = fmpz_get_str(static_cast<char*>(nullptr), 10, &a);
56 o << str;
57 }
58}
59
61 const ElementType& b,
63 ElementType& y) const
64{
65 assert(!is_zero(b));
66 // First check the special cases a = 0, b = 1, -1. Other cases: use gcd.
67 if (is_zero(a))
68 {
69 set_from_long(x, 1);
70 set_zero(y);
71 return;
72 }
73 if (fmpz_cmp_ui(&b, 1) == 0)
74 {
75 set_from_long(x, 1);
76 negate(y, a);
77 return;
78 }
79 if (fmpz_cmp_si(&b, -1) == 0)
80 {
81 set_from_long(x, 1);
82 set(y, a);
83 return;
84 }
86 init(g);
87 fmpz_gcd(&g, &a, &b);
88 divide(y, a, g);
89 divide(x, b, g);
90 if (fmpz_sgn(&x) > 0)
91 negate(y, y);
92 else
93 negate(x, x);
94 clear(g);
95}
96};
97
98// Local Variables:
99// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
100// indent-tabs-mode: nil
101// End:
M2::ARingZZ — FLINT-backed arbitrary-precision integers with small-value inlining.
#define FLINT_RAND_INIT(x)
Definition aring.hpp:59
#define FLINT_RAND_CLEAR(x)
Definition aring.hpp:60
bool is_zero(const ElementType &f) const
void set(ElementType &result, const ElementType &a) const
void negate(ElementType &result, const ElementType &a) const
void set_zero(ElementType &result) const
bool divide(ElementType &result, const ElementType &a, const ElementType &b) const
test doc
void syzygy(const ElementType &a, const ElementType &b, ElementType &x, ElementType &y) const
flint_rand_t mRandomState
void init(ElementType &result) const
void elem_text_out(buffer &o, const ElementType &a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
void eval(const RingMap *map, const ElementType &f, int first_var, ring_elem &result) const
void set_from_long(ElementType &result, long a) const
static void clear(ElementType &result)
virtual ring_elem from_int(mpz_srcptr n) const =0
const Ring * get_ring() const
Definition ringmap.hpp:111
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
Definition ringmap.hpp:60
VALGRIND_MAKE_MEM_DEFINED & result(result)
Definition aring-CC.cpp:3
volatile int x
RingMap — engine representation of a ring homomorphism.