58template <
class Exponent,
bool overflow_check>
64template <
class E,
bool OC>
82 for (
int i = 0; i < nvars; i++) *
result++ = 0;
88 for (
int i = 0; i < nvars; i++)
89 if (a[i] != 0)
return false;
96 return std::equal(a, a + nvars, b);
100 static inline void mult(
int nvars,
108 for (
int i = nvars; i > 0; i--) *
result++ = *a++ + *b++;
120 for (
int i = nvars; i > 0; i--) *
result++ = *a++ * n;
131 for (
int i = nvars; i > 0; i--)
134 for (
int i = nvars; i > 0; i--) *
result++ = *a++ + *b++ * n;
141 for (
int i = 0; i < nvars; i++)
142 if (a[i] > b[i])
return false;
155 for (
int i = 0; i < nvars; i++) *
result++ = *a++ - *b++;
165 for (
int i = nvars; i > 0; i--)
168 assert(*a >= 0 && *b >= 0);
172 for (
int i = 0; i < nvars; i++)
181 static inline void gcd(
int nvars,
186 for (
int i = nvars; i > 0; i--)
195 static inline void lcm(
int nvars,
200 for (
int i = nvars; i > 0; i--)
211 for (
int i = 0; i < nvars; i++)
214 else if (a[i] < b[i])
223 if (nvars == 0)
return 0;
226 for (
int i = 1; i < nvars; i++)
227 sum =
safe::add(sum, a[i],
"degree overflow");
229 for (
int i = 1; i < nvars; i++) sum += a[i];
236 const std::vector<Exponent> &wts)
240 if (nvars < top) top = nvars;
241 if (top == 0)
return 0;
243 for (
int i = 1; i < top; i++)
257 static inline void syz(
int nvars,
263 for (
int i = 0; i < nvars; i++)
284 const std::vector<std::string> &varnames,
288 for (
unsigned int v = 0; v < nvars; v++)
292 if (varnames.size() < v)
297 int single = (varnames[v].size() == 1);
303 o <<
"^(" << e <<
")";
305 if (len_ == 0 && p_one) o <<
"1";
319 for (
int i = nvars - 1; i >= 0; i--)
321 if (exp[i] > 0)
result |= bit;
323 if (bit == 0) bit = 1;
ExponentVector< int, true > exponents
exponents::ConstExponents const_exponents
exponents::Exponents exponents_t
Append-only GC-backed byte buffer used throughout the engine for text output.
static void syz(int nvars, ConstExponents a, ConstExponents b, Exponents c, Exponents d)
static Exponent weight(int nvars, ConstExponents a, const std::vector< Exponent > &wts)
static Exponent simple_degree(int nvars, ConstExponents a)
static void gcd(int nvars, ConstExponents a, ConstExponents b, Exponents result)
std::make_unsigned< Exponent >::type HashExponent
static void divide(int nvars, ConstExponents a, ConstExponents b, Exponents result)
static Exponent weight(int nvars, ConstExponents a, M2_arrayint wts)
static void one(int nvars, Exponents result)
static void mult(int nvars, ConstExponents a, ConstExponents b, Exponents result)
static bool equal(int nvars, ConstExponents a, ConstExponents b)
static void power(int nvars, ConstExponents a, const Exponent n, Exponents result)
static bool is_one(int nvars, ConstExponents a)
static void copy(int nvars, ConstExponents a, Exponents result)
static void multpower(int nvars, ConstExponents a, ConstExponents b, const Exponent n, Exponents result)
static void elem_text_out(buffer &o, int nvars, ConstExponents a, const std::vector< std::string > &varnames, bool p_one)
static void quotient(int nvars, ConstExponents a, ConstExponents b, Exponents result)
static int lex_compare(int nvars, ConstExponents a, ConstExponents b)
const Exponent * ConstExponents
static void lcm(int nvars, ConstExponents a, ConstExponents b, Exponents result)
static bool divides(int nvars, ConstExponents a, ConstExponents b)
static HashExponent mask(int nvars, ConstExponents a)
VALGRIND_MAKE_MEM_DEFINED & result(result)
static int32_t mult(int32_t x, int32_t y, const char *msg)
static int32_t add(int32_t x, int32_t y, const char *msg)
static int32_t sub(int32_t x, int32_t y, const char *msg)
static int32_t sub_pos(int32_t x, int32_t y, const char *msg)
Overflow-checked integer arithmetic for monomial exponents and degree sums.
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.
std::vector< T > M2_arrayint_to_stdvector(M2_arrayint arr)
Conversion helpers between M2 boundary types and standard C++ containers.