1 #ifndef __MONOMIAL_CPP_ 2 #define __MONOMIAL_CPP_ 24 #include "monomial.hpp" 27 #define MASKALL 0b1111111111111111111111111111111111111111111111111111111111111111 28 const uint64_t MASK [] = {
29 0b0000000000000000000000000000000000000000000000000000000011111111,
30 0b0000000000000000000000000000000000000000000000001111111100000000,
31 0b0000000000000000000000000000000000000000111111110000000000000000,
32 0b0000000000000000000000000000000011111111000000000000000000000000,
33 0b0000000000000000000000001111111100000000000000000000000000000000,
34 0b0000000000000000111111110000000000000000000000000000000000000000,
35 0b0000000011111111000000000000000000000000000000000000000000000000,
36 0b1111111100000000000000000000000000000000000000000000000000000000
55 void * Monomial::operator
new(
size_t size) {
61 void Monomial::operator
delete(
void *t) {
69 for (NVAR_TYPE i = 0; i <
n; ++i) exponents[i] = 0;
83 if (i < NPACK) emask &= ~MASK[i];
89 if (i < NPACK) emask |= (MASK[i] & (((uint64_t )((PACKSIZE )e)) << (i*NPACK)));
131 auto pi = powers.begin();
139 if (i < NPACK) emask |= (MASK[i] & (((uint64_t )((PACKSIZE )
exponents[i])) << (i*NPACK)));
158 for (NVAR_TYPE i = 0; i <
n; ++i) {
159 exponents[i] = powers[i];
160 if (exponents[i] != 0) {
163 if (i < NPACK) emask |= (MASK[i] & (((uint64_t )((PACKSIZE )exponents[i])) << (i*NPACK)));
178 for (NVAR_TYPE i = 0; result and i <
n; ++i)
192 m = ( m == 0 or m >
n ) ?
n : m;
194 for (NVAR_TYPE i = 0; i < m; ++i)
202 m = ( m == 0 or m >
n ) ?
n : m;
203 if (weights ==
nullptr)
206 for (NVAR_TYPE i = 0; i < m; ++i)
225 bool result = (
n == other.
n) and (
mask == other.
mask)
227 and (emask == other.emask)
231 for (NVAR_TYPE i = 0; result and i <
n; ++i)
233 for (NVAR_TYPE i = NPACK; result and i <
n; ++i)
240 return not (*
this == other);
250 bool result = (
n == v.
n);
251 for (NVAR_TYPE i = 0; result and i <
n; ++i)
259 and (emask == (u.emask + v.emask))
263 for (NVAR_TYPE i = 0; result and i <
n; ++i)
265 for (NVAR_TYPE i = NPACK; result and i <
n; ++i)
287 bool result = (
n == other.
n) and (((~
mask) & other.
mask) == 0);
289 for (NVAR_TYPE i = 0; result and i <
n; ++i)
292 for (NVAR_TYPE i = 0; result and i < NPACK; ++i)
294 and ((emask & MASK[i]) >= (other.emask & MASK[i]));
295 for (NVAR_TYPE i = NPACK; result and i <
n; ++i)
317 for (NVAR_TYPE i = 0; i <
n; ++i)
332 emask += other.emask;
335 for (i = 0; i + 1 <
n; i += 2) {
346 for (NVAR_TYPE i = 0; i <
n; ++i)
352 bool result = (
n == other.
n);
354 emask -= other.emask;
357 for (NVAR_TYPE i = 0; i <
n; ++i) {
369 result.emask = emask;
372 for (NVAR_TYPE i = 0; i <
n; ++i)
378 result.emask &= ~MASK[i];
379 result.emask |= ((((uint64_t )((PACKSIZE )u.
exponents[i])) << (i*NPACK)) & MASK[i]);
391 result.emask = emask;
393 for (NVAR_TYPE i = 0; i <
n; ++i)
399 result.emask &= ~MASK[i];
400 result.emask |= ((((uint64_t )((PACKSIZE )u.
exponents[i])) << (i*NPACK)) & MASK[i]);
414 for (NVAR_TYPE i = 0; i <
n; ++i)
419 result.
mask += (1 << i);
421 if (i < NPACK) result.emask |= (((uint64_t )((PACKSIZE )
exponents[i])) << (i*NPACK)) & MASK[i];
437 #define SHOW_MASK false 438 #define SHOW_EPACK false 441 if (
is_one()) cout <<
"1 ";
443 for (NVAR_TYPE i = 0; i <
n; ++i)
446 if (names ==
nullptr)
455 os <<
'(' <<
mask <<
')';
459 for (NVAR_TYPE i = 0; i < NPACK; ++i)
460 os << std::bitset<NPACK>(((emask & MASK[i]) >> (i*NPACK))) <<
' ';
474 return t.
is_like(u) or first_larger(t, u);
480 return t.
like_multiple(u, v) or first_larger_than_multiple(t, u, v);
DEG_TYPE total_degree(NVAR_TYPE m=0) const
Sum of exponents of the first m variables.
void set_ordering_data(Monomial_Order_Data *mordat)
sets the Monomial_Order_Data associated with this Monomial
special memory pool allocator for Grevlex_Order_Data and WGrevlex_Order_Data
Grading_Order_Data_Allocator< Monomial > * monoda
memory manager for monomials (not their exponents; see moda for that).
DEG_TYPE weighted_degree(const WT_TYPE *weights, NVAR_TYPE m=0) const
Monomial operator*(const Monomial &other) const
Return result of this by other.
bool operator<(const Monomial &u) const
Compares monomial with according to monomial ordering.
NVAR_TYPE n
number of variables
bool operator|(const Monomial &other) const
operator for divisibility
bool first_larger_or_equal(const Monomial &, const Monomial &) const
Monomial(NVAR_TYPE number_of_vars, const Monomial_Ordering *order=generic_grevlex_ptr)
The first constructor is equivalent to instantiating 1.
Grading_Order_Data_Allocator< EXP_TYPE > * moda
memory manager for monomial exponents
Monomial & operator=(const Monomial &other)
assignment
const Monomial_Ordering * ordering
Monomial_Ordering associated with this polynomial.
TYPE * get_new_block()
allocates and returns a block of memory
Monomial & operator*=(const Monomial &other)
Multiply this by other.
void set_monomial_ordering(const Monomial_Ordering *mord)
sets the Monomial_Ordering associated with this Monomial
void set_exponent(NVAR_TYPE i, DEG_TYPE e)
change th exponent to
bool larger_than_multiple(const Monomial &u, const Monomial &v) const
Compares monomial with according to monomial ordering.
data for a monomial ordering: optional, but stored in Monomial
void print(bool=true, ostream &=cout, const string *names=nullptr) const
prints the monomial to the give stream with the given names; adds a newline if the boolean is true ...
bool divisible_by(const Monomial &other) const
Divisible by other?
bool is_one() const
all exponents 0?
Monomial_Order_Data * ordering_data
optional data for a monomial ordering
Monomial colon(const Monomial &u) const
colon operator: exponents needed to make divisible by this
Implementation of monomials.
bool first_larger_or_equal_than_multiple(const Monomial &, const Monomial &, const Monomial &) const
interface to a monomial ordering
virtual void set_data(Monomial &) const
sets monomial ordering’s data; default is to do nothing
friend ostream & operator<<(ostream &, const Monomial &u)
essentially u.print(false, ostream)
bool operator!=(const Monomial &other) const
unequal/unlike?
bool operator>(const Monomial &u) const
Compares monomial with according to monomial ordering.
bool operator/=(const Monomial &other)
divide this by other
EXP_TYPE * exponents
has size n
bool is_coprime(const Monomial &other) const
true iff this has no common factor with other.
void initialize_exponents(NVAR_TYPE number_of_vars)
allocates memory for exponents This is useful when you want to allocate an array of monomials...
DEG_TYPE degree(NVAR_TYPE i) const
Degree of th variable.
Monomial lcm(const Monomial &u) const
Least common multiple: largest exponents.
bool operator>=(const Monomial &u) const
Compares monomial with according to monomial ordering.
bool operator==(const Monomial &other) const
equal/alike?
Monomial_Order_Data * monomial_ordering_data() const
the Monomial_Order_Data associated with this Monomial
virtual bool first_larger(const Monomial &, const Monomial &) const =0
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
void deinitialize()
deallocates memory for exponents This is useful when you want to deallocate an array of monomials...
void return_used_block(TYPE *freed_block)
returns a block of memory that is no longer needed to the pool
Monomial gcd(const Monomial &u) const
Greatest common divisor: smallest exponents.
bool larger_than(const Monomial &) const
compares monomial with according to monomial ordering
bool is_like(const Monomial &other) const
Have same variables, same powers? Synonymous with operator==().
DEG_TYPE ord_degree
degree associated with monomial ordering (used for faster comparisons)
virtual Monomial_Order_Data * clone()
default clone returns nullptr
bool operator<=(const Monomial &u) const
Compares monomial with according to monomial ordering.
uint64_t mask
divisibility mask (up to 64 variables)
bool like_multiple(const Monomial &u, const Monomial &v) const
is this like ?
virtual bool first_larger_than_multiple(const Monomial &, const Monomial &, const Monomial &) const =0
returns true iff the first Monomial is larger than the specified multiple of the second ...
void common_initialization(const Monomial_Ordering *ord=nullptr)
things all Monomial initializers must do
~Monomial()
Destructor deallocates exponents.
DEG_TYPE operator[](NVAR_TYPE i) const
Degree of th variable. Synonymous with degree().