18#define sizeofgbvector(s, len) \
19 (sizeof(*s) - sizeof(s->monom) + (len) * sizeof(s->monom[0]))
30 void *
p =
mem->new_elem();
78 const Z_mod *Kp =
K->cast_to_Z_mod();
108 int monlen =
M->monomial_size();
114 t->
comp =
s->comp + comp;
115 t->
coeff =
K->mult(u,
s->coeff);
118 inresult = inresult->
next;
120 inresult->
next =
nullptr;
137 for (
int v = 0; v <
_skew.n_skew_vars(); v++)
139 exp[
_skew.skew_variable(v)]++;
142 exp[
_skew.skew_variable(v)]--;
167 M->to_expvector(m, EXP1);
172 int sign =
_skew.mult_sign(EXP1, EXP2);
173 if (sign == 0)
continue;
177 t->
comp =
s->comp + comp;
178 t->
coeff =
K->mult(c,
s->coeff);
179 if (sign < 0)
K->negate_to(t->
coeff);
181 M->mult(m,
s->monom, t->
monom);
183 inresult = inresult->
next;
185 inresult->
next =
nullptr;
224 return weyl->gbvector_mult_by_term(
result, f, u, monom, comp);
235 return weyl->gbvector_mult_by_term(
result, f, u, monom, comp);
270#warning "implement GBRingSolvable::mult_by_term"
357 M->from_expvector(exp, v->
monom);
382 if (b ==
nullptr)
return true;
385 if (b ==
nullptr)
return false;
386 if (a->
comp != b->
comp)
return false;
387 if (!
K->is_equal(a->
coeff, b->
coeff))
return false;
388 if (
M->compare(a->
monom, b->
monom) != 0)
return false;
407 result_degree =
M->degree_monoid()->make_one();
408 M->multi_degree(MONOM1, result_degree);
409 M->degree_monoid()->mult(
410 result_degree, F->
degree(f->
comp - 1), result_degree);
425 f->monom, f->comp - 1, g->monom, g->comp - 1);
433 cmp =
M->compare(f->monom, -f->comp, g->monom, -g->comp);
435 cmp =
M->compare(f->monom, f->comp, g->monom, g->comp);
450#warning "Schreyer order question"
452 if (v ==
nullptr)
return nullptr;
459 int nslots =
M->n_slots(nparts);
464 if (
M->compare(nslots, t->monom, v->
monom) != 0)
break;
480 for (i = 0; i < nvars; i++)
484 if (w->array[i] != 0)
return false;
487 for (j = i + 1; j < nvars; j++)
490 if (a * w->array[j] != b * w->array[i])
return false;
501 if (v ==
nullptr)
return nullptr;
511 M->to_expvector(leadv->
monom, lead);
517 M->to_expvector(t->monom, e);
551 M->to_expvector(MONOM1,
result);
559 for (; f !=
nullptr; f = f->
next)
K->mult_to(f->
coeff, u);
564 for (; f !=
nullptr; f = f->
next)
K->negate_to(f->
coeff);
594 if (g ==
nullptr)
return;
606 if (compare_result ==
LT)
618 else if (compare_result ==
GT)
638 zzp->init(result_coeff);
670 if (g ==
nullptr)
return;
723 if (
K->is_zero(tmf->
coeff))
756 if (f ==
nullptr || f->
next ==
nullptr)
return;
766 if (f ==
nullptr)
break;
793 bool p_parens =
false;
796 for (t = v; t !=
nullptr && count != 0; t = t->
next, count--)
798 int isone = (
M ==
nullptr ||
M->is_one(t->
monom));
799 K->elem_text_out(o, t->
coeff, p_one, p_plus, p_parens);
800 if (!isone)
M->elem_text_out(o, t->
monom, p_one);
801 if (t->
comp >= 1) o <<
"<" << t->
comp <<
">";
804 if (t !=
nullptr) o <<
"+...";
811 for (
int i = 0; i <
_nvars; i++) *
result++ = *exp1++ - *exp2++;
819 for (
int i = 0; i <
_nvars; i++)
821 int a = exp1[i] - exp2[i];
880 K->syzygy(a, b, u, v);
890 if (
_skew.mult_sign(EXP3, EXP2) < 0)
K->negate_to(v);
904 rem =
globalZZ->remainderAndQuotient(a, b, v);
905 if (
globalZZ->is_zero(v))
return false;
916 if (
_skew.mult_sign(EXP3, EXP2) < 0)
K->negate_to(v);
962 if (!
K->is_equal(u,
_one))
967 if (use_denom)
K->mult_to(denom, u);
998 if (!
K->is_equal(u,
_one))
1003 if (use_denom)
K->mult_to(denom, u);
1008 if (gsyz !=
nullptr)
1042 if (
K->is_zero(v))
return false;
1048 if (gsyz !=
nullptr)
1085 K->syzygy(a, b, u, v);
1096 if (
_skew.mult_sign(EXP3, EXP1) !=
_skew.mult_sign(EXP4, EXP2))
1099 M->from_expvector(EXP3, MONOM1);
1100 M->from_expvector(EXP4, MONOM2);
1104 if (fsyz ==
nullptr && gsyz ==
nullptr)
1105 result_syz =
nullptr;
1138 if (mpz_sgn(v) != 0)
1143 if (mpz_sgn(u) != 0)
1216 result_syz =
nullptr;
1231 if (
_skew.mult_sign(EXP3, EXP1) !=
_skew.mult_sign(EXP4, EXP2))
1234 M->from_expvector(EXP3, MONOM1);
1235 M->from_expvector(EXP4, MONOM2);
1239 if (fsyz ==
nullptr && gsyz ==
nullptr)
1240 result_syz =
nullptr;
1268 for (; gsyz !=
nullptr; gsyz = gsyz->
next)
1295 for (; f !=
nullptr; f = f->
next)
1307 if (f ==
nullptr)
return;
1308 for (; f !=
nullptr; f = f->next)
1310 mpz_gcd(content, content, f->coeff.get_mpz());
1334 else if (gsyz !=
nullptr)
1346 mpz_abs(content, content);
1359 if (leadsign < 0) mpz_neg(content, content);
1388 else if (fsyz !=
nullptr)
1392 cinv =
K->invert(c);
1395 if (use_denom)
K->mult_to(denom, c);
1415 while (f !=
nullptr)
1444 if (!
K->is_equal(u,
_one))
1458 o <<
"auto reducing by ";
1460 o <<
"\n -- giving ";
1494 o <<
"auto reducing by ";
1496 o <<
"\n -- giving ";
1510 K(GR0->get_flattened_coefficients()),
1529 if (
heap[i] !=
nullptr)
GR->gbvector_mult_by_coeff_to(
heap[i], a);
1535 int len =
GR->gbvector_n_terms(
p);
1538 GR->gbvector_add_to(
F,
heap[i],
p);
1539 len =
GR->gbvector_n_terms(
heap[i]);
1545 len =
GR->gbvector_n_terms(
heap[i]);
1546 heap[i - 1] =
nullptr;
1553 int lead_so_far = -1;
1556 if (
heap[i] ==
nullptr)
continue;
1557 if (lead_so_far < 0)
1562 int cmp =
GR->gbvector_compare(
F,
heap[lead_so_far],
heap[i]);
1563 if (cmp ==
GT)
continue;
1570 K->add_to(
heap[lead_so_far]->coeff,
heap[i]->coeff);
1573 tmp->
next =
nullptr;
1574 GR->gbvector_remove(tmp);
1576 if (
K->is_zero(
heap[lead_so_far]->coeff))
1579 tmp =
heap[lead_so_far];
1581 tmp->
next =
nullptr;
1582 GR->gbvector_remove(tmp);
1587 mLead = lead_so_far;
1588 if (lead_so_far < 0)
return nullptr;
1595 if (
mLead < 0)
return nullptr;
1608 if (
heap[i] ==
nullptr)
continue;
1621 if (
heap[i] ==
nullptr)
continue;
1633 if (
heap[i] ==
nullptr)
continue;
1662 if (!
K->is_equal(u,
_one))
1671 if (gsyz !=
nullptr)
1674 fsyz.
add(result_syz1);
1690 F, Fsyz, fcurrent_lead, exp, flead, f, fsyz, g, g, gsyz);
exponents::ConstExponents const_exponents
exponents::Exponents exponents_t
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
int mask_mpz_cmp_si(mpz_srcptr x, long int i)
Legacy RingZZ — a Ring-derived integer ring backed by GMP mpz_t.
Legacy Z_mod — a Ring-derived Z/p with log / exp tables.
ConcreteRing<RingType> — the templated bridge between aring and the legacy Ring API.
static void mult(int nvars, ConstExponents a, ConstExponents b, Exponents result)
const_monomial degree(int i) const
const SchreyerOrder * get_schreyer_order() const
Engine-side free module R^n over a Ring.
void gbvector_mult_by_coeff_to(gbvector *f, ring_elem u)
static GBRing * create_WeylAlgebra(const Ring *K0, const Monoid *M0, const WeylAlgebra *W0)
void exponents_delete(exponents_t e)
gbvector * gbvector_copy(const gbvector *f)
static GBRing * create_SkewPolynomialRing(const Ring *K0, const Monoid *M0, SkewMultiplication skew0)
gbvector * mult_by_term(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
bool gbvector_reduce_lead_term_ZZ(const FreeModule *F, const FreeModule *Fsyz, gbvector *&f, gbvector *&fsyz, const gbvector *g, const gbvector *gsyz)
void gbvector_remove(gbvector *f)
static GBRing * create_PolynomialRing(const Ring *K, const Monoid *M)
void gbvector_remove_content_ZZ(gbvector *f, gbvector *fsyz, bool use_denom, ring_elem &denom) const
bool is_skew_commutative() const
void gbvector_get_lead_monomial(const FreeModule *F, const gbvector *f, int *result)
void gbvector_add_to_zzp(const FreeModule *F, gbvector *&f, gbvector *&g)
bool gbvector_is_equal(const gbvector *f, const gbvector *g) const
void gbvector_text_out(buffer &o, const FreeModule *F, const gbvector *f, int nterms=-1) const
GBRing(const Ring *K0, const Monoid *M0)
void divide_exponents(const int *exp1, const int *exp2, int *result) const
const SolvableAlgebra * solvable
void gbvector_cancel_lead_terms(const FreeModule *F, const FreeModule *Fsyz, const gbvector *f, const gbvector *fsyz, const gbvector *g, const gbvector *gsyz, gbvector *&result, gbvector *&result_syz)
gbvector * gbvector_parallel_lead_terms(M2_arrayint w, const FreeModule *F, const gbvector *leadv, const gbvector *v)
void reduce_marked_lead_term_heap(const FreeModule *F, const FreeModule *Fsyz, const gbvector *fcurrent_lead, const_exponents exp, gbvector *flead, gbvectorHeap &f, gbvectorHeap &fsyz, const gbvector *marked_in_g, const gbvector *g, const gbvector *gsyz)
void gbvector_mult_by_term(const FreeModule *F, const FreeModule *Fsyz, ring_elem a, const int *m, const gbvector *f, const gbvector *fsyz, gbvector *&result, gbvector *&esult_syz)
gbvector * gbvector_term(const FreeModule *F, ring_elem coeff, int comp)
gbvector * gbvector_raw_term(ring_elem coeff, const int *monom, int comp)
void find_reduction_monomial(const FreeModule *F, const gbvector *f, const gbvector *g, int &comp, int *&monom)
void reduce_lead_term_heap(const FreeModule *F, const FreeModule *Fsyz, const gbvector *fcurrent_lead, const_exponents exp, gbvector *flead, gbvectorHeap &f, gbvectorHeap &fsyz, const gbvector *g, const gbvector *gsyz)
void gbvector_replace_2by2_ZZ(const FreeModule *F, const FreeModule *Fsyz, gbvector *&f, gbvector *&fsyz, gbvector *&g, gbvector *&gsyz)
void gbvector_remove_content(gbvector *f, gbvector *fsyz, bool use_denom, ring_elem &denom)
void find_reduction_coeffs(const FreeModule *F, const gbvector *f, const gbvector *g, ring_elem &u, ring_elem &v)
void gbvector_combine_lead_terms_ZZ(const FreeModule *F, const FreeModule *Fsyz, const gbvector *f, const gbvector *fsyz, const gbvector *g, const gbvector *gsyz, gbvector *&result, gbvector *&result_syz)
gbvector * new_raw_term()
gbvector * gbvector_lead_term(int n, const FreeModule *F, const gbvector *f)
void gbvector_reduce_with_marked_lead_term(const FreeModule *F, const FreeModule *Fsyz, gbvector *flead, gbvector *&f, gbvector *&fsyz, const gbvector *ginitial, const gbvector *g, const gbvector *gsyz, bool use_denom, ring_elem &denom)
void lower_content_ZZ(gbvector *f, mpz_ptr content) const
void gbvector_negate_to(gbvector *f) const
int gbvector_compare(const FreeModule *F, const gbvector *f, const gbvector *g) const
static GBRing * create_SolvableAlgebra(const Ring *K0, const Monoid *M0, const SolvableAlgebra *R)
void gbvector_add_to(const FreeModule *F, gbvector *&f, gbvector *&g)
void gbvector_auto_reduce(const FreeModule *F, const FreeModule *Fsyz, gbvector *&f, gbvector *&fsyz, const gbvector *g, const gbvector *gsyz)
const gbvector * find_coeff(const FreeModule *F, const gbvector *f, const gbvector *g) const
gbvector * gbvector_copy_term(const gbvector *t)
void gbvector_sort(const FreeModule *F, gbvector *&f)
void gbvector_apply(const FreeModule *F, const FreeModule *Fsyz, gbvector *&f, gbvector *&fsyz, const gbvector *gsyz, const gbvector **elems, const gbvector **elems_syz, const gbvector **quotients)
void gbvector_multidegree(const FreeModule *F, const gbvector *f, int *&result_degree)
void gbvector_auto_reduce_ZZ(const FreeModule *F, const FreeModule *Fsyz, gbvector *&f, gbvector *&fsyz, const gbvector *g, const gbvector *gsyz)
void gbvector_remove_term(gbvector *f)
void gbvector_get_lead_exponents(const FreeModule *F, const gbvector *f, int *result)
void exponent_syzygy(const int *exp1, const int *exp2, int *exp3, int *exp4)
exponents_t exponents_make()
gbvector * gbvector_term_exponents(const FreeModule *F, ring_elem coeff, const int *exp, int comp)
void divide_coeff_exact_to_ZZ(gbvector *f, gmp_ZZ u) const
int gbvector_n_terms(const gbvector *f) const
bool find_reduction_coeffs_ZZ(const FreeModule *F, const gbvector *f, const gbvector *g, ring_elem &v)
void gbvector_reduce_lead_term(const FreeModule *F, const FreeModule *Fsyz, gbvector *flead, gbvector *&f, gbvector *&fsyz, const gbvector *g, const gbvector *gsyz, bool use_denom, ring_elem &denom)
int *const * _skew_monoms
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)=0
gbvector * gbvector_mult_by_coeff(const gbvector *f, ring_elem u)
Polynomial-ring view tuned for the inner loop of classical Buchberger Groebner-basis computations.
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
GBRing specialisation for ordinary commutative polynomial rings.
GBRingSkew(const Ring *K0, const Monoid *M0, SkewMultiplication skew0)
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
GBRing specialisation for skew-commutative (exterior-like) polynomial rings.
GBRingSolvable(const Ring *K0, const Monoid *M0, const SolvableAlgebra *R0)
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
virtual ~GBRingSolvable()
GBRing specialisation for solvable polynomial algebras (PBW-style non-commutative rings whose relatio...
GBRingWeyl(const Ring *K0, const Monoid *M0, const WeylAlgebra *R0)
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
GBRing specialisation for Weyl algebras over a field.
GBRingWeylZZ(const Ring *K0, const Monoid *M0, const WeylAlgebra *R0)
virtual gbvector * mult_by_term1(const FreeModule *F, const gbvector *f, ring_elem u, const int *monom, int comp)
GBRingWeyl specialisation for Weyl algebras over ZZ.
monomial make_one() const
void from_expvector(const_exponents exp, monomial result) const
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
int schreyer_compare_encoded(const_monomial m, int m_comp, const_monomial n, int n_comp) const
int schreyer_compare(const_monomial m, int m_comp, const_monomial n, int n_comp) const
void schreyer_up(const_monomial m, int comp, monomial result) const
void schreyer_down(const_monomial m, int comp, monomial result) const
Per-component tie-breaker data for a Schreyer monomial order on a FreeModule.
Sign-rule helper used by every ring that has a skew-commutative subset of variables (exterior factor,...
PolyRing subclass for solvable polynomial algebras (PBW-type non-commutative rings where each pair of...
CoefficientRingZZp * get_CoeffRing() const
Engine-side Z/p ring for small primes (p < 32767), using a discrete-log (Zech) representation.
gbvector * heap[GEOHEAP_SIZE]
gbvector * remove_lead_term()
gbvector * current_value() const
gbvectorHeap(GBRing *GR, const FreeModule *F)
const gbvector * get_lead_term()
void mult_by_coeff(ring_elem a)
Two SimpleARing-style coefficient adapters: CoefficientRingZZp and CoefficientRingR.
void dgbvec(const GBRing *R, gbvector *v)
Debugger-callable d* helpers that pretty-print engine values to stderr.
const int heap_size[GEOHEAP_SIZE]
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
#define sizeofgbvector(s, len)
static bool isparallel(M2_arrayint w, int *e, int *f)
GBRing and gbvector — the GB-tuned polynomial-ring view used by classical Buchberger code.
VALGRIND_MAKE_MEM_DEFINED & result(result)
stash and doubling_stash — legacy size-class allocator interfaces, now stubbed to plain GC allocation...
#define MONOMIAL_BYTE_SIZE(mon_size)
#define ALLOCATE_EXPONENTS(byte_len)
#define EXPONENT_BYTE_SIZE(nvars)
#define ALLOCATE_MONOMIAL(byte_len)
#define newarray_atomic_clear(T, len)
#define newarray_atomic(T, len)
Ring — the legacy abstract base class for every coefficient and polynomial ring.
SchreyerOrder — per-basis-element data backing the Schreyer order on a free module.
void emit_line(const char *s)
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.
mpz_srcptr get_mpz() const
WeylAlgebra — ring of polynomial differential operators with [d_i, x_i] = 1.