Macaulay2 Engine
Loading...
Searching...
No Matches
relem.hpp
Go to the documentation of this file.
1// Copyright 1995 Michael E. Stillman
2
3#ifndef _ring_elem_hh_
4#define _ring_elem_hh_
5
46
47#include "ring.hpp"
48
49class EngineMonomial;
50
67{
68 const Ring *R;
70
71 protected:
72 virtual unsigned int computeHashValue() const;
73
74 public:
75 RingElement(const Ring *R, ring_elem f);
76
77 static RingElement *make_raw(const Ring *R, ring_elem f);
78
79 ring_elem get_value() const { return val; }
80
81 const Ring *get_ring() const { return R; }
82
83 // ring arithmetic
84
85 bool is_zero() const;
86 bool is_equal(const RingElement &b) const;
87 bool is_unit() const;
88
89 RingElement *operator-() const;
90 RingElement *operator+(const RingElement &b) const;
91 RingElement *operator-(const RingElement &b) const;
92 RingElement *operator*(const RingElement &b) const;
93 RingElement *operator*(int n) const;
94 RingElement *power(mpz_srcptr n) const;
95 RingElement *power(int n) const;
96
97 RingElement *operator/(const RingElement &b) const;
98 RingElement *invert() const;
99
100 static RingElement *random(const Ring *R);
101
102 void text_out(buffer &o) const;
103
104 // We have several ways of moving from one ring to the next:
105 // R ---> R[x1..xn]
106 // R ---> R/I
107 // R ---> frac R
108 // Z/p[x]/F(x) ---> GF(p,n)
109 // R ---> local(R,I) (much later...)
110
111 // Both of the following routines assume that S ---> 'this'
112 // is one of these construction steps. Promote takes an element of
113 // S, and maps it into 'this', while lift goes the other way.
114
115 bool promote(const Ring *S, const RingElement *&result) const;
116 bool lift(const Ring *S, const RingElement *&result) const;
117
118 // functions primarily for polynomial ring elements
119
120 RingElement *lead_term(int n = -1) const;
122
124 // The following take extra arguments, using logical monoid and coefficient
125 // ring
126 // nvars is the number of variables in an outermost monoid
127 // coeffR is the coefficient ring the result coefficients will be in
128 int n_terms(int nvars) const;
129 RingElement /* or null */ *get_terms(int nvars, int lo, int hi) const;
130 RingElement /* or null */ *get_coeff(const Ring *coeffR,
131 const EngineMonomial *m) const;
132 RingElement /* or null */ *lead_coeff(const Ring *coeffR) const;
133 EngineMonomial /* or null */ *lead_monom(int nvars) const;
135
136 bool is_homogeneous() const;
137 RingElement *homogenize(int v, const std::vector<int> &wts) const;
138 RingElement *homogenize(int v, int deg, const std::vector<int> &wts) const;
139 void degree_weights(const std::vector<int> &wts, int &lo, int &hi) const;
140 const_monomial degree() const { return R->degree(val); }
141 bool multi_degree(monomial d) const { return R->multi_degree(val, d); }
142
143 // See engine.h for the definition of 'content' here
144 const RingElement /* or null */ *content() const;
145 const RingElement /* or null */ *remove_content() const;
146 const RingElement /* or null */ *split_off_content(
147 const RingElement /* or null */ *&result) const;
148
149 // functions for fraction fields
150
151 RingElement *numerator() const;
152 RingElement *denominator() const;
153 RingElement *fraction(const Ring *R, const RingElement *bottom) const;
154
155 // functions for univariate polynomials
156
157 // raises an exception if ring is not a univariate polynomial ring
158 // returns false if the polynomial coefficients cannot be coerced to long
159 // ints.
160 // otherwise: returns true, and sets result_coeffs.
161 // (Mainly useful for univariate poly rings over finite fields)
162 bool getSmallIntegerCoefficients(std::vector<long> &result_coeffs) const;
164};
165
166inline RingElement::RingElement(const Ring *R0, ring_elem f) : R(R0), val(f) {}
167inline bool RingElement::is_zero() const { return get_ring()->is_zero(val); }
168inline bool RingElement::is_unit() const { return get_ring()->is_unit(val); }
169inline bool RingElement::is_equal(const RingElement &b) const
170{
171 if (this == &b) return true;
172 if (get_ring() != b.get_ring())
173 {
174 ERROR("cannot compare ring elements from different rings");
175 return false;
176 }
177 return get_ring()->is_equal(val, b.val);
178}
179
180#endif
181
182// Local Variables:
183// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
184// indent-tabs-mode: nil
185// End:
Engine-side immutable monomial value type wrapping a varpower- encoded exponent vector.
Definition monomial.hpp:61
EngineObject()
Definition hash.hpp:66
virtual bool is_unit(const ring_elem f) const =0
virtual bool is_equal(const ring_elem f, const ring_elem g) const =0
virtual bool is_zero(const ring_elem f) const =0
RingElement(const Ring *R, ring_elem f)
Definition relem.hpp:166
RingElement * power(mpz_srcptr n) const
Definition relem.cpp:130
RingElement * operator+(const RingElement &b) const
Definition relem.cpp:57
void text_out(buffer &o) const
Definition relem.cpp:142
RingElement * fraction(const Ring *R, const RingElement *bottom) const
Definition relem.cpp:388
static RingElement * random(const Ring *R)
Definition relem.cpp:137
bool is_homogeneous() const
Definition relem.cpp:225
EngineMonomial * lead_monom(int nvars) const
Definition relem.cpp:197
const_monomial degree() const
Definition relem.hpp:140
RingElement * denominator() const
Definition relem.cpp:374
RingElement * operator/(const RingElement &b) const
Definition relem.cpp:105
RingElement * rest() const
ring_elem val
Definition relem.hpp:69
M2_arrayintOrNull getSmallIntegerCoefficients() const
Definition relem.cpp:462
ring_elem get_value() const
Definition relem.hpp:79
bool promote(const Ring *S, const RingElement *&result) const
Definition relem.cpp:305
const RingElement * split_off_content(const RingElement *&result) const
Definition relem.cpp:351
bool is_zero() const
Definition relem.hpp:167
bool multi_degree(monomial d) const
Definition relem.hpp:141
int n_terms(int nvars) const
Definition relem.cpp:25
RingElement * lead_term(int n=-1) const
RingElement * lead_coeff(const Ring *coeffR) const
Definition relem.cpp:165
bool is_unit() const
Definition relem.hpp:168
RingElement * get_terms(int nvars, int lo, int hi) const
Definition relem.cpp:147
const Ring * R
Definition relem.hpp:68
RingElement * numerator() const
Definition relem.cpp:360
RingElement * operator-() const
Definition relem.cpp:42
RingElement * invert() const
Definition relem.cpp:47
static RingElement * make_raw(const Ring *R, ring_elem f)
Definition relem.cpp:20
void degree_weights(const std::vector< int > &wts, int &lo, int &hi) const
Definition relem.cpp:227
const RingElement * remove_content() const
Definition relem.cpp:345
RingElement * get_coeff(const Ring *coeffR, const EngineMonomial *m) const
Definition relem.cpp:185
bool lift(const Ring *S, const RingElement *&result) const
Definition relem.cpp:321
bool is_equal(const RingElement &b) const
Definition relem.hpp:169
const RingElement * content() const
Definition relem.cpp:337
const Ring * get_ring() const
Definition relem.hpp:81
virtual unsigned int computeHashValue() const
Definition relem.cpp:15
RingElement * homogenize(int v, const std::vector< int > &wts) const
Definition relem.cpp:245
RingElement * operator*(const RingElement &b) const
Definition relem.cpp:82
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
xxx xxx xxx
Definition ring.hpp:102
#define monomial
Definition gb-toric.cpp:11
const int * const_monomial
Definition imonorder.hpp:45
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_arrayintOrNull
Definition m2-types.h:99
Ring — the legacy abstract base class for every coefficient and polynomial ring.