1 #ifndef __PARTICULAR_ORDERINGS_CPP_ 2 #define __PARTICULAR_ORDERINGS_CPP_ 23 #include "system_constants.hpp" 26 #include "particular_orderings.hpp" 44 void * WGrevlex_Order_Data::operator
new(
size_t size) {
50 void WGrevlex_Order_Data::operator
delete(
void *t) {
57 const EXP_TYPE * a = t.
log();
61 for (k = 0; k < n; ++k) {
72 bool searching = dtk == duk;
75 const EXP_TYPE * a = t.
log();
76 const EXP_TYPE * b = u.
log();
78 for (; searching and k < n; ++k) {
81 searching = dtk == duk;
92 bool searching = dtk == duk;
95 const EXP_TYPE * a = t.
log();
96 const EXP_TYPE * b = u.
log();
98 for (; searching and k < n; ++k) {
101 searching = dtk == duk;
113 bool searching = dtk == duk + dvk;
116 const EXP_TYPE * a = t.
log();
117 const EXP_TYPE * b = u.
log();
118 const EXP_TYPE * c = v.
log();
120 for (; searching and k < n; ++k) {
124 searching = dtk == duk + dvk;
127 return dtk > duk + dvk;
134 n(num_vars), weights(wts), thorough_weighting(thorough)
139 const EXP_TYPE * a = t.
log();
143 for (k = 0; k + 1 <
n; k += 2) {
145 d += a[k + 1] * weights[k + 1];
148 if (n % 2) d += a[k] *
weights[k];
157 bool searching = dtk == duk;
160 const EXP_TYPE * a = t.
log();
161 const EXP_TYPE * b = u.
log();
163 for (; searching and k <
n; ++k) {
164 dtk -= a[n - k - 1] *
weights[n - k - 1];
165 duk -= b[n - k - 1] * weights[n - k - 1];
166 searching = dtk == duk;
177 bool searching = dtk == duk;
180 const EXP_TYPE * a = t.
log();
181 const EXP_TYPE * b = u.
log();
183 for (; searching and k <
n; ++k) {
184 dtk -= a[n - k - 1] *
weights[n - k - 1];
185 duk -= b[n - k - 1] * weights[n - k - 1];
186 searching = dtk == duk;
198 bool searching = dtk == duk + dvk;
201 const EXP_TYPE * a = t.
log();
202 const EXP_TYPE * b = u.
log();
203 const EXP_TYPE * c = v.
log();
205 for (; searching and k <
n; ++k) {
206 dtk -= a[n - k - 1] *
weights[n - k - 1];
207 duk -= b[n - k - 1] * weights[n - k - 1];
208 dvk -= c[n - k - 1] * weights[n - k - 1];
209 searching = dtk == duk + dvk;
212 return dtk > duk + dvk;
217 for (NVAR_TYPE l = 0; l < number_of_gradings; ++l) {
219 gradings[number_of_gradings-l-1] = value;
224 : number_of_gradings(t.num_vars())
250 : n(number_of_variables)
255 bool still_tied =
true;
257 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
262 else if (dtk > duk) {
272 bool still_tied =
true;
274 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
279 else if (dtk < duk) {
290 bool still_tied =
true;
292 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
298 else if (dtk > duk + dvk) {
316 for (NVAR_TYPE k = 0; k <
n - i; ++k)
333 bool still_tied =
true;
335 const EXP_TYPE * a = t.
log();
336 const EXP_TYPE * b = u.
log();
337 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
340 else if (a[k] > b[k]) {
349 bool still_tied =
true;
351 const EXP_TYPE * a = t.
log();
352 const EXP_TYPE * b = u.
log();
353 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
356 else if (a[k] < b[k]) {
367 bool still_tied =
true;
369 const EXP_TYPE * a = t.
log();
370 const EXP_TYPE * b = u.
log();
371 const EXP_TYPE * c = v.
log();
372 for (NVAR_TYPE k = 0; still_tied and k <
n; ++k) {
373 if (a[k] < b[k] + c[k])
375 else if (a[k] > b[k] + c[k]) {
389 const EXP_TYPE * a = t.
log();
390 for (NVAR_TYPE l = 0; l < number_of_gradings; ++l) {
391 value += w[l] * a[l];
392 gradings[number_of_gradings-l-1] = value;
398 : number_of_gradings(t.num_vars())
419 DEG_TYPE WGrevlex_Order_Data::operator [] (NVAR_TYPE i)
const {
424 NVAR_TYPE number_of_variables, WT_TYPE * w,
bool thorough
425 ) : n(number_of_variables), weights(w), fully_apply(thorough)
431 if (cmp < 0) result = -1;
432 else if (cmp > 0) result = 1;
433 for (NVAR_TYPE k = 1; result == 0 and k <
n; ++k) {
443 bool still_tied =
true;
452 for (NVAR_TYPE k = 1; still_tied and k <
n; ++k) {
457 else if (dtk > duk) {
467 bool still_tied =
true;
476 for (NVAR_TYPE k = 1; still_tied and k <
n; ++k) {
481 else if (dtk < duk) {
496 bool still_tied =
true;
505 for (NVAR_TYPE k = 1; still_tied and k <
n; ++k) {
511 else if (dtk > duk + dvk) {
523 const EXP_TYPE * a = t.
log();
524 for (NVAR_TYPE k = 0; k <
n - i; ++k)
539 ->assign_gradings(t);
542 const char * Nonsingular_Matrix_Ordering_Exception::what()
const throw() {
543 return "Nonsingular matrix supplied for matrix ordering";
559 bool possibly =
true;
561 long long ** M =
new long long * [m];
562 for (NVAR_TYPE i = 0; i < m; ++i) {
563 M[i] =
new long long [
n];
564 for (NVAR_TYPE j = 0; j <
n; ++j)
567 std::cout << m <<
',' << n << std::endl;
568 for (NVAR_TYPE i = 0; i < m; ++i) {
569 for (NVAR_TYPE j = 0; j <
n; ++j)
570 std::cout << M[i][j] <<
' ';
571 std::cout << std::endl;
573 std::cout << std::endl;
574 for (NVAR_TYPE i = 0; possibly and i < m; ++i) {
576 bool searching =
true;
578 for (; searching and j < m; ++j)
583 possibly = not searching;
584 if (possibly and j < m) {
587 for (NVAR_TYPE k = i; k <
n; ++k) {
588 long long temp = M[j][k];
594 for (j = i + 1; j < m; ++j) {
595 WT_TYPE header = M[j][i];
598 for (NVAR_TYPE k = i; k <
n; ++k)
599 M[j][k] = M[j][k] * M[i][i] - M[i][k] * header;
604 std::cout << m <<
',' << n << std::endl;
605 for (NVAR_TYPE i = 0; i < m; ++i) {
606 for (NVAR_TYPE j = 0; j <
n; ++j)
607 std::cout << M[i][j] <<
' ';
608 std::cout << std::endl;
610 std::cout << std::endl;
612 for (NVAR_TYPE i = 0; i < m; ++i)
621 NVAR_TYPE rows, NVAR_TYPE cols,
const WT_TYPE **data
622 ) : m(rows),
n(cols), W(data) {
630 bool searching =
true;
631 const EXP_TYPE * a = t.
log();
632 const EXP_TYPE * b = u.
log();
633 for (NVAR_TYPE i = 0; searching and i <
m; ++i) {
636 for (NVAR_TYPE j = 0; j <
n; ++j) {
637 wt +=
W[i][j] * a[j];
638 wu +=
W[i][j] * b[j];
653 bool searching =
true;
654 const EXP_TYPE * a = t.
log();
655 const EXP_TYPE * b = u.
log();
656 for (NVAR_TYPE i = 0; searching and i <
m; ++i) {
659 for (NVAR_TYPE j = 0; j <
n; ++j) {
660 wt +=
W[i][j] * a[j];
661 wu +=
W[i][j] * b[j];
677 bool searching =
true;
678 const EXP_TYPE * a = t.
log();
679 const EXP_TYPE * b = u.
log();
680 const EXP_TYPE * c = v.
log();
681 for (NVAR_TYPE i = 0; searching and i <
m; ++i) {
685 for (NVAR_TYPE j = 0; j <
n; ++j) {
686 wt +=
W[i][j] * a[j];
687 wu +=
W[i][j] * b[j];
688 wv +=
W[i][j] * c[j];
692 else if (wt > wu + wv) {
virtual const WT_TYPE * order_weights() const override
the weights that define this ordering
void set_ordering_data(Monomial_Order_Data *mordat)
sets the Monomial_Order_Data associated with this Monomial
virtual bool first_larger_than_multiple(const Monomial &t, const Monomial &u, const Monomial &v) const override
returns true iff by weighted sums of successively fewer exponents
special memory pool allocator for Grevlex_Order_Data and WGrevlex_Order_Data
virtual bool first_smaller(const Monomial &t, const Monomial &u) const override
void assign_gradings(const Monomial &)
assigns gradings to a pre-allocated array
virtual void set_data(Monomial &t) const override
sets the Monomial’s monomial_ordering_data
virtual bool first_larger(const Monomial &t, const Monomial &u) const override
returns true iff by sums of successively fewer exponents
data for the grevlex monomial ordering
~WGrevlex_Order_Data()
deletes the array of partial weights
const NVAR_TYPE n
the number of variables, which should remain constant
virtual void set_data(Monomial &t) const override
sets the Monomial’s monomial_ordering_data
const NVAR_TYPE number_of_gradings
length of gradings
virtual bool first_smaller(const Monomial &t, const Monomial &u) const override
returns true iff by weighted sums of successively fewer exponents
virtual bool first_larger_than_multiple(const Monomial &t, const Monomial &u, const Monomial &v) const override
returns true iff by sums of successively fewer exponents
~Grevlex_Order_Data()
deletes the array creates by the constructor
virtual bool first_larger_than_multiple(const Monomial &t, const Monomial &u, const Monomial &v) const override
DEG_TYPE operator[](NVAR_TYPE i) const
returns the sum of the first variables’ exponents
WT_TYPE * weights
the weights for this ordering
DEG_TYPE ordering_degree() const
returns the ordering degree for this Monomial
DEG_TYPE partial_degree(const Monomial &t, NVAR_TYPE i) const
virtual bool first_larger_than_multiple(const Monomial &, const Monomial &, const Monomial &) const override
returns true iff the first Monomial is larger than the product of the second and the third ...
TYPE * get_new_block()
allocates and returns a block of memory
const WT_TYPE ** W
the matrix that defines this ordering
virtual bool first_larger(const Monomial &, const Monomial &) const override
returns true iff the first Monomial is larger than the second
exceptions for Matrix_Ordering
CachedWGrevlex_Ordering(NVAR_TYPE number_of_variables, WT_TYPE *w, bool thorough=true)
creates a weighted grevlex ordering specific to variables, using the weights specified by ...
virtual bool first_smaller(const Monomial &, const Monomial &) const override
returns true iff the first Monomial is smaller than the second
Lex_Ordering(NVAR_TYPE number_of_variables)
creates a lex ordering specific to variables
Grading_Order_Data_Allocator< WGrevlex_Order_Data > * woda
Memory manager for graded orderings (not their data; see goda for that).
Matrix_Ordering(NVAR_TYPE rows, NVAR_TYPE cols, const WT_TYPE **data)
checks that data defines a nonsingular matrix, and sets things up
DEG_TYPE partial_degree(const Monomial &t, NVAR_TYPE i) const
virtual bool first_larger(const Monomial &t, const Monomial &u) const override
returns true iff by sums of successively fewer exponents
const NVAR_TYPE n
the number of columns
const NVAR_TYPE m
the number of rows
WGrevlex(NVAR_TYPE, WT_TYPE *, bool=true)
Creates a grevlex ordering specific to the specified number of variables, with the given weights...
virtual bool first_smaller(const Monomial &t, const Monomial &u) const override
const WT_TYPE * weights
the weights that define this ordering
NVAR_TYPE num_vars() const
number of variables
WGrevlex_Order_Data(Monomial &t)
creates an array of partial weights of t
Grevlex_Order_Data(const Monomial &t)
creates an array of partial weights of t
virtual bool first_larger_than_multiple(const Monomial &t, const Monomial &u, const Monomial &v) const override
virtual bool first_larger(const Monomial &t, const Monomial &u) const override
Implementation of monomials.
virtual int cmp(const Monomial &, const Monomial &) const override
resturns 0 if they are alike; positive if first larger; negative otherwise
const NVAR_TYPE n
the number of variables, which should remain constant
interface to a monomial ordering
Grading_Order_Data_Allocator< WT_TYPE > * goda
Memory manager for graded ordering data.
virtual void set_data(Monomial &t) const override
sets monomial ordering’s data; default is to do nothing
bool nonsingular(NVAR_TYPE m, NVAR_TYPE n, const WT_TYPE **A)
verifies that a matrix supplied for an ordering is not nonsingular
DEG_TYPE * gradings
list of partial sums of exponents
const NVAR_TYPE n
the number of variables, which should remain constant
DEG_TYPE degree(NVAR_TYPE i) const
Degree of th variable.
virtual Grevlex_Order_Data * clone() override
clone “constructor”
const EXP_TYPE * log() const
Direct access to the exponents, for whatever reason.
generic grevlex ordering, works with any number of variables
Monomial_Order_Data * monomial_ordering_data() const
the Monomial_Order_Data associated with this Monomial
const Monomial_Ordering * monomial_ordering() const
the Monomial_Ordering associated with this Monomial
virtual bool first_larger_than_multiple(const Monomial &t, const Monomial &u, const Monomial &v) const override
virtual WGrevlex_Order_Data * clone() override
clone constructor
virtual void set_data(Monomial &t) const override
sets the Monomial’s monomial_ordering_data
void return_used_block(TYPE *freed_block)
returns a block of memory that is no longer needed to the pool
virtual bool first_smaller(const Monomial &t, const Monomial &u) const override
returns true iff by sums of successively fewer exponents
void assign_gradings(Monomial &t)
assigns gradings to a pre-allocated array
DEG_TYPE compute_ith_weight(const Monomial &t, NVAR_TYPE i) const
computes the sum of the first i exponents
virtual bool first_larger(const Monomial &t, const Monomial &u) const override
data for the weighted grevlex monomial ordering
the weighted grevlex ordering for a specified number of variables, with cached weights for each monom...
const NVAR_TYPE n
the number of variables, which should remain constant
const bool fully_apply
whether to apply the weights to more than the first sum
virtual bool first_larger(const Monomial &t, const Monomial &u) const override
returns true iff by weighted sums of successively fewer exponents
virtual bool first_smaller(const Monomial &t, const Monomial &u) const override
returns true iff by sums of successively fewer exponents
const NVAR_TYPE number_of_gradings
length of gradings
DEG_TYPE * gradings
array of partial weighted sums of exponents
void set_ordering_degree(DEG_TYPE d)
sets the ordering degree for this Monomial
Grevlex_Ordering(NVAR_TYPE number_of_variables)
creates a grevlex ordering specific to the specified number of variables
DEG_TYPE compute_ith_weight(const Monomial &t, NVAR_TYPE i) const