21 for (
int i = 0; i < nvars; i++)
23 if (a[i] < b[i])
return false;
24 if (a[i] > b[i])
return true;
33 for (
int i = 0; i < nvars; i++) fprintf(fil,
"%d ", exp[i]);
41 for (i = 0, j = 0; i < nvars; i++, j++)
43 if (j == 8 *
sizeof(
long)) j = 0;
44 if (exp[i] > 0)
result |= (1 << j);
71 result->_head.push_back(
nullptr);
84int MonomialTableZZ::find_divisors(
int max,
88 VECTOR(
int) *result_term_divisors,
89 VECTOR(
int) *result_mon_divisors)
const,
96 if (comp >=
static_cast<int>(_head.size()))
return 0;
97 mon_term *head = _head[comp];
104 for (t = head->_next; t != head; t = t->_next)
105 if ((expmask & t->_mask) == 0)
108 for (i=0; i<_nvars; i++)
109 if (exp[i] < t->_lead[i])
116 if (mpz_divisible_p(coeff, t->_coeff))
119 if (result_term_divisors != 0) result_term_divisors->push_back(t->_val);
121 else if (result_mon_divisors != 0) result_mon_divisors->push_back(t->_val);
124 if (is_div && mpz_divisible_p(coeff,t->_coeff))
128 if (
max >= 0 && nmatches >=
max)
break;
134 o <<
"find_term_divisors called on ";
135 show_mon_term(o, coeff, exp, comp);
136 o <<
" #matches=" << nmatches <<
newline;
138 for (
int i=0; i<
result->size(); i++)
139 show_mon_term(stderr, (*
result)[i]);
156 if (comp >=
static_cast<int>(_head.size()))
return 0;
163 for (t = head->
_next; t != head; t = t->
_next)
164 if ((expmask & t->
_mask) == 0)
167 for (
int i = 0; i <
_nvars; i++)
168 if (exp[i] < t->
_lead[i])
173 if (is_div && mpz_divisible_p(coeff, t->
_coeff))
177 if (
max >= 0 && nmatches >=
max)
break;
183 o <<
"find_term_divisors called on ";
185 o <<
" #matches=" << nmatches <<
newline;
205 if (comp >=
static_cast<int>(_head.size()))
return 0;
212 bool g_is_set =
false;
213 for (t = head->
_next; t != head; t = t->
_next)
214 if ((expmask & t->
_mask) == 0)
217 for (i = 0; i <
_nvars; i++)
218 if (exp[i] < t->
_lead[i])
223 if (!is_div)
continue;
226 mpz_init_set(g, t->
_coeff);
232 if (mpz_divisible_p(c, g))
238 if (g_is_set) mpz_clear(g);
250 if (comp >=
static_cast<int>(_head.size()))
return -1;
254 int smallest_val = -1;
255 mpz_srcptr smallest =
nullptr;
259 for (t = head->
_next; t != head; t = t->
_next)
260 if ((expmask & t->
_mask) == 0)
263 for (
int i = 0; i <
_nvars; i++)
264 if (exp[i] < t->
_lead[i])
271 if (smallest_val < 0 || (mpz_cmpabs(smallest, t->
_coeff) > 0))
273 smallest_val = t->
_val;
287 if (comp >=
static_cast<int>(_head.size()))
return 0;
294 for (t = head->
_next; t != head; t = t->
_next)
295 if ((expmask & t->
_mask) == 0)
298 for (
int i = 0; i <
_nvars; i++)
299 if (exp[i] < t->
_lead[i])
308 if (
max >= 0 && nmatches >=
max)
break;
315 o <<
"find_monomial_divisors called on ";
317 o <<
" #matches=" << nmatches <<
newline;
329 if (comp >=
static_cast<int>(_head.size()))
return nullptr;
336 for (t = head->
_next; t != head; t = t->
_next)
337 if (expmask == t->
_mask)
340 for (i = 0; i <
_nvars; i++)
341 if (exp[i] != t->
_lead[i])
346 if (is_eq && !mpz_cmp(coeff, t->
_coeff))
return t;
356 if (comp >=
static_cast<int>(_head.size()))
return nullptr;
366 for (t = head->
_next; t != head; t = t->
_next)
368 if (t->
_val < first_val)
continue;
369 if (expmask == t->
_mask)
372 for (i = 0; i <
_nvars; i++)
373 if (exp[i] != t->
_lead[i])
387 printf(
"number of exact matches: %d\n", neqs);
393 mpz_srcptr new_coeff,
409 for (
int i =
INTSIZE(_head); i <= comp; i++)
418 newterm->
_lead = exp;
425 for (t = head; t->
_next != head; t = t->
_next)
452 const VECTOR(mpz_srcptr) & coeffs0,
454 const VECTOR(
int) & comps0)
455 :
nvars(nvars0), coeffs(coeffs0), exps(exps0), comps(comps0)
463 for (
int i = 0; i <
nvars; i++)
466 else if (xx[i] > yy[i])
468 if (comps[
x] < comps[y])
470 else if (comps[
x] > comps[y])
474 return (mpz_cmp(coeffs[
x], coeffs[y]) < 0);
503 fprintf(fil,
" elem coeff=");
504 mpz_out_str(fil, 10, coeff);
505 fprintf(fil,
" exp=");
507 fprintf(fil,
" comp=");
508 fprintf(fil,
"%d", comp);
509 fprintf(fil,
" val=");
510 fprintf(fil,
"%d\n", val);
514 const VECTOR(mpz_srcptr) & coeffs,
516 const VECTOR(
int) & comps,
517 VECTOR(
int) & result_positions,
518 bool use_stable_sort)
534 if (coeffs.size() != exps.size())
535 fprintf(stderr,
"size mismatch\n");
536 if (coeffs.size() != exps.size())
537 fprintf(stderr,
"size mismatch2\n");
538 if (coeffs.size() != comps.size())
539 fprintf(stderr,
"size mismatch3\n");
543 fprintf(stderr,
"-------------\n");
544 fprintf(stderr,
"find_weak_generators %ld\n", coeffs.size());
545 for (
size_t i = 0; i < coeffs.size(); i++)
546 T->show_weak(stderr, coeffs[i], exps[i], comps[i], i);
550 positions.reserve(exps.size());
551 for (
unsigned int i = 0; i < exps.size(); i++) positions.push_back(i);
557 std::stable_sort(positions.begin(),
561 std::sort(positions.begin(),
567 fprintf(stderr,
"sorted find_weak_generators\n");
568 for (
size_t i = 0; i < coeffs.size(); i++)
569 T->show_weak(stderr, coeffs[i], exps[i], comps[i], positions[i]);
579 for (
VECTOR(
int)::iterator j = positions.begin(); j != positions.end(); j++)
580 if (!
T->is_weak_member(coeffs[*j], exps[*j], comps[*j]))
582 result_positions.push_back(*j);
583 T->insert(coeffs[*j], exps[*j], comps[*j], *j);
588 fprintf(stderr,
"ones we take: find_weak_generators %ld\n", coeffs.size());
589 for (
size_t i = 0; i < result_positions.size(); i++)
591 coeffs[result_positions[i]],
592 exps[result_positions[i]],
593 comps[result_positions[i]],
594 result_positions[i]);
595 fprintf(stderr,
"\n\n");
602 const VECTOR(mpz_srcptr) & coeffs,
604 const VECTOR(
int) & comps,
605 VECTOR(
int) & result_positions)
611 positions.reserve(exps.size());
612 for (
unsigned int i = 0; i < exps.size(); i++) positions.push_back(i);
617 std::stable_sort(positions.begin(),
629 for (
VECTOR(
int)::iterator j = positions.begin(); j != positions.end(); j++)
630 if (!
T->is_strong_member(coeffs[*j], exps[*j], comps[*j]))
632 result_positions.push_back(*j);
633 T->insert(coeffs[*j], exps[*j], comps[*j], *j);
643 fprintf(fil,
"%s", o.
str());
656 if (coeff !=
nullptr)
659 mpz_get_str(
s, 10, coeff);
667 for (
int i = 1; i <
_nvars; i++) o <<
"," << lead[i];
669 o <<
"] (" << comp <<
")" <<
newline;
677 "monomial table: %d vars, %d components, %d elements\n",
679 static_cast<int>(_head.size()),
681 for (
unsigned i = 1; i < _head.size(); i++)
683 head = this->_head[i];
684 if (head->
_next == head)
continue;
685 fprintf(fil,
" -- component %d --\n", i);
686 for (t = head->
_next; t != head; t = t->
_next)
exponents::Exponents exponents_t
bool is_strong_member(mpz_srcptr c, exponents_t exp, int comp) const
mon_term * find_exact_monomial(exponents_t exp, int comp, int first_val) const
static mon_term * make_list_head()
void insert(mpz_srcptr coeff, exponents_t exp, int comp, int id)
static MonomialTableZZ * make(int nvars)
void show_mon_term(FILE *fil, mon_term *t) const
void change_coefficient(mon_term *t, mpz_srcptr new_coeff, int new_id)
bool is_weak_member(mpz_srcptr c, exponents_t exp, int comp) const
static void find_strong_generators(int nvars, const VECTOR(mpz_srcptr) &coeffs, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, VECTOR(int) &result_positions)
void show(FILE *fil) const
int find_smallest_coeff_divisor(exponents_t exp, int comp) const
int find_monomial_divisors(int max, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr) const
static void find_weak_generators(int nvars, const VECTOR(mpz_srcptr) &coeffs, const VECTOR(exponents_t) &exps, const VECTOR(int) &comps, VECTOR(int) &result_positions, bool use_stable_sort=true)
mon_term * find_exact(mpz_srcptr coeff, exponents_t exp, int comp) const
void show_weak(FILE *fil, mpz_srcptr coeff, exponents_t exp, int comp, int val) const
int find_term_divisors(int max, mpz_srcptr coeff, exponents_t exp, int comp, VECTOR(mon_term *) *result=nullptr) const
MonomialTable analogue for monomials carrying a ZZ coefficient.
VALGRIND_MAKE_MEM_DEFINED & result(result)
static void exponents_show(FILE *fil, exponents_t exp, int nvars)
static unsigned long monomial_mask(int nvars, exponents_t exp)
static bool exponents_greater(int nvars, exponents_t a, exponents_t b)
static void exponents_show(FILE *fil, exponents_t exp, int nvars)
MonomialTableZZ — coefficient-aware leading-monomial index for ZZ-coefficient Groebner bases.
MonomialTable::mon_term plus an _coeff slot pointing at the entry's leading ZZ coefficient (or nullpt...
const VECTOR(mpz_srcptr) &coeffs
bool operator()(int x, int y)
montable_sorter_ZZ(int nvars0, const VECTOR(mpz_srcptr) &coeffs0, const VECTOR(exponents_t) &exps0, const VECTOR(int) &comps0)
const VECTOR(exponents_t) &exps