Macaulay2 Engine
Loading...
Searching...
No Matches
hilb.hpp
Go to the documentation of this file.
1// Copyright 1996 Michael E. Stillman
2
3#ifndef _hilb_hh_
4#define _hilb_hh_
5
36
37// Computation of Hilbert functions via Bigatti's (et al) algorithm.
38
39#include "hash.hpp" // for MutableEngineObject
40#include "monoid.hpp" // for Monoid, monomial
41#include "newdelete.hpp" // for gc_vector, our_new_delete
42#include "ringelem.hpp" // for ring_elem
43
44class FreeModule;
45class Matrix;
46class MonomialIdeal;
47class PolynomialRing;
48class RingElement;
49class stash;
50
52// Partition a monomial ideal into several such that
53// the graph of variables occurring in each is connected.
54// Implemented using a union-find algorithm.
55{
56 int n_vars;
57 int n_sets;
60 int *dad;
61 int *occurs;
62
63 int merge_in(int x, int y);
65 int representative(int x);
66
67 stash *mi_stash; // for all of the nodes in all of the monomial ideals
68 public:
69 partition_table(int nvars, stash *mi_stash0);
71 void reset(int nvars);
72 void partition(MonomialIdeal *&I,
73 gc_vector<MonomialIdeal*>& result); // Consumes I.
74};
75
77{
80 int i; // Which monomial ideal is next
81 ring_elem h0; // Hilbert function so far computed 'to the left'
83 int first_sum; // First monomial ideal which corresponds to the 'sum' part
84 gc_vector<MonomialIdeal*> monids; // The (partitioned) array of monomial ideals
85};
86
93{
94 const PolynomialRing *S; // This is the base ring of the monomial ideal
95 const PolynomialRing *R; // This is the output degree ring.
96 const Monoid *M; // S->getMonoid()
97 const Monoid *D; // R->getMonoid() == S->degree_monoid()
98
99 stash *mi_stash; // for all of the nodes in all of the monomial ideals
100
101 // Collected values from the matrix
102 const Matrix *input_mat; // The input matrix
103 ring_elem result_poincare; // The result poincare polynomial from components
104 // 0..this_comp-1
106 int n_components; // If input_mat is not NULL,
107 // this is the number of rows
108
109 // The recursion stack is the following:
111
112 // Statistics
114 int depth;
118
119 // Some useful precomputed values
122
123 // Local variables that are allocated once and for all
124 // extreme care is needed for their use!
125 monomial LOCAL_deg1; // An element of the degree monoid
128
129 int step(); // Returns 0 when done
130 void recurse(MonomialIdeal *&I, const_varpower pivot_vp);
131 void do_ideal(MonomialIdeal *I);
132
133 public:
134 hilb_comp(const PolynomialRing *R, const Matrix *M);
135 hilb_comp(const PolynomialRing *R, const MonomialIdeal *I);
136 ~hilb_comp();
137
138 void reset();
139 void next_monideal();
140 int calc(int nsteps);
141 int is_done() const;
143 void stats() const;
144
145 // static routines
146
147 // If the coefficient in degree 'deg' is < 0, then
148 // set an error, and return 0. The caller MUST check this.
149 static int coeff_of(const RingElement *h, int deg);
150
151#if 0
152// static int hilbertSeries(const Matrix *M, RingElement * &result);
153// // A return of 0 means that the result can be used. A non-zero return
154// // value means that the computation was interrupted, and so control should
155// // return to the user.
156#endif
157
158 static RingElement /* or null */ *hilbertNumerator(const Matrix *M);
159 /* This routine computes the numerator of the Hilbert series
160 for coker leadterms(M), using the degrees of the rows of M.
161 NULL is returned if the ring is not appropriate for
162 computing Hilbert series, or the computation was interrupted. */
163
164 static RingElement *hilbertNumerator(const FreeModule *F);
165
166 static RingElement /* or null */ *hilbertNumerator(const MonomialIdeal *I);
167 /* This routine computes the numerator of the Hilbert series
168 for coker I. NULL is returned if the ring is not appropriate for
169 computing Hilbert series, or the computation was interrupted. */
170};
171
172#if 0
173// class HilbertComputation
174// {
175// ring_elem hilbert(const MonomialIdeal *M);
176//
177// ring_elem hilbert(const MonomialTable *M);
178//
179// RingElement /* or null */ *hilbert(const Matrix *M);
180// // This one is pretty easy: loop through each component,
181// // make a monomial ideal, and compute its Hilbert function,
182// // then multiply it by the degree of that row component.
183//
184//
185// };
186//
187// class hilb_comp : public mutable_object
188// {
189// const PolynomialRing *S; // This is the base ring of the monomial ideal
190// const PolynomialRing *R; // This is the output degree ring.
191// const Monoid *M; // S->getMonoid()
192// const Monoid *D; // R->getMonoid() == S->degree_monoid()
193//
194// // Collected values from the matrix
195// const Matrix *input_mat; // The input matrix
196// ring_elem result_poincare; // The result poincare polynomial from components
197// // 0..this_comp-1
198// int this_comp;
199// int n_components; // If input_mat is not NULL,
200// // this is the number of rows
201//
202// // The recursion stack is the following:
203// hilb_step *current;
204//
205// // Statistics
206// int nsteps;
207// int depth;
208// int maxdepth;
209// int nideal;
210// int nrecurse;
211//
212// // Some useful precomputed values
213// ring_elem one;
214// ring_elem minus_one;
215//
216// // Local variables that are allocated once and for all
217// // extreme care is needed for their use!
218// int *LOCAL_deg1; // An element of the degree monoid
219// gc_vector<int> LOCAL_vp;
220// partition_table part_table;
221//
222// int step(); // Returns 0 when done
223// void recurse(MonomialIdeal * &I, const int *pivot_vp);
224// void do_ideal(MonomialIdeal * I);
225//
226// public:
227// hilb_comp(const PolynomialRing *R, const Matrix * M);
228// ~hilb_comp();
229//
230// void reset();
231// void next_monideal();
232// int calc(int nsteps);
233// int is_done() const;
234// RingElement *value();
235// void stats() const;
236//
237// // static routines
238// static int coeff_of(const RingElement *h, int deg);
239//
240// #if 0
241// // static int hilbertSeries(const Matrix *M, RingElement * &result);
242// // // A return of 0 means that the result can be used. A non-zero return
243// // // value means that the computation was interrupted, and so control should
244// // // return to the user.
245// #endif
246//
247// static RingElement /* or null */ *hilbertNumerator(const Matrix *M);
248// /* This routine computes the numerator of the Hilbert series
249// for coker leadterms(M), using the degrees of the rows of M.
250// NULL is returned if the ring is not appropriate for
251// computing Hilbert series, or the computation was interrupted. */
252//
253//
254// };
255//
256//
257//
258//
259// class HilbertComputation
260// {
261// public:
262// HilbertComputation(const Ring *R,
263// gc_vector<int> &comp,
264// M2_arrayint wts);
265//
266// insert_generator(const int *m, int comp);
267//
268// RingElement /* or null */ * multDegreeHilbert(const FreeModule *F);
269// RingElement /* or null */ * hilbert(gc_vector<int> &comp);
270//
271// // The following routines all use the singly graded degree ring.
272// static RingElement /* or null */ * hilbert(const Ring *R,
273// gc_vector<exponents> &exps,
274// gc_vector<int> &comps,
275// gc_vector<int> &comp_degs,
276// M2_arrayint wts);
277//
278// static int codimension(const RingElement *hf);
279// static int coefficient(const RingElement *hf, int deg);
280// // Should this return (as an argument) an mpz_ptr instead?
281// static int degree(const RingElement *hf);
282// static int reduce_hilb_fcn(const RingElement *hf, RingElement *&result_hf);
283// // returns the codimension, and places hf/(1-t)^codim into result_hf.
284//
285// static RingElement /* or null */ * multDegreeHilbert(const Ring *R,
286// gc_vector<exponents> &exps,
287// gc_vector<int> &comps,
288// const FreeModule *F);
289//
290// // The following routines all use the singly graded degree ring.
291// static RingElement /* or null */ * hilbert(const Ring *R,
292// gc_vector<exponents> &exps,
293// gc_vector<int> &comps,
294// gc_vector<int> &comp_degs,
295// M2_arrayint wts);
296//
297// static int codimension(const RingElement *hf);
298// static int coefficient(const RingElement *hf, int deg);
299// // Should this return (as an argument) an mpz_ptr instead?
300// static int degree(const RingElement *hf);
301// static int reduce_hilb_fcn(const RingElement *hf, RingElement *&result_hf);
302// // returns the codimension, and places hf/(1-t)^codim into result_hf.
303// };
304#endif
305
306#endif
307
308// Local Variables:
309// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
310// indent-tabs-mode: nil
311// End:
varpower::ConstExponents const_varpower
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
Engine-side monomial ideal: a decision tree of Nmi_nodes storing the (typically minimal) generators b...
Definition monideal.hpp:136
Abstract base for the engine's polynomial-ring hierarchy.
Definition polyring.hpp:96
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Definition relem.hpp:67
int nideal
Definition hilb.hpp:116
int calc(int nsteps)
Definition hilb.cpp:422
const Monoid * D
Definition hilb.hpp:97
void do_ideal(MonomialIdeal *I)
Definition hilb.cpp:524
ring_elem result_poincare
Definition hilb.hpp:103
int is_done() const
Definition hilb.cpp:602
ring_elem minus_one
Definition hilb.hpp:121
gc_vector< int > LOCAL_vp
Definition hilb.hpp:126
const Matrix * input_mat
Definition hilb.hpp:102
int nrecurse
Definition hilb.hpp:117
void stats() const
Definition hilb.cpp:618
const PolynomialRing * R
Definition hilb.hpp:95
int step()
Definition hilb.cpp:446
void next_monideal()
Definition hilb.cpp:314
const PolynomialRing * S
Definition hilb.hpp:94
monomial LOCAL_deg1
Definition hilb.hpp:125
hilb_comp(const PolynomialRing *R, const Matrix *M)
Definition hilb.cpp:343
void recurse(MonomialIdeal *&I, const_varpower pivot_vp)
Definition hilb.cpp:500
void reset()
Definition hilb.cpp:325
hilb_step * current
Definition hilb.hpp:110
int nsteps
Definition hilb.hpp:113
~hilb_comp()
Definition hilb.cpp:401
partition_table part_table
Definition hilb.hpp:127
int n_components
Definition hilb.hpp:106
int this_comp
Definition hilb.hpp:105
int depth
Definition hilb.hpp:114
int maxdepth
Definition hilb.hpp:115
RingElement * value()
Definition hilb.cpp:607
const Monoid * M
Definition hilb.hpp:96
static int coeff_of(const RingElement *h, int deg)
Definition hilb.cpp:704
static RingElement * hilbertNumerator(const Matrix *M)
Definition hilb.cpp:665
ring_elem one
Definition hilb.hpp:120
stash * mi_stash
Definition hilb.hpp:99
partition_table(int nvars, stash *mi_stash0)
Definition hilb.cpp:95
int * occurs
Definition hilb.hpp:61
void partition(MonomialIdeal *&I, gc_vector< MonomialIdeal * > &result)
Definition hilb.cpp:121
gc_vector< int > adad
Definition hilb.hpp:58
stash * mi_stash
Definition hilb.hpp:67
int representative(int x)
Definition hilb.cpp:29
int merge_in(int x, int y)
Definition hilb.cpp:43
gc_vector< int > aoccurs
Definition hilb.hpp:59
void reset(int nvars)
Definition hilb.cpp:111
Definition mem.hpp:78
#define Matrix
Definition factory.cpp:14
#define monomial
Definition gb-toric.cpp:11
EngineObject / MutableEngineObject — shared bases that supply the hash an M2 interpreter object expec...
VALGRIND_MAKE_MEM_DEFINED & result(result)
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
Definition newdelete.hpp:76
our_new_delete — per-class opt-in routing of new / delete through bdwgc.
volatile int x
ring_elem — the universal value type carried by every Ring* in the engine.
ring_elem h1
Definition hilb.hpp:82
int first_sum
Definition hilb.hpp:83
hilb_step * down
Definition hilb.hpp:79
hilb_step * up
Definition hilb.hpp:78
gc_vector< MonomialIdeal * > monids
Definition hilb.hpp:84
ring_elem h0
Definition hilb.hpp:81
int i
Definition hilb.hpp:80