32 while (
dad[i] >= 0) i =
dad[i];
49 while (
dad[i] >= 0) i =
dad[i];
50 while (
dad[j] >= 0) j =
dad[j];
88 for (; i.
valid(); ++i)
104 for (
int i = 0; i < nvars; i++)
115 for (
int i = 0; i < nvars; i++)
142 for (k = 0; k <
n_vars; k++)
145 dad[k] = this_label--;
155 int first =
result.size();
156 for (k = 0; k <
n_sets; k++)
165 result[first + loc]->insert_minimal(b);
171#define MAX_EXP (1 << (8 * sizeof(int) - 2))
185 int nvars = I.
topvar() + 1;
186 for (k = 0; k < nvars; k++) pure[k] = -1;
190 for (k = 0; k < nvars; k++) hits[k] = 0;
191 for (k = 0; k < nvars; k++) minnonzero[k] =
MAX_EXP;
193 non_pure_power =
nullptr;
206 for (; j.
valid(); ++j)
210 if (minnonzero[v] > e) minnonzero[v] = e;
221 else if (pure[v] > e)
227 for (k = 1; k < nvars; k++)
228 if (hits[k] > hits[popular]) popular = k;
229 nhits = hits[popular];
230 exp_of_popular = minnonzero[popular];
249 int v =
popular_var(I, npure, pure, nhits, vp, exp_of_v);
257 if (npure >= I.
size() - 1)
278 sum->insert_minimal(bmin);
287 sum->insert_minimal(
new Bag(0, a.monom()));
293 std::vector<std::pair<int, int>> degs_and_indices;
295 for (
auto& b : elems)
298 degs_and_indices.push_back(std::make_pair(deg, count));
301 std::stable_sort(degs_and_indices.begin(), degs_and_indices.end());
303 for (
auto p : degs_and_indices)
305 Bag* b = elems[
p.second];
344 :
S(m->get_ring()->cast_to_PolynomialRing()),
347 D(
S->degree_monoid()),
355 assert(
D ==
R->getMonoid());
356 one =
R->getCoefficientRing()->from_long(1);
357 minus_one =
R->getCoefficientRing()->from_long(-1);
372 :
S(I->get_ring()->cast_to_PolynomialRing()),
375 D(
S->degree_monoid()),
383 assert(
D ==
R->getMonoid());
384 one =
R->getCoefficientRing()->from_long(1);
385 minus_one =
R->getCoefficientRing()->from_long(-1);
411 for (
int i = 0; i <
p->monids.size(); i++)
delete p->monids[i];
416 R->getCoefficientRing()->remove(
one);
428 int calc_nsteps =
nsteps + n_steps;
429 while (calc_nsteps-- > 0)
568 if (pure[i.var()] != -1)
571 D->power(
M->degree_of_var(i.var()), pure[i.var()],
LOCAL_deg1);
578 D->power(
M->degree_of_var(i.var()),
579 pure[i.var()] - i.exponent(),
586 R->subtract_to(F,
G);
611 ERROR(
"Hilbert function computation not complete");
621 o <<
"--- Hilbert Function Statistics---------------------" <<
newline;
632 o <<
"----- depth " << d <<
" -------------" <<
newline;
633 o <<
" " <<
p->monids.size() <<
" monomial ideals total" <<
newline;
634 o <<
" " <<
p->i <<
" = current location" <<
newline;
635 o <<
" " <<
p->first_sum + 1 <<
" sum monomial ideals" <<
newline;
637 R->elem_text_out(o,
p->h0);
640 R->elem_text_out(o,
p->h1);
642 for (
int i = 0; i <
p->monids.size(); i++)
644 o <<
" ---- monomial ideal ---------------" <<
newline;
646 p->monids[i]->text_out(o);
672 if (P ==
nullptr)
return nullptr;
674 int retval = hf->
calc(-1);
683 const Matrix *Fmatrix = Matrix::make(F, 0,
nullptr);
695 if (P ==
nullptr)
return nullptr;
697 int retval = hf->
calc(-1);
719 ERROR(
"incorrect Hilbert function given");
722 "internal error: incorrect Hilbert function given, aborting\n");
725 "exp[0]: %d deg: %d\n", exp[0], deg);
728 else if (exp[0] == deg)
730 std::pair<bool, long> res =
733 std::abs(res.second) < std::numeric_limits<int>::max());
734 int n =
static_cast<int>(res.second);
varpower::ConstExponents const_varpower
ExponentListIterator< int, true > index_varpower
Variable-length sparse (variable, exponent) encoding of monomials.
exponents::Exponents exponents_t
Dense exponent-vector template [e_0, ..., e_{nvars-1}] for monomial operations.
Append-only GC-backed byte buffer used throughout the engine for text output.
static void lcm(ConstExponents a, ConstExponents b, Vector &result)
static void quotient(ConstExponents a, ConstExponents b, Vector &result)
static Exponent topvar(ConstExponents a)
static Exponent simple_degree(ConstExponents m)
static void copy(ConstExponents vp, Vector &result)
static bool divides(ConstExponents a, ConstExponents b)
static void var(Exponent v, Exponent e, Vector &result)
Engine-side free module R^n over a Ring.
void to_expvector(const_monomial m, exponents_t result_exp) const
int search(const_varpower m, Bag *&b) const
void insert_minimal(Bag *b)
MonomialIdeal * copy() const
const_varpower second_elem() const
const PolynomialRing * get_ring() const
const_varpower first_elem() const
Engine-side monomial ideal: a decision tree of Nmi_nodes storing the (typically minimal) generators b...
Internal tree node of the MonomialIdeal decision tree.
const Ring * getCoefficientRing() const
virtual const Monoid * getMonoid() const
Abstract base for the engine's polynomial-ring hierarchy.
virtual std::pair< bool, long > coerceToLongInteger(ring_elem a) const
virtual const PolynomialRing * cast_to_PolynomialRing() const
const PolynomialRing * get_degree_ring() const
ring_elem get_value() const
static RingElement * make_raw(const Ring *R, ring_elem f)
const Ring * get_ring() const
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
void do_ideal(MonomialIdeal *I)
ring_elem result_poincare
gc_vector< int > LOCAL_vp
hilb_comp(const PolynomialRing *R, const Matrix *M)
void recurse(MonomialIdeal *&I, const_varpower pivot_vp)
partition_table part_table
static int coeff_of(const RingElement *h, int deg)
static RingElement * hilbertNumerator(const Matrix *M)
gc_vector< int > & monom()
partition_table(int nvars, stash *mi_stash0)
void partition(MonomialIdeal *&I, gc_vector< MonomialIdeal * > &result)
int representative(int x)
int merge_in(int x, int y)
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
static int find_pivot(const MonomialIdeal &I, int &npure, exponents_t pure, gc_vector< int > &m)
static void iquotient_and_sum(MonomialIdeal &I, const_varpower m, MonomialIdeal *", MonomialIdeal *&sum, stash *mi_stash)
static int popular_var(const MonomialIdeal &I, int &npure, exponents_t pure, int &nhits, const_varpower &non_pure_power, int &exp_of_popular)
Hilbert-series numerator via the Bigatti-Caboara-Robbiano recursion.
int_bag / Bag — minimal (payload, varpower monomial) carrier shared by monomial-ideal code.
bool system_interrupted()
system_interrupted() — thread-safe polling predicate for Ctrl+C handling.
VALGRIND_MAKE_MEM_DEFINED & result(result)
Engine-wide GC allocator surface (getmem / getmem_atomic) and debug-allocation trap.
Matrix — the engine's immutable homomorphism F -> G between free modules.
stash and doubling_stash — legacy size-class allocator interfaces, now stubbed to plain GC allocation...
MonomialIdeal — exponent-vector-only representation of an ideal generated by monomials.
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
#define newarray_atomic_clear(T, len)
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
#define newarray_atomic(T, len)
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
Singly linked-list node carrying one term of a polynomial-ring element.