Macaulay2 Engine
Loading...
Searching...
No Matches
hilb-fcn.cpp
Go to the documentation of this file.
1/* Copyright 2010-2021, Michael E. Stillman */
2
3#include "hilb-fcn.hpp"
4
5#include "error.h" // for error
6#include "freemod.hpp" // for FreeModule
7#include "hilb.hpp" // for hilb_comp
8#include "matrix-con.hpp" // for MatrixConstructor
9#include "monoid.hpp" // for Monoid, monomial
10#include "polyring.hpp" // for PolynomialRing
11#include "relem.hpp" // for RingElement
12#include "ring.hpp" // for Ring
13#include "style.hpp" // for INTSIZE
14
15#include <cstdio> // for fprintf, stderr
16#include <vector> // for vector
17
18class Matrix;
19
21 const RingElement *hf)
22 : F(F0),
23 leadterms(nullptr), // set later
24 hilb_new_elems(true),
25 hilb_n_in_degree(0), // will be really set later
26 hf_orig(hf),
27 hf_diff(nullptr) // will be set later
28{
29 // TODO: check and write
30 R = F->get_ring()->cast_to_PolynomialRing();
31}
32
34{
35 // TODO: check and write
36 delete leadterms;
37 F = nullptr;
38 hf_orig = nullptr;
39 hf_diff = nullptr;
40}
41
42bool HilbertController::setDegree(int this_degree)
43{
44 // Recomputes Hilbert function, returns #elems expected in degree this_degree
45 // There should be NO elements expected in lower degrees than that.
46 // false is returned if either the computation was interrupted, or
47 // it was determined that the Hilbert function could not be correct
48 // (by expecting a negative number of elements).
49 if (!recomputeHilbertFunction()) return false;
51 if (error()) return false;
52 return true;
53}
54
55bool HilbertController::addMonomial(int *a, int comp)
56// return true if that was the last one expected
57{
58 monomial m = R->getMonoid()->make_one();
59 R->getMonoid()->from_expvector(a, m);
60 ring_elem r = R->make_flat_term(R->getCoefficientRing()->one(), m);
61 vec v = R->make_vec(comp - 1, r);
62 elems.push_back(v);
63 hilb_new_elems = true;
65 return hilb_n_in_degree == 0;
66}
67
69{
71 {
72 // Recompute h, hf_diff
75 if (h == nullptr) return false; // computation was interrupted
76 hf_diff = (*h) - (*hf_orig);
77 hilb_new_elems = false;
78 }
79 return true;
80}
81
83{
84 MatrixConstructor mat(F, INTSIZE(elems));
85 for (int i = 0; i < elems.size(); i++) mat.set_column(i, elems[i]);
86 return mat.to_matrix();
87}
88
89// Local Variables:
90// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
91// indent-tabs-mode: nil
92// End:
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
const PolynomialRing * R
Definition hilb-fcn.hpp:80
const RingElement * hf_orig
Definition hilb-fcn.hpp:89
bool addMonomial(int *a, int comp)
Definition hilb-fcn.cpp:55
RingElement * hf_diff
Definition hilb-fcn.hpp:91
HilbertController(const FreeModule *F0, const RingElement *hf)
Definition hilb-fcn.cpp:20
const FreeModule * F
Definition hilb-fcn.hpp:81
bool recomputeHilbertFunction()
Definition hilb-fcn.cpp:68
MatrixConstructor * leadterms
Definition hilb-fcn.hpp:82
bool setDegree(int this_degree)
Definition hilb-fcn.cpp:42
Matrix * make_lead_term_matrix()
Definition hilb-fcn.cpp:82
Matrix * to_matrix()
void set_column(int c, vec v)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
static int coeff_of(const RingElement *h, int deg)
Definition hilb.cpp:704
static RingElement * hilbertNumerator(const Matrix *M)
Definition hilb.cpp:665
int error()
Definition error.c:48
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
#define Matrix
Definition factory.cpp:14
FreeModule — finite-rank free module R^n, the type-level anchor for every Matrix.
#define monomial
Definition gb-toric.cpp:11
HilbertController — early-exit driver for F4 given a known Hilbert series.
Hilbert-series numerator via the Bigatti-Caboara-Robbiano recursion.
MatrixConstructor — the mutable builder that produces an immutable Matrix.
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
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.
#define INTSIZE(a)
Definition style.hpp:37
Engine-wide stylistic constants: LT / EQ / GT codes, INTSIZE, GEOHEAP_SIZE.